| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 struct ServiceWorkerVersionAttributes; | 45 struct ServiceWorkerVersionAttributes; |
| 46 | 46 |
| 47 // This class manages communication with the browser process about | 47 // This class manages communication with the browser process about |
| 48 // registration of the service worker, exposed to renderer and worker | 48 // registration of the service worker, exposed to renderer and worker |
| 49 // scripts through methods like navigator.registerServiceWorker(). | 49 // scripts through methods like navigator.registerServiceWorker(). |
| 50 class CONTENT_EXPORT ServiceWorkerDispatcher | 50 class CONTENT_EXPORT ServiceWorkerDispatcher |
| 51 : public WorkerTaskRunner::Observer { | 51 : public WorkerTaskRunner::Observer { |
| 52 public: | 52 public: |
| 53 typedef blink::WebServiceWorkerProvider::WebServiceWorkerRegistrationCallbacks | 53 typedef blink::WebServiceWorkerProvider::WebServiceWorkerRegistrationCallbacks |
| 54 WebServiceWorkerRegistrationCallbacks; | 54 WebServiceWorkerRegistrationCallbacks; |
| 55 typedef blink::WebServiceWorkerRegistration::WebServiceWorkerUpdateCallbacks |
| 56 WebServiceWorkerUpdateCallbacks; |
| 55 typedef blink::WebServiceWorkerRegistration:: | 57 typedef blink::WebServiceWorkerRegistration:: |
| 56 WebServiceWorkerUnregistrationCallbacks | 58 WebServiceWorkerUnregistrationCallbacks |
| 57 WebServiceWorkerUnregistrationCallbacks; | 59 WebServiceWorkerUnregistrationCallbacks; |
| 58 typedef | 60 typedef |
| 59 blink::WebServiceWorkerProvider::WebServiceWorkerGetRegistrationCallbacks | 61 blink::WebServiceWorkerProvider::WebServiceWorkerGetRegistrationCallbacks |
| 60 WebServiceWorkerGetRegistrationCallbacks; | 62 WebServiceWorkerGetRegistrationCallbacks; |
| 61 typedef | 63 typedef |
| 62 blink::WebServiceWorkerProvider::WebServiceWorkerGetRegistrationsCallbacks | 64 blink::WebServiceWorkerProvider::WebServiceWorkerGetRegistrationsCallbacks |
| 63 WebServiceWorkerGetRegistrationsCallbacks; | 65 WebServiceWorkerGetRegistrationsCallbacks; |
| 64 typedef blink::WebServiceWorkerProvider:: | 66 typedef blink::WebServiceWorkerProvider:: |
| 65 WebServiceWorkerGetRegistrationForReadyCallbacks | 67 WebServiceWorkerGetRegistrationForReadyCallbacks |
| 66 WebServiceWorkerGetRegistrationForReadyCallbacks; | 68 WebServiceWorkerGetRegistrationForReadyCallbacks; |
| 67 | 69 |
| 68 ServiceWorkerDispatcher( | 70 ServiceWorkerDispatcher( |
| 69 ThreadSafeSender* thread_safe_sender, | 71 ThreadSafeSender* thread_safe_sender, |
| 70 base::SingleThreadTaskRunner* main_thread_task_runner); | 72 base::SingleThreadTaskRunner* main_thread_task_runner); |
| 71 ~ServiceWorkerDispatcher() override; | 73 ~ServiceWorkerDispatcher() override; |
| 72 | 74 |
| 73 void OnMessageReceived(const IPC::Message& msg); | 75 void OnMessageReceived(const IPC::Message& msg); |
| 74 bool Send(IPC::Message* msg); | 76 bool Send(IPC::Message* msg); |
| 75 | 77 |
| 76 // Corresponds to navigator.serviceWorker.register(). | 78 // Corresponds to navigator.serviceWorker.register(). |
| 77 void RegisterServiceWorker( | 79 void RegisterServiceWorker( |
| 78 int provider_id, | 80 int provider_id, |
| 79 const GURL& pattern, | 81 const GURL& pattern, |
| 80 const GURL& script_url, | 82 const GURL& script_url, |
| 81 WebServiceWorkerRegistrationCallbacks* callbacks); | 83 WebServiceWorkerRegistrationCallbacks* callbacks); |
| 82 // Corresponds to ServiceWorkerRegistration.update(). | 84 // Corresponds to ServiceWorkerRegistration.update(). |
| 83 void UpdateServiceWorker(int provider_id, int64 registration_id); | 85 void UpdateServiceWorker(int provider_id, |
| 86 int64 registration_id, |
| 87 WebServiceWorkerUpdateCallbacks* callbacks); |
| 84 // Corresponds to ServiceWorkerRegistration.unregister(). | 88 // Corresponds to ServiceWorkerRegistration.unregister(). |
| 85 void UnregisterServiceWorker( | 89 void UnregisterServiceWorker( |
| 86 int provider_id, | 90 int provider_id, |
| 87 int64 registration_id, | 91 int64 registration_id, |
| 88 WebServiceWorkerUnregistrationCallbacks* callbacks); | 92 WebServiceWorkerUnregistrationCallbacks* callbacks); |
| 89 // Corresponds to navigator.serviceWorker.getRegistration(). | 93 // Corresponds to navigator.serviceWorker.getRegistration(). |
| 90 void GetRegistration( | 94 void GetRegistration( |
| 91 int provider_id, | 95 int provider_id, |
| 92 const GURL& document_url, | 96 const GURL& document_url, |
| 93 WebServiceWorkerRegistrationCallbacks* callbacks); | 97 WebServiceWorkerRegistrationCallbacks* callbacks); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 // instance if thread-local instance doesn't exist. | 150 // instance if thread-local instance doesn't exist. |
| 147 static ServiceWorkerDispatcher* GetThreadSpecificInstance(); | 151 static ServiceWorkerDispatcher* GetThreadSpecificInstance(); |
| 148 | 152 |
| 149 base::SingleThreadTaskRunner* main_thread_task_runner() { | 153 base::SingleThreadTaskRunner* main_thread_task_runner() { |
| 150 return main_thread_task_runner_.get(); | 154 return main_thread_task_runner_.get(); |
| 151 } | 155 } |
| 152 | 156 |
| 153 private: | 157 private: |
| 154 typedef IDMap<WebServiceWorkerRegistrationCallbacks, | 158 typedef IDMap<WebServiceWorkerRegistrationCallbacks, |
| 155 IDMapOwnPointer> RegistrationCallbackMap; | 159 IDMapOwnPointer> RegistrationCallbackMap; |
| 160 typedef IDMap<WebServiceWorkerUpdateCallbacks, IDMapOwnPointer> |
| 161 UpdateCallbackMap; |
| 156 typedef IDMap<WebServiceWorkerUnregistrationCallbacks, | 162 typedef IDMap<WebServiceWorkerUnregistrationCallbacks, |
| 157 IDMapOwnPointer> UnregistrationCallbackMap; | 163 IDMapOwnPointer> UnregistrationCallbackMap; |
| 158 typedef IDMap<WebServiceWorkerGetRegistrationCallbacks, | 164 typedef IDMap<WebServiceWorkerGetRegistrationCallbacks, |
| 159 IDMapOwnPointer> GetRegistrationCallbackMap; | 165 IDMapOwnPointer> GetRegistrationCallbackMap; |
| 160 typedef IDMap<WebServiceWorkerGetRegistrationsCallbacks, | 166 typedef IDMap<WebServiceWorkerGetRegistrationsCallbacks, |
| 161 IDMapOwnPointer> GetRegistrationsCallbackMap; | 167 IDMapOwnPointer> GetRegistrationsCallbackMap; |
| 162 typedef IDMap<WebServiceWorkerGetRegistrationForReadyCallbacks, | 168 typedef IDMap<WebServiceWorkerGetRegistrationForReadyCallbacks, |
| 163 IDMapOwnPointer> GetRegistrationForReadyCallbackMap; | 169 IDMapOwnPointer> GetRegistrationForReadyCallbackMap; |
| 164 | 170 |
| 165 typedef std::map<int, blink::WebServiceWorkerProviderClient*> | 171 typedef std::map<int, blink::WebServiceWorkerProviderClient*> |
| (...skipping 19 matching lines...) Expand all Loading... |
| 185 void OnAssociateRegistration(int thread_id, | 191 void OnAssociateRegistration(int thread_id, |
| 186 int provider_id, | 192 int provider_id, |
| 187 const ServiceWorkerRegistrationObjectInfo& info, | 193 const ServiceWorkerRegistrationObjectInfo& info, |
| 188 const ServiceWorkerVersionAttributes& attrs); | 194 const ServiceWorkerVersionAttributes& attrs); |
| 189 void OnDisassociateRegistration(int thread_id, | 195 void OnDisassociateRegistration(int thread_id, |
| 190 int provider_id); | 196 int provider_id); |
| 191 void OnRegistered(int thread_id, | 197 void OnRegistered(int thread_id, |
| 192 int request_id, | 198 int request_id, |
| 193 const ServiceWorkerRegistrationObjectInfo& info, | 199 const ServiceWorkerRegistrationObjectInfo& info, |
| 194 const ServiceWorkerVersionAttributes& attrs); | 200 const ServiceWorkerVersionAttributes& attrs); |
| 201 void OnUpdated(int thread_id, int request_id); |
| 195 void OnUnregistered(int thread_id, | 202 void OnUnregistered(int thread_id, |
| 196 int request_id, | 203 int request_id, |
| 197 bool is_success); | 204 bool is_success); |
| 198 void OnDidGetRegistration(int thread_id, | 205 void OnDidGetRegistration(int thread_id, |
| 199 int request_id, | 206 int request_id, |
| 200 const ServiceWorkerRegistrationObjectInfo& info, | 207 const ServiceWorkerRegistrationObjectInfo& info, |
| 201 const ServiceWorkerVersionAttributes& attrs); | 208 const ServiceWorkerVersionAttributes& attrs); |
| 202 void OnDidGetRegistrations( | 209 void OnDidGetRegistrations( |
| 203 int thread_id, | 210 int thread_id, |
| 204 int request_id, | 211 int request_id, |
| 205 const std::vector<ServiceWorkerRegistrationObjectInfo>& infos, | 212 const std::vector<ServiceWorkerRegistrationObjectInfo>& infos, |
| 206 const std::vector<ServiceWorkerVersionAttributes>& attrs); | 213 const std::vector<ServiceWorkerVersionAttributes>& attrs); |
| 207 void OnDidGetRegistrationForReady( | 214 void OnDidGetRegistrationForReady( |
| 208 int thread_id, | 215 int thread_id, |
| 209 int request_id, | 216 int request_id, |
| 210 const ServiceWorkerRegistrationObjectInfo& info, | 217 const ServiceWorkerRegistrationObjectInfo& info, |
| 211 const ServiceWorkerVersionAttributes& attrs); | 218 const ServiceWorkerVersionAttributes& attrs); |
| 212 void OnRegistrationError(int thread_id, | 219 void OnRegistrationError(int thread_id, |
| 213 int request_id, | 220 int request_id, |
| 214 blink::WebServiceWorkerError::ErrorType error_type, | 221 blink::WebServiceWorkerError::ErrorType error_type, |
| 215 const base::string16& message); | 222 const base::string16& message); |
| 223 void OnUpdateError(int thread_id, |
| 224 int request_id, |
| 225 blink::WebServiceWorkerError::ErrorType error_type, |
| 226 const base::string16& message); |
| 216 void OnUnregistrationError(int thread_id, | 227 void OnUnregistrationError(int thread_id, |
| 217 int request_id, | 228 int request_id, |
| 218 blink::WebServiceWorkerError::ErrorType error_type, | 229 blink::WebServiceWorkerError::ErrorType error_type, |
| 219 const base::string16& message); | 230 const base::string16& message); |
| 220 void OnGetRegistrationError( | 231 void OnGetRegistrationError( |
| 221 int thread_id, | 232 int thread_id, |
| 222 int request_id, | 233 int request_id, |
| 223 blink::WebServiceWorkerError::ErrorType error_type, | 234 blink::WebServiceWorkerError::ErrorType error_type, |
| 224 const base::string16& message); | 235 const base::string16& message); |
| 225 void OnGetRegistrationsError( | 236 void OnGetRegistrationsError( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 // Returns an existing registration or new one filled in with version | 268 // Returns an existing registration or new one filled in with version |
| 258 // attributes. This function assumes given |info| and |attrs| retain handle | 269 // attributes. This function assumes given |info| and |attrs| retain handle |
| 259 // references and always adopts them. | 270 // references and always adopts them. |
| 260 // TODO(nhiroki): This assumption seems to impair readability. We could | 271 // TODO(nhiroki): This assumption seems to impair readability. We could |
| 261 // explictly pass ServiceWorker(Registration)HandleReference instead. | 272 // explictly pass ServiceWorker(Registration)HandleReference instead. |
| 262 WebServiceWorkerRegistrationImpl* FindOrCreateRegistration( | 273 WebServiceWorkerRegistrationImpl* FindOrCreateRegistration( |
| 263 const ServiceWorkerRegistrationObjectInfo& info, | 274 const ServiceWorkerRegistrationObjectInfo& info, |
| 264 const ServiceWorkerVersionAttributes& attrs); | 275 const ServiceWorkerVersionAttributes& attrs); |
| 265 | 276 |
| 266 RegistrationCallbackMap pending_registration_callbacks_; | 277 RegistrationCallbackMap pending_registration_callbacks_; |
| 278 UpdateCallbackMap pending_update_callbacks_; |
| 267 UnregistrationCallbackMap pending_unregistration_callbacks_; | 279 UnregistrationCallbackMap pending_unregistration_callbacks_; |
| 268 GetRegistrationCallbackMap pending_get_registration_callbacks_; | 280 GetRegistrationCallbackMap pending_get_registration_callbacks_; |
| 269 GetRegistrationsCallbackMap pending_get_registrations_callbacks_; | 281 GetRegistrationsCallbackMap pending_get_registrations_callbacks_; |
| 270 GetRegistrationForReadyCallbackMap get_for_ready_callbacks_; | 282 GetRegistrationForReadyCallbackMap get_for_ready_callbacks_; |
| 271 | 283 |
| 272 ProviderClientMap provider_clients_; | 284 ProviderClientMap provider_clients_; |
| 273 ProviderContextMap provider_contexts_; | 285 ProviderContextMap provider_contexts_; |
| 274 | 286 |
| 275 WorkerObjectMap service_workers_; | 287 WorkerObjectMap service_workers_; |
| 276 RegistrationObjectMap registrations_; | 288 RegistrationObjectMap registrations_; |
| 277 | 289 |
| 278 // A map for ServiceWorkers that are associated to a particular document | 290 // A map for ServiceWorkers that are associated to a particular document |
| 279 // (e.g. as .current). | 291 // (e.g. as .current). |
| 280 WorkerToProviderMap worker_to_provider_; | 292 WorkerToProviderMap worker_to_provider_; |
| 281 | 293 |
| 282 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 294 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
| 283 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | 295 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
| 284 | 296 |
| 285 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcher); | 297 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcher); |
| 286 }; | 298 }; |
| 287 | 299 |
| 288 } // namespace content | 300 } // namespace content |
| 289 | 301 |
| 290 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ | 302 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ |
| OLD | NEW |