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 26 matching lines...) Expand all Loading... |
37 struct ServiceWorkerRegistrationObjectInfo; | 37 struct ServiceWorkerRegistrationObjectInfo; |
38 struct ServiceWorkerVersionAttributes; | 38 struct ServiceWorkerVersionAttributes; |
39 | 39 |
40 // This class manages communication with the browser process about | 40 // This class manages communication with the browser process about |
41 // registration of the service worker, exposed to renderer and worker | 41 // registration of the service worker, exposed to renderer and worker |
42 // scripts through methods like navigator.registerServiceWorker(). | 42 // scripts through methods like navigator.registerServiceWorker(). |
43 class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { | 43 class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { |
44 public: | 44 public: |
45 typedef blink::WebServiceWorkerProvider::WebServiceWorkerRegistrationCallbacks | 45 typedef blink::WebServiceWorkerProvider::WebServiceWorkerRegistrationCallbacks |
46 WebServiceWorkerRegistrationCallbacks; | 46 WebServiceWorkerRegistrationCallbacks; |
| 47 typedef |
| 48 blink::WebServiceWorkerProvider::WebServiceWorkerUnregistrationCallbacks |
| 49 WebServiceWorkerUnregistrationCallbacks; |
47 | 50 |
48 explicit ServiceWorkerDispatcher(ThreadSafeSender* thread_safe_sender); | 51 explicit ServiceWorkerDispatcher(ThreadSafeSender* thread_safe_sender); |
49 virtual ~ServiceWorkerDispatcher(); | 52 virtual ~ServiceWorkerDispatcher(); |
50 | 53 |
51 void OnMessageReceived(const IPC::Message& msg); | 54 void OnMessageReceived(const IPC::Message& msg); |
52 bool Send(IPC::Message* msg); | 55 bool Send(IPC::Message* msg); |
53 | 56 |
54 // Corresponds to navigator.serviceWorker.register() | 57 // Corresponds to navigator.serviceWorker.register() |
55 void RegisterServiceWorker( | 58 void RegisterServiceWorker( |
56 int provider_id, | 59 int provider_id, |
57 const GURL& pattern, | 60 const GURL& pattern, |
58 const GURL& script_url, | 61 const GURL& script_url, |
59 WebServiceWorkerRegistrationCallbacks* callbacks); | 62 WebServiceWorkerRegistrationCallbacks* callbacks); |
60 // Corresponds to navigator.serviceWorker.unregister() | 63 // Corresponds to navigator.serviceWorker.unregister() |
61 void UnregisterServiceWorker( | 64 void UnregisterServiceWorker( |
62 int provider_id, | 65 int provider_id, |
63 const GURL& pattern, | 66 const GURL& pattern, |
64 WebServiceWorkerRegistrationCallbacks* callbacks); | 67 WebServiceWorkerUnregistrationCallbacks* callbacks); |
65 | 68 |
66 // Called when a new provider context for a document is created. Usually | 69 // Called when a new provider context for a document is created. Usually |
67 // this happens when a new document is being loaded, and is called much | 70 // this happens when a new document is being loaded, and is called much |
68 // earlier than AddScriptClient. | 71 // earlier than AddScriptClient. |
69 // (This is attached only to the document thread's ServiceWorkerDispatcher) | 72 // (This is attached only to the document thread's ServiceWorkerDispatcher) |
70 void AddProviderContext(ServiceWorkerProviderContext* provider_context); | 73 void AddProviderContext(ServiceWorkerProviderContext* provider_context); |
71 void RemoveProviderContext(ServiceWorkerProviderContext* provider_context); | 74 void RemoveProviderContext(ServiceWorkerProviderContext* provider_context); |
72 | 75 |
73 // Called when navigator.serviceWorker is instantiated or detached | 76 // Called when navigator.serviceWorker is instantiated or detached |
74 // for a document whose provider can be identified by |provider_id|. | 77 // for a document whose provider can be identified by |provider_id|. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 // construction it will be needed. | 109 // construction it will be needed. |
107 static ServiceWorkerDispatcher* GetOrCreateThreadSpecificInstance( | 110 static ServiceWorkerDispatcher* GetOrCreateThreadSpecificInstance( |
108 ThreadSafeSender* thread_safe_sender); | 111 ThreadSafeSender* thread_safe_sender); |
109 | 112 |
110 // Unlike GetOrCreateThreadSpecificInstance() this doesn't create a new | 113 // Unlike GetOrCreateThreadSpecificInstance() this doesn't create a new |
111 // instance if thread-local instance doesn't exist. | 114 // instance if thread-local instance doesn't exist. |
112 static ServiceWorkerDispatcher* GetThreadSpecificInstance(); | 115 static ServiceWorkerDispatcher* GetThreadSpecificInstance(); |
113 | 116 |
114 private: | 117 private: |
115 typedef IDMap<WebServiceWorkerRegistrationCallbacks, | 118 typedef IDMap<WebServiceWorkerRegistrationCallbacks, |
116 IDMapOwnPointer> CallbackMap; | 119 IDMapOwnPointer> RegistrationCallbackMap; |
| 120 typedef IDMap<WebServiceWorkerUnregistrationCallbacks, |
| 121 IDMapOwnPointer> UnregistrationCallbackMap; |
117 typedef std::map<int, blink::WebServiceWorkerProviderClient*> ScriptClientMap; | 122 typedef std::map<int, blink::WebServiceWorkerProviderClient*> ScriptClientMap; |
118 typedef std::map<int, ServiceWorkerProviderContext*> ProviderContextMap; | 123 typedef std::map<int, ServiceWorkerProviderContext*> ProviderContextMap; |
119 typedef std::map<int, WebServiceWorkerImpl*> WorkerObjectMap; | 124 typedef std::map<int, WebServiceWorkerImpl*> WorkerObjectMap; |
120 typedef std::map<int, ServiceWorkerProviderContext*> WorkerToProviderMap; | 125 typedef std::map<int, ServiceWorkerProviderContext*> WorkerToProviderMap; |
121 typedef std::map<int, WebServiceWorkerRegistrationImpl*> | 126 typedef std::map<int, WebServiceWorkerRegistrationImpl*> |
122 RegistrationObjectMap; | 127 RegistrationObjectMap; |
123 | 128 |
124 friend class WebServiceWorkerImpl; | 129 friend class WebServiceWorkerImpl; |
125 friend class WebServiceWorkerRegistrationImpl; | 130 friend class WebServiceWorkerRegistrationImpl; |
126 | 131 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 void AddServiceWorker(int handle_id, WebServiceWorkerImpl* worker); | 175 void AddServiceWorker(int handle_id, WebServiceWorkerImpl* worker); |
171 void RemoveServiceWorker(int handle_id); | 176 void RemoveServiceWorker(int handle_id); |
172 | 177 |
173 // Keeps map from registration_handle_id to ServiceWorkerRegistration object. | 178 // Keeps map from registration_handle_id to ServiceWorkerRegistration object. |
174 void AddServiceWorkerRegistration( | 179 void AddServiceWorkerRegistration( |
175 int registration_handle_id, | 180 int registration_handle_id, |
176 WebServiceWorkerRegistrationImpl* registration); | 181 WebServiceWorkerRegistrationImpl* registration); |
177 void RemoveServiceWorkerRegistration( | 182 void RemoveServiceWorkerRegistration( |
178 int registration_handle_id); | 183 int registration_handle_id); |
179 | 184 |
180 CallbackMap pending_callbacks_; | 185 RegistrationCallbackMap pending_registration_callbacks_; |
| 186 UnregistrationCallbackMap pending_unregistration_callbacks_; |
181 ScriptClientMap script_clients_; | 187 ScriptClientMap script_clients_; |
182 ProviderContextMap provider_contexts_; | 188 ProviderContextMap provider_contexts_; |
183 WorkerObjectMap service_workers_; | 189 WorkerObjectMap service_workers_; |
184 RegistrationObjectMap registrations_; | 190 RegistrationObjectMap registrations_; |
185 | 191 |
186 // A map for ServiceWorkers that are associated to a particular document | 192 // A map for ServiceWorkers that are associated to a particular document |
187 // (e.g. as .current). | 193 // (e.g. as .current). |
188 WorkerToProviderMap worker_to_provider_; | 194 WorkerToProviderMap worker_to_provider_; |
189 | 195 |
190 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 196 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
191 | 197 |
192 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcher); | 198 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcher); |
193 }; | 199 }; |
194 | 200 |
195 } // namespace content | 201 } // namespace content |
196 | 202 |
197 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ | 203 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ |
OLD | NEW |