Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(426)

Side by Side Diff: content/browser/service_worker/service_worker_provider_host.h

Issue 2779763004: Create ServiceWorkerProviderHost before starting worker (Closed)
Patch Set: Addressed comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 instance is possible to be created on the browser
62 // ServiceWorkerNetworkProvider is created on the renderer process, which 62 // and the renderer. 1) When it's for a document or worker (i.e., a service
falken 2017/06/14 08:10:35 "created on the browser and the renderer" sounds l
shimazu 2017/06/16 04:18:44 Yeah, that looks great! Updated the comment.
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
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 ServiceWorkerProviderHost for the worker's context. Information
101 // about the ServiceWorkerProviderHost is passed with the StartWorker message.
falken 2017/06/14 08:10:35 The use of "context" here is confusing since the |
kinuko 2017/06/14 08:37:40 Or PreCreateForController? (The version is actuall
shimazu 2017/06/16 04:18:44 Done.
102 static std::unique_ptr<ServiceWorkerProviderHost> PreCreateForWorkerContext(
103 ServiceWorkerVersion* hosted_version,
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
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
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.
falken 2017/06/14 08:10:35 When is this called?
falken 2017/06/14 08:30:18 (I mean to add something to the documentation like
shimazu 2017/06/16 04:18:43 Done.
284 virtual void CompleteStartWorkerPreparation(
285 int process_id,
286 mojom::ServiceWorkerProviderClientInfoPtr* provider_client_info);
falken 2017/06/14 08:10:35 Does this mutate |provider_client_info|? If so, |o
shimazu 2017/06/16 04:18:44 Done.
287
273 // Sends event messages to the renderer. Events for the worker are queued up 288 // Sends event messages to the renderer. Events for the worker are queued up
274 // until the worker thread id is known via SetReadyToSendMessagesToWorker(). 289 // until the worker thread id is known via SetReadyToSendMessagesToWorker().
275 void SendUpdateFoundMessage( 290 void SendUpdateFoundMessage(
276 int registration_handle_id); 291 int registration_handle_id);
277 void SendSetVersionAttributesMessage( 292 void SendSetVersionAttributesMessage(
278 int registration_handle_id, 293 int registration_handle_id,
279 ChangedVersionAttributesMask changed_mask, 294 ChangedVersionAttributesMask changed_mask,
280 ServiceWorkerVersion* installing_version, 295 ServiceWorkerVersion* installing_version,
281 ServiceWorkerVersion* waiting_version, 296 ServiceWorkerVersion* waiting_version,
282 ServiceWorkerVersion* active_version); 297 ServiceWorkerVersion* active_version);
(...skipping 15 matching lines...) Expand all
298 // exceptional condition like it could no longer be read from the script 313 // exceptional condition like it could no longer be read from the script
299 // cache. 314 // cache.
300 void NotifyControllerLost(); 315 void NotifyControllerLost();
301 316
302 // Binds the ServiceWorkerWorkerClient of a dedicated (or shared) worker to 317 // Binds the ServiceWorkerWorkerClient of a dedicated (or shared) worker to
303 // the parent frame's ServiceWorkerProviderHost. (This is used only when 318 // the parent frame's ServiceWorkerProviderHost. (This is used only when
304 // off-main-thread-fetch is enabled.) 319 // off-main-thread-fetch is enabled.)
305 void BindWorkerFetchContext( 320 void BindWorkerFetchContext(
306 mojom::ServiceWorkerWorkerClientAssociatedPtrInfo client_ptr_info); 321 mojom::ServiceWorkerWorkerClientAssociatedPtrInfo client_ptr_info);
307 322
323 protected:
324 ServiceWorkerProviderHost(int process_id,
325 ServiceWorkerProviderHostInfo info,
326 base::WeakPtr<ServiceWorkerContextCore> context,
327 ServiceWorkerDispatcherHost* dispatcher_host);
328
308 private: 329 private:
309 friend class ForeignFetchRequestHandlerTest; 330 friend class ForeignFetchRequestHandlerTest;
310 friend class LinkHeaderServiceWorkerTest; 331 friend class LinkHeaderServiceWorkerTest;
311 friend class ServiceWorkerProviderHostTest; 332 friend class ServiceWorkerProviderHostTest;
312 friend class ServiceWorkerWriteToCacheJobTest; 333 friend class ServiceWorkerWriteToCacheJobTest;
313 friend class ServiceWorkerContextRequestHandlerTest; 334 friend class ServiceWorkerContextRequestHandlerTest;
314 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWriteToCacheJobTest, Update_SameScript); 335 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWriteToCacheJobTest, Update_SameScript);
315 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWriteToCacheJobTest, 336 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWriteToCacheJobTest,
316 Update_SameSizeScript); 337 Update_SameSizeScript);
317 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWriteToCacheJobTest, 338 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWriteToCacheJobTest,
(...skipping 10 matching lines...) Expand all
328 349
329 struct OneShotGetReadyCallback { 350 struct OneShotGetReadyCallback {
330 GetRegistrationForReadyCallback callback; 351 GetRegistrationForReadyCallback callback;
331 bool called; 352 bool called;
332 353
333 explicit OneShotGetReadyCallback( 354 explicit OneShotGetReadyCallback(
334 const GetRegistrationForReadyCallback& callback); 355 const GetRegistrationForReadyCallback& callback);
335 ~OneShotGetReadyCallback(); 356 ~OneShotGetReadyCallback();
336 }; 357 };
337 358
338 ServiceWorkerProviderHost(int process_id,
339 ServiceWorkerProviderHostInfo info,
340 base::WeakPtr<ServiceWorkerContextCore> context,
341 ServiceWorkerDispatcherHost* dispatcher_host);
342
343 // ServiceWorkerRegistration::Listener overrides. 359 // ServiceWorkerRegistration::Listener overrides.
344 void OnVersionAttributesChanged( 360 void OnVersionAttributesChanged(
345 ServiceWorkerRegistration* registration, 361 ServiceWorkerRegistration* registration,
346 ChangedVersionAttributesMask changed_mask, 362 ChangedVersionAttributesMask changed_mask,
347 const ServiceWorkerRegistrationInfo& info) override; 363 const ServiceWorkerRegistrationInfo& info) override;
348 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override; 364 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override;
349 void OnRegistrationFinishedUninstalling( 365 void OnRegistrationFinishedUninstalling(
350 ServiceWorkerRegistration* registration) override; 366 ServiceWorkerRegistration* registration) override;
351 void OnSkippedWaiting(ServiceWorkerRegistration* registration) override; 367 void OnSkippedWaiting(ServiceWorkerRegistration* registration) override;
352 368
(...skipping 13 matching lines...) Expand all
366 382
367 // Increase/decrease this host's process reference for |pattern|. 383 // Increase/decrease this host's process reference for |pattern|.
368 void IncreaseProcessReference(const GURL& pattern); 384 void IncreaseProcessReference(const GURL& pattern);
369 void DecreaseProcessReference(const GURL& pattern); 385 void DecreaseProcessReference(const GURL& pattern);
370 386
371 void ReturnRegistrationForReadyIfNeeded(); 387 void ReturnRegistrationForReadyIfNeeded();
372 388
373 bool IsReadyToSendMessages() const; 389 bool IsReadyToSendMessages() const;
374 void Send(IPC::Message* message) const; 390 void Send(IPC::Message* message) const;
375 391
392 // Sets the version hosted by this provider. This method should be used only
393 // for provider hosts for controllers.
394 void SetHostedVersion(ServiceWorkerVersion* version);
395
376 // Notifies the information about the controller and associated registration 396 // Notifies the information about the controller and associated registration
377 // to the provider on the renderer. This is for cross site transfer and 397 // to the provider on the renderer. This is for cross site transfer and
378 // browser side navigation which need to decide which process will handle the 398 // browser side navigation which need to decide which process will handle the
379 // request later. 399 // request later.
380 void NotifyControllerToAssociatedProvider(); 400 void NotifyControllerToAssociatedProvider();
381 401
382 // Clears the information of the ServiceWorkerWorkerClient of dedicated (or 402 // Clears the information of the ServiceWorkerWorkerClient of dedicated (or
383 // shared) worker, when the connection to the worker is disconnected. 403 // shared) worker, when the connection to the worker is disconnected.
384 void UnregisterWorkerFetchContext(mojom::ServiceWorkerWorkerClient*); 404 void UnregisterWorkerFetchContext(mojom::ServiceWorkerWorkerClient*);
385 405
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698