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