1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_NETWORK_PROVIDER_IMPL_H_ 6 #define CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_NETWORK_PROVIDER_IMPL_H_ 7 8 #include "base/compiler_specific.h" 9 #include "base/memory/ref_counted.h" 10 #include "base/memory/scoped_ptr.h" 11 #include "base/supports_user_data.h" 12 #include "content/common/content_export.h" 13 14 namespace content { 15 16 class ServiceWorkerProviderContext; 17 18 // A unique provider_id is generated for each instance. 19 // Instantiated prior to the main resource load being started and remains 20 // allocated until after the last subresource load has occurred. 21 // This is used to track the lifetime of a Document to create 22 // and dispose the ServiceWorkerProviderHost in the browser process 23 // to match its lifetime. Each request coming from the Document is 24 // tagged with this id in willSendRequest. 25 // 26 // Basically, it's a scoped integer that sends an ipc upon construction 27 // and destruction. 28 class CONTENT_EXPORT ServiceWorkerNetworkProvider 29 : public base::SupportsUserData::Data { 30 public: 31 // Ownership is transferred to the DocumentState. 32 static void AttachToDocumentState( 33 base::SupportsUserData* document_state, 34 scoped_ptr<ServiceWorkerNetworkProvider> network_provider); 35 36 static ServiceWorkerNetworkProvider* FromDocumentState( 37 base::SupportsUserData* document_state); 38 39 ServiceWorkerNetworkProvider(); 40 virtual ~ServiceWorkerNetworkProvider(); 41 42 int provider_id() const { return provider_id_; } 43 ServiceWorkerProviderContext* context() { return context_.get(); } 44 45 // This method is called for a provider that's associated with a 46 // running service worker script. The version_id indicates which 47 // ServiceWorkerVersion should be used. 48 void SetServiceWorkerVersionId(int64 version_id); 49 50 private: 51 const int provider_id_; 52 scoped_refptr<ServiceWorkerProviderContext> context_; 53 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerNetworkProvider); 54 }; 55 56 } // namespace content 57 58 #endif // CONTENT_CHILD_SERVICE_WORKER_WEB_SERVICE_WORKER_PROVIDER_IMPL_H_ 59