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_DISPATCHER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_ |
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/id_map.h" | 13 #include "base/id_map.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/optional.h" | 16 #include "base/optional.h" |
17 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
18 #include "content/browser/service_worker/service_worker_registration_status.h" | 18 #include "content/browser/service_worker/service_worker_registration_status.h" |
19 #include "content/common/service_worker/service_worker.mojom.h" | 19 #include "content/common/service_worker/service_worker.mojom.h" |
20 #include "content/common/service_worker/service_worker_types.h" | 20 #include "content/common/service_worker/service_worker_types.h" |
21 #include "content/public/browser/browser_message_filter.h" | 21 #include "content/public/browser/browser_message_filter.h" |
22 #include "mojo/public/cpp/bindings/associated_binding_set.h" | 22 #include "mojo/public/cpp/bindings/associated_binding_set.h" |
| 23 #include "mojo/public/cpp/bindings/strong_associated_binding_set.h" |
23 | 24 |
24 class GURL; | 25 class GURL; |
25 | 26 |
26 namespace url { | 27 namespace url { |
27 class Origin; | 28 class Origin; |
28 } // namespace url | 29 } // namespace url |
29 | 30 |
30 namespace content { | 31 namespace content { |
31 | 32 |
32 class MessagePort; | 33 class MessagePort; |
33 class ResourceContext; | 34 class ResourceContext; |
34 class ServiceWorkerContextCore; | 35 class ServiceWorkerContextCore; |
35 class ServiceWorkerContextWrapper; | 36 class ServiceWorkerContextWrapper; |
36 class ServiceWorkerHandle; | 37 class ServiceWorkerHandle; |
37 class ServiceWorkerProviderHost; | 38 class ServiceWorkerProviderHost; |
38 class ServiceWorkerRegistration; | 39 class ServiceWorkerRegistration; |
39 class ServiceWorkerRegistrationHandle; | 40 class ServiceWorkerRegistrationHandle; |
40 class ServiceWorkerVersion; | 41 class ServiceWorkerVersion; |
41 struct ServiceWorkerObjectInfo; | 42 struct ServiceWorkerObjectInfo; |
42 struct ServiceWorkerRegistrationObjectInfo; | 43 struct ServiceWorkerRegistrationObjectInfo; |
43 struct ServiceWorkerVersionAttributes; | 44 struct ServiceWorkerVersionAttributes; |
44 | 45 |
45 // This class is bound with mojom::ServiceWorkerDispatcherHost. All | 46 // This class is bound with mojom::ServiceWorkerDispatcherHost. All |
46 // InterfacePtrs on the same render process are bound to the same | 47 // InterfacePtrs on the same render process are bound to the same |
47 // content::ServiceWorkerDispatcherHost. | 48 // content::ServiceWorkerDispatcherHost. This can be overridden only for |
| 49 // testing. |
48 class CONTENT_EXPORT ServiceWorkerDispatcherHost | 50 class CONTENT_EXPORT ServiceWorkerDispatcherHost |
49 : public mojom::ServiceWorkerDispatcherHost, | 51 : public mojom::ServiceWorkerDispatcherHost, |
50 public BrowserMessageFilter { | 52 public BrowserMessageFilter { |
51 public: | 53 public: |
52 ServiceWorkerDispatcherHost( | 54 ServiceWorkerDispatcherHost( |
53 int render_process_id, | 55 int render_process_id, |
54 ResourceContext* resource_context); | 56 ResourceContext* resource_context); |
55 | 57 |
| 58 // |blob_storage_context| and |loader_factory_getter| are used only |
| 59 // if IsServicificationEnabled is true. |
56 void Init(ServiceWorkerContextWrapper* context_wrapper); | 60 void Init(ServiceWorkerContextWrapper* context_wrapper); |
57 | 61 |
58 // BrowserMessageFilter implementation | 62 // BrowserMessageFilter implementation |
59 void OnFilterAdded(IPC::Channel* channel) override; | 63 void OnFilterAdded(IPC::Channel* channel) override; |
60 void OnFilterRemoved() override; | 64 void OnFilterRemoved() override; |
61 void OnDestruct() const override; | 65 void OnDestruct() const override; |
62 bool OnMessageReceived(const IPC::Message& message) override; | 66 bool OnMessageReceived(const IPC::Message& message) override; |
63 | 67 |
64 // IPC::Sender implementation | 68 // IPC::Sender implementation |
65 | 69 |
66 // Send() queues the message until the underlying sender is ready. This | 70 // Send() queues the message until the underlying sender is ready. This |
67 // class assumes that Send() can only fail after that when the renderer | 71 // class assumes that Send() can only fail after that when the renderer |
68 // process has terminated, at which point the whole instance will eventually | 72 // process has terminated, at which point the whole instance will eventually |
69 // be destroyed. | 73 // be destroyed. |
70 bool Send(IPC::Message* message) override; | 74 bool Send(IPC::Message* message) override; |
71 | 75 |
72 void RegisterServiceWorkerHandle(std::unique_ptr<ServiceWorkerHandle> handle); | 76 // Virtual for testing. |
73 void RegisterServiceWorkerRegistrationHandle( | 77 virtual void RegisterServiceWorkerHandle( |
| 78 std::unique_ptr<ServiceWorkerHandle> handle); |
| 79 // Virtual for testing. |
| 80 virtual void RegisterServiceWorkerRegistrationHandle( |
74 std::unique_ptr<ServiceWorkerRegistrationHandle> handle); | 81 std::unique_ptr<ServiceWorkerRegistrationHandle> handle); |
75 | 82 |
76 ServiceWorkerHandle* FindServiceWorkerHandle(int provider_id, | 83 ServiceWorkerHandle* FindServiceWorkerHandle(int provider_id, |
77 int64_t version_id); | 84 int64_t version_id); |
78 | 85 |
| 86 void GetRegistrationObjectInfoAndVersionAttributes( |
| 87 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| 88 ServiceWorkerRegistration* registration, |
| 89 ServiceWorkerRegistrationObjectInfo* out_info, |
| 90 ServiceWorkerVersionAttributes* out_attrs); |
| 91 |
79 // Returns the existing registration handle whose reference count is | 92 // Returns the existing registration handle whose reference count is |
80 // incremented or a newly created one if it doesn't exist. | 93 // incremented or a newly created one if it doesn't exist. |
81 ServiceWorkerRegistrationHandle* GetOrCreateRegistrationHandle( | 94 ServiceWorkerRegistrationHandle* GetOrCreateRegistrationHandle( |
82 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 95 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
83 ServiceWorkerRegistration* registration); | 96 ServiceWorkerRegistration* registration); |
84 | 97 |
85 protected: | 98 protected: |
86 ~ServiceWorkerDispatcherHost() override; | 99 ~ServiceWorkerDispatcherHost() override; |
87 | 100 |
88 private: | 101 private: |
89 friend class BrowserThread; | 102 friend class BrowserThread; |
90 friend class base::DeleteHelper<ServiceWorkerDispatcherHost>; | 103 friend class base::DeleteHelper<ServiceWorkerDispatcherHost>; |
91 friend class ServiceWorkerDispatcherHostTest; | 104 friend class ServiceWorkerDispatcherHostTest; |
92 friend class TestingServiceWorkerDispatcherHost; | 105 friend class TestingServiceWorkerDispatcherHost; |
93 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDispatcherHostTest, | 106 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDispatcherHostTest, |
94 ProviderCreatedAndDestroyed); | 107 ProviderCreatedAndDestroyed); |
95 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDispatcherHostTest, | 108 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDispatcherHostTest, |
96 CleanupOnRendererCrash); | 109 CleanupOnRendererCrash); |
| 110 FRIEND_TEST_ALL_PREFIXES(BackgroundSyncManagerTest, |
| 111 RegisterWithoutLiveSWRegistration); |
97 | 112 |
98 using StatusCallback = base::Callback<void(ServiceWorkerStatusCode status)>; | 113 using StatusCallback = base::Callback<void(ServiceWorkerStatusCode status)>; |
99 enum class ProviderStatus { OK, NO_CONTEXT, DEAD_HOST, NO_HOST, NO_URL }; | 114 enum class ProviderStatus { OK, NO_CONTEXT, DEAD_HOST, NO_HOST, NO_URL }; |
100 | 115 |
101 // Called when mojom::ServiceWorkerDispatcherHostPtr is created on the | 116 // Called when mojom::ServiceWorkerDispatcherHostPtr is created on the |
102 // renderer-side. | 117 // renderer-side. |
103 void AddMojoBinding(mojo::ScopedInterfaceEndpointHandle handle); | 118 void AddMojoBinding(mojo::ScopedInterfaceEndpointHandle handle); |
104 | 119 |
105 // mojom::ServiceWorkerDispatcherHost implementation | 120 // mojom::ServiceWorkerDispatcherHost implementation |
106 void OnProviderCreated(ServiceWorkerProviderHostInfo info) override; | 121 void OnProviderCreated(ServiceWorkerProviderHostInfo info) override; |
107 void OnSetHostedVersionId(int provider_id, | |
108 int64_t version_id, | |
109 int embedded_worker_id) override; | |
110 | 122 |
111 // IPC Message handlers | 123 // IPC Message handlers |
112 void OnRegisterServiceWorker(int thread_id, | 124 void OnRegisterServiceWorker(int thread_id, |
113 int request_id, | 125 int request_id, |
114 int provider_id, | 126 int provider_id, |
115 const GURL& pattern, | 127 const GURL& pattern, |
116 const GURL& script_url); | 128 const GURL& script_url); |
117 void OnUpdateServiceWorker(int thread_id, | 129 void OnUpdateServiceWorker(int thread_id, |
118 int request_id, | 130 int request_id, |
119 int provider_id, | 131 int provider_id, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 const SourceInfo& source_info, | 200 const SourceInfo& source_info, |
189 const StatusCallback& callback, | 201 const StatusCallback& callback, |
190 ServiceWorkerStatusCode status); | 202 ServiceWorkerStatusCode status); |
191 void ReleaseSourceInfo(const ServiceWorkerClientInfo& source_info); | 203 void ReleaseSourceInfo(const ServiceWorkerClientInfo& source_info); |
192 void ReleaseSourceInfo(const ServiceWorkerObjectInfo& source_info); | 204 void ReleaseSourceInfo(const ServiceWorkerObjectInfo& source_info); |
193 | 205 |
194 ServiceWorkerRegistrationHandle* FindRegistrationHandle( | 206 ServiceWorkerRegistrationHandle* FindRegistrationHandle( |
195 int provider_id, | 207 int provider_id, |
196 int64_t registration_handle_id); | 208 int64_t registration_handle_id); |
197 | 209 |
198 void GetRegistrationObjectInfoAndVersionAttributes( | |
199 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | |
200 ServiceWorkerRegistration* registration, | |
201 ServiceWorkerRegistrationObjectInfo* info, | |
202 ServiceWorkerVersionAttributes* attrs); | |
203 | |
204 // Callbacks from ServiceWorkerContextCore | 210 // Callbacks from ServiceWorkerContextCore |
205 void RegistrationComplete(int thread_id, | 211 void RegistrationComplete(int thread_id, |
206 int provider_id, | 212 int provider_id, |
207 int request_id, | 213 int request_id, |
208 ServiceWorkerStatusCode status, | 214 ServiceWorkerStatusCode status, |
209 const std::string& status_message, | 215 const std::string& status_message, |
210 int64_t registration_id); | 216 int64_t registration_id); |
211 void UpdateComplete(int thread_id, | 217 void UpdateComplete(int thread_id, |
212 int provider_id, | 218 int provider_id, |
213 int request_id, | 219 int request_id, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 mojo::AssociatedBindingSet<mojom::ServiceWorkerDispatcherHost> bindings_; | 277 mojo::AssociatedBindingSet<mojom::ServiceWorkerDispatcherHost> bindings_; |
272 | 278 |
273 base::WeakPtrFactory<ServiceWorkerDispatcherHost> weak_factory_; | 279 base::WeakPtrFactory<ServiceWorkerDispatcherHost> weak_factory_; |
274 | 280 |
275 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcherHost); | 281 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcherHost); |
276 }; | 282 }; |
277 | 283 |
278 } // namespace content | 284 } // namespace content |
279 | 285 |
280 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_ | 286 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_ |
OLD | NEW |