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

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

Issue 2779763004: Create ServiceWorkerProviderHost before starting worker (Closed)
Patch Set: Rebased 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 // resource loads made directly by the service worker. 58 // resource loads made directly by the service worker.
59 // 59 //
60 // This instance is created when navigation is started and 60 // This instance is created when navigation is started and
61 // ServiceWorkerNetworkProvider is create on the renderer process. Mojo's 61 // ServiceWorkerNetworkProvider is create on the renderer process. Mojo's
62 // connection from ServiceWorkerNetworkProvider is established on the creation 62 // connection from ServiceWorkerNetworkProvider is established on the creation
63 // time, and the instance is destroyed on disconnection from the renderer side. 63 // time, and the instance is destroyed on disconnection from the renderer side.
64 // If PlzNavigate is turned on, this instance is pre-created on the browser 64 // If PlzNavigate is turned on, this instance is pre-created on the browser
65 // before ServiceWorkerNetworkProvider is created on the renderer because 65 // before ServiceWorkerNetworkProvider is created on the renderer because
66 // navigation is possible to be initiated on the browser side. In that case, 66 // navigation is possible to be initiated on the browser side. In that case,
67 // establishment of Mojo's connection will be deferred until 67 // establishment of Mojo's connection will be deferred until
68 // ServiceWorkerNetworkProvider is created on the renderer. 68 // ServiceWorkerNetworkProvider is created on the renderer.
falken 2017/06/01 08:12:34 This comment seems to need updating now.
shimazu 2017/06/06 04:16:56 Done.
69 class CONTENT_EXPORT ServiceWorkerProviderHost 69 class CONTENT_EXPORT ServiceWorkerProviderHost
70 : public NON_EXPORTED_BASE(ServiceWorkerRegistration::Listener), 70 : public NON_EXPORTED_BASE(ServiceWorkerRegistration::Listener),
71 public base::SupportsWeakPtr<ServiceWorkerProviderHost>, 71 public base::SupportsWeakPtr<ServiceWorkerProviderHost>,
72 public NON_EXPORTED_BASE(mojom::ServiceWorkerProviderHost) { 72 public NON_EXPORTED_BASE(mojom::ServiceWorkerProviderHost) {
73 public: 73 public:
74 using GetRegistrationForReadyCallback = 74 using GetRegistrationForReadyCallback =
75 base::Callback<void(ServiceWorkerRegistration* reigstration)>; 75 base::Callback<void(ServiceWorkerRegistration* reigstration)>;
76 76
77 using WebContentsGetter = base::Callback<WebContents*(void)>; 77 using WebContentsGetter = base::Callback<WebContents*(void)>;
78 78
79 // PlzNavigate 79 // PlzNavigate
80 // Used to pre-create a ServiceWorkerProviderHost for a navigation. The 80 // Used to pre-create a ServiceWorkerProviderHost for a navigation. The
81 // ServiceWorkerNetworkProvider will later be created in the renderer, should 81 // ServiceWorkerNetworkProvider will later be created in the renderer, should
82 // the navigation succeed. |is_parent_frame_is_secure| should be true for main 82 // the navigation succeed. |is_parent_frame_is_secure| should be true for main
83 // frames. Otherwise it is true iff all ancestor frames of this frame have a 83 // frames. Otherwise it is true iff all ancestor frames of this frame have a
84 // secure origin. |web_contents_getter| indicates the tab where the navigation 84 // secure origin. |web_contents_getter| indicates the tab where the navigation
85 // is occurring. 85 // is occurring.
86 static std::unique_ptr<ServiceWorkerProviderHost> PreCreateNavigationHost( 86 static std::unique_ptr<ServiceWorkerProviderHost> PreCreateNavigationHost(
87 base::WeakPtr<ServiceWorkerContextCore> context, 87 base::WeakPtr<ServiceWorkerContextCore> context,
88 bool are_ancestors_secure, 88 bool are_ancestors_secure,
89 const WebContentsGetter& web_contents_getter); 89 const WebContentsGetter& web_contents_getter);
90 90
91 // Creates ServiceWorkerProviderHost for the worker's context. Information
92 // about the ServiceWorkerProviderHost is passed with the StartWorker message.
93 static std::unique_ptr<ServiceWorkerProviderHost> PreCreateForWorkerContext(
94 ServiceWorkerVersion* hosted_version,
95 base::WeakPtr<ServiceWorkerContextCore> context);
96
91 // Used to create a ServiceWorkerProviderHost when the renderer-side provider 97 // Used to create a ServiceWorkerProviderHost when the renderer-side provider
92 // is created. This ProviderHost will be created for the process specified by 98 // is created. This ProviderHost will be created for the process specified by
93 // |process_id|. 99 // |process_id|.
94 static std::unique_ptr<ServiceWorkerProviderHost> Create( 100 static std::unique_ptr<ServiceWorkerProviderHost> Create(
95 int process_id, 101 int process_id,
96 ServiceWorkerProviderHostInfo info, 102 ServiceWorkerProviderHostInfo info,
97 base::WeakPtr<ServiceWorkerContextCore> context, 103 base::WeakPtr<ServiceWorkerContextCore> context,
98 ServiceWorkerDispatcherHost* dispatcher_host); 104 ServiceWorkerDispatcherHost* dispatcher_host);
99 105
100 ~ServiceWorkerProviderHost() override; 106 ~ServiceWorkerProviderHost() override;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 195
190 // Associates to |registration| to listen for its version change events and 196 // Associates to |registration| to listen for its version change events and
191 // sets the controller. If |notify_controllerchange| is true, instructs the 197 // sets the controller. If |notify_controllerchange| is true, instructs the
192 // renderer to dispatch a 'controllerchange' event. 198 // renderer to dispatch a 'controllerchange' event.
193 void AssociateRegistration(ServiceWorkerRegistration* registration, 199 void AssociateRegistration(ServiceWorkerRegistration* registration,
194 bool notify_controllerchange); 200 bool notify_controllerchange);
195 201
196 // Clears the associated registration and stop listening to it. 202 // Clears the associated registration and stop listening to it.
197 void DisassociateRegistration(); 203 void DisassociateRegistration();
198 204
199 void SetHostedVersion(ServiceWorkerVersion* version);
200
201 // Returns a handler for a request, the handler may return NULL if 205 // Returns a handler for a request, the handler may return NULL if
202 // the request doesn't require special handling. 206 // the request doesn't require special handling.
203 std::unique_ptr<ServiceWorkerRequestHandler> CreateRequestHandler( 207 std::unique_ptr<ServiceWorkerRequestHandler> CreateRequestHandler(
204 FetchRequestMode request_mode, 208 FetchRequestMode request_mode,
205 FetchCredentialsMode credentials_mode, 209 FetchCredentialsMode credentials_mode,
206 FetchRedirectMode redirect_mode, 210 FetchRedirectMode redirect_mode,
207 ResourceType resource_type, 211 ResourceType resource_type,
208 RequestContextType request_context_type, 212 RequestContextType request_context_type,
209 RequestContextFrameType frame_type, 213 RequestContextFrameType frame_type,
210 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, 214 base::WeakPtr<storage::BlobStorageContext> blob_storage_context,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 return dispatcher_host_; 263 return dispatcher_host_;
260 } 264 }
261 265
262 // PlzNavigate 266 // PlzNavigate
263 // Completes initialization of provider hosts used for navigation requests. 267 // Completes initialization of provider hosts used for navigation requests.
264 void CompleteNavigationInitialized( 268 void CompleteNavigationInitialized(
265 int process_id, 269 int process_id,
266 ServiceWorkerProviderHostInfo info, 270 ServiceWorkerProviderHostInfo info,
267 ServiceWorkerDispatcherHost* dispatcher_host); 271 ServiceWorkerDispatcherHost* dispatcher_host);
268 272
273 // Completes initialization of provider hosts used for the service worker's
274 // context.
falken 2017/06/01 08:12:34 It's pretty lame but this class historically calls
shimazu 2017/06/06 04:16:56 Done.
275 virtual void CompleteStartWorkerPreparation(
276 int process_id,
277 mojom::ServiceWorkerProviderClientInfoPtr* provider_client_info);
278
269 // Sends event messages to the renderer. Events for the worker are queued up 279 // Sends event messages to the renderer. Events for the worker are queued up
270 // until the worker thread id is known via SetReadyToSendMessagesToWorker(). 280 // until the worker thread id is known via SetReadyToSendMessagesToWorker().
271 void SendUpdateFoundMessage( 281 void SendUpdateFoundMessage(
272 int registration_handle_id); 282 int registration_handle_id);
273 void SendSetVersionAttributesMessage( 283 void SendSetVersionAttributesMessage(
274 int registration_handle_id, 284 int registration_handle_id,
275 ChangedVersionAttributesMask changed_mask, 285 ChangedVersionAttributesMask changed_mask,
276 ServiceWorkerVersion* installing_version, 286 ServiceWorkerVersion* installing_version,
277 ServiceWorkerVersion* waiting_version, 287 ServiceWorkerVersion* waiting_version,
278 ServiceWorkerVersion* active_version); 288 ServiceWorkerVersion* active_version);
(...skipping 15 matching lines...) Expand all
294 // exceptional condition like it could no longer be read from the script 304 // exceptional condition like it could no longer be read from the script
295 // cache. 305 // cache.
296 void NotifyControllerLost(); 306 void NotifyControllerLost();
297 307
298 // Binds the ServiceWorkerWorkerClient of a dedicated (or shared) worker to 308 // Binds the ServiceWorkerWorkerClient of a dedicated (or shared) worker to
299 // the parent frame's ServiceWorkerProviderHost. (This is used only when 309 // the parent frame's ServiceWorkerProviderHost. (This is used only when
300 // off-main-thread-fetch is enabled.) 310 // off-main-thread-fetch is enabled.)
301 void BindWorkerFetchContext( 311 void BindWorkerFetchContext(
302 mojom::ServiceWorkerWorkerClientAssociatedPtrInfo client_ptr_info); 312 mojom::ServiceWorkerWorkerClientAssociatedPtrInfo client_ptr_info);
303 313
314 protected:
315 ServiceWorkerProviderHost(int process_id,
316 ServiceWorkerProviderHostInfo info,
317 base::WeakPtr<ServiceWorkerContextCore> context,
318 ServiceWorkerDispatcherHost* dispatcher_host);
319
304 private: 320 private:
305 friend class ForeignFetchRequestHandlerTest; 321 friend class ForeignFetchRequestHandlerTest;
306 friend class LinkHeaderServiceWorkerTest; 322 friend class LinkHeaderServiceWorkerTest;
307 friend class ServiceWorkerProviderHostTest; 323 friend class ServiceWorkerProviderHostTest;
308 friend class ServiceWorkerWriteToCacheJobTest; 324 friend class ServiceWorkerWriteToCacheJobTest;
309 friend class ServiceWorkerContextRequestHandlerTest; 325 friend class ServiceWorkerContextRequestHandlerTest;
310 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWriteToCacheJobTest, Update_SameScript); 326 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWriteToCacheJobTest, Update_SameScript);
311 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWriteToCacheJobTest, 327 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWriteToCacheJobTest,
312 Update_SameSizeScript); 328 Update_SameSizeScript);
313 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWriteToCacheJobTest, 329 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWriteToCacheJobTest,
(...skipping 10 matching lines...) Expand all
324 340
325 struct OneShotGetReadyCallback { 341 struct OneShotGetReadyCallback {
326 GetRegistrationForReadyCallback callback; 342 GetRegistrationForReadyCallback callback;
327 bool called; 343 bool called;
328 344
329 explicit OneShotGetReadyCallback( 345 explicit OneShotGetReadyCallback(
330 const GetRegistrationForReadyCallback& callback); 346 const GetRegistrationForReadyCallback& callback);
331 ~OneShotGetReadyCallback(); 347 ~OneShotGetReadyCallback();
332 }; 348 };
333 349
334 ServiceWorkerProviderHost(int process_id,
335 ServiceWorkerProviderHostInfo info,
336 base::WeakPtr<ServiceWorkerContextCore> context,
337 ServiceWorkerDispatcherHost* dispatcher_host);
338
339 // ServiceWorkerRegistration::Listener overrides. 350 // ServiceWorkerRegistration::Listener overrides.
340 void OnVersionAttributesChanged( 351 void OnVersionAttributesChanged(
341 ServiceWorkerRegistration* registration, 352 ServiceWorkerRegistration* registration,
342 ChangedVersionAttributesMask changed_mask, 353 ChangedVersionAttributesMask changed_mask,
343 const ServiceWorkerRegistrationInfo& info) override; 354 const ServiceWorkerRegistrationInfo& info) override;
344 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override; 355 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override;
345 void OnRegistrationFinishedUninstalling( 356 void OnRegistrationFinishedUninstalling(
346 ServiceWorkerRegistration* registration) override; 357 ServiceWorkerRegistration* registration) override;
347 void OnSkippedWaiting(ServiceWorkerRegistration* registration) override; 358 void OnSkippedWaiting(ServiceWorkerRegistration* registration) override;
348 359
(...skipping 13 matching lines...) Expand all
362 373
363 // Increase/decrease this host's process reference for |pattern|. 374 // Increase/decrease this host's process reference for |pattern|.
364 void IncreaseProcessReference(const GURL& pattern); 375 void IncreaseProcessReference(const GURL& pattern);
365 void DecreaseProcessReference(const GURL& pattern); 376 void DecreaseProcessReference(const GURL& pattern);
366 377
367 void ReturnRegistrationForReadyIfNeeded(); 378 void ReturnRegistrationForReadyIfNeeded();
368 379
369 bool IsReadyToSendMessages() const; 380 bool IsReadyToSendMessages() const;
370 void Send(IPC::Message* message) const; 381 void Send(IPC::Message* message) const;
371 382
383 // Sets the version hosted by this provider. This method should be used only
384 // for providers for service worker contexts.
falken 2017/06/01 08:12:34 ditto
shimazu 2017/06/06 04:16:56 Done.
385 void SetHostedVersion(ServiceWorkerVersion* version);
386
372 // Finalizes cross-site transfers and navigation-initalized hosts. 387 // Finalizes cross-site transfers and navigation-initalized hosts.
373 void FinalizeInitialization(int process_id, 388 void FinalizeInitialization(int process_id,
374 ServiceWorkerDispatcherHost* dispatcher_host); 389 ServiceWorkerDispatcherHost* dispatcher_host);
375 390
376 // Clears the information of the ServiceWorkerWorkerClient of dedicated (or 391 // Clears the information of the ServiceWorkerWorkerClient of dedicated (or
377 // shared) worker, when the connection to the worker is disconnected. 392 // shared) worker, when the connection to the worker is disconnected.
378 void UnregisterWorkerFetchContext(mojom::ServiceWorkerWorkerClient*); 393 void UnregisterWorkerFetchContext(mojom::ServiceWorkerWorkerClient*);
379 394
380 std::string client_uuid_; 395 std::string client_uuid_;
381 int render_process_id_; 396 int render_process_id_;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 std::unordered_map<mojom::ServiceWorkerWorkerClient*, 445 std::unordered_map<mojom::ServiceWorkerWorkerClient*,
431 mojom::ServiceWorkerWorkerClientAssociatedPtr> 446 mojom::ServiceWorkerWorkerClientAssociatedPtr>
432 worker_clients_; 447 worker_clients_;
433 448
434 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); 449 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost);
435 }; 450 };
436 451
437 } // namespace content 452 } // namespace content
438 453
439 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ 454 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698