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 |
11 #include "base/id_map.h" | 11 #include "base/id_map.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" |
13 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
14 #include "content/child/worker_task_runner.h" | 15 #include "content/child/worker_task_runner.h" |
15 #include "third_party/WebKit/public/platform/WebServiceWorkerError.h" | 16 #include "third_party/WebKit/public/platform/WebServiceWorkerError.h" |
16 #include "third_party/WebKit/public/platform/WebServiceWorkerProvider.h" | 17 #include "third_party/WebKit/public/platform/WebServiceWorkerProvider.h" |
17 #include "third_party/WebKit/public/platform/WebServiceWorkerState.h" | 18 #include "third_party/WebKit/public/platform/WebServiceWorkerState.h" |
18 | 19 |
19 class GURL; | 20 class GURL; |
20 | 21 |
21 namespace blink { | 22 namespace blink { |
22 class WebURL; | 23 class WebURL; |
(...skipping 20 matching lines...) Expand all Loading... |
43 class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { | 44 class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { |
44 public: | 45 public: |
45 typedef blink::WebServiceWorkerProvider::WebServiceWorkerRegistrationCallbacks | 46 typedef blink::WebServiceWorkerProvider::WebServiceWorkerRegistrationCallbacks |
46 WebServiceWorkerRegistrationCallbacks; | 47 WebServiceWorkerRegistrationCallbacks; |
47 typedef | 48 typedef |
48 blink::WebServiceWorkerProvider::WebServiceWorkerUnregistrationCallbacks | 49 blink::WebServiceWorkerProvider::WebServiceWorkerUnregistrationCallbacks |
49 WebServiceWorkerUnregistrationCallbacks; | 50 WebServiceWorkerUnregistrationCallbacks; |
50 typedef | 51 typedef |
51 blink::WebServiceWorkerProvider::WebServiceWorkerGetRegistrationCallbacks | 52 blink::WebServiceWorkerProvider::WebServiceWorkerGetRegistrationCallbacks |
52 WebServiceWorkerGetRegistrationCallbacks; | 53 WebServiceWorkerGetRegistrationCallbacks; |
| 54 typedef blink::WebServiceWorkerProvider:: |
| 55 WebServiceWorkerGetReadyRegistrationCallbacks |
| 56 WebServiceWorkerGetReadyRegistrationCallbacks; |
53 | 57 |
54 explicit ServiceWorkerDispatcher(ThreadSafeSender* thread_safe_sender); | 58 explicit ServiceWorkerDispatcher(ThreadSafeSender* thread_safe_sender); |
55 ~ServiceWorkerDispatcher() override; | 59 ~ServiceWorkerDispatcher() override; |
56 | 60 |
57 void OnMessageReceived(const IPC::Message& msg); | 61 void OnMessageReceived(const IPC::Message& msg); |
58 bool Send(IPC::Message* msg); | 62 bool Send(IPC::Message* msg); |
59 | 63 |
60 // Corresponds to navigator.serviceWorker.register() | 64 // Corresponds to navigator.serviceWorker.register() |
61 void RegisterServiceWorker( | 65 void RegisterServiceWorker( |
62 int provider_id, | 66 int provider_id, |
63 const GURL& pattern, | 67 const GURL& pattern, |
64 const GURL& script_url, | 68 const GURL& script_url, |
65 WebServiceWorkerRegistrationCallbacks* callbacks); | 69 WebServiceWorkerRegistrationCallbacks* callbacks); |
66 // Corresponds to navigator.serviceWorker.unregister() | 70 // Corresponds to navigator.serviceWorker.unregister() |
67 void UnregisterServiceWorker( | 71 void UnregisterServiceWorker( |
68 int provider_id, | 72 int provider_id, |
69 const GURL& pattern, | 73 const GURL& pattern, |
70 WebServiceWorkerUnregistrationCallbacks* callbacks); | 74 WebServiceWorkerUnregistrationCallbacks* callbacks); |
71 // Corresponds to navigator.serviceWorker.getRegistration() | 75 // Corresponds to navigator.serviceWorker.getRegistration() |
72 void GetRegistration( | 76 void GetRegistration( |
73 int provider_id, | 77 int provider_id, |
74 const GURL& document_url, | 78 const GURL& document_url, |
75 WebServiceWorkerRegistrationCallbacks* callbacks); | 79 WebServiceWorkerRegistrationCallbacks* callbacks); |
76 | 80 |
| 81 void GetReadyRegistration( |
| 82 int provider_id, |
| 83 WebServiceWorkerGetReadyRegistrationCallbacks* callbacks); |
| 84 |
77 // Called when a new provider context for a document is created. Usually | 85 // Called when a new provider context for a document is created. Usually |
78 // this happens when a new document is being loaded, and is called much | 86 // this happens when a new document is being loaded, and is called much |
79 // earlier than AddScriptClient. | 87 // earlier than AddScriptClient. |
80 // (This is attached only to the document thread's ServiceWorkerDispatcher) | 88 // (This is attached only to the document thread's ServiceWorkerDispatcher) |
81 void AddProviderContext(ServiceWorkerProviderContext* provider_context); | 89 void AddProviderContext(ServiceWorkerProviderContext* provider_context); |
82 void RemoveProviderContext(ServiceWorkerProviderContext* provider_context); | 90 void RemoveProviderContext(ServiceWorkerProviderContext* provider_context); |
83 | 91 |
84 // Called when navigator.serviceWorker is instantiated or detached | 92 // Called when navigator.serviceWorker is instantiated or detached |
85 // for a document whose provider can be identified by |provider_id|. | 93 // for a document whose provider can be identified by |provider_id|. |
86 void AddProviderClient(int provider_id, | 94 void AddProviderClient(int provider_id, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 // instance if thread-local instance doesn't exist. | 137 // instance if thread-local instance doesn't exist. |
130 static ServiceWorkerDispatcher* GetThreadSpecificInstance(); | 138 static ServiceWorkerDispatcher* GetThreadSpecificInstance(); |
131 | 139 |
132 private: | 140 private: |
133 typedef IDMap<WebServiceWorkerRegistrationCallbacks, | 141 typedef IDMap<WebServiceWorkerRegistrationCallbacks, |
134 IDMapOwnPointer> RegistrationCallbackMap; | 142 IDMapOwnPointer> RegistrationCallbackMap; |
135 typedef IDMap<WebServiceWorkerUnregistrationCallbacks, | 143 typedef IDMap<WebServiceWorkerUnregistrationCallbacks, |
136 IDMapOwnPointer> UnregistrationCallbackMap; | 144 IDMapOwnPointer> UnregistrationCallbackMap; |
137 typedef IDMap<WebServiceWorkerGetRegistrationCallbacks, | 145 typedef IDMap<WebServiceWorkerGetRegistrationCallbacks, |
138 IDMapOwnPointer> GetRegistrationCallbackMap; | 146 IDMapOwnPointer> GetRegistrationCallbackMap; |
| 147 typedef IDMap<WebServiceWorkerGetReadyRegistrationCallbacks, |
| 148 IDMapOwnPointer> GetReadyRegistrationCallbackMap; |
139 | 149 |
140 typedef std::map<int, blink::WebServiceWorkerProviderClient*> | 150 typedef std::map<int, blink::WebServiceWorkerProviderClient*> |
141 ProviderClientMap; | 151 ProviderClientMap; |
142 typedef std::map<int, ServiceWorkerProviderContext*> ProviderContextMap; | 152 typedef std::map<int, ServiceWorkerProviderContext*> ProviderContextMap; |
143 typedef std::map<int, ServiceWorkerProviderContext*> WorkerToProviderMap; | 153 typedef std::map<int, ServiceWorkerProviderContext*> WorkerToProviderMap; |
144 typedef std::map<int, WebServiceWorkerImpl*> WorkerObjectMap; | 154 typedef std::map<int, WebServiceWorkerImpl*> WorkerObjectMap; |
145 typedef std::map<int, WebServiceWorkerRegistrationImpl*> | 155 typedef std::map<int, WebServiceWorkerRegistrationImpl*> |
146 RegistrationObjectMap; | 156 RegistrationObjectMap; |
147 | 157 |
148 friend class WebServiceWorkerImpl; | 158 friend class WebServiceWorkerImpl; |
(...skipping 17 matching lines...) Expand all Loading... |
166 int request_id, | 176 int request_id, |
167 const ServiceWorkerRegistrationObjectInfo& info, | 177 const ServiceWorkerRegistrationObjectInfo& info, |
168 const ServiceWorkerVersionAttributes& attrs); | 178 const ServiceWorkerVersionAttributes& attrs); |
169 void OnUnregistered(int thread_id, | 179 void OnUnregistered(int thread_id, |
170 int request_id, | 180 int request_id, |
171 bool is_success); | 181 bool is_success); |
172 void OnDidGetRegistration(int thread_id, | 182 void OnDidGetRegistration(int thread_id, |
173 int request_id, | 183 int request_id, |
174 const ServiceWorkerRegistrationObjectInfo& info, | 184 const ServiceWorkerRegistrationObjectInfo& info, |
175 const ServiceWorkerVersionAttributes& attrs); | 185 const ServiceWorkerVersionAttributes& attrs); |
| 186 void OnDidGetReadyRegistration( |
| 187 int thread_id, |
| 188 int request_id, |
| 189 const ServiceWorkerRegistrationObjectInfo& info, |
| 190 const ServiceWorkerVersionAttributes& attrs); |
176 void OnRegistrationError(int thread_id, | 191 void OnRegistrationError(int thread_id, |
177 int request_id, | 192 int request_id, |
178 blink::WebServiceWorkerError::ErrorType error_type, | 193 blink::WebServiceWorkerError::ErrorType error_type, |
179 const base::string16& message); | 194 const base::string16& message); |
180 void OnUnregistrationError(int thread_id, | 195 void OnUnregistrationError(int thread_id, |
181 int request_id, | 196 int request_id, |
182 blink::WebServiceWorkerError::ErrorType error_type, | 197 blink::WebServiceWorkerError::ErrorType error_type, |
183 const base::string16& message); | 198 const base::string16& message); |
184 void OnGetRegistrationError( | 199 void OnGetRegistrationError( |
185 int thread_id, | 200 int thread_id, |
(...skipping 13 matching lines...) Expand all Loading... |
199 void OnSetControllerServiceWorker(int thread_id, | 214 void OnSetControllerServiceWorker(int thread_id, |
200 int provider_id, | 215 int provider_id, |
201 const ServiceWorkerObjectInfo& info, | 216 const ServiceWorkerObjectInfo& info, |
202 bool should_notify_controllerchange); | 217 bool should_notify_controllerchange); |
203 void OnPostMessage(int thread_id, | 218 void OnPostMessage(int thread_id, |
204 int provider_id, | 219 int provider_id, |
205 const base::string16& message, | 220 const base::string16& message, |
206 const std::vector<int>& sent_message_port_ids, | 221 const std::vector<int>& sent_message_port_ids, |
207 const std::vector<int>& new_routing_ids); | 222 const std::vector<int>& new_routing_ids); |
208 | 223 |
209 void SetReadyRegistration( | |
210 int provider_id, | |
211 int registration_handle_id); | |
212 | |
213 // Keeps map from handle_id to ServiceWorker object. | 224 // Keeps map from handle_id to ServiceWorker object. |
214 void AddServiceWorker(int handle_id, WebServiceWorkerImpl* worker); | 225 void AddServiceWorker(int handle_id, WebServiceWorkerImpl* worker); |
215 void RemoveServiceWorker(int handle_id); | 226 void RemoveServiceWorker(int handle_id); |
216 | 227 |
217 // Keeps map from registration_handle_id to ServiceWorkerRegistration object. | 228 // Keeps map from registration_handle_id to ServiceWorkerRegistration object. |
218 void AddServiceWorkerRegistration( | 229 void AddServiceWorkerRegistration( |
219 int registration_handle_id, | 230 int registration_handle_id, |
220 WebServiceWorkerRegistrationImpl* registration); | 231 WebServiceWorkerRegistrationImpl* registration); |
221 void RemoveServiceWorkerRegistration( | 232 void RemoveServiceWorkerRegistration( |
222 int registration_handle_id); | 233 int registration_handle_id); |
223 | 234 |
224 WebServiceWorkerRegistrationImpl* FindOrCreateRegistration( | 235 WebServiceWorkerRegistrationImpl* FindOrCreateRegistration( |
225 const ServiceWorkerRegistrationObjectInfo& info, | 236 const ServiceWorkerRegistrationObjectInfo& info, |
226 const ServiceWorkerVersionAttributes& attrs); | 237 const ServiceWorkerVersionAttributes& attrs); |
227 | 238 |
228 RegistrationCallbackMap pending_registration_callbacks_; | 239 RegistrationCallbackMap pending_registration_callbacks_; |
229 UnregistrationCallbackMap pending_unregistration_callbacks_; | 240 UnregistrationCallbackMap pending_unregistration_callbacks_; |
230 GetRegistrationCallbackMap pending_get_registration_callbacks_; | 241 GetRegistrationCallbackMap pending_get_registration_callbacks_; |
| 242 GetReadyRegistrationCallbackMap ready_registration_callbacks_; |
231 | 243 |
232 ProviderClientMap provider_clients_; | 244 ProviderClientMap provider_clients_; |
233 ProviderContextMap provider_contexts_; | 245 ProviderContextMap provider_contexts_; |
234 | 246 |
235 WorkerObjectMap service_workers_; | 247 WorkerObjectMap service_workers_; |
236 RegistrationObjectMap registrations_; | 248 RegistrationObjectMap registrations_; |
237 | 249 |
238 // A map for ServiceWorkers that are associated to a particular document | 250 // A map for ServiceWorkers that are associated to a particular document |
239 // (e.g. as .current). | 251 // (e.g. as .current). |
240 WorkerToProviderMap worker_to_provider_; | 252 WorkerToProviderMap worker_to_provider_; |
241 | 253 |
242 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 254 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
243 | 255 |
244 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcher); | 256 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcher); |
245 }; | 257 }; |
246 | 258 |
247 } // namespace content | 259 } // namespace content |
248 | 260 |
249 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ | 261 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ |
OLD | NEW |