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

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

Issue 2653493009: Add two interfaces for ServiceWorkerProviderContext/ProviderHost (Closed)
Patch Set: Rebase Created 3 years, 9 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 <vector> 15 #include <vector>
16 16
17 #include "base/gtest_prod_util.h" 17 #include "base/gtest_prod_util.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/memory/ref_counted.h" 19 #include "base/memory/ref_counted.h"
20 #include "base/memory/weak_ptr.h" 20 #include "base/memory/weak_ptr.h"
21 #include "content/browser/service_worker/service_worker_registration.h" 21 #include "content/browser/service_worker/service_worker_registration.h"
22 #include "content/common/content_export.h" 22 #include "content/common/content_export.h"
23 #include "content/common/service_worker/service_worker_provider_host_info.h" 23 #include "content/common/service_worker/service_worker_provider_host_info.h"
24 #include "content/common/service_worker/service_worker_provider_interfaces.mojom .h"
24 #include "content/common/service_worker/service_worker_types.h" 25 #include "content/common/service_worker/service_worker_types.h"
25 #include "content/public/common/request_context_frame_type.h" 26 #include "content/public/common/request_context_frame_type.h"
26 #include "content/public/common/request_context_type.h" 27 #include "content/public/common/request_context_type.h"
27 #include "content/public/common/resource_type.h" 28 #include "content/public/common/resource_type.h"
29 #include "mojo/public/cpp/bindings/associated_binding.h"
28 30
29 namespace storage { 31 namespace storage {
30 class BlobStorageContext; 32 class BlobStorageContext;
31 } 33 }
32 34
33 namespace content { 35 namespace content {
34 36
35 class MessagePort; 37 class MessagePort;
36 class ResourceRequestBodyImpl; 38 class ResourceRequestBodyImpl;
37 class ServiceWorkerContextCore; 39 class ServiceWorkerContextCore;
38 class ServiceWorkerDispatcherHost; 40 class ServiceWorkerDispatcherHost;
39 class ServiceWorkerRequestHandler; 41 class ServiceWorkerRequestHandler;
40 class ServiceWorkerVersion; 42 class ServiceWorkerVersion;
41 class WebContents; 43 class WebContents;
42 44
43 // This class is the browser-process representation of a service worker 45 // This class is the browser-process representation of a service worker
44 // provider. There are two general types of providers: 1) those for a client 46 // provider. There are two general types of providers: 1) those for a client
45 // (windows, dedicated workers, or shared workers), and 2) those for hosting a 47 // (windows, dedicated workers, or shared workers), and 2) those for hosting a
46 // running service worker. 48 // running service worker.
47 // 49 //
48 // For client providers, there is a provider per document or a worker and the 50 // For client providers, there is a provider per document or a worker and the
49 // lifetime of this object is tied to the lifetime of its document or the worker 51 // lifetime of this object is tied to the lifetime of its document or the worker
50 // in the renderer process. This class holds service worker state that is scoped 52 // in the renderer process. This class holds service worker state that is scoped
51 // to an individual document or a worker. 53 // to an individual document or a worker.
52 // 54 //
53 // For providers hosting a running service worker, this class will observe 55 // For providers hosting a running service worker, this class will observe
54 // resource loads made directly by the service worker. 56 // resource loads made directly by the service worker.
55 class CONTENT_EXPORT ServiceWorkerProviderHost 57 class CONTENT_EXPORT ServiceWorkerProviderHost
56 : public NON_EXPORTED_BASE(ServiceWorkerRegistration::Listener), 58 : public NON_EXPORTED_BASE(ServiceWorkerRegistration::Listener),
57 public base::SupportsWeakPtr<ServiceWorkerProviderHost> { 59 public base::SupportsWeakPtr<ServiceWorkerProviderHost>,
60 public NON_EXPORTED_BASE(mojom::ServiceWorkerProviderHost) {
58 public: 61 public:
59 using GetRegistrationForReadyCallback = 62 using GetRegistrationForReadyCallback =
60 base::Callback<void(ServiceWorkerRegistration* reigstration)>; 63 base::Callback<void(ServiceWorkerRegistration* reigstration)>;
61 64
62 using WebContentsGetter = base::Callback<WebContents*(void)>; 65 using WebContentsGetter = base::Callback<WebContents*(void)>;
63 66
64 // PlzNavigate 67 // PlzNavigate
65 // Used to pre-create a ServiceWorkerProviderHost for a navigation. The 68 // Used to pre-create a ServiceWorkerProviderHost for a navigation. The
66 // ServiceWorkerNetworkProvider will later be created in the renderer, should 69 // ServiceWorkerNetworkProvider will later be created in the renderer, should
67 // the navigation succeed. |is_parent_frame_is_secure| should be true for main 70 // the navigation succeed. |is_parent_frame_is_secure| should be true for main
68 // frames. Otherwise it is true iff all ancestor frames of this frame have a 71 // frames. Otherwise it is true iff all ancestor frames of this frame have a
69 // secure origin. |web_contents_getter| indicates the tab where the navigation 72 // secure origin. |web_contents_getter| indicates the tab where the navigation
70 // is occurring. 73 // is occurring.
71 static std::unique_ptr<ServiceWorkerProviderHost> PreCreateNavigationHost( 74 static std::unique_ptr<ServiceWorkerProviderHost> PreCreateNavigationHost(
72 base::WeakPtr<ServiceWorkerContextCore> context, 75 base::WeakPtr<ServiceWorkerContextCore> context,
73 bool are_ancestors_secure, 76 bool are_ancestors_secure,
74 const WebContentsGetter& web_contents_getter); 77 const WebContentsGetter& web_contents_getter);
75 78
76 // Used to create a ServiceWorkerProviderHost when the renderer-side provider 79 // Used to create a ServiceWorkerProviderHost when the renderer-side provider
77 // is created. This ProviderHost will be created for the process specified by 80 // is created. This ProviderHost will be created for the process specified by
78 // |process_id|. 81 // |process_id|.
79 static std::unique_ptr<ServiceWorkerProviderHost> Create( 82 static std::unique_ptr<ServiceWorkerProviderHost> Create(
80 int process_id, 83 int process_id,
81 ServiceWorkerProviderHostInfo info, 84 ServiceWorkerProviderHostInfo info,
82 base::WeakPtr<ServiceWorkerContextCore> context, 85 base::WeakPtr<ServiceWorkerContextCore> context,
83 ServiceWorkerDispatcherHost* dispatcher_host); 86 ServiceWorkerDispatcherHost* dispatcher_host);
84 87
85 virtual ~ServiceWorkerProviderHost(); 88 ~ServiceWorkerProviderHost() override;
86 89
87 const std::string& client_uuid() const { return client_uuid_; } 90 const std::string& client_uuid() const { return client_uuid_; }
88 int process_id() const { return render_process_id_; } 91 int process_id() const { return render_process_id_; }
89 int provider_id() const { return provider_id_; } 92 int provider_id() const { return provider_id_; }
90 int frame_id() const; 93 int frame_id() const;
91 int route_id() const { return route_id_; } 94 int route_id() const { return route_id_; }
92 const WebContentsGetter& web_contents_getter() const { 95 const WebContentsGetter& web_contents_getter() const {
93 return web_contents_getter_; 96 return web_contents_getter_;
94 } 97 }
95 98
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 311
309 struct OneShotGetReadyCallback { 312 struct OneShotGetReadyCallback {
310 GetRegistrationForReadyCallback callback; 313 GetRegistrationForReadyCallback callback;
311 bool called; 314 bool called;
312 315
313 explicit OneShotGetReadyCallback( 316 explicit OneShotGetReadyCallback(
314 const GetRegistrationForReadyCallback& callback); 317 const GetRegistrationForReadyCallback& callback);
315 ~OneShotGetReadyCallback(); 318 ~OneShotGetReadyCallback();
316 }; 319 };
317 320
318 ServiceWorkerProviderHost(int render_process_id, 321 ServiceWorkerProviderHost(
319 int route_id, 322 int render_process_id,
320 int provider_id, 323 int route_id,
321 ServiceWorkerProviderType provider_type, 324 int provider_id,
322 bool is_parent_frame_secure, 325 ServiceWorkerProviderType provider_type,
323 base::WeakPtr<ServiceWorkerContextCore> context, 326 bool is_parent_frame_secure,
324 ServiceWorkerDispatcherHost* dispatcher_host); 327 mojom::ServiceWorkerProviderAssociatedPtrInfo client_info,
328 mojom::ServiceWorkerProviderHostAssociatedRequest request,
falken 2017/03/28 06:29:43 Can ServiceWorkerProviderHost just take a ServiceW
shimazu 2017/05/08 08:34:29 Done.
329 base::WeakPtr<ServiceWorkerContextCore> context,
330 ServiceWorkerDispatcherHost* dispatcher_host);
325 331
326 // ServiceWorkerRegistration::Listener overrides. 332 // ServiceWorkerRegistration::Listener overrides.
327 void OnVersionAttributesChanged( 333 void OnVersionAttributesChanged(
328 ServiceWorkerRegistration* registration, 334 ServiceWorkerRegistration* registration,
329 ChangedVersionAttributesMask changed_mask, 335 ChangedVersionAttributesMask changed_mask,
330 const ServiceWorkerRegistrationInfo& info) override; 336 const ServiceWorkerRegistrationInfo& info) override;
331 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override; 337 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override;
332 void OnRegistrationFinishedUninstalling( 338 void OnRegistrationFinishedUninstalling(
333 ServiceWorkerRegistration* registration) override; 339 ServiceWorkerRegistration* registration) override;
334 void OnSkippedWaiting(ServiceWorkerRegistration* registration) override; 340 void OnSkippedWaiting(ServiceWorkerRegistration* registration) override;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 // false. 403 // false.
398 ServiceWorkerRegistrationMap matching_registrations_; 404 ServiceWorkerRegistrationMap matching_registrations_;
399 405
400 std::unique_ptr<OneShotGetReadyCallback> get_ready_callback_; 406 std::unique_ptr<OneShotGetReadyCallback> get_ready_callback_;
401 scoped_refptr<ServiceWorkerVersion> controlling_version_; 407 scoped_refptr<ServiceWorkerVersion> controlling_version_;
402 scoped_refptr<ServiceWorkerVersion> running_hosted_version_; 408 scoped_refptr<ServiceWorkerVersion> running_hosted_version_;
403 base::WeakPtr<ServiceWorkerContextCore> context_; 409 base::WeakPtr<ServiceWorkerContextCore> context_;
404 ServiceWorkerDispatcherHost* dispatcher_host_; 410 ServiceWorkerDispatcherHost* dispatcher_host_;
405 bool allow_association_; 411 bool allow_association_;
406 412
413 mojom::ServiceWorkerProviderAssociatedPtr client_;
414 mojo::AssociatedBinding<mojom::ServiceWorkerProviderHost> binding_;
415
407 std::vector<base::Closure> queued_events_; 416 std::vector<base::Closure> queued_events_;
408 417
409 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); 418 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost);
410 }; 419 };
411 420
412 } // namespace content 421 } // namespace content
413 422
414 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ 423 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698