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