Chromium Code Reviews| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <functional> | 10 #include <functional> |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 // This class corresponds to a specific version of a ServiceWorker | 66 // This class corresponds to a specific version of a ServiceWorker |
| 67 // script for a given pattern. When a script is upgraded, there may be | 67 // script for a given pattern. When a script is upgraded, there may be |
| 68 // more than one ServiceWorkerVersion "running" at a time, but only | 68 // more than one ServiceWorkerVersion "running" at a time, but only |
| 69 // one of them is activated. This class connects the actual script with a | 69 // one of them is activated. This class connects the actual script with a |
| 70 // running worker. | 70 // running worker. |
| 71 class CONTENT_EXPORT ServiceWorkerVersion | 71 class CONTENT_EXPORT ServiceWorkerVersion |
| 72 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerVersion>), | 72 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerVersion>), |
| 73 public EmbeddedWorkerInstance::Listener { | 73 public EmbeddedWorkerInstance::Listener { |
| 74 public: | 74 public: |
| 75 using StatusCallback = base::Callback<void(ServiceWorkerStatusCode)>; | 75 using StatusCallback = base::Callback<void(ServiceWorkerStatusCode)>; |
| 76 using SimpleEventCallback = | |
| 77 base::Callback<void(ServiceWorkerStatusCode, base::Time)>; | |
| 76 | 78 |
| 77 // Current version status; some of the status (e.g. INSTALLED and ACTIVATED) | 79 // Current version status; some of the status (e.g. INSTALLED and ACTIVATED) |
| 78 // should be persisted unlike running status. | 80 // should be persisted unlike running status. |
| 79 enum Status { | 81 enum Status { |
| 80 NEW, // The version is just created. | 82 NEW, // The version is just created. |
| 81 INSTALLING, // Install event is dispatched and being handled. | 83 INSTALLING, // Install event is dispatched and being handled. |
| 82 INSTALLED, // Install event is finished and is ready to be activated. | 84 INSTALLED, // Install event is finished and is ready to be activated. |
| 83 ACTIVATING, // Activate event is dispatched and being handled. | 85 ACTIVATING, // Activate event is dispatched and being handled. |
| 84 ACTIVATED, // Activation is finished and can run as activated. | 86 ACTIVATED, // Activation is finished and can run as activated. |
| 85 REDUNDANT, // The version is no longer running as activated, due to | 87 REDUNDANT, // The version is no longer running as activated, due to |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 // TODO(mek): Use something other than a bool for event status. | 270 // TODO(mek): Use something other than a bool for event status. |
| 269 bool FinishRequest(int request_id, | 271 bool FinishRequest(int request_id, |
| 270 bool was_handled, | 272 bool was_handled, |
| 271 base::Time dispatch_event_time); | 273 base::Time dispatch_event_time); |
| 272 | 274 |
| 273 // Finishes an external request that was started by StartExternalRequest(). | 275 // Finishes an external request that was started by StartExternalRequest(). |
| 274 // Returns false if there was an error finishing the request: e.g. the request | 276 // Returns false if there was an error finishing the request: e.g. the request |
| 275 // was not found or the worker already terminated. | 277 // was not found or the worker already terminated. |
| 276 bool FinishExternalRequest(const std::string& request_uuid); | 278 bool FinishExternalRequest(const std::string& request_uuid); |
| 277 | 279 |
| 280 // Creates a callback that is to be used for marking simple events dispatched | |
| 281 // through the ServiceWorkerEventDispatcher as finished for the |request_id|. | |
| 282 SimpleEventCallback CreateSimpleEventCallback(int request_id); | |
| 283 | |
| 278 // This must be called when the worker is running. | 284 // This must be called when the worker is running. |
| 279 mojom::ServiceWorkerEventDispatcher* event_dispatcher() { | 285 mojom::ServiceWorkerEventDispatcher* event_dispatcher() { |
| 280 DCHECK(event_dispatcher_.is_bound()); | 286 DCHECK(event_dispatcher_.is_bound()); |
| 281 return event_dispatcher_.get(); | 287 return event_dispatcher_.get(); |
| 282 } | 288 } |
| 283 | 289 |
| 284 // Dispatches an event. If dispatching the event fails, all of the error | 290 // Dispatches an event. If dispatching the event fails, all of the error |
| 285 // callbacks that were associated with |request_ids| via StartRequest are | 291 // callbacks that were associated with |request_ids| via StartRequest are |
| 286 // called. | 292 // called. |
| 287 // Use RegisterRequestCallback or RegisterSimpleRequest to register a callback | 293 // Use RegisterRequestCallback or RegisterSimpleRequest to register a callback |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 422 // expiration time expires. | 428 // expiration time expires. |
| 423 base::TimeDelta remaining_timeout() const { | 429 base::TimeDelta remaining_timeout() const { |
| 424 return max_request_expiration_time_ - tick_clock_->NowTicks(); | 430 return max_request_expiration_time_ - tick_clock_->NowTicks(); |
| 425 } | 431 } |
| 426 | 432 |
| 427 // Callback function for simple events dispatched through mojo interface | 433 // Callback function for simple events dispatched through mojo interface |
| 428 // mojom::ServiceWorkerEventDispatcher, once all simple events got dispatched | 434 // mojom::ServiceWorkerEventDispatcher, once all simple events got dispatched |
| 429 // through mojo, OnSimpleEventResponse function could be removed. | 435 // through mojo, OnSimpleEventResponse function could be removed. |
| 430 void OnSimpleEventFinished(int request_id, | 436 void OnSimpleEventFinished(int request_id, |
| 431 ServiceWorkerStatusCode status, | 437 ServiceWorkerStatusCode status, |
| 432 base::Time dispatch_event_time); | 438 base::Time dispatch_event_time); |
|
shimazu
2017/02/13 00:28:52
Could you use CreateSimpleEventCallback at service
Peter Beverloo
2017/02/13 14:08:40
Done.
| |
| 433 | 439 |
| 434 // Returns the Navigation Preload support status of the service worker. | 440 // Returns the Navigation Preload support status of the service worker. |
| 435 // - Origin Trial: Have an effective token. | 441 // - Origin Trial: Have an effective token. |
| 436 // Command line | 442 // Command line |
| 437 // Default Enable Disabled | 443 // Default Enable Disabled |
| 438 // Default A A B2 | 444 // Default A A B2 |
| 439 // Field trial Enabled A A B2 | 445 // Field trial Enabled A A B2 |
| 440 // Disabled B1 A B2 | 446 // Disabled B1 A B2 |
| 441 // | 447 // |
| 442 // - Origin Trial: No token. | 448 // - Origin Trial: No token. |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 895 | 901 |
| 896 // At this point |this| can have been deleted, so don't do anything other | 902 // At this point |this| can have been deleted, so don't do anything other |
| 897 // than returning. | 903 // than returning. |
| 898 | 904 |
| 899 return true; | 905 return true; |
| 900 } | 906 } |
| 901 | 907 |
| 902 } // namespace content | 908 } // namespace content |
| 903 | 909 |
| 904 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 910 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
| OLD | NEW |