OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 // running service worker. | 51 // running service worker. |
52 // | 52 // |
53 // For client providers, there is a provider per document or a worker and the | 53 // For client providers, there is a provider per document or a worker and the |
54 // lifetime of this object is tied to the lifetime of its document or the worker | 54 // lifetime of this object is tied to the lifetime of its document or the worker |
55 // in the renderer process. This class holds service worker state that is scoped | 55 // in the renderer process. This class holds service worker state that is scoped |
56 // to an individual document or a worker. | 56 // to an individual document or a worker. |
57 // | 57 // |
58 // For providers hosting a running service worker, this class will observe | 58 // For providers hosting a running service worker, this class will observe |
59 // resource loads made directly by the service worker. | 59 // resource loads made directly by the service worker. |
60 // | 60 // |
61 // A ServiceWorkerProviderHost instance is created when a | 61 // A ServiceWorkerProviderHost is created in the following situations: |
62 // ServiceWorkerNetworkProvider is created on the renderer process, which | 62 // 1) When it's for a document or worker (i.e., a service |
63 // happens 1) when a document or worker (i.e., a service worker client) is | 63 // worker client), the provider host is created when |
64 // created, or 2) during service worker startup. Mojo's connection from | 64 // ServiceWorkerNetworkProvider is created on the renderer process. Mojo's |
65 // ServiceWorkerNetworkProvider is established on the creation time, and the | 65 // connection from ServiceWorkerNetworkProvider is established on the creation |
66 // instance is destroyed on disconnection from the renderer side. | 66 // time. |
67 // If PlzNavigate is turned on, an instance is pre-created on the browser | 67 // 2) When it's for a service worker context, the provider host is created on |
falken
2017/06/16 15:44:46
"for a running service worker" for consistency wit
shimazu
2017/06/19 03:53:30
Done.
| |
68 // the browser process before launching the service worker's thread. Mojo's | |
69 // connection to the renderer is established with the StartWorker message. | |
70 // 3) When PlzNavigate is turned on, an instance is pre-created on the browser | |
68 // before ServiceWorkerNetworkProvider is created on the renderer because | 71 // before ServiceWorkerNetworkProvider is created on the renderer because |
69 // navigation is initiated on the browser side. In that case, establishment of | 72 // navigation is initiated on the browser side. In that case, establishment of |
70 // Mojo's connection will be deferred until ServiceWorkerNetworkProvider is | 73 // Mojo's connection will be deferred until ServiceWorkerNetworkProvider is |
71 // created on the renderer. | 74 // created on the renderer. |
75 // Destruction of the ServiceWorkerProviderHost instance happens on | |
76 // disconnection of the Mojo's pipe from the renderer side regardless of what | |
77 // the provider is for. | |
72 class CONTENT_EXPORT ServiceWorkerProviderHost | 78 class CONTENT_EXPORT ServiceWorkerProviderHost |
73 : public NON_EXPORTED_BASE(ServiceWorkerRegistration::Listener), | 79 : public NON_EXPORTED_BASE(ServiceWorkerRegistration::Listener), |
74 public base::SupportsWeakPtr<ServiceWorkerProviderHost>, | 80 public base::SupportsWeakPtr<ServiceWorkerProviderHost>, |
75 public NON_EXPORTED_BASE(mojom::ServiceWorkerProviderHost) { | 81 public NON_EXPORTED_BASE(mojom::ServiceWorkerProviderHost) { |
76 public: | 82 public: |
77 using GetRegistrationForReadyCallback = | 83 using GetRegistrationForReadyCallback = |
78 base::Callback<void(ServiceWorkerRegistration* reigstration)>; | 84 base::Callback<void(ServiceWorkerRegistration* reigstration)>; |
79 | 85 |
80 using WebContentsGetter = base::Callback<WebContents*(void)>; | 86 using WebContentsGetter = base::Callback<WebContents*(void)>; |
81 | 87 |
82 // PlzNavigate | 88 // PlzNavigate |
83 // Used to pre-create a ServiceWorkerProviderHost for a navigation. The | 89 // Used to pre-create a ServiceWorkerProviderHost for a navigation. The |
84 // ServiceWorkerNetworkProvider will later be created in the renderer, should | 90 // ServiceWorkerNetworkProvider will later be created in the renderer, should |
85 // the navigation succeed. |is_parent_frame_is_secure| should be true for main | 91 // the navigation succeed. |is_parent_frame_is_secure| should be true for main |
86 // frames. Otherwise it is true iff all ancestor frames of this frame have a | 92 // frames. Otherwise it is true iff all ancestor frames of this frame have a |
87 // secure origin. |web_contents_getter| indicates the tab where the navigation | 93 // secure origin. |web_contents_getter| indicates the tab where the navigation |
88 // is occurring. | 94 // is occurring. |
89 static std::unique_ptr<ServiceWorkerProviderHost> PreCreateNavigationHost( | 95 static std::unique_ptr<ServiceWorkerProviderHost> PreCreateNavigationHost( |
90 base::WeakPtr<ServiceWorkerContextCore> context, | 96 base::WeakPtr<ServiceWorkerContextCore> context, |
91 bool are_ancestors_secure, | 97 bool are_ancestors_secure, |
92 const WebContentsGetter& web_contents_getter); | 98 const WebContentsGetter& web_contents_getter); |
93 | 99 |
100 // Creates a ServiceWorkerProviderHost for hosting a running service worker. | |
101 // Information about the ServiceWorkerProviderHost is passed with the | |
102 // StartWorker message. | |
kinuko
2017/06/16 09:33:50
It feels a bit unclear what the second sentence is
falken
2017/06/16 15:44:46
Sounds good.
kinuko
2017/06/19 03:27:56
(Also feel free to use some other term than 'contr
shimazu
2017/06/19 03:53:30
Thanks, done.
| |
103 static std::unique_ptr<ServiceWorkerProviderHost> PreCreateForController( | |
104 base::WeakPtr<ServiceWorkerContextCore> context); | |
105 | |
94 // Used to create a ServiceWorkerProviderHost when the renderer-side provider | 106 // Used to create a ServiceWorkerProviderHost when the renderer-side provider |
95 // is created. This ProviderHost will be created for the process specified by | 107 // is created. This ProviderHost will be created for the process specified by |
96 // |process_id|. | 108 // |process_id|. |
97 static std::unique_ptr<ServiceWorkerProviderHost> Create( | 109 static std::unique_ptr<ServiceWorkerProviderHost> Create( |
98 int process_id, | 110 int process_id, |
99 ServiceWorkerProviderHostInfo info, | 111 ServiceWorkerProviderHostInfo info, |
100 base::WeakPtr<ServiceWorkerContextCore> context, | 112 base::WeakPtr<ServiceWorkerContextCore> context, |
101 ServiceWorkerDispatcherHost* dispatcher_host); | 113 ServiceWorkerDispatcherHost* dispatcher_host); |
102 | 114 |
103 ~ServiceWorkerProviderHost() override; | 115 ~ServiceWorkerProviderHost() override; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 | 205 |
194 // Associates to |registration| to listen for its version change events and | 206 // Associates to |registration| to listen for its version change events and |
195 // sets the controller. If |notify_controllerchange| is true, instructs the | 207 // sets the controller. If |notify_controllerchange| is true, instructs the |
196 // renderer to dispatch a 'controllerchange' event. | 208 // renderer to dispatch a 'controllerchange' event. |
197 void AssociateRegistration(ServiceWorkerRegistration* registration, | 209 void AssociateRegistration(ServiceWorkerRegistration* registration, |
198 bool notify_controllerchange); | 210 bool notify_controllerchange); |
199 | 211 |
200 // Clears the associated registration and stop listening to it. | 212 // Clears the associated registration and stop listening to it. |
201 void DisassociateRegistration(); | 213 void DisassociateRegistration(); |
202 | 214 |
203 void SetHostedVersion(ServiceWorkerVersion* version); | |
204 | |
205 // Returns a handler for a request, the handler may return NULL if | 215 // Returns a handler for a request, the handler may return NULL if |
206 // the request doesn't require special handling. | 216 // the request doesn't require special handling. |
207 std::unique_ptr<ServiceWorkerRequestHandler> CreateRequestHandler( | 217 std::unique_ptr<ServiceWorkerRequestHandler> CreateRequestHandler( |
208 FetchRequestMode request_mode, | 218 FetchRequestMode request_mode, |
209 FetchCredentialsMode credentials_mode, | 219 FetchCredentialsMode credentials_mode, |
210 FetchRedirectMode redirect_mode, | 220 FetchRedirectMode redirect_mode, |
211 ResourceType resource_type, | 221 ResourceType resource_type, |
212 RequestContextType request_context_type, | 222 RequestContextType request_context_type, |
213 RequestContextFrameType frame_type, | 223 RequestContextFrameType frame_type, |
214 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, | 224 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
263 return dispatcher_host_; | 273 return dispatcher_host_; |
264 } | 274 } |
265 | 275 |
266 // PlzNavigate | 276 // PlzNavigate |
267 // Completes initialization of provider hosts used for navigation requests. | 277 // Completes initialization of provider hosts used for navigation requests. |
268 void CompleteNavigationInitialized( | 278 void CompleteNavigationInitialized( |
269 int process_id, | 279 int process_id, |
270 ServiceWorkerProviderHostInfo info, | 280 ServiceWorkerProviderHostInfo info, |
271 ServiceWorkerDispatcherHost* dispatcher_host); | 281 ServiceWorkerDispatcherHost* dispatcher_host); |
272 | 282 |
283 // Completes initialization of provider hosts for controllers and returns the | |
284 // value to create ServiceWorkerNetworkProvider on the renderer which will be | |
285 // connected to this instance. | |
286 // This instance will keep the reference to |hosted_version|, so please be | |
287 // careful not to create a reference cycle. | |
288 mojom::ServiceWorkerProviderClientInfoPtr CompleteStartWorkerPreparation( | |
289 int process_id, | |
290 ServiceWorkerVersion* hosted_version); | |
dcheng
2017/06/20 21:09:47
Earlier comment about passing this as a scoped_ref
shimazu
2017/06/21 03:11:26
Done.
| |
291 | |
273 // Sends event messages to the renderer. Events for the worker are queued up | 292 // Sends event messages to the renderer. Events for the worker are queued up |
274 // until the worker thread id is known via SetReadyToSendMessagesToWorker(). | 293 // until the worker thread id is known via SetReadyToSendMessagesToWorker(). |
275 void SendUpdateFoundMessage( | 294 void SendUpdateFoundMessage( |
276 int registration_handle_id); | 295 int registration_handle_id); |
277 void SendSetVersionAttributesMessage( | 296 void SendSetVersionAttributesMessage( |
278 int registration_handle_id, | 297 int registration_handle_id, |
279 ChangedVersionAttributesMask changed_mask, | 298 ChangedVersionAttributesMask changed_mask, |
280 ServiceWorkerVersion* installing_version, | 299 ServiceWorkerVersion* installing_version, |
281 ServiceWorkerVersion* waiting_version, | 300 ServiceWorkerVersion* waiting_version, |
282 ServiceWorkerVersion* active_version); | 301 ServiceWorkerVersion* active_version); |
(...skipping 15 matching lines...) Expand all Loading... | |
298 // exceptional condition like it could no longer be read from the script | 317 // exceptional condition like it could no longer be read from the script |
299 // cache. | 318 // cache. |
300 void NotifyControllerLost(); | 319 void NotifyControllerLost(); |
301 | 320 |
302 // Binds the ServiceWorkerWorkerClient of a dedicated (or shared) worker to | 321 // Binds the ServiceWorkerWorkerClient of a dedicated (or shared) worker to |
303 // the parent frame's ServiceWorkerProviderHost. (This is used only when | 322 // the parent frame's ServiceWorkerProviderHost. (This is used only when |
304 // off-main-thread-fetch is enabled.) | 323 // off-main-thread-fetch is enabled.) |
305 void BindWorkerFetchContext( | 324 void BindWorkerFetchContext( |
306 mojom::ServiceWorkerWorkerClientAssociatedPtrInfo client_ptr_info); | 325 mojom::ServiceWorkerWorkerClientAssociatedPtrInfo client_ptr_info); |
307 | 326 |
327 protected: | |
328 ServiceWorkerProviderHost(int process_id, | |
329 ServiceWorkerProviderHostInfo info, | |
330 base::WeakPtr<ServiceWorkerContextCore> context, | |
331 ServiceWorkerDispatcherHost* dispatcher_host); | |
332 | |
308 private: | 333 private: |
309 friend class ForeignFetchRequestHandlerTest; | 334 friend class ForeignFetchRequestHandlerTest; |
310 friend class LinkHeaderServiceWorkerTest; | 335 friend class LinkHeaderServiceWorkerTest; |
311 friend class ServiceWorkerProviderHostTest; | 336 friend class ServiceWorkerProviderHostTest; |
312 friend class ServiceWorkerWriteToCacheJobTest; | 337 friend class ServiceWorkerWriteToCacheJobTest; |
313 friend class ServiceWorkerContextRequestHandlerTest; | 338 friend class ServiceWorkerContextRequestHandlerTest; |
314 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWriteToCacheJobTest, Update_SameScript); | 339 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWriteToCacheJobTest, Update_SameScript); |
315 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWriteToCacheJobTest, | 340 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWriteToCacheJobTest, |
316 Update_SameSizeScript); | 341 Update_SameSizeScript); |
317 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWriteToCacheJobTest, | 342 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWriteToCacheJobTest, |
(...skipping 10 matching lines...) Expand all Loading... | |
328 | 353 |
329 struct OneShotGetReadyCallback { | 354 struct OneShotGetReadyCallback { |
330 GetRegistrationForReadyCallback callback; | 355 GetRegistrationForReadyCallback callback; |
331 bool called; | 356 bool called; |
332 | 357 |
333 explicit OneShotGetReadyCallback( | 358 explicit OneShotGetReadyCallback( |
334 const GetRegistrationForReadyCallback& callback); | 359 const GetRegistrationForReadyCallback& callback); |
335 ~OneShotGetReadyCallback(); | 360 ~OneShotGetReadyCallback(); |
336 }; | 361 }; |
337 | 362 |
338 ServiceWorkerProviderHost(int process_id, | |
339 ServiceWorkerProviderHostInfo info, | |
340 base::WeakPtr<ServiceWorkerContextCore> context, | |
341 ServiceWorkerDispatcherHost* dispatcher_host); | |
342 | |
343 // ServiceWorkerRegistration::Listener overrides. | 363 // ServiceWorkerRegistration::Listener overrides. |
344 void OnVersionAttributesChanged( | 364 void OnVersionAttributesChanged( |
345 ServiceWorkerRegistration* registration, | 365 ServiceWorkerRegistration* registration, |
346 ChangedVersionAttributesMask changed_mask, | 366 ChangedVersionAttributesMask changed_mask, |
347 const ServiceWorkerRegistrationInfo& info) override; | 367 const ServiceWorkerRegistrationInfo& info) override; |
348 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override; | 368 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override; |
349 void OnRegistrationFinishedUninstalling( | 369 void OnRegistrationFinishedUninstalling( |
350 ServiceWorkerRegistration* registration) override; | 370 ServiceWorkerRegistration* registration) override; |
351 void OnSkippedWaiting(ServiceWorkerRegistration* registration) override; | 371 void OnSkippedWaiting(ServiceWorkerRegistration* registration) override; |
352 | 372 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
437 std::unordered_map<mojom::ServiceWorkerWorkerClient*, | 457 std::unordered_map<mojom::ServiceWorkerWorkerClient*, |
438 mojom::ServiceWorkerWorkerClientAssociatedPtr> | 458 mojom::ServiceWorkerWorkerClientAssociatedPtr> |
439 worker_clients_; | 459 worker_clients_; |
440 | 460 |
441 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); | 461 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); |
442 }; | 462 }; |
443 | 463 |
444 } // namespace content | 464 } // namespace content |
445 | 465 |
446 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ | 466 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
OLD | NEW |