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> |
(...skipping 24 matching lines...) Expand all Loading... |
35 class ServiceWorkerContextWrapper; | 35 class ServiceWorkerContextWrapper; |
36 class ServiceWorkerHandle; | 36 class ServiceWorkerHandle; |
37 class ServiceWorkerProviderHost; | 37 class ServiceWorkerProviderHost; |
38 class ServiceWorkerRegistration; | 38 class ServiceWorkerRegistration; |
39 class ServiceWorkerRegistrationHandle; | 39 class ServiceWorkerRegistrationHandle; |
40 class ServiceWorkerVersion; | 40 class ServiceWorkerVersion; |
41 struct ServiceWorkerObjectInfo; | 41 struct ServiceWorkerObjectInfo; |
42 struct ServiceWorkerRegistrationObjectInfo; | 42 struct ServiceWorkerRegistrationObjectInfo; |
43 struct ServiceWorkerVersionAttributes; | 43 struct ServiceWorkerVersionAttributes; |
44 | 44 |
| 45 // MessageFilter for service workers. This class receives IPCs to manipulate |
| 46 // service workers from the renderer process regardless of hosting page or |
| 47 // service worker's context. This can be override only for testing. |
45 class CONTENT_EXPORT ServiceWorkerDispatcherHost | 48 class CONTENT_EXPORT ServiceWorkerDispatcherHost |
46 : public mojom::ServiceWorkerDispatcherHost, | 49 : public mojom::ServiceWorkerDispatcherHost, |
47 public BrowserMessageFilter { | 50 public BrowserMessageFilter { |
48 public: | 51 public: |
49 ServiceWorkerDispatcherHost( | 52 ServiceWorkerDispatcherHost( |
50 int render_process_id, | 53 int render_process_id, |
51 ResourceContext* resource_context); | 54 ResourceContext* resource_context); |
52 | 55 |
53 void Init(ServiceWorkerContextWrapper* context_wrapper); | 56 void Init(ServiceWorkerContextWrapper* context_wrapper); |
54 | 57 |
55 // BrowserMessageFilter implementation | 58 // BrowserMessageFilter implementation |
56 void OnFilterAdded(IPC::Channel* channel) override; | 59 void OnFilterAdded(IPC::Channel* channel) override; |
57 void OnFilterRemoved() override; | 60 void OnFilterRemoved() override; |
58 void OnDestruct() const override; | 61 void OnDestruct() const override; |
59 bool OnMessageReceived(const IPC::Message& message) override; | 62 bool OnMessageReceived(const IPC::Message& message) override; |
60 | 63 |
61 // IPC::Sender implementation | 64 // IPC::Sender implementation |
62 | 65 |
63 // Send() queues the message until the underlying sender is ready. This | 66 // Send() queues the message until the underlying sender is ready. This |
64 // class assumes that Send() can only fail after that when the renderer | 67 // class assumes that Send() can only fail after that when the renderer |
65 // process has terminated, at which point the whole instance will eventually | 68 // process has terminated, at which point the whole instance will eventually |
66 // be destroyed. | 69 // be destroyed. |
67 bool Send(IPC::Message* message) override; | 70 bool Send(IPC::Message* message) override; |
68 | 71 |
69 void RegisterServiceWorkerHandle(std::unique_ptr<ServiceWorkerHandle> handle); | 72 // Virtual for testing. |
70 void RegisterServiceWorkerRegistrationHandle( | 73 virtual void RegisterServiceWorkerHandle( |
| 74 std::unique_ptr<ServiceWorkerHandle> handle); |
| 75 // Virtual for testing. |
| 76 virtual void RegisterServiceWorkerRegistrationHandle( |
71 std::unique_ptr<ServiceWorkerRegistrationHandle> handle); | 77 std::unique_ptr<ServiceWorkerRegistrationHandle> handle); |
72 | 78 |
73 ServiceWorkerHandle* FindServiceWorkerHandle(int provider_id, | 79 ServiceWorkerHandle* FindServiceWorkerHandle(int provider_id, |
74 int64_t version_id); | 80 int64_t version_id); |
75 | 81 |
| 82 void GetRegistrationObjectInfoAndVersionAttributes( |
| 83 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| 84 ServiceWorkerRegistration* registration, |
| 85 ServiceWorkerRegistrationObjectInfo* info, |
| 86 ServiceWorkerVersionAttributes* attrs); |
| 87 |
76 // Returns the existing registration handle whose reference count is | 88 // Returns the existing registration handle whose reference count is |
77 // incremented or a newly created one if it doesn't exist. | 89 // incremented or a newly created one if it doesn't exist. |
78 ServiceWorkerRegistrationHandle* GetOrCreateRegistrationHandle( | 90 ServiceWorkerRegistrationHandle* GetOrCreateRegistrationHandle( |
79 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 91 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
80 ServiceWorkerRegistration* registration); | 92 ServiceWorkerRegistration* registration); |
81 | 93 |
82 protected: | 94 protected: |
83 ~ServiceWorkerDispatcherHost() override; | 95 ~ServiceWorkerDispatcherHost() override; |
84 | 96 |
85 private: | 97 private: |
86 friend class BrowserThread; | 98 friend class BrowserThread; |
87 friend class base::DeleteHelper<ServiceWorkerDispatcherHost>; | 99 friend class base::DeleteHelper<ServiceWorkerDispatcherHost>; |
88 friend class ServiceWorkerDispatcherHostTest; | 100 friend class ServiceWorkerDispatcherHostTest; |
89 friend class TestingServiceWorkerDispatcherHost; | 101 friend class TestingServiceWorkerDispatcherHost; |
90 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDispatcherHostTest, | 102 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDispatcherHostTest, |
91 ProviderCreatedAndDestroyed); | 103 ProviderCreatedAndDestroyed); |
92 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDispatcherHostTest, | 104 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDispatcherHostTest, |
93 CleanupOnRendererCrash); | 105 CleanupOnRendererCrash); |
94 | 106 |
95 using StatusCallback = base::Callback<void(ServiceWorkerStatusCode status)>; | 107 using StatusCallback = base::Callback<void(ServiceWorkerStatusCode status)>; |
96 enum class ProviderStatus { OK, NO_CONTEXT, DEAD_HOST, NO_HOST, NO_URL }; | 108 enum class ProviderStatus { OK, NO_CONTEXT, DEAD_HOST, NO_HOST, NO_URL }; |
97 | 109 |
98 // Called when mojom::ServiceWorkerDispatcherHostPtr is created on the | 110 // Called when mojom::ServiceWorkerDispatcherHostPtr is created on the |
99 // renderer-side. | 111 // renderer-side. |
100 void AddMojoBinding(mojo::ScopedInterfaceEndpointHandle handle); | 112 void AddMojoBinding(mojo::ScopedInterfaceEndpointHandle handle); |
101 | 113 |
102 // mojom::ServiceWorkerDispatcherHost implementation | 114 // mojom::ServiceWorkerDispatcherHost implementation |
103 void OnProviderCreated(ServiceWorkerProviderHostInfo info) override; | 115 void OnProviderCreated(ServiceWorkerProviderHostInfo info) override; |
104 void OnSetHostedVersionId(int provider_id, | |
105 int64_t version_id, | |
106 int embedded_worker_id) override; | |
107 | 116 |
108 // IPC Message handlers | 117 // IPC Message handlers |
109 void OnRegisterServiceWorker(int thread_id, | 118 void OnRegisterServiceWorker(int thread_id, |
110 int request_id, | 119 int request_id, |
111 int provider_id, | 120 int provider_id, |
112 const GURL& pattern, | 121 const GURL& pattern, |
113 const GURL& script_url); | 122 const GURL& script_url); |
114 void OnUpdateServiceWorker(int thread_id, | 123 void OnUpdateServiceWorker(int thread_id, |
115 int request_id, | 124 int request_id, |
116 int provider_id, | 125 int provider_id, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 const SourceInfo& source_info, | 194 const SourceInfo& source_info, |
186 const StatusCallback& callback, | 195 const StatusCallback& callback, |
187 ServiceWorkerStatusCode status); | 196 ServiceWorkerStatusCode status); |
188 void ReleaseSourceInfo(const ServiceWorkerClientInfo& source_info); | 197 void ReleaseSourceInfo(const ServiceWorkerClientInfo& source_info); |
189 void ReleaseSourceInfo(const ServiceWorkerObjectInfo& source_info); | 198 void ReleaseSourceInfo(const ServiceWorkerObjectInfo& source_info); |
190 | 199 |
191 ServiceWorkerRegistrationHandle* FindRegistrationHandle( | 200 ServiceWorkerRegistrationHandle* FindRegistrationHandle( |
192 int provider_id, | 201 int provider_id, |
193 int64_t registration_handle_id); | 202 int64_t registration_handle_id); |
194 | 203 |
195 void GetRegistrationObjectInfoAndVersionAttributes( | |
196 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | |
197 ServiceWorkerRegistration* registration, | |
198 ServiceWorkerRegistrationObjectInfo* info, | |
199 ServiceWorkerVersionAttributes* attrs); | |
200 | |
201 // Callbacks from ServiceWorkerContextCore | 204 // Callbacks from ServiceWorkerContextCore |
202 void RegistrationComplete(int thread_id, | 205 void RegistrationComplete(int thread_id, |
203 int provider_id, | 206 int provider_id, |
204 int request_id, | 207 int request_id, |
205 ServiceWorkerStatusCode status, | 208 ServiceWorkerStatusCode status, |
206 const std::string& status_message, | 209 const std::string& status_message, |
207 int64_t registration_id); | 210 int64_t registration_id); |
208 void UpdateComplete(int thread_id, | 211 void UpdateComplete(int thread_id, |
209 int provider_id, | 212 int provider_id, |
210 int request_id, | 213 int request_id, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 mojo::AssociatedBindingSet<mojom::ServiceWorkerDispatcherHost> bindings_; | 271 mojo::AssociatedBindingSet<mojom::ServiceWorkerDispatcherHost> bindings_; |
269 | 272 |
270 base::WeakPtrFactory<ServiceWorkerDispatcherHost> weak_factory_; | 273 base::WeakPtrFactory<ServiceWorkerDispatcherHost> weak_factory_; |
271 | 274 |
272 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcherHost); | 275 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcherHost); |
273 }; | 276 }; |
274 | 277 |
275 } // namespace content | 278 } // namespace content |
276 | 279 |
277 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_ | 280 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_ |
OLD | NEW |