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 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
406 | 406 |
407 // Returns true if the service worker has work to do: it has pending | 407 // Returns true if the service worker has work to do: it has pending |
408 // requests, in-progress streaming URLRequestJobs, or pending start callbacks. | 408 // requests, in-progress streaming URLRequestJobs, or pending start callbacks. |
409 bool HasWork() const; | 409 bool HasWork() const; |
410 | 410 |
411 // Returns the number of pending external request count of this worker. | 411 // Returns the number of pending external request count of this worker. |
412 size_t GetExternalRequestCountForTest() const { | 412 size_t GetExternalRequestCountForTest() const { |
413 return external_request_uuid_to_request_id_.size(); | 413 return external_request_uuid_to_request_id_.size(); |
414 } | 414 } |
415 | 415 |
416 // Returns the amount of time left until the request with the latest | |
417 // expiration time expires. | |
418 base::TimeDelta remaining_timeout() const { | |
419 return max_request_expiration_time_ - tick_clock_->NowTicks(); | |
420 } | |
421 | |
416 private: | 422 private: |
417 friend class base::RefCounted<ServiceWorkerVersion>; | 423 friend class base::RefCounted<ServiceWorkerVersion>; |
418 friend class ServiceWorkerMetrics; | 424 friend class ServiceWorkerMetrics; |
419 friend class ServiceWorkerReadFromCacheJobTest; | 425 friend class ServiceWorkerReadFromCacheJobTest; |
420 friend class ServiceWorkerStallInStoppingTest; | 426 friend class ServiceWorkerStallInStoppingTest; |
421 friend class ServiceWorkerURLRequestJobTest; | 427 friend class ServiceWorkerURLRequestJobTest; |
422 friend class ServiceWorkerVersionBrowserTest; | 428 friend class ServiceWorkerVersionBrowserTest; |
423 friend class ServiceWorkerVersionTestP; | 429 friend class ServiceWorkerVersionTestP; |
424 | 430 |
425 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTestP, | 431 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTestP, |
(...skipping 22 matching lines...) Expand all Loading... | |
448 RegisterForeignFetchScopes); | 454 RegisterForeignFetchScopes); |
449 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTestP, RequestNowTimeout); | 455 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTestP, RequestNowTimeout); |
450 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTestP, RequestNowTimeoutKill); | 456 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTestP, RequestNowTimeoutKill); |
451 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTestP, RequestCustomizedTimeout); | 457 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTestP, RequestCustomizedTimeout); |
452 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTestP, MixedRequestTimeouts); | 458 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTestP, MixedRequestTimeouts); |
453 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerURLRequestJobTest, EarlyResponse); | 459 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerURLRequestJobTest, EarlyResponse); |
454 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerURLRequestJobTest, CancelRequest); | 460 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerURLRequestJobTest, CancelRequest); |
455 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerActivationTest, SkipWaiting); | 461 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerActivationTest, SkipWaiting); |
456 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerActivationTest, | 462 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerActivationTest, |
457 SkipWaitingWithInflightRequest); | 463 SkipWaitingWithInflightRequest); |
464 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest, MessageSelf); | |
458 | 465 |
459 class Metrics; | 466 class Metrics; |
460 class PingController; | 467 class PingController; |
461 | 468 |
462 struct RequestInfo { | 469 struct RequestInfo { |
463 RequestInfo(int id, | 470 RequestInfo(int id, |
464 ServiceWorkerMetrics::EventType event_type, | 471 ServiceWorkerMetrics::EventType event_type, |
465 const base::TimeTicks& expiration, | 472 const base::TimeTicks& expiration, |
466 TimeoutBehavior timeout_behavior); | 473 TimeoutBehavior timeout_behavior); |
467 ~RequestInfo(); | 474 ~RequestInfo(); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
581 // The timeout timer interval. | 588 // The timeout timer interval. |
582 static const int kTimeoutTimerDelaySeconds; | 589 static const int kTimeoutTimerDelaySeconds; |
583 // Timeout for an installed worker to start. | 590 // Timeout for an installed worker to start. |
584 static const int kStartInstalledWorkerTimeoutSeconds; | 591 static const int kStartInstalledWorkerTimeoutSeconds; |
585 // Timeout for a new worker to start. | 592 // Timeout for a new worker to start. |
586 static const int kStartNewWorkerTimeoutMinutes; | 593 static const int kStartNewWorkerTimeoutMinutes; |
587 // Timeout for a request to be handled. | 594 // Timeout for a request to be handled. |
588 static const int kRequestTimeoutMinutes; | 595 static const int kRequestTimeoutMinutes; |
589 // Timeout for the worker to stop. | 596 // Timeout for the worker to stop. |
590 static const int kStopWorkerTimeoutSeconds; | 597 static const int kStopWorkerTimeoutSeconds; |
598 // Time to wait until stopping an idle worker. | |
599 static const int kIdleWorkerTimeoutSeconds; | |
591 | 600 |
592 ~ServiceWorkerVersion() override; | 601 ~ServiceWorkerVersion() override; |
593 | 602 |
594 // The following methods all rely on the internal clock for the current time. | 603 // The following methods all rely on the internal clock for the current time. |
595 void RestartTick(base::TimeTicks* time) const; | 604 void RestartTick(base::TimeTicks* time) const; |
596 bool RequestExpired(const base::TimeTicks& expiration) const; | 605 bool RequestExpired(const base::TimeTicks& expiration) const; |
597 base::TimeDelta GetTickDuration(const base::TimeTicks& time) const; | 606 base::TimeDelta GetTickDuration(const base::TimeTicks& time) const; |
598 | 607 |
599 // EmbeddedWorkerInstance::Listener overrides: | 608 // EmbeddedWorkerInstance::Listener overrides: |
600 void OnThreadStarted() override; | 609 void OnThreadStarted() override; |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
788 // Holds the time that the outstanding StartWorker() request started. | 797 // Holds the time that the outstanding StartWorker() request started. |
789 base::TimeTicks start_time_; | 798 base::TimeTicks start_time_; |
790 // Holds the time the worker entered STOPPING status. This is also used as a | 799 // Holds the time the worker entered STOPPING status. This is also used as a |
791 // trace event id. | 800 // trace event id. |
792 base::TimeTicks stop_time_; | 801 base::TimeTicks stop_time_; |
793 // Holds the time the worker was detected as stale and needs updating. We try | 802 // Holds the time the worker was detected as stale and needs updating. We try |
794 // to update once the worker stops, but will also update if it stays alive too | 803 // to update once the worker stops, but will also update if it stays alive too |
795 // long. | 804 // long. |
796 base::TimeTicks stale_time_; | 805 base::TimeTicks stale_time_; |
797 | 806 |
807 base::TimeTicks max_request_expiration_time_; | |
falken
2016/11/21 08:01:48
nit: All these times are hard to keep track off so
Marijn Kruisselbrink
2016/12/01 19:54:30
Done
| |
808 | |
798 // Keeps track of requests for timeout purposes. Requests are sorted by | 809 // Keeps track of requests for timeout purposes. Requests are sorted by |
799 // their expiration time (soonest to expire on top of the priority queue). The | 810 // their expiration time (soonest to expire on top of the priority queue). The |
800 // timeout timer periodically checks |timeout_queue_| for entries that should | 811 // timeout timer periodically checks |timeout_queue_| for entries that should |
801 // time out or have already been fulfilled (i.e., removed from | 812 // time out or have already been fulfilled (i.e., removed from |
802 // |pending_requests_|). | 813 // |pending_requests_|). |
803 RequestInfoPriorityQueue timeout_queue_; | 814 RequestInfoPriorityQueue timeout_queue_; |
804 | 815 |
805 bool skip_waiting_ = false; | 816 bool skip_waiting_ = false; |
806 bool skip_recording_startup_time_ = false; | 817 bool skip_recording_startup_time_ = false; |
807 bool force_bypass_cache_for_scripts_ = false; | 818 bool force_bypass_cache_for_scripts_ = false; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
907 | 918 |
908 // At this point |this| can have been deleted, so don't do anything other | 919 // At this point |this| can have been deleted, so don't do anything other |
909 // than returning. | 920 // than returning. |
910 | 921 |
911 return true; | 922 return true; |
912 } | 923 } |
913 | 924 |
914 } // namespace content | 925 } // namespace content |
915 | 926 |
916 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 927 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
OLD | NEW |