Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: content/child/service_worker/service_worker_dispatcher.h

Issue 535753002: ServiceWorker: Implement navigator.serviceWorker.getRegistration [2/3] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 29 matching lines...) Expand all
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 47 typedef
48 blink::WebServiceWorkerProvider::WebServiceWorkerUnregistrationCallbacks 48 blink::WebServiceWorkerProvider::WebServiceWorkerUnregistrationCallbacks
49 WebServiceWorkerUnregistrationCallbacks; 49 WebServiceWorkerUnregistrationCallbacks;
50 typedef
51 blink::WebServiceWorkerProvider::WebServiceWorkerGetRegistrationCallbacks
52 WebServiceWorkerGetRegistrationCallbacks;
50 53
51 explicit ServiceWorkerDispatcher(ThreadSafeSender* thread_safe_sender); 54 explicit ServiceWorkerDispatcher(ThreadSafeSender* thread_safe_sender);
52 virtual ~ServiceWorkerDispatcher(); 55 virtual ~ServiceWorkerDispatcher();
53 56
54 void OnMessageReceived(const IPC::Message& msg); 57 void OnMessageReceived(const IPC::Message& msg);
55 bool Send(IPC::Message* msg); 58 bool Send(IPC::Message* msg);
56 59
57 // Corresponds to navigator.serviceWorker.register() 60 // Corresponds to navigator.serviceWorker.register()
58 void RegisterServiceWorker( 61 void RegisterServiceWorker(
59 int provider_id, 62 int provider_id,
60 const GURL& pattern, 63 const GURL& pattern,
61 const GURL& script_url, 64 const GURL& script_url,
62 WebServiceWorkerRegistrationCallbacks* callbacks); 65 WebServiceWorkerRegistrationCallbacks* callbacks);
63 // Corresponds to navigator.serviceWorker.unregister() 66 // Corresponds to navigator.serviceWorker.unregister()
64 void UnregisterServiceWorker( 67 void UnregisterServiceWorker(
65 int provider_id, 68 int provider_id,
66 const GURL& pattern, 69 const GURL& pattern,
67 WebServiceWorkerUnregistrationCallbacks* callbacks); 70 WebServiceWorkerUnregistrationCallbacks* callbacks);
71 // Corresponds to navigator.serviceWorker.getRegistration()
72 void GetRegistration(
73 int provider_id,
74 const GURL& document_url,
75 WebServiceWorkerRegistrationCallbacks* callbacks);
68 76
69 // Called when a new provider context for a document is created. Usually 77 // Called when a new provider context for a document is created. Usually
70 // this happens when a new document is being loaded, and is called much 78 // this happens when a new document is being loaded, and is called much
71 // earlier than AddScriptClient. 79 // earlier than AddScriptClient.
72 // (This is attached only to the document thread's ServiceWorkerDispatcher) 80 // (This is attached only to the document thread's ServiceWorkerDispatcher)
73 void AddProviderContext(ServiceWorkerProviderContext* provider_context); 81 void AddProviderContext(ServiceWorkerProviderContext* provider_context);
74 void RemoveProviderContext(ServiceWorkerProviderContext* provider_context); 82 void RemoveProviderContext(ServiceWorkerProviderContext* provider_context);
75 83
76 // Called when navigator.serviceWorker is instantiated or detached 84 // Called when navigator.serviceWorker is instantiated or detached
77 // for a document whose provider can be identified by |provider_id|. 85 // for a document whose provider can be identified by |provider_id|.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 127
120 // Unlike GetOrCreateThreadSpecificInstance() this doesn't create a new 128 // Unlike GetOrCreateThreadSpecificInstance() this doesn't create a new
121 // instance if thread-local instance doesn't exist. 129 // instance if thread-local instance doesn't exist.
122 static ServiceWorkerDispatcher* GetThreadSpecificInstance(); 130 static ServiceWorkerDispatcher* GetThreadSpecificInstance();
123 131
124 private: 132 private:
125 typedef IDMap<WebServiceWorkerRegistrationCallbacks, 133 typedef IDMap<WebServiceWorkerRegistrationCallbacks,
126 IDMapOwnPointer> RegistrationCallbackMap; 134 IDMapOwnPointer> RegistrationCallbackMap;
127 typedef IDMap<WebServiceWorkerUnregistrationCallbacks, 135 typedef IDMap<WebServiceWorkerUnregistrationCallbacks,
128 IDMapOwnPointer> UnregistrationCallbackMap; 136 IDMapOwnPointer> UnregistrationCallbackMap;
137 typedef IDMap<WebServiceWorkerGetRegistrationCallbacks,
138 IDMapOwnPointer> GetRegistrationCallbackMap;
129 typedef std::map<int, blink::WebServiceWorkerProviderClient*> ScriptClientMap; 139 typedef std::map<int, blink::WebServiceWorkerProviderClient*> ScriptClientMap;
130 typedef std::map<int, ServiceWorkerProviderContext*> ProviderContextMap; 140 typedef std::map<int, ServiceWorkerProviderContext*> ProviderContextMap;
131 typedef std::map<int, WebServiceWorkerImpl*> WorkerObjectMap; 141 typedef std::map<int, WebServiceWorkerImpl*> WorkerObjectMap;
132 typedef std::map<int, ServiceWorkerProviderContext*> WorkerToProviderMap; 142 typedef std::map<int, ServiceWorkerProviderContext*> WorkerToProviderMap;
133 typedef std::map<int, WebServiceWorkerRegistrationImpl*> 143 typedef std::map<int, WebServiceWorkerRegistrationImpl*>
134 RegistrationObjectMap; 144 RegistrationObjectMap;
135 145
136 friend class WebServiceWorkerImpl; 146 friend class WebServiceWorkerImpl;
137 friend class WebServiceWorkerRegistrationImpl; 147 friend class WebServiceWorkerRegistrationImpl;
138 148
139 // WorkerTaskRunner::Observer implementation. 149 // WorkerTaskRunner::Observer implementation.
140 virtual void OnWorkerRunLoopStopped() OVERRIDE; 150 virtual void OnWorkerRunLoopStopped() OVERRIDE;
141 151
142 void OnAssociateRegistration(int thread_id, 152 void OnAssociateRegistration(int thread_id,
143 int provider_id, 153 int provider_id,
144 const ServiceWorkerRegistrationObjectInfo& info, 154 const ServiceWorkerRegistrationObjectInfo& info,
145 const ServiceWorkerVersionAttributes& attrs); 155 const ServiceWorkerVersionAttributes& attrs);
146 void OnDisassociateRegistration(int thread_id, 156 void OnDisassociateRegistration(int thread_id,
147 int provider_id); 157 int provider_id);
148 void OnRegistered(int thread_id, 158 void OnRegistered(int thread_id,
149 int request_id, 159 int request_id,
150 const ServiceWorkerRegistrationObjectInfo& info, 160 const ServiceWorkerRegistrationObjectInfo& info,
151 const ServiceWorkerVersionAttributes& attrs); 161 const ServiceWorkerVersionAttributes& attrs);
152 void OnUnregistered(int thread_id, 162 void OnUnregistered(int thread_id,
153 int request_id, 163 int request_id,
154 bool is_success); 164 bool is_success);
165 void OnDidGetRegistration(int thread_id,
166 int request_id,
167 const ServiceWorkerRegistrationObjectInfo& info,
168 const ServiceWorkerVersionAttributes& attrs);
155 void OnRegistrationError(int thread_id, 169 void OnRegistrationError(int thread_id,
156 int request_id, 170 int request_id,
157 blink::WebServiceWorkerError::ErrorType error_type, 171 blink::WebServiceWorkerError::ErrorType error_type,
158 const base::string16& message); 172 const base::string16& message);
159 void OnUnregistrationError(int thread_id, 173 void OnUnregistrationError(int thread_id,
160 int request_id, 174 int request_id,
161 blink::WebServiceWorkerError::ErrorType error_type, 175 blink::WebServiceWorkerError::ErrorType error_type,
162 const base::string16& message); 176 const base::string16& message);
177 void OnGetRegistrationError(
178 int thread_id,
179 int request_id,
180 blink::WebServiceWorkerError::ErrorType error_type,
181 const base::string16& message);
163 void OnServiceWorkerStateChanged(int thread_id, 182 void OnServiceWorkerStateChanged(int thread_id,
164 int handle_id, 183 int handle_id,
165 blink::WebServiceWorkerState state); 184 blink::WebServiceWorkerState state);
166 void OnSetVersionAttributes(int thread_id, 185 void OnSetVersionAttributes(int thread_id,
167 int provider_id, 186 int provider_id,
168 int registration_handle_id, 187 int registration_handle_id,
169 int changed_mask, 188 int changed_mask,
170 const ServiceWorkerVersionAttributes& attributes); 189 const ServiceWorkerVersionAttributes& attributes);
171 void OnUpdateFound(int thread_id, 190 void OnUpdateFound(int thread_id,
172 const ServiceWorkerRegistrationObjectInfo& info); 191 const ServiceWorkerRegistrationObjectInfo& info);
(...skipping 28 matching lines...) Expand all
201 220
202 // Keeps map from registration_handle_id to ServiceWorkerRegistration object. 221 // Keeps map from registration_handle_id to ServiceWorkerRegistration object.
203 void AddServiceWorkerRegistration( 222 void AddServiceWorkerRegistration(
204 int registration_handle_id, 223 int registration_handle_id,
205 WebServiceWorkerRegistrationImpl* registration); 224 WebServiceWorkerRegistrationImpl* registration);
206 void RemoveServiceWorkerRegistration( 225 void RemoveServiceWorkerRegistration(
207 int registration_handle_id); 226 int registration_handle_id);
208 227
209 RegistrationCallbackMap pending_registration_callbacks_; 228 RegistrationCallbackMap pending_registration_callbacks_;
210 UnregistrationCallbackMap pending_unregistration_callbacks_; 229 UnregistrationCallbackMap pending_unregistration_callbacks_;
230 GetRegistrationCallbackMap pending_get_registration_callbacks_;
211 ScriptClientMap script_clients_; 231 ScriptClientMap script_clients_;
212 ProviderContextMap provider_contexts_; 232 ProviderContextMap provider_contexts_;
213 WorkerObjectMap service_workers_; 233 WorkerObjectMap service_workers_;
214 RegistrationObjectMap registrations_; 234 RegistrationObjectMap registrations_;
215 235
216 // A map for ServiceWorkers that are associated to a particular document 236 // A map for ServiceWorkers that are associated to a particular document
217 // (e.g. as .current). 237 // (e.g. as .current).
218 WorkerToProviderMap worker_to_provider_; 238 WorkerToProviderMap worker_to_provider_;
219 239
220 scoped_refptr<ThreadSafeSender> thread_safe_sender_; 240 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
221 241
222 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcher); 242 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcher);
223 }; 243 };
224 244
225 } // namespace content 245 } // namespace content
226 246
227 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ 247 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698