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