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

Side by Side Diff: content/browser/service_worker/service_worker_version.h

Issue 629393002: Chromium side of geofencing event dispatching. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@geofencing_serviceworker
Patch Set: nit Created 6 years, 1 month 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_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
15 #include "base/id_map.h" 15 #include "base/id_map.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
18 #include "base/observer_list.h" 18 #include "base/observer_list.h"
19 #include "base/timer/timer.h" 19 #include "base/timer/timer.h"
20 #include "content/browser/service_worker/embedded_worker_instance.h" 20 #include "content/browser/service_worker/embedded_worker_instance.h"
21 #include "content/browser/service_worker/service_worker_cache_listener.h" 21 #include "content/browser/service_worker/service_worker_cache_listener.h"
22 #include "content/browser/service_worker/service_worker_script_cache_map.h" 22 #include "content/browser/service_worker/service_worker_script_cache_map.h"
23 #include "content/common/content_export.h" 23 #include "content/common/content_export.h"
24 #include "content/common/service_worker/service_worker_status_code.h" 24 #include "content/common/service_worker/service_worker_status_code.h"
25 #include "content/common/service_worker/service_worker_types.h" 25 #include "content/common/service_worker/service_worker_types.h"
26 #include "third_party/WebKit/public/platform/WebGeofencingEventType.h"
26 #include "third_party/WebKit/public/platform/WebServiceWorkerEventResult.h" 27 #include "third_party/WebKit/public/platform/WebServiceWorkerEventResult.h"
27 28
28 class GURL; 29 class GURL;
29 30
31 namespace blink {
32 struct WebCircularGeofencingRegion;
33 }
34
30 namespace content { 35 namespace content {
31 36
32 class EmbeddedWorkerRegistry; 37 class EmbeddedWorkerRegistry;
33 class ServiceWorkerContextCore; 38 class ServiceWorkerContextCore;
34 class ServiceWorkerProviderHost; 39 class ServiceWorkerProviderHost;
35 class ServiceWorkerRegistration; 40 class ServiceWorkerRegistration;
36 class ServiceWorkerVersionInfo; 41 class ServiceWorkerVersionInfo;
37 42
38 // This class corresponds to a specific version of a ServiceWorker 43 // This class corresponds to a specific version of a ServiceWorker
39 // script for a given pattern. When a script is upgraded, there may be 44 // script for a given pattern. When a script is upgraded, there may be
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 void StartUpdate(); 149 void StartUpdate();
145 150
146 // Sends an IPC message to the worker. 151 // Sends an IPC message to the worker.
147 // If the worker is not running this first tries to start it by 152 // If the worker is not running this first tries to start it by
148 // calling StartWorker internally. 153 // calling StartWorker internally.
149 // |callback| can be null if the sender does not need to know if the 154 // |callback| can be null if the sender does not need to know if the
150 // message is successfully sent or not. 155 // message is successfully sent or not.
151 void SendMessage(const IPC::Message& message, const StatusCallback& callback); 156 void SendMessage(const IPC::Message& message, const StatusCallback& callback);
152 157
153 // Sends install event to the associated embedded worker and asynchronously 158 // Sends install event to the associated embedded worker and asynchronously
154 // calls |callback| when it errors out or it gets response from the worker 159 // calls |callback| when it errors out or it gets a response from the worker
155 // to notify install completion. 160 // to notify install completion.
156 // |active_version_id| must be a valid positive ID 161 // |active_version_id| must be a valid positive ID
157 // if there's an activated (previous) version running. 162 // if there's an activated (previous) version running.
158 // 163 //
159 // This must be called when the status() is NEW. Calling this changes 164 // This must be called when the status() is NEW. Calling this changes
160 // the version's status to INSTALLING. 165 // the version's status to INSTALLING.
161 // Upon completion, the version's status will be changed to INSTALLED 166 // Upon completion, the version's status will be changed to INSTALLED
162 // on success, or back to NEW on failure. 167 // on success, or back to NEW on failure.
163 void DispatchInstallEvent(int active_version_id, 168 void DispatchInstallEvent(int active_version_id,
164 const StatusCallback& callback); 169 const StatusCallback& callback);
165 170
166 // Sends activate event to the associated embedded worker and asynchronously 171 // Sends activate event to the associated embedded worker and asynchronously
167 // calls |callback| when it errors out or it gets response from the worker 172 // calls |callback| when it errors out or it gets a response from the worker
168 // to notify activation completion. 173 // to notify activation completion.
169 // 174 //
170 // This must be called when the status() is INSTALLED. Calling this changes 175 // This must be called when the status() is INSTALLED. Calling this changes
171 // the version's status to ACTIVATING. 176 // the version's status to ACTIVATING.
172 // Upon completion, the version's status will be changed to ACTIVATED 177 // Upon completion, the version's status will be changed to ACTIVATED
173 // on success, or back to INSTALLED on failure. 178 // on success, or back to INSTALLED on failure.
174 void DispatchActivateEvent(const StatusCallback& callback); 179 void DispatchActivateEvent(const StatusCallback& callback);
175 180
176 // Sends fetch event to the associated embedded worker and calls 181 // Sends fetch event to the associated embedded worker and calls
177 // |callback| with the response from the worker. 182 // |callback| with the response from the worker.
178 // 183 //
179 // This must be called when the status() is ACTIVATED. Calling this in other 184 // This must be called when the status() is ACTIVATED. Calling this in other
180 // statuses will result in an error SERVICE_WORKER_ERROR_FAILED. 185 // statuses will result in an error SERVICE_WORKER_ERROR_FAILED.
181 void DispatchFetchEvent(const ServiceWorkerFetchRequest& request, 186 void DispatchFetchEvent(const ServiceWorkerFetchRequest& request,
182 const base::Closure& prepare_callback, 187 const base::Closure& prepare_callback,
183 const FetchCallback& fetch_callback); 188 const FetchCallback& fetch_callback);
184 189
185 // Sends sync event to the associated embedded worker and asynchronously calls 190 // Sends sync event to the associated embedded worker and asynchronously calls
186 // |callback| when it errors out or it gets response from the worker to notify 191 // |callback| when it errors out or it gets a response from the worker to
187 // completion. 192 // notify completion.
188 // 193 //
189 // This must be called when the status() is ACTIVATED. 194 // This must be called when the status() is ACTIVATED.
190 void DispatchSyncEvent(const StatusCallback& callback); 195 void DispatchSyncEvent(const StatusCallback& callback);
191 196
192 // Sends push event to the associated embedded worker and asynchronously calls 197 // Sends push event to the associated embedded worker and asynchronously calls
193 // |callback| when it errors out or it gets response from the worker to notify 198 // |callback| when it errors out or it gets a response from the worker to
194 // completion. 199 // notify completion.
195 // 200 //
196 // This must be called when the status() is ACTIVATED. 201 // This must be called when the status() is ACTIVATED.
197 void DispatchPushEvent(const StatusCallback& callback, 202 void DispatchPushEvent(const StatusCallback& callback,
198 const std::string& data); 203 const std::string& data);
199 204
205 // Sends geofencing event to the associated embedded worker and asynchronously
206 // calls |callback| when it errors out or it gets a response from the worker
207 // to notify completion.
208 //
209 // This must be called when the status() is ACTIVATED.
210 void DispatchGeofencingEvent(
211 const StatusCallback& callback,
212 blink::WebGeofencingEventType event_type,
213 const std::string& region_id,
214 const blink::WebCircularGeofencingRegion& region);
215
200 // Adds and removes |provider_host| as a controllee of this ServiceWorker. 216 // Adds and removes |provider_host| as a controllee of this ServiceWorker.
201 // A potential controllee is a host having the version as its .installing 217 // A potential controllee is a host having the version as its .installing
202 // or .waiting version. 218 // or .waiting version.
203 void AddControllee(ServiceWorkerProviderHost* provider_host); 219 void AddControllee(ServiceWorkerProviderHost* provider_host);
204 void RemoveControllee(ServiceWorkerProviderHost* provider_host); 220 void RemoveControllee(ServiceWorkerProviderHost* provider_host);
205 221
206 // Returns if it has controllee. 222 // Returns if it has controllee.
207 bool HasControllee() const { return !controllee_map_.empty(); } 223 bool HasControllee() const { return !controllee_map_.empty(); }
208 224
209 // Adds and removes Listeners. 225 // Adds and removes Listeners.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 void OnGetClientDocuments(int request_id); 271 void OnGetClientDocuments(int request_id);
256 void OnActivateEventFinished(int request_id, 272 void OnActivateEventFinished(int request_id,
257 blink::WebServiceWorkerEventResult result); 273 blink::WebServiceWorkerEventResult result);
258 void OnInstallEventFinished(int request_id, 274 void OnInstallEventFinished(int request_id,
259 blink::WebServiceWorkerEventResult result); 275 blink::WebServiceWorkerEventResult result);
260 void OnFetchEventFinished(int request_id, 276 void OnFetchEventFinished(int request_id,
261 ServiceWorkerFetchEventResult result, 277 ServiceWorkerFetchEventResult result,
262 const ServiceWorkerResponse& response); 278 const ServiceWorkerResponse& response);
263 void OnSyncEventFinished(int request_id); 279 void OnSyncEventFinished(int request_id);
264 void OnPushEventFinished(int request_id); 280 void OnPushEventFinished(int request_id);
281 void OnGeofencingEventFinished(int request_id);
265 void OnPostMessageToDocument(int client_id, 282 void OnPostMessageToDocument(int client_id,
266 const base::string16& message, 283 const base::string16& message,
267 const std::vector<int>& sent_message_port_ids); 284 const std::vector<int>& sent_message_port_ids);
268 285
269 void ScheduleStopWorker(); 286 void ScheduleStopWorker();
270 void DoomInternal(); 287 void DoomInternal();
271 288
272 const int64 version_id_; 289 const int64 version_id_;
273 int64 registration_id_; 290 int64 registration_id_;
274 GURL script_url_; 291 GURL script_url_;
275 GURL scope_; 292 GURL scope_;
276 Status status_; 293 Status status_;
277 scoped_ptr<EmbeddedWorkerInstance> embedded_worker_; 294 scoped_ptr<EmbeddedWorkerInstance> embedded_worker_;
278 scoped_ptr<ServiceWorkerCacheListener> cache_listener_; 295 scoped_ptr<ServiceWorkerCacheListener> cache_listener_;
279 std::vector<StatusCallback> start_callbacks_; 296 std::vector<StatusCallback> start_callbacks_;
280 std::vector<StatusCallback> stop_callbacks_; 297 std::vector<StatusCallback> stop_callbacks_;
281 std::vector<base::Closure> status_change_callbacks_; 298 std::vector<base::Closure> status_change_callbacks_;
282 299
283 // Message callbacks. 300 // Message callbacks.
284 IDMap<StatusCallback, IDMapOwnPointer> activate_callbacks_; 301 IDMap<StatusCallback, IDMapOwnPointer> activate_callbacks_;
285 IDMap<StatusCallback, IDMapOwnPointer> install_callbacks_; 302 IDMap<StatusCallback, IDMapOwnPointer> install_callbacks_;
286 IDMap<FetchCallback, IDMapOwnPointer> fetch_callbacks_; 303 IDMap<FetchCallback, IDMapOwnPointer> fetch_callbacks_;
287 IDMap<StatusCallback, IDMapOwnPointer> sync_callbacks_; 304 IDMap<StatusCallback, IDMapOwnPointer> sync_callbacks_;
288 IDMap<StatusCallback, IDMapOwnPointer> push_callbacks_; 305 IDMap<StatusCallback, IDMapOwnPointer> push_callbacks_;
306 IDMap<StatusCallback, IDMapOwnPointer> geofencing_callbacks_;
289 307
290 ControlleeMap controllee_map_; 308 ControlleeMap controllee_map_;
291 ControlleeByIDMap controllee_by_id_; 309 ControlleeByIDMap controllee_by_id_;
292 base::WeakPtr<ServiceWorkerContextCore> context_; 310 base::WeakPtr<ServiceWorkerContextCore> context_;
293 ObserverList<Listener> listeners_; 311 ObserverList<Listener> listeners_;
294 ServiceWorkerScriptCacheMap script_cache_map_; 312 ServiceWorkerScriptCacheMap script_cache_map_;
295 base::OneShotTimer<ServiceWorkerVersion> stop_worker_timer_; 313 base::OneShotTimer<ServiceWorkerVersion> stop_worker_timer_;
296 base::OneShotTimer<ServiceWorkerVersion> update_timer_; 314 base::OneShotTimer<ServiceWorkerVersion> update_timer_;
297 bool is_doomed_; 315 bool is_doomed_;
298 316
299 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; 317 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_;
300 318
301 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); 319 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion);
302 }; 320 };
303 321
304 } // namespace content 322 } // namespace content
305 323
306 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ 324 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_
OLDNEW
« no previous file with comments | « content/browser/geofencing/geofencing_service_unittest.cc ('k') | content/browser/service_worker/service_worker_version.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698