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

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: 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 120
113 // Unlike GetOrCreateThreadSpecificInstance() this doesn't create a new 121 // Unlike GetOrCreateThreadSpecificInstance() this doesn't create a new
114 // instance if thread-local instance doesn't exist. 122 // instance if thread-local instance doesn't exist.
115 static ServiceWorkerDispatcher* GetThreadSpecificInstance(); 123 static ServiceWorkerDispatcher* GetThreadSpecificInstance();
116 124
117 private: 125 private:
118 typedef IDMap<WebServiceWorkerRegistrationCallbacks, 126 typedef IDMap<WebServiceWorkerRegistrationCallbacks,
119 IDMapOwnPointer> RegistrationCallbackMap; 127 IDMapOwnPointer> RegistrationCallbackMap;
120 typedef IDMap<WebServiceWorkerUnregistrationCallbacks, 128 typedef IDMap<WebServiceWorkerUnregistrationCallbacks,
121 IDMapOwnPointer> UnregistrationCallbackMap; 129 IDMapOwnPointer> UnregistrationCallbackMap;
130 typedef IDMap<WebServiceWorkerGetRegistrationCallbacks,
131 IDMapOwnPointer> GetRegistrationCallbackMap;
122 typedef std::map<int, blink::WebServiceWorkerProviderClient*> ScriptClientMap; 132 typedef std::map<int, blink::WebServiceWorkerProviderClient*> ScriptClientMap;
123 typedef std::map<int, ServiceWorkerProviderContext*> ProviderContextMap; 133 typedef std::map<int, ServiceWorkerProviderContext*> ProviderContextMap;
124 typedef std::map<int, WebServiceWorkerImpl*> WorkerObjectMap; 134 typedef std::map<int, WebServiceWorkerImpl*> WorkerObjectMap;
125 typedef std::map<int, ServiceWorkerProviderContext*> WorkerToProviderMap; 135 typedef std::map<int, ServiceWorkerProviderContext*> WorkerToProviderMap;
126 typedef std::map<int, WebServiceWorkerRegistrationImpl*> 136 typedef std::map<int, WebServiceWorkerRegistrationImpl*>
127 RegistrationObjectMap; 137 RegistrationObjectMap;
128 138
129 friend class WebServiceWorkerImpl; 139 friend class WebServiceWorkerImpl;
130 friend class WebServiceWorkerRegistrationImpl; 140 friend class WebServiceWorkerRegistrationImpl;
131 141
132 // WorkerTaskRunner::Observer implementation. 142 // WorkerTaskRunner::Observer implementation.
133 virtual void OnWorkerRunLoopStopped() OVERRIDE; 143 virtual void OnWorkerRunLoopStopped() OVERRIDE;
134 144
135 void OnRegistered(int thread_id, 145 void OnRegistered(int thread_id,
136 int request_id, 146 int request_id,
137 const ServiceWorkerRegistrationObjectInfo& info, 147 const ServiceWorkerRegistrationObjectInfo& info,
138 const ServiceWorkerVersionAttributes& attrs); 148 const ServiceWorkerVersionAttributes& attrs);
139 void OnUnregistered(int thread_id, 149 void OnUnregistered(int thread_id,
140 int request_id); 150 int request_id);
151 void OnDidGetRegistration(int thread_id,
152 int request_id,
153 const ServiceWorkerRegistrationObjectInfo& info,
154 const ServiceWorkerVersionAttributes& attrs);
141 void OnRegistrationError(int thread_id, 155 void OnRegistrationError(int thread_id,
142 int request_id, 156 int request_id,
143 blink::WebServiceWorkerError::ErrorType error_type, 157 blink::WebServiceWorkerError::ErrorType error_type,
144 const base::string16& message); 158 const base::string16& message);
145 void OnUnregistrationError(int thread_id, 159 void OnUnregistrationError(int thread_id,
146 int request_id, 160 int request_id,
147 blink::WebServiceWorkerError::ErrorType error_type, 161 blink::WebServiceWorkerError::ErrorType error_type,
148 const base::string16& message); 162 const base::string16& message);
163 void OnGetRegistrationError(
164 int thread_id,
165 int request_id,
166 blink::WebServiceWorkerError::ErrorType error_type,
167 const base::string16& message);
149 void OnServiceWorkerStateChanged(int thread_id, 168 void OnServiceWorkerStateChanged(int thread_id,
150 int handle_id, 169 int handle_id,
151 blink::WebServiceWorkerState state); 170 blink::WebServiceWorkerState state);
152 void OnSetVersionAttributes(int thread_id, 171 void OnSetVersionAttributes(int thread_id,
153 int provider_id, 172 int provider_id,
154 int registration_handle_id, 173 int registration_handle_id,
155 int changed_mask, 174 int changed_mask,
156 const ServiceWorkerVersionAttributes& attributes); 175 const ServiceWorkerVersionAttributes& attributes);
157 void OnUpdateFound(int thread_id, 176 void OnUpdateFound(int thread_id,
158 const ServiceWorkerRegistrationObjectInfo& info); 177 const ServiceWorkerRegistrationObjectInfo& info);
(...skipping 25 matching lines...) Expand all
184 203
185 // Keeps map from registration_handle_id to ServiceWorkerRegistration object. 204 // Keeps map from registration_handle_id to ServiceWorkerRegistration object.
186 void AddServiceWorkerRegistration( 205 void AddServiceWorkerRegistration(
187 int registration_handle_id, 206 int registration_handle_id,
188 WebServiceWorkerRegistrationImpl* registration); 207 WebServiceWorkerRegistrationImpl* registration);
189 void RemoveServiceWorkerRegistration( 208 void RemoveServiceWorkerRegistration(
190 int registration_handle_id); 209 int registration_handle_id);
191 210
192 RegistrationCallbackMap pending_registration_callbacks_; 211 RegistrationCallbackMap pending_registration_callbacks_;
193 UnregistrationCallbackMap pending_unregistration_callbacks_; 212 UnregistrationCallbackMap pending_unregistration_callbacks_;
213 GetRegistrationCallbackMap pending_get_registration_callbacks_;
194 ScriptClientMap script_clients_; 214 ScriptClientMap script_clients_;
195 ProviderContextMap provider_contexts_; 215 ProviderContextMap provider_contexts_;
196 WorkerObjectMap service_workers_; 216 WorkerObjectMap service_workers_;
197 RegistrationObjectMap registrations_; 217 RegistrationObjectMap registrations_;
198 218
199 // A map for ServiceWorkers that are associated to a particular document 219 // A map for ServiceWorkers that are associated to a particular document
200 // (e.g. as .current). 220 // (e.g. as .current).
201 WorkerToProviderMap worker_to_provider_; 221 WorkerToProviderMap worker_to_provider_;
202 222
203 scoped_refptr<ThreadSafeSender> thread_safe_sender_; 223 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
204 224
205 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcher); 225 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcher);
206 }; 226 };
207 227
208 } // namespace content 228 } // namespace content
209 229
210 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ 230 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698