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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 size_t GetExternalRequestCountForTest() const { | 423 size_t GetExternalRequestCountForTest() const { |
418 return external_request_uuid_to_request_id_.size(); | 424 return external_request_uuid_to_request_id_.size(); |
419 } | 425 } |
420 | 426 |
421 // Returns the amount of time left until the request with the latest | 427 // Returns the amount of time left until the request with the latest |
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 | |
428 // mojom::ServiceWorkerEventDispatcher, once all simple events got dispatched | |
429 // through mojo, OnSimpleEventResponse function could be removed. | |
430 void OnSimpleEventFinished(int request_id, | |
431 ServiceWorkerStatusCode status, | |
432 base::Time dispatch_event_time); | |
433 | |
434 // Returns the Navigation Preload support status of the service worker. | 433 // Returns the Navigation Preload support status of the service worker. |
435 // - Origin Trial: Have an effective token. | 434 // - Origin Trial: Have an effective token. |
436 // Command line | 435 // Command line |
437 // Default Enable Disabled | 436 // Default Enable Disabled |
438 // Default A A B2 | 437 // Default A A B2 |
439 // Field trial Enabled A A B2 | 438 // Field trial Enabled A A B2 |
440 // Disabled B1 A B2 | 439 // Disabled B1 A B2 |
441 // | 440 // |
442 // - Origin Trial: No token. | 441 // - Origin Trial: No token. |
443 // Command line | 442 // Command line |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 ServiceWorkerMetrics::EventType purpose, | 677 ServiceWorkerMetrics::EventType purpose, |
679 Status prestart_status, | 678 Status prestart_status, |
680 bool is_browser_startup_complete, | 679 bool is_browser_startup_complete, |
681 const StatusCallback& callback, | 680 const StatusCallback& callback, |
682 ServiceWorkerStatusCode status, | 681 ServiceWorkerStatusCode status, |
683 scoped_refptr<ServiceWorkerRegistration> registration); | 682 scoped_refptr<ServiceWorkerRegistration> registration); |
684 void StartWorkerInternal(); | 683 void StartWorkerInternal(); |
685 | 684 |
686 void DidSkipWaiting(int request_id); | 685 void DidSkipWaiting(int request_id); |
687 | 686 |
| 687 // Callback function for simple events dispatched through mojo interface |
| 688 // mojom::ServiceWorkerEventDispatcher. Use CreateSimpleEventCallback() to |
| 689 // create a callback for a given |request_id|. |
| 690 void OnSimpleEventFinished(int request_id, |
| 691 ServiceWorkerStatusCode status, |
| 692 base::Time dispatch_event_time); |
| 693 |
688 void OnGetClientFinished(int request_id, | 694 void OnGetClientFinished(int request_id, |
689 const ServiceWorkerClientInfo& client_info); | 695 const ServiceWorkerClientInfo& client_info); |
690 | 696 |
691 void OnGetClientsFinished(int request_id, ServiceWorkerClients* clients); | 697 void OnGetClientsFinished(int request_id, ServiceWorkerClients* clients); |
692 | 698 |
693 // The timeout timer periodically calls OnTimeoutTimer, which stops the worker | 699 // The timeout timer periodically calls OnTimeoutTimer, which stops the worker |
694 // if it is excessively idle or unresponsive to ping. | 700 // if it is excessively idle or unresponsive to ping. |
695 void StartTimeoutTimer(); | 701 void StartTimeoutTimer(); |
696 void StopTimeoutTimer(); | 702 void StopTimeoutTimer(); |
697 void OnTimeoutTimer(); | 703 void OnTimeoutTimer(); |
(...skipping 197 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 |