| 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_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> |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 class CONTENT_EXPORT ServiceWorkerVersion | 48 class CONTENT_EXPORT ServiceWorkerVersion |
| 49 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerVersion>), | 49 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerVersion>), |
| 50 public EmbeddedWorkerInstance::Listener { | 50 public EmbeddedWorkerInstance::Listener { |
| 51 public: | 51 public: |
| 52 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback; | 52 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback; |
| 53 typedef base::Callback<void(ServiceWorkerStatusCode, | 53 typedef base::Callback<void(ServiceWorkerStatusCode, |
| 54 const IPC::Message& message)> MessageCallback; | 54 const IPC::Message& message)> MessageCallback; |
| 55 typedef base::Callback<void(ServiceWorkerStatusCode, | 55 typedef base::Callback<void(ServiceWorkerStatusCode, |
| 56 ServiceWorkerFetchEventResult, | 56 ServiceWorkerFetchEventResult, |
| 57 const ServiceWorkerResponse&)> FetchCallback; | 57 const ServiceWorkerResponse&)> FetchCallback; |
| 58 typedef base::Callback<void(ServiceWorkerStatusCode, bool)> |
| 59 CrossOriginConnectCallback; |
| 58 | 60 |
| 59 enum RunningStatus { | 61 enum RunningStatus { |
| 60 STOPPED = EmbeddedWorkerInstance::STOPPED, | 62 STOPPED = EmbeddedWorkerInstance::STOPPED, |
| 61 STARTING = EmbeddedWorkerInstance::STARTING, | 63 STARTING = EmbeddedWorkerInstance::STARTING, |
| 62 RUNNING = EmbeddedWorkerInstance::RUNNING, | 64 RUNNING = EmbeddedWorkerInstance::RUNNING, |
| 63 STOPPING = EmbeddedWorkerInstance::STOPPING, | 65 STOPPING = EmbeddedWorkerInstance::STOPPING, |
| 64 }; | 66 }; |
| 65 | 67 |
| 66 // Current version status; some of the status (e.g. INSTALLED and ACTIVATED) | 68 // Current version status; some of the status (e.g. INSTALLED and ACTIVATED) |
| 67 // should be persisted unlike running status. | 69 // should be persisted unlike running status. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 // calling StartWorker internally. | 155 // calling StartWorker internally. |
| 154 // |callback| can be null if the sender does not need to know if the | 156 // |callback| can be null if the sender does not need to know if the |
| 155 // message is successfully sent or not. | 157 // message is successfully sent or not. |
| 156 void SendMessage(const IPC::Message& message, const StatusCallback& callback); | 158 void SendMessage(const IPC::Message& message, const StatusCallback& callback); |
| 157 | 159 |
| 158 // Sends a message event to the associated embedded worker. | 160 // Sends a message event to the associated embedded worker. |
| 159 void DispatchMessageEvent(const base::string16& message, | 161 void DispatchMessageEvent(const base::string16& message, |
| 160 const std::vector<int>& sent_message_port_ids, | 162 const std::vector<int>& sent_message_port_ids, |
| 161 const StatusCallback& callback); | 163 const StatusCallback& callback); |
| 162 | 164 |
| 165 void SendCrossOriginMessage(const CrossOriginServiceWorkerClient& client, |
| 166 const base::string16& message, |
| 167 const std::vector<int>& sent_message_port_ids, |
| 168 const StatusCallback& callback); |
| 169 |
| 163 // Sends install event to the associated embedded worker and asynchronously | 170 // Sends install event to the associated embedded worker and asynchronously |
| 164 // calls |callback| when it errors out or it gets a response from the worker | 171 // calls |callback| when it errors out or it gets a response from the worker |
| 165 // to notify install completion. | 172 // to notify install completion. |
| 166 // |active_version_id| must be a valid positive ID | 173 // |active_version_id| must be a valid positive ID |
| 167 // if there's an activated (previous) version running. | 174 // if there's an activated (previous) version running. |
| 168 // | 175 // |
| 169 // This must be called when the status() is NEW. Calling this changes | 176 // This must be called when the status() is NEW. Calling this changes |
| 170 // the version's status to INSTALLING. | 177 // the version's status to INSTALLING. |
| 171 // Upon completion, the version's status will be changed to INSTALLED | 178 // Upon completion, the version's status will be changed to INSTALLED |
| 172 // on success, or back to NEW on failure. | 179 // on success, or back to NEW on failure. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 const std::string& notification_id); | 215 const std::string& notification_id); |
| 209 | 216 |
| 210 // Sends push event to the associated embedded worker and asynchronously calls | 217 // Sends push event to the associated embedded worker and asynchronously calls |
| 211 // |callback| when it errors out or it gets a response from the worker to | 218 // |callback| when it errors out or it gets a response from the worker to |
| 212 // notify completion. | 219 // notify completion. |
| 213 // | 220 // |
| 214 // This must be called when the status() is ACTIVATED. | 221 // This must be called when the status() is ACTIVATED. |
| 215 void DispatchPushEvent(const StatusCallback& callback, | 222 void DispatchPushEvent(const StatusCallback& callback, |
| 216 const std::string& data); | 223 const std::string& data); |
| 217 | 224 |
| 225 void DispatchCrossOriginConnectEvent( |
| 226 const CrossOriginConnectCallback& callback, |
| 227 const GURL& target_url, |
| 228 int message_port_id); |
| 229 |
| 218 // Sends geofencing event to the associated embedded worker and asynchronously | 230 // Sends geofencing event to the associated embedded worker and asynchronously |
| 219 // calls |callback| when it errors out or it gets a response from the worker | 231 // calls |callback| when it errors out or it gets a response from the worker |
| 220 // to notify completion. | 232 // to notify completion. |
| 221 // | 233 // |
| 222 // This must be called when the status() is ACTIVATED. | 234 // This must be called when the status() is ACTIVATED. |
| 223 void DispatchGeofencingEvent( | 235 void DispatchGeofencingEvent( |
| 224 const StatusCallback& callback, | 236 const StatusCallback& callback, |
| 225 blink::WebGeofencingEventType event_type, | 237 blink::WebGeofencingEventType event_type, |
| 226 const std::string& region_id, | 238 const std::string& region_id, |
| 227 const blink::WebCircularGeofencingRegion& region); | 239 const blink::WebCircularGeofencingRegion& region); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 void OnInstallEventFinished(int request_id, | 304 void OnInstallEventFinished(int request_id, |
| 293 blink::WebServiceWorkerEventResult result); | 305 blink::WebServiceWorkerEventResult result); |
| 294 void OnFetchEventFinished(int request_id, | 306 void OnFetchEventFinished(int request_id, |
| 295 ServiceWorkerFetchEventResult result, | 307 ServiceWorkerFetchEventResult result, |
| 296 const ServiceWorkerResponse& response); | 308 const ServiceWorkerResponse& response); |
| 297 void OnSyncEventFinished(int request_id); | 309 void OnSyncEventFinished(int request_id); |
| 298 void OnNotificationClickEventFinished(int request_id); | 310 void OnNotificationClickEventFinished(int request_id); |
| 299 void OnPushEventFinished(int request_id, | 311 void OnPushEventFinished(int request_id, |
| 300 blink::WebServiceWorkerEventResult result); | 312 blink::WebServiceWorkerEventResult result); |
| 301 void OnGeofencingEventFinished(int request_id); | 313 void OnGeofencingEventFinished(int request_id); |
| 314 void OnCrossOriginConnectEventFinished(int request_id, bool allow_connect); |
| 302 void OnPostMessageToDocument(int client_id, | 315 void OnPostMessageToDocument(int client_id, |
| 303 const base::string16& message, | 316 const base::string16& message, |
| 304 const std::vector<int>& sent_message_port_ids); | 317 const std::vector<int>& sent_message_port_ids); |
| 305 | 318 |
| 306 void ScheduleStopWorker(); | 319 void ScheduleStopWorker(); |
| 307 void DoomInternal(); | 320 void DoomInternal(); |
| 308 | 321 |
| 309 const int64 version_id_; | 322 const int64 version_id_; |
| 310 int64 registration_id_; | 323 int64 registration_id_; |
| 311 GURL script_url_; | 324 GURL script_url_; |
| 312 GURL scope_; | 325 GURL scope_; |
| 313 Status status_; | 326 Status status_; |
| 314 scoped_ptr<EmbeddedWorkerInstance> embedded_worker_; | 327 scoped_ptr<EmbeddedWorkerInstance> embedded_worker_; |
| 315 scoped_ptr<ServiceWorkerCacheListener> cache_listener_; | 328 scoped_ptr<ServiceWorkerCacheListener> cache_listener_; |
| 316 std::vector<StatusCallback> start_callbacks_; | 329 std::vector<StatusCallback> start_callbacks_; |
| 317 std::vector<StatusCallback> stop_callbacks_; | 330 std::vector<StatusCallback> stop_callbacks_; |
| 318 std::vector<base::Closure> status_change_callbacks_; | 331 std::vector<base::Closure> status_change_callbacks_; |
| 319 | 332 |
| 320 // Message callbacks. | 333 // Message callbacks. |
| 321 IDMap<StatusCallback, IDMapOwnPointer> activate_callbacks_; | 334 IDMap<StatusCallback, IDMapOwnPointer> activate_callbacks_; |
| 322 IDMap<StatusCallback, IDMapOwnPointer> install_callbacks_; | 335 IDMap<StatusCallback, IDMapOwnPointer> install_callbacks_; |
| 323 IDMap<FetchCallback, IDMapOwnPointer> fetch_callbacks_; | 336 IDMap<FetchCallback, IDMapOwnPointer> fetch_callbacks_; |
| 324 IDMap<StatusCallback, IDMapOwnPointer> sync_callbacks_; | 337 IDMap<StatusCallback, IDMapOwnPointer> sync_callbacks_; |
| 325 IDMap<StatusCallback, IDMapOwnPointer> notification_click_callbacks_; | 338 IDMap<StatusCallback, IDMapOwnPointer> notification_click_callbacks_; |
| 326 IDMap<StatusCallback, IDMapOwnPointer> push_callbacks_; | 339 IDMap<StatusCallback, IDMapOwnPointer> push_callbacks_; |
| 327 IDMap<StatusCallback, IDMapOwnPointer> geofencing_callbacks_; | 340 IDMap<StatusCallback, IDMapOwnPointer> geofencing_callbacks_; |
| 341 IDMap<CrossOriginConnectCallback, IDMapOwnPointer> |
| 342 cross_origin_connect_callbacks_; |
| 328 | 343 |
| 329 ControlleeMap controllee_map_; | 344 ControlleeMap controllee_map_; |
| 330 ControlleeByIDMap controllee_by_id_; | 345 ControlleeByIDMap controllee_by_id_; |
| 331 base::WeakPtr<ServiceWorkerContextCore> context_; | 346 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 332 ObserverList<Listener> listeners_; | 347 ObserverList<Listener> listeners_; |
| 333 ServiceWorkerScriptCacheMap script_cache_map_; | 348 ServiceWorkerScriptCacheMap script_cache_map_; |
| 334 base::OneShotTimer<ServiceWorkerVersion> stop_worker_timer_; | 349 base::OneShotTimer<ServiceWorkerVersion> stop_worker_timer_; |
| 335 base::OneShotTimer<ServiceWorkerVersion> update_timer_; | 350 base::OneShotTimer<ServiceWorkerVersion> update_timer_; |
| 336 bool is_doomed_; | 351 bool is_doomed_; |
| 337 | 352 |
| 338 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; | 353 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; |
| 339 | 354 |
| 340 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); | 355 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); |
| 341 }; | 356 }; |
| 342 | 357 |
| 343 } // namespace content | 358 } // namespace content |
| 344 | 359 |
| 345 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 360 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
| OLD | NEW |