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_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ | 5 #ifndef CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ |
6 #define CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ | 6 #define CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 namespace blink { | 21 namespace blink { |
22 class WebURL; | 22 class WebURL; |
23 } | 23 } |
24 | 24 |
25 namespace IPC { | 25 namespace IPC { |
26 class Message; | 26 class Message; |
27 } | 27 } |
28 | 28 |
29 namespace content { | 29 namespace content { |
30 | 30 |
31 class ServiceWorkerMessageFilter; | 31 class ServiceWorkerMessageSender; |
32 class ServiceWorkerProviderContext; | 32 class ServiceWorkerProviderContext; |
33 class ThreadSafeSender; | 33 class ThreadSafeSender; |
34 class WebServiceWorkerImpl; | 34 class WebServiceWorkerImpl; |
35 class WebServiceWorkerRegistrationImpl; | 35 class WebServiceWorkerRegistrationImpl; |
36 struct ServiceWorkerObjectInfo; | 36 struct ServiceWorkerObjectInfo; |
37 struct ServiceWorkerRegistrationObjectInfo; | 37 struct ServiceWorkerRegistrationObjectInfo; |
38 struct ServiceWorkerVersionAttributes; | 38 struct ServiceWorkerVersionAttributes; |
39 struct TransferredMessagePort; | 39 struct TransferredMessagePort; |
40 | 40 |
41 // This class manages communication with the browser process about | 41 // This class manages communication with the browser process about |
42 // registration of the service worker, exposed to renderer and worker | 42 // registration of the service worker, exposed to renderer and worker |
43 // scripts through methods like navigator.registerServiceWorker(). | 43 // scripts through methods like navigator.registerServiceWorker(). |
44 class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { | 44 class CONTENT_EXPORT ServiceWorkerDispatcher |
| 45 : public WorkerTaskRunner::Observer { |
45 public: | 46 public: |
46 typedef blink::WebServiceWorkerProvider::WebServiceWorkerRegistrationCallbacks | 47 typedef blink::WebServiceWorkerProvider::WebServiceWorkerRegistrationCallbacks |
47 WebServiceWorkerRegistrationCallbacks; | 48 WebServiceWorkerRegistrationCallbacks; |
48 typedef | 49 typedef |
49 blink::WebServiceWorkerProvider::WebServiceWorkerUnregistrationCallbacks | 50 blink::WebServiceWorkerProvider::WebServiceWorkerUnregistrationCallbacks |
50 WebServiceWorkerUnregistrationCallbacks; | 51 WebServiceWorkerUnregistrationCallbacks; |
51 typedef | 52 typedef |
52 blink::WebServiceWorkerProvider::WebServiceWorkerGetRegistrationCallbacks | 53 blink::WebServiceWorkerProvider::WebServiceWorkerGetRegistrationCallbacks |
53 WebServiceWorkerGetRegistrationCallbacks; | 54 WebServiceWorkerGetRegistrationCallbacks; |
54 typedef blink::WebServiceWorkerProvider:: | 55 typedef blink::WebServiceWorkerProvider:: |
55 WebServiceWorkerGetRegistrationForReadyCallbacks | 56 WebServiceWorkerGetRegistrationForReadyCallbacks |
56 WebServiceWorkerGetRegistrationForReadyCallbacks; | 57 WebServiceWorkerGetRegistrationForReadyCallbacks; |
57 | 58 |
58 explicit ServiceWorkerDispatcher(ThreadSafeSender* thread_safe_sender); | 59 explicit ServiceWorkerDispatcher(ServiceWorkerMessageSender* sender); |
59 ~ServiceWorkerDispatcher() override; | 60 ~ServiceWorkerDispatcher() override; |
60 | 61 |
61 void OnMessageReceived(const IPC::Message& msg); | 62 void OnMessageReceived(const IPC::Message& msg); |
62 bool Send(IPC::Message* msg); | |
63 | 63 |
64 // Corresponds to navigator.serviceWorker.register() | 64 // Corresponds to navigator.serviceWorker.register() |
65 void RegisterServiceWorker( | 65 void RegisterServiceWorker( |
66 int provider_id, | 66 int provider_id, |
67 const GURL& pattern, | 67 const GURL& pattern, |
68 const GURL& script_url, | 68 const GURL& script_url, |
69 WebServiceWorkerRegistrationCallbacks* callbacks); | 69 WebServiceWorkerRegistrationCallbacks* callbacks); |
70 // Corresponds to navigator.serviceWorker.unregister() | 70 // Corresponds to navigator.serviceWorker.unregister() |
71 void UnregisterServiceWorker( | 71 void UnregisterServiceWorker( |
72 int provider_id, | 72 int provider_id, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 bool adopt_handle); | 121 bool adopt_handle); |
122 | 122 |
123 // Creates a WebServiceWorkerRegistrationImpl for the specified registration | 123 // Creates a WebServiceWorkerRegistrationImpl for the specified registration |
124 // and transfers its ownership to the caller. If |adopt_handle| is true, a | 124 // and transfers its ownership to the caller. If |adopt_handle| is true, a |
125 // ServiceWorkerRegistrationHandleReference will be adopted for the | 125 // ServiceWorkerRegistrationHandleReference will be adopted for the |
126 // registration. | 126 // registration. |
127 WebServiceWorkerRegistrationImpl* CreateServiceWorkerRegistration( | 127 WebServiceWorkerRegistrationImpl* CreateServiceWorkerRegistration( |
128 const ServiceWorkerRegistrationObjectInfo& info, | 128 const ServiceWorkerRegistrationObjectInfo& info, |
129 bool adopt_handle); | 129 bool adopt_handle); |
130 | 130 |
131 // |thread_safe_sender| needs to be passed in because if the call leads to | 131 // |sender| needs to be passed in because if the call leads to construction |
132 // construction it will be needed. | 132 // it will be needed. |
133 static ServiceWorkerDispatcher* GetOrCreateThreadSpecificInstance( | 133 static ServiceWorkerDispatcher* GetOrCreateThreadSpecificInstance( |
134 ThreadSafeSender* thread_safe_sender); | 134 ServiceWorkerMessageSender* sender); |
135 | 135 |
136 // Unlike GetOrCreateThreadSpecificInstance() this doesn't create a new | 136 // Unlike GetOrCreateThreadSpecificInstance() this doesn't create a new |
137 // instance if thread-local instance doesn't exist. | 137 // instance if thread-local instance doesn't exist. |
138 static ServiceWorkerDispatcher* GetThreadSpecificInstance(); | 138 static ServiceWorkerDispatcher* GetThreadSpecificInstance(); |
139 | 139 |
140 private: | 140 private: |
141 typedef IDMap<WebServiceWorkerRegistrationCallbacks, | 141 typedef IDMap<WebServiceWorkerRegistrationCallbacks, |
142 IDMapOwnPointer> RegistrationCallbackMap; | 142 IDMapOwnPointer> RegistrationCallbackMap; |
143 typedef IDMap<WebServiceWorkerUnregistrationCallbacks, | 143 typedef IDMap<WebServiceWorkerUnregistrationCallbacks, |
144 IDMapOwnPointer> UnregistrationCallbackMap; | 144 IDMapOwnPointer> UnregistrationCallbackMap; |
145 typedef IDMap<WebServiceWorkerGetRegistrationCallbacks, | 145 typedef IDMap<WebServiceWorkerGetRegistrationCallbacks, |
146 IDMapOwnPointer> GetRegistrationCallbackMap; | 146 IDMapOwnPointer> GetRegistrationCallbackMap; |
147 typedef IDMap<WebServiceWorkerGetRegistrationForReadyCallbacks, | 147 typedef IDMap<WebServiceWorkerGetRegistrationForReadyCallbacks, |
148 IDMapOwnPointer> GetRegistrationForReadyCallbackMap; | 148 IDMapOwnPointer> GetRegistrationForReadyCallbackMap; |
149 | 149 |
150 typedef std::map<int, blink::WebServiceWorkerProviderClient*> | 150 typedef std::map<int, blink::WebServiceWorkerProviderClient*> |
151 ProviderClientMap; | 151 ProviderClientMap; |
152 typedef std::map<int, ServiceWorkerProviderContext*> ProviderContextMap; | 152 typedef std::map<int, ServiceWorkerProviderContext*> ProviderContextMap; |
153 typedef std::map<int, ServiceWorkerProviderContext*> WorkerToProviderMap; | 153 typedef std::map<int, ServiceWorkerProviderContext*> WorkerToProviderMap; |
154 typedef std::map<int, WebServiceWorkerImpl*> WorkerObjectMap; | 154 typedef std::map<int, WebServiceWorkerImpl*> WorkerObjectMap; |
155 typedef std::map<int, WebServiceWorkerRegistrationImpl*> | 155 typedef std::map<int, WebServiceWorkerRegistrationImpl*> |
156 RegistrationObjectMap; | 156 RegistrationObjectMap; |
157 | 157 |
| 158 friend class ServiceWorkerDispatcherTest; |
158 friend class WebServiceWorkerImpl; | 159 friend class WebServiceWorkerImpl; |
159 friend class WebServiceWorkerRegistrationImpl; | 160 friend class WebServiceWorkerRegistrationImpl; |
160 | 161 |
161 // WorkerTaskRunner::Observer implementation. | 162 // WorkerTaskRunner::Observer implementation. |
162 void OnWorkerRunLoopStopped() override; | 163 void OnWorkerRunLoopStopped() override; |
163 | 164 |
164 void OnAssociateRegistrationWithServiceWorker( | 165 void OnAssociateRegistrationWithServiceWorker( |
165 int thread_id, | 166 int thread_id, |
166 int provider_id, | 167 int provider_id, |
167 const ServiceWorkerRegistrationObjectInfo& info, | 168 const ServiceWorkerRegistrationObjectInfo& info, |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 ProviderClientMap provider_clients_; | 246 ProviderClientMap provider_clients_; |
246 ProviderContextMap provider_contexts_; | 247 ProviderContextMap provider_contexts_; |
247 | 248 |
248 WorkerObjectMap service_workers_; | 249 WorkerObjectMap service_workers_; |
249 RegistrationObjectMap registrations_; | 250 RegistrationObjectMap registrations_; |
250 | 251 |
251 // A map for ServiceWorkers that are associated to a particular document | 252 // A map for ServiceWorkers that are associated to a particular document |
252 // (e.g. as .current). | 253 // (e.g. as .current). |
253 WorkerToProviderMap worker_to_provider_; | 254 WorkerToProviderMap worker_to_provider_; |
254 | 255 |
255 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 256 scoped_refptr<ServiceWorkerMessageSender> sender_; |
256 | 257 |
257 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcher); | 258 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcher); |
258 }; | 259 }; |
259 | 260 |
260 } // namespace content | 261 } // namespace content |
261 | 262 |
262 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ | 263 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ |
OLD | NEW |