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 |
127 // WorkerTaskRunner::Observer implementation. | 132 // WorkerTaskRunner::Observer implementation. |
128 virtual void OnWorkerRunLoopStopped() OVERRIDE; | 133 virtual void OnWorkerRunLoopStopped() OVERRIDE; |
129 | 134 |
130 void OnRegistered(int thread_id, | 135 void OnRegistered(int thread_id, |
131 int request_id, | 136 int request_id, |
132 const ServiceWorkerRegistrationObjectInfo& info, | 137 const ServiceWorkerRegistrationObjectInfo& info, |
133 const ServiceWorkerVersionAttributes& attrs); | 138 const ServiceWorkerVersionAttributes& attrs); |
134 void OnUnregistered(int thread_id, | 139 void OnUnregistered(int thread_id, |
135 int request_id); | 140 int request_id); |
136 void OnRegistrationError(int thread_id, | 141 void OnRegistrationError(int thread_id, |
137 int request_id, | 142 int request_id, |
138 blink::WebServiceWorkerError::ErrorType error_type, | 143 blink::WebServiceWorkerError::ErrorType error_type, |
139 const base::string16& message); | 144 const base::string16& message); |
| 145 void OnUnregistrationError(int thread_id, |
| 146 int request_id, |
| 147 blink::WebServiceWorkerError::ErrorType error_type, |
| 148 const base::string16& message); |
140 void OnServiceWorkerStateChanged(int thread_id, | 149 void OnServiceWorkerStateChanged(int thread_id, |
141 int handle_id, | 150 int handle_id, |
142 blink::WebServiceWorkerState state); | 151 blink::WebServiceWorkerState state); |
143 void OnSetVersionAttributes(int thread_id, | 152 void OnSetVersionAttributes(int thread_id, |
144 int provider_id, | 153 int provider_id, |
145 int registration_handle_id, | 154 int registration_handle_id, |
146 int changed_mask, | 155 int changed_mask, |
147 const ServiceWorkerVersionAttributes& attributes); | 156 const ServiceWorkerVersionAttributes& attributes); |
148 void OnUpdateFound(int thread_id, | 157 void OnUpdateFound(int thread_id, |
149 const ServiceWorkerRegistrationObjectInfo& info); | 158 const ServiceWorkerRegistrationObjectInfo& info); |
(...skipping 23 matching lines...) Expand all Loading... |
173 void AddServiceWorker(int handle_id, WebServiceWorkerImpl* worker); | 182 void AddServiceWorker(int handle_id, WebServiceWorkerImpl* worker); |
174 void RemoveServiceWorker(int handle_id); | 183 void RemoveServiceWorker(int handle_id); |
175 | 184 |
176 // Keeps map from registration_handle_id to ServiceWorkerRegistration object. | 185 // Keeps map from registration_handle_id to ServiceWorkerRegistration object. |
177 void AddServiceWorkerRegistration( | 186 void AddServiceWorkerRegistration( |
178 int registration_handle_id, | 187 int registration_handle_id, |
179 WebServiceWorkerRegistrationImpl* registration); | 188 WebServiceWorkerRegistrationImpl* registration); |
180 void RemoveServiceWorkerRegistration( | 189 void RemoveServiceWorkerRegistration( |
181 int registration_handle_id); | 190 int registration_handle_id); |
182 | 191 |
183 CallbackMap pending_callbacks_; | 192 RegistrationCallbackMap pending_registration_callbacks_; |
| 193 UnregistrationCallbackMap pending_unregistration_callbacks_; |
184 ScriptClientMap script_clients_; | 194 ScriptClientMap script_clients_; |
185 ProviderContextMap provider_contexts_; | 195 ProviderContextMap provider_contexts_; |
186 WorkerObjectMap service_workers_; | 196 WorkerObjectMap service_workers_; |
187 RegistrationObjectMap registrations_; | 197 RegistrationObjectMap registrations_; |
188 | 198 |
189 // A map for ServiceWorkers that are associated to a particular document | 199 // A map for ServiceWorkers that are associated to a particular document |
190 // (e.g. as .current). | 200 // (e.g. as .current). |
191 WorkerToProviderMap worker_to_provider_; | 201 WorkerToProviderMap worker_to_provider_; |
192 | 202 |
193 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 203 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
194 | 204 |
195 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcher); | 205 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcher); |
196 }; | 206 }; |
197 | 207 |
198 } // namespace content | 208 } // namespace content |
199 | 209 |
200 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ | 210 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ |
OLD | NEW |