| 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 10 matching lines...) Expand all Loading... |
| 21 namespace blink { | 21 namespace blink { |
| 22 class WebURL; | 22 class WebURL; |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace IPC { | 25 namespace IPC { |
| 26 class Message; | 26 class Message; |
| 27 } | 27 } |
| 28 | 28 |
| 29 namespace content { | 29 namespace content { |
| 30 | 30 |
| 31 class ServiceWorkerMessageSender; | 31 class ServiceWorkerMessageFilter; |
| 32 class ServiceWorkerProviderContext; | 32 class ServiceWorkerProviderContext; |
| 33 class ThreadSafeSender; | 33 class ThreadSafeSender; |
| 34 class WebServiceWorkerImpl; | 34 class WebServiceWorkerImpl; |
| 35 class WebServiceWorkerRegistrationImpl; | 35 class WebServiceWorkerRegistrationImpl; |
| 36 struct ServiceWorkerObjectInfo; | 36 struct ServiceWorkerObjectInfo; |
| 37 struct ServiceWorkerRegistrationObjectInfo; | 37 struct ServiceWorkerRegistrationObjectInfo; |
| 38 struct ServiceWorkerVersionAttributes; | 38 struct ServiceWorkerVersionAttributes; |
| 39 struct TransferredMessagePort; | 39 struct TransferredMessagePort; |
| 40 | 40 |
| 41 // This class manages communication with the browser process about | 41 // This class manages communication with the browser process about |
| 42 // registration of the service worker, exposed to renderer and worker | 42 // registration of the service worker, exposed to renderer and worker |
| 43 // scripts through methods like navigator.registerServiceWorker(). | 43 // scripts through methods like navigator.registerServiceWorker(). |
| 44 class CONTENT_EXPORT ServiceWorkerDispatcher | 44 class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { |
| 45 : public WorkerTaskRunner::Observer { | |
| 46 public: | 45 public: |
| 47 typedef blink::WebServiceWorkerProvider::WebServiceWorkerRegistrationCallbacks | 46 typedef blink::WebServiceWorkerProvider::WebServiceWorkerRegistrationCallbacks |
| 48 WebServiceWorkerRegistrationCallbacks; | 47 WebServiceWorkerRegistrationCallbacks; |
| 49 typedef | 48 typedef |
| 50 blink::WebServiceWorkerProvider::WebServiceWorkerUnregistrationCallbacks | 49 blink::WebServiceWorkerProvider::WebServiceWorkerUnregistrationCallbacks |
| 51 WebServiceWorkerUnregistrationCallbacks; | 50 WebServiceWorkerUnregistrationCallbacks; |
| 52 typedef | 51 typedef |
| 53 blink::WebServiceWorkerProvider::WebServiceWorkerGetRegistrationCallbacks | 52 blink::WebServiceWorkerProvider::WebServiceWorkerGetRegistrationCallbacks |
| 54 WebServiceWorkerGetRegistrationCallbacks; | 53 WebServiceWorkerGetRegistrationCallbacks; |
| 55 typedef blink::WebServiceWorkerProvider:: | 54 typedef blink::WebServiceWorkerProvider:: |
| 56 WebServiceWorkerGetRegistrationForReadyCallbacks | 55 WebServiceWorkerGetRegistrationForReadyCallbacks |
| 57 WebServiceWorkerGetRegistrationForReadyCallbacks; | 56 WebServiceWorkerGetRegistrationForReadyCallbacks; |
| 58 | 57 |
| 59 explicit ServiceWorkerDispatcher(ServiceWorkerMessageSender* sender); | 58 explicit ServiceWorkerDispatcher(ThreadSafeSender* thread_safe_sender); |
| 60 ~ServiceWorkerDispatcher() override; | 59 ~ServiceWorkerDispatcher() override; |
| 61 | 60 |
| 62 void OnMessageReceived(const IPC::Message& msg); | 61 void OnMessageReceived(const IPC::Message& msg); |
| 62 bool Send(IPC::Message* msg); |
| 63 | 63 |
| 64 // Corresponds to navigator.serviceWorker.register() | 64 // Corresponds to navigator.serviceWorker.register() |
| 65 void RegisterServiceWorker( | 65 void RegisterServiceWorker( |
| 66 int provider_id, | 66 int provider_id, |
| 67 const GURL& pattern, | 67 const GURL& pattern, |
| 68 const GURL& script_url, | 68 const GURL& script_url, |
| 69 WebServiceWorkerRegistrationCallbacks* callbacks); | 69 WebServiceWorkerRegistrationCallbacks* callbacks); |
| 70 // Corresponds to navigator.serviceWorker.unregister() | 70 // Corresponds to navigator.serviceWorker.unregister() |
| 71 void UnregisterServiceWorker( | 71 void UnregisterServiceWorker( |
| 72 int provider_id, | 72 int provider_id, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 bool adopt_handle); | 113 bool adopt_handle); |
| 114 | 114 |
| 115 // Creates a WebServiceWorkerRegistrationImpl for the specified registration | 115 // Creates a WebServiceWorkerRegistrationImpl for the specified registration |
| 116 // and transfers its ownership to the caller. If |adopt_handle| is true, a | 116 // and transfers its ownership to the caller. If |adopt_handle| is true, a |
| 117 // ServiceWorkerRegistrationHandleReference will be adopted for the | 117 // ServiceWorkerRegistrationHandleReference will be adopted for the |
| 118 // registration. | 118 // registration. |
| 119 WebServiceWorkerRegistrationImpl* CreateServiceWorkerRegistration( | 119 WebServiceWorkerRegistrationImpl* CreateServiceWorkerRegistration( |
| 120 const ServiceWorkerRegistrationObjectInfo& info, | 120 const ServiceWorkerRegistrationObjectInfo& info, |
| 121 bool adopt_handle); | 121 bool adopt_handle); |
| 122 | 122 |
| 123 // |sender| needs to be passed in because if the call leads to construction | 123 // |thread_safe_sender| needs to be passed in because if the call leads to |
| 124 // it will be needed. | 124 // construction it will be needed. |
| 125 static ServiceWorkerDispatcher* GetOrCreateThreadSpecificInstance( | 125 static ServiceWorkerDispatcher* GetOrCreateThreadSpecificInstance( |
| 126 ServiceWorkerMessageSender* sender); | 126 ThreadSafeSender* thread_safe_sender); |
| 127 | 127 |
| 128 // Unlike GetOrCreateThreadSpecificInstance() this doesn't create a new | 128 // Unlike GetOrCreateThreadSpecificInstance() this doesn't create a new |
| 129 // instance if thread-local instance doesn't exist. | 129 // instance if thread-local instance doesn't exist. |
| 130 static ServiceWorkerDispatcher* GetThreadSpecificInstance(); | 130 static ServiceWorkerDispatcher* GetThreadSpecificInstance(); |
| 131 | 131 |
| 132 private: | 132 private: |
| 133 typedef IDMap<WebServiceWorkerRegistrationCallbacks, | 133 typedef IDMap<WebServiceWorkerRegistrationCallbacks, |
| 134 IDMapOwnPointer> RegistrationCallbackMap; | 134 IDMapOwnPointer> RegistrationCallbackMap; |
| 135 typedef IDMap<WebServiceWorkerUnregistrationCallbacks, | 135 typedef IDMap<WebServiceWorkerUnregistrationCallbacks, |
| 136 IDMapOwnPointer> UnregistrationCallbackMap; | 136 IDMapOwnPointer> UnregistrationCallbackMap; |
| 137 typedef IDMap<WebServiceWorkerGetRegistrationCallbacks, | 137 typedef IDMap<WebServiceWorkerGetRegistrationCallbacks, |
| 138 IDMapOwnPointer> GetRegistrationCallbackMap; | 138 IDMapOwnPointer> GetRegistrationCallbackMap; |
| 139 typedef IDMap<WebServiceWorkerGetRegistrationForReadyCallbacks, | 139 typedef IDMap<WebServiceWorkerGetRegistrationForReadyCallbacks, |
| 140 IDMapOwnPointer> GetRegistrationForReadyCallbackMap; | 140 IDMapOwnPointer> GetRegistrationForReadyCallbackMap; |
| 141 | 141 |
| 142 typedef std::map<int, blink::WebServiceWorkerProviderClient*> | 142 typedef std::map<int, blink::WebServiceWorkerProviderClient*> |
| 143 ProviderClientMap; | 143 ProviderClientMap; |
| 144 typedef std::map<int, ServiceWorkerProviderContext*> ProviderContextMap; | 144 typedef std::map<int, ServiceWorkerProviderContext*> ProviderContextMap; |
| 145 typedef std::map<int, ServiceWorkerProviderContext*> WorkerToProviderMap; | 145 typedef std::map<int, ServiceWorkerProviderContext*> WorkerToProviderMap; |
| 146 typedef std::map<int, WebServiceWorkerImpl*> WorkerObjectMap; | 146 typedef std::map<int, WebServiceWorkerImpl*> WorkerObjectMap; |
| 147 typedef std::map<int, WebServiceWorkerRegistrationImpl*> | 147 typedef std::map<int, WebServiceWorkerRegistrationImpl*> |
| 148 RegistrationObjectMap; | 148 RegistrationObjectMap; |
| 149 | 149 |
| 150 friend class ServiceWorkerDispatcherTest; | |
| 151 friend class WebServiceWorkerImpl; | 150 friend class WebServiceWorkerImpl; |
| 152 friend class WebServiceWorkerRegistrationImpl; | 151 friend class WebServiceWorkerRegistrationImpl; |
| 153 | 152 |
| 154 // WorkerTaskRunner::Observer implementation. | 153 // WorkerTaskRunner::Observer implementation. |
| 155 void OnWorkerRunLoopStopped() override; | 154 void OnWorkerRunLoopStopped() override; |
| 156 | 155 |
| 157 void OnAssociateRegistrationWithServiceWorker( | 156 void OnAssociateRegistrationWithServiceWorker( |
| 158 int thread_id, | 157 int thread_id, |
| 159 int provider_id, | 158 int provider_id, |
| 160 const ServiceWorkerRegistrationObjectInfo& info, | 159 const ServiceWorkerRegistrationObjectInfo& info, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 ProviderClientMap provider_clients_; | 242 ProviderClientMap provider_clients_; |
| 244 ProviderContextMap provider_contexts_; | 243 ProviderContextMap provider_contexts_; |
| 245 | 244 |
| 246 WorkerObjectMap service_workers_; | 245 WorkerObjectMap service_workers_; |
| 247 RegistrationObjectMap registrations_; | 246 RegistrationObjectMap registrations_; |
| 248 | 247 |
| 249 // A map for ServiceWorkers that are associated to a particular document | 248 // A map for ServiceWorkers that are associated to a particular document |
| 250 // (e.g. as .current). | 249 // (e.g. as .current). |
| 251 WorkerToProviderMap worker_to_provider_; | 250 WorkerToProviderMap worker_to_provider_; |
| 252 | 251 |
| 253 scoped_refptr<ServiceWorkerMessageSender> sender_; | 252 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
| 254 | 253 |
| 255 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcher); | 254 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcher); |
| 256 }; | 255 }; |
| 257 | 256 |
| 258 } // namespace content | 257 } // namespace content |
| 259 | 258 |
| 260 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ | 259 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ |
| OLD | NEW |