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

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

Issue 2653493009: Add two interfaces for ServiceWorkerProviderContext/ProviderHost (Closed)
Patch Set: Addressed comments from falken Created 3 years, 7 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
11 #include <map> 11 #include <map>
12 #include <memory> 12 #include <memory>
13 #include <set> 13 #include <set>
14 #include <string> 14 #include <string>
15 #include <unordered_map> 15 #include <unordered_map>
16 #include <vector> 16 #include <vector>
17 17
18 #include "base/gtest_prod_util.h" 18 #include "base/gtest_prod_util.h"
19 #include "base/macros.h" 19 #include "base/macros.h"
20 #include "base/memory/ref_counted.h" 20 #include "base/memory/ref_counted.h"
21 #include "base/memory/weak_ptr.h" 21 #include "base/memory/weak_ptr.h"
22 #include "content/browser/service_worker/service_worker_registration.h" 22 #include "content/browser/service_worker/service_worker_registration.h"
23 #include "content/common/content_export.h" 23 #include "content/common/content_export.h"
24 #include "content/common/service_worker/service_worker_provider_host_info.h" 24 #include "content/common/service_worker/service_worker_provider_host_info.h"
25 #include "content/common/service_worker/service_worker_provider_interfaces.mojom .h"
25 #include "content/common/service_worker/service_worker_types.h" 26 #include "content/common/service_worker/service_worker_types.h"
26 #include "content/common/worker_url_loader_factory_provider.mojom.h" 27 #include "content/common/worker_url_loader_factory_provider.mojom.h"
27 #include "content/public/common/request_context_frame_type.h" 28 #include "content/public/common/request_context_frame_type.h"
28 #include "content/public/common/request_context_type.h" 29 #include "content/public/common/request_context_type.h"
29 #include "content/public/common/resource_type.h" 30 #include "content/public/common/resource_type.h"
31 #include "mojo/public/cpp/bindings/associated_binding.h"
30 32
31 namespace storage { 33 namespace storage {
32 class BlobStorageContext; 34 class BlobStorageContext;
33 } 35 }
34 36
35 namespace content { 37 namespace content {
36 38
37 class MessagePort; 39 class MessagePort;
38 class ResourceRequestBodyImpl; 40 class ResourceRequestBodyImpl;
39 class ServiceWorkerContextCore; 41 class ServiceWorkerContextCore;
40 class ServiceWorkerDispatcherHost; 42 class ServiceWorkerDispatcherHost;
41 class ServiceWorkerRequestHandler; 43 class ServiceWorkerRequestHandler;
42 class ServiceWorkerVersion; 44 class ServiceWorkerVersion;
43 class WebContents; 45 class WebContents;
44 46
45 // This class is the browser-process representation of a service worker 47 // This class is the browser-process representation of a service worker
46 // provider. There are two general types of providers: 1) those for a client 48 // provider. There are two general types of providers: 1) those for a client
47 // (windows, dedicated workers, or shared workers), and 2) those for hosting a 49 // (windows, dedicated workers, or shared workers), and 2) those for hosting a
48 // running service worker. 50 // running service worker.
49 // 51 //
50 // For client providers, there is a provider per document or a worker and the 52 // For client providers, there is a provider per document or a worker and the
51 // lifetime of this object is tied to the lifetime of its document or the worker 53 // lifetime of this object is tied to the lifetime of its document or the worker
52 // in the renderer process. This class holds service worker state that is scoped 54 // in the renderer process. This class holds service worker state that is scoped
53 // to an individual document or a worker. 55 // to an individual document or a worker.
54 // 56 //
55 // For providers hosting a running service worker, this class will observe 57 // For providers hosting a running service worker, this class will observe
56 // resource loads made directly by the service worker. 58 // resource loads made directly by the service worker.
57 class CONTENT_EXPORT ServiceWorkerProviderHost 59 class CONTENT_EXPORT ServiceWorkerProviderHost
58 : public NON_EXPORTED_BASE(ServiceWorkerRegistration::Listener), 60 : public NON_EXPORTED_BASE(ServiceWorkerRegistration::Listener),
59 public base::SupportsWeakPtr<ServiceWorkerProviderHost> { 61 public base::SupportsWeakPtr<ServiceWorkerProviderHost>,
62 public NON_EXPORTED_BASE(mojom::ServiceWorkerProviderHost) {
60 public: 63 public:
61 using GetRegistrationForReadyCallback = 64 using GetRegistrationForReadyCallback =
62 base::Callback<void(ServiceWorkerRegistration* reigstration)>; 65 base::Callback<void(ServiceWorkerRegistration* reigstration)>;
63 66
64 using WebContentsGetter = base::Callback<WebContents*(void)>; 67 using WebContentsGetter = base::Callback<WebContents*(void)>;
65 68
66 // PlzNavigate 69 // PlzNavigate
67 // Used to pre-create a ServiceWorkerProviderHost for a navigation. The 70 // Used to pre-create a ServiceWorkerProviderHost for a navigation. The
68 // ServiceWorkerNetworkProvider will later be created in the renderer, should 71 // ServiceWorkerNetworkProvider will later be created in the renderer, should
69 // the navigation succeed. |is_parent_frame_is_secure| should be true for main 72 // the navigation succeed. |is_parent_frame_is_secure| should be true for main
70 // frames. Otherwise it is true iff all ancestor frames of this frame have a 73 // frames. Otherwise it is true iff all ancestor frames of this frame have a
71 // secure origin. |web_contents_getter| indicates the tab where the navigation 74 // secure origin. |web_contents_getter| indicates the tab where the navigation
72 // is occurring. 75 // is occurring.
73 static std::unique_ptr<ServiceWorkerProviderHost> PreCreateNavigationHost( 76 static std::unique_ptr<ServiceWorkerProviderHost> PreCreateNavigationHost(
74 base::WeakPtr<ServiceWorkerContextCore> context, 77 base::WeakPtr<ServiceWorkerContextCore> context,
75 bool are_ancestors_secure, 78 bool are_ancestors_secure,
76 const WebContentsGetter& web_contents_getter); 79 const WebContentsGetter& web_contents_getter);
77 80
78 // Used to create a ServiceWorkerProviderHost when the renderer-side provider 81 // Used to create a ServiceWorkerProviderHost when the renderer-side provider
79 // is created. This ProviderHost will be created for the process specified by 82 // is created. This ProviderHost will be created for the process specified by
80 // |process_id|. 83 // |process_id|.
81 static std::unique_ptr<ServiceWorkerProviderHost> Create( 84 static std::unique_ptr<ServiceWorkerProviderHost> Create(
82 int process_id, 85 int process_id,
83 ServiceWorkerProviderHostInfo info, 86 ServiceWorkerProviderHostInfo info,
84 base::WeakPtr<ServiceWorkerContextCore> context, 87 base::WeakPtr<ServiceWorkerContextCore> context,
85 ServiceWorkerDispatcherHost* dispatcher_host); 88 ServiceWorkerDispatcherHost* dispatcher_host);
86 89
87 virtual ~ServiceWorkerProviderHost(); 90 ~ServiceWorkerProviderHost() override;
88 91
89 const std::string& client_uuid() const { return client_uuid_; } 92 const std::string& client_uuid() const { return client_uuid_; }
90 int process_id() const { return render_process_id_; } 93 int process_id() const { return render_process_id_; }
91 int provider_id() const { return info_.provider_id; } 94 int provider_id() const { return info_.provider_id; }
92 int frame_id() const; 95 int frame_id() const;
93 int route_id() const { return info_.route_id; } 96 int route_id() const { return info_.route_id; }
94 const WebContentsGetter& web_contents_getter() const { 97 const WebContentsGetter& web_contents_getter() const {
95 return web_contents_getter_; 98 return web_contents_getter_;
96 } 99 }
97 100
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 std::unique_ptr<ServiceWorkerProviderHost> PrepareForCrossSiteTransfer(); 246 std::unique_ptr<ServiceWorkerProviderHost> PrepareForCrossSiteTransfer();
244 void CompleteCrossSiteTransfer(ServiceWorkerProviderHost* provisional_host); 247 void CompleteCrossSiteTransfer(ServiceWorkerProviderHost* provisional_host);
245 ServiceWorkerDispatcherHost* dispatcher_host() const { 248 ServiceWorkerDispatcherHost* dispatcher_host() const {
246 return dispatcher_host_; 249 return dispatcher_host_;
247 } 250 }
248 251
249 // PlzNavigate 252 // PlzNavigate
250 // Completes initialization of provider hosts used for navigation requests. 253 // Completes initialization of provider hosts used for navigation requests.
251 void CompleteNavigationInitialized( 254 void CompleteNavigationInitialized(
252 int process_id, 255 int process_id,
253 int frame_routing_id, 256 ServiceWorkerProviderHostInfo info,
254 ServiceWorkerDispatcherHost* dispatcher_host); 257 ServiceWorkerDispatcherHost* dispatcher_host);
255 258
256 // Sends event messages to the renderer. Events for the worker are queued up 259 // Sends event messages to the renderer. Events for the worker are queued up
257 // until the worker thread id is known via SetReadyToSendMessagesToWorker(). 260 // until the worker thread id is known via SetReadyToSendMessagesToWorker().
258 void SendUpdateFoundMessage( 261 void SendUpdateFoundMessage(
259 int registration_handle_id); 262 int registration_handle_id);
260 void SendSetVersionAttributesMessage( 263 void SendSetVersionAttributesMessage(
261 int registration_handle_id, 264 int registration_handle_id,
262 ChangedVersionAttributesMask changed_mask, 265 ChangedVersionAttributesMask changed_mask,
263 ServiceWorkerVersion* installing_version, 266 ServiceWorkerVersion* installing_version,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 314
312 struct OneShotGetReadyCallback { 315 struct OneShotGetReadyCallback {
313 GetRegistrationForReadyCallback callback; 316 GetRegistrationForReadyCallback callback;
314 bool called; 317 bool called;
315 318
316 explicit OneShotGetReadyCallback( 319 explicit OneShotGetReadyCallback(
317 const GetRegistrationForReadyCallback& callback); 320 const GetRegistrationForReadyCallback& callback);
318 ~OneShotGetReadyCallback(); 321 ~OneShotGetReadyCallback();
319 }; 322 };
320 323
321 ServiceWorkerProviderHost(int render_process_id, 324 ServiceWorkerProviderHost(int process_id,
322 ServiceWorkerProviderHostInfo info, 325 ServiceWorkerProviderHostInfo info,
323 base::WeakPtr<ServiceWorkerContextCore> context, 326 base::WeakPtr<ServiceWorkerContextCore> context,
324 ServiceWorkerDispatcherHost* dispatcher_host); 327 ServiceWorkerDispatcherHost* dispatcher_host);
325 328
326 // ServiceWorkerRegistration::Listener overrides. 329 // ServiceWorkerRegistration::Listener overrides.
327 void OnVersionAttributesChanged( 330 void OnVersionAttributesChanged(
328 ServiceWorkerRegistration* registration, 331 ServiceWorkerRegistration* registration,
329 ChangedVersionAttributesMask changed_mask, 332 ChangedVersionAttributesMask changed_mask,
330 const ServiceWorkerRegistrationInfo& info) override; 333 const ServiceWorkerRegistrationInfo& info) override;
331 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override; 334 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 // false. 399 // false.
397 ServiceWorkerRegistrationMap matching_registrations_; 400 ServiceWorkerRegistrationMap matching_registrations_;
398 401
399 std::unique_ptr<OneShotGetReadyCallback> get_ready_callback_; 402 std::unique_ptr<OneShotGetReadyCallback> get_ready_callback_;
400 scoped_refptr<ServiceWorkerVersion> controlling_version_; 403 scoped_refptr<ServiceWorkerVersion> controlling_version_;
401 scoped_refptr<ServiceWorkerVersion> running_hosted_version_; 404 scoped_refptr<ServiceWorkerVersion> running_hosted_version_;
402 base::WeakPtr<ServiceWorkerContextCore> context_; 405 base::WeakPtr<ServiceWorkerContextCore> context_;
403 ServiceWorkerDispatcherHost* dispatcher_host_; 406 ServiceWorkerDispatcherHost* dispatcher_host_;
404 bool allow_association_; 407 bool allow_association_;
405 408
409 // The renderer-side Mojo endpoint for this provider.
falken 2017/05/22 08:28:12 Can you docu binding_ also? // |provider_| is the
shimazu 2017/05/23 06:29:34 Done.
410 mojom::ServiceWorkerProviderAssociatedPtr provider_;
411 mojo::AssociatedBinding<mojom::ServiceWorkerProviderHost> binding_;
412
406 std::vector<base::Closure> queued_events_; 413 std::vector<base::Closure> queued_events_;
407 414
408 // Keeps ServiceWorkerWorkerClient pointers of dedicated or shared workers 415 // Keeps ServiceWorkerWorkerClient pointers of dedicated or shared workers
409 // which are associated with the ServiceWorkerProviderHost. 416 // which are associated with the ServiceWorkerProviderHost.
410 std::unordered_map<mojom::ServiceWorkerWorkerClient*, 417 std::unordered_map<mojom::ServiceWorkerWorkerClient*,
411 mojom::ServiceWorkerWorkerClientAssociatedPtr> 418 mojom::ServiceWorkerWorkerClientAssociatedPtr>
412 worker_clients_; 419 worker_clients_;
413 420
414 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); 421 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost);
415 }; 422 };
416 423
417 } // namespace content 424 } // namespace content
418 425
419 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ 426 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698