| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/id_map.h" | 14 #include "base/id_map.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
| 18 #include "content/public/child/worker_thread.h" | 18 #include "content/public/child/worker_thread.h" |
| 19 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
ker.h" |
| 19 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerError.h" | 20 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerError.h" |
| 20 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerProvider.h" | 21 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerProvider.h" |
| 21 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerRegistration.h" | 22 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerRegistration.h" |
| 22 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerState.h" | 23 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerState.h" |
| 23 | 24 |
| 24 class GURL; | 25 class GURL; |
| 25 | 26 |
| 26 namespace base { | 27 namespace base { |
| 27 class SingleThreadTaskRunner; | 28 class SingleThreadTaskRunner; |
| 28 } | 29 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 WebServiceWorkerUnregistrationCallbacks; | 61 WebServiceWorkerUnregistrationCallbacks; |
| 61 typedef | 62 typedef |
| 62 blink::WebServiceWorkerProvider::WebServiceWorkerGetRegistrationCallbacks | 63 blink::WebServiceWorkerProvider::WebServiceWorkerGetRegistrationCallbacks |
| 63 WebServiceWorkerGetRegistrationCallbacks; | 64 WebServiceWorkerGetRegistrationCallbacks; |
| 64 typedef | 65 typedef |
| 65 blink::WebServiceWorkerProvider::WebServiceWorkerGetRegistrationsCallbacks | 66 blink::WebServiceWorkerProvider::WebServiceWorkerGetRegistrationsCallbacks |
| 66 WebServiceWorkerGetRegistrationsCallbacks; | 67 WebServiceWorkerGetRegistrationsCallbacks; |
| 67 typedef blink::WebServiceWorkerProvider:: | 68 typedef blink::WebServiceWorkerProvider:: |
| 68 WebServiceWorkerGetRegistrationForReadyCallbacks | 69 WebServiceWorkerGetRegistrationForReadyCallbacks |
| 69 WebServiceWorkerGetRegistrationForReadyCallbacks; | 70 WebServiceWorkerGetRegistrationForReadyCallbacks; |
| 71 using WebSetNavigationPreloadCallbacks = |
| 72 blink::WebServiceWorker::WebSetNavigationPreloadCallbacks; |
| 73 using WebGetNavigationPreloadCallbacks = |
| 74 blink::WebServiceWorker::WebGetNavigationPreloadCallbacks; |
| 70 | 75 |
| 71 ServiceWorkerDispatcher( | 76 ServiceWorkerDispatcher( |
| 72 ThreadSafeSender* thread_safe_sender, | 77 ThreadSafeSender* thread_safe_sender, |
| 73 base::SingleThreadTaskRunner* main_thread_task_runner); | 78 base::SingleThreadTaskRunner* main_thread_task_runner); |
| 74 ~ServiceWorkerDispatcher() override; | 79 ~ServiceWorkerDispatcher() override; |
| 75 | 80 |
| 76 void OnMessageReceived(const IPC::Message& msg); | 81 void OnMessageReceived(const IPC::Message& msg); |
| 77 | 82 |
| 78 // Corresponds to navigator.serviceWorker.register(). | 83 // Corresponds to navigator.serviceWorker.register(). |
| 79 void RegisterServiceWorker( | 84 void RegisterServiceWorker( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 96 WebServiceWorkerGetRegistrationCallbacks* callbacks); | 101 WebServiceWorkerGetRegistrationCallbacks* callbacks); |
| 97 // Corresponds to navigator.serviceWorker.getRegistrations(). | 102 // Corresponds to navigator.serviceWorker.getRegistrations(). |
| 98 void GetRegistrations( | 103 void GetRegistrations( |
| 99 int provider_id, | 104 int provider_id, |
| 100 WebServiceWorkerGetRegistrationsCallbacks* callbacks); | 105 WebServiceWorkerGetRegistrationsCallbacks* callbacks); |
| 101 | 106 |
| 102 void GetRegistrationForReady( | 107 void GetRegistrationForReady( |
| 103 int provider_id, | 108 int provider_id, |
| 104 WebServiceWorkerGetRegistrationForReadyCallbacks* callbacks); | 109 WebServiceWorkerGetRegistrationForReadyCallbacks* callbacks); |
| 105 | 110 |
| 111 void SetNavigationPreload(int handle_id, |
| 112 const std::string& value, |
| 113 WebSetNavigationPreloadCallbacks* callback); |
| 114 void GetNavigationPreload(int handle_id, |
| 115 WebGetNavigationPreloadCallbacks* callback); |
| 116 |
| 106 // Called when a new provider context for a document is created. Usually | 117 // Called when a new provider context for a document is created. Usually |
| 107 // this happens when a new document is being loaded, and is called much | 118 // this happens when a new document is being loaded, and is called much |
| 108 // earlier than AddScriptClient. | 119 // earlier than AddScriptClient. |
| 109 // (This is attached only to the document thread's ServiceWorkerDispatcher) | 120 // (This is attached only to the document thread's ServiceWorkerDispatcher) |
| 110 void AddProviderContext(ServiceWorkerProviderContext* provider_context); | 121 void AddProviderContext(ServiceWorkerProviderContext* provider_context); |
| 111 void RemoveProviderContext(ServiceWorkerProviderContext* provider_context); | 122 void RemoveProviderContext(ServiceWorkerProviderContext* provider_context); |
| 112 | 123 |
| 113 // Called when navigator.serviceWorker is instantiated or detached | 124 // Called when navigator.serviceWorker is instantiated or detached |
| 114 // for a document whose provider can be identified by |provider_id|. | 125 // for a document whose provider can be identified by |provider_id|. |
| 115 void AddProviderClient(int provider_id, | 126 void AddProviderClient(int provider_id, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 typedef IDMap<WebServiceWorkerUpdateCallbacks, IDMapOwnPointer> | 164 typedef IDMap<WebServiceWorkerUpdateCallbacks, IDMapOwnPointer> |
| 154 UpdateCallbackMap; | 165 UpdateCallbackMap; |
| 155 typedef IDMap<WebServiceWorkerUnregistrationCallbacks, | 166 typedef IDMap<WebServiceWorkerUnregistrationCallbacks, |
| 156 IDMapOwnPointer> UnregistrationCallbackMap; | 167 IDMapOwnPointer> UnregistrationCallbackMap; |
| 157 typedef IDMap<WebServiceWorkerGetRegistrationCallbacks, | 168 typedef IDMap<WebServiceWorkerGetRegistrationCallbacks, |
| 158 IDMapOwnPointer> GetRegistrationCallbackMap; | 169 IDMapOwnPointer> GetRegistrationCallbackMap; |
| 159 typedef IDMap<WebServiceWorkerGetRegistrationsCallbacks, | 170 typedef IDMap<WebServiceWorkerGetRegistrationsCallbacks, |
| 160 IDMapOwnPointer> GetRegistrationsCallbackMap; | 171 IDMapOwnPointer> GetRegistrationsCallbackMap; |
| 161 typedef IDMap<WebServiceWorkerGetRegistrationForReadyCallbacks, | 172 typedef IDMap<WebServiceWorkerGetRegistrationForReadyCallbacks, |
| 162 IDMapOwnPointer> GetRegistrationForReadyCallbackMap; | 173 IDMapOwnPointer> GetRegistrationForReadyCallbackMap; |
| 174 using GetNavigationPreloadCallbackMap = |
| 175 IDMap<WebGetNavigationPreloadCallbacks, IDMapOwnPointer>; |
| 176 using SetNavigationPreloadCallbackMap = |
| 177 IDMap<WebSetNavigationPreloadCallbacks, IDMapOwnPointer>; |
| 163 | 178 |
| 164 typedef std::map<int, blink::WebServiceWorkerProviderClient*> | 179 typedef std::map<int, blink::WebServiceWorkerProviderClient*> |
| 165 ProviderClientMap; | 180 ProviderClientMap; |
| 166 typedef std::map<int, ServiceWorkerProviderContext*> ProviderContextMap; | 181 typedef std::map<int, ServiceWorkerProviderContext*> ProviderContextMap; |
| 167 typedef std::map<int, ServiceWorkerProviderContext*> WorkerToProviderMap; | 182 typedef std::map<int, ServiceWorkerProviderContext*> WorkerToProviderMap; |
| 168 typedef std::map<int, WebServiceWorkerImpl*> WorkerObjectMap; | 183 typedef std::map<int, WebServiceWorkerImpl*> WorkerObjectMap; |
| 169 typedef std::map<int, WebServiceWorkerRegistrationImpl*> | 184 typedef std::map<int, WebServiceWorkerRegistrationImpl*> |
| 170 RegistrationObjectMap; | 185 RegistrationObjectMap; |
| 171 | 186 |
| 172 friend class ServiceWorkerDispatcherTest; | 187 friend class ServiceWorkerDispatcherTest; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 197 void OnDidGetRegistrations( | 212 void OnDidGetRegistrations( |
| 198 int thread_id, | 213 int thread_id, |
| 199 int request_id, | 214 int request_id, |
| 200 const std::vector<ServiceWorkerRegistrationObjectInfo>& infos, | 215 const std::vector<ServiceWorkerRegistrationObjectInfo>& infos, |
| 201 const std::vector<ServiceWorkerVersionAttributes>& attrs); | 216 const std::vector<ServiceWorkerVersionAttributes>& attrs); |
| 202 void OnDidGetRegistrationForReady( | 217 void OnDidGetRegistrationForReady( |
| 203 int thread_id, | 218 int thread_id, |
| 204 int request_id, | 219 int request_id, |
| 205 const ServiceWorkerRegistrationObjectInfo& info, | 220 const ServiceWorkerRegistrationObjectInfo& info, |
| 206 const ServiceWorkerVersionAttributes& attrs); | 221 const ServiceWorkerVersionAttributes& attrs); |
| 222 void OnDidGetNavigationPreload(int thread_id, |
| 223 int request_id, |
| 224 bool is_enabled, |
| 225 const std::string& value); |
| 226 void OnDidSetNavigationPreload(int thread_id, int request_id); |
| 207 void OnRegistrationError(int thread_id, | 227 void OnRegistrationError(int thread_id, |
| 208 int request_id, | 228 int request_id, |
| 209 blink::WebServiceWorkerError::ErrorType error_type, | 229 blink::WebServiceWorkerError::ErrorType error_type, |
| 210 const base::string16& message); | 230 const base::string16& message); |
| 211 void OnUpdateError(int thread_id, | 231 void OnUpdateError(int thread_id, |
| 212 int request_id, | 232 int request_id, |
| 213 blink::WebServiceWorkerError::ErrorType error_type, | 233 blink::WebServiceWorkerError::ErrorType error_type, |
| 214 const base::string16& message); | 234 const base::string16& message); |
| 215 void OnUnregistrationError(int thread_id, | 235 void OnUnregistrationError(int thread_id, |
| 216 int request_id, | 236 int request_id, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 const ServiceWorkerRegistrationObjectInfo& info); | 278 const ServiceWorkerRegistrationObjectInfo& info); |
| 259 std::unique_ptr<ServiceWorkerHandleReference> Adopt( | 279 std::unique_ptr<ServiceWorkerHandleReference> Adopt( |
| 260 const ServiceWorkerObjectInfo& info); | 280 const ServiceWorkerObjectInfo& info); |
| 261 | 281 |
| 262 RegistrationCallbackMap pending_registration_callbacks_; | 282 RegistrationCallbackMap pending_registration_callbacks_; |
| 263 UpdateCallbackMap pending_update_callbacks_; | 283 UpdateCallbackMap pending_update_callbacks_; |
| 264 UnregistrationCallbackMap pending_unregistration_callbacks_; | 284 UnregistrationCallbackMap pending_unregistration_callbacks_; |
| 265 GetRegistrationCallbackMap pending_get_registration_callbacks_; | 285 GetRegistrationCallbackMap pending_get_registration_callbacks_; |
| 266 GetRegistrationsCallbackMap pending_get_registrations_callbacks_; | 286 GetRegistrationsCallbackMap pending_get_registrations_callbacks_; |
| 267 GetRegistrationForReadyCallbackMap get_for_ready_callbacks_; | 287 GetRegistrationForReadyCallbackMap get_for_ready_callbacks_; |
| 288 GetNavigationPreloadCallbackMap pending_get_navigation_preload_callbacks_; |
| 289 SetNavigationPreloadCallbackMap pending_set_navigation_preload_callbacks_; |
| 268 | 290 |
| 269 ProviderClientMap provider_clients_; | 291 ProviderClientMap provider_clients_; |
| 270 ProviderContextMap provider_contexts_; | 292 ProviderContextMap provider_contexts_; |
| 271 | 293 |
| 272 WorkerObjectMap service_workers_; | 294 WorkerObjectMap service_workers_; |
| 273 RegistrationObjectMap registrations_; | 295 RegistrationObjectMap registrations_; |
| 274 | 296 |
| 275 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 297 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
| 276 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | 298 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
| 277 | 299 |
| 278 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcher); | 300 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcher); |
| 279 }; | 301 }; |
| 280 | 302 |
| 281 } // namespace content | 303 } // namespace content |
| 282 | 304 |
| 283 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ | 305 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ |
| OLD | NEW |