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> |
11 #include <map> | 11 #include <map> |
12 #include <memory> | 12 #include <memory> |
13 #include <queue> | 13 #include <queue> |
14 #include <set> | 14 #include <set> |
15 #include <string> | 15 #include <string> |
16 #include <utility> | 16 #include <utility> |
17 #include <vector> | 17 #include <vector> |
18 | 18 |
19 #include "base/callback.h" | 19 #include "base/callback.h" |
20 #include "base/gtest_prod_util.h" | 20 #include "base/gtest_prod_util.h" |
21 #include "base/id_map.h" | 21 #include "base/id_map.h" |
22 #include "base/macros.h" | 22 #include "base/macros.h" |
23 #include "base/memory/ptr_util.h" | 23 #include "base/memory/ptr_util.h" |
24 #include "base/memory/ref_counted.h" | 24 #include "base/memory/ref_counted.h" |
25 #include "base/observer_list.h" | 25 #include "base/observer_list.h" |
26 #include "base/optional.h" | 26 #include "base/optional.h" |
27 #include "base/threading/thread_task_runner_handle.h" | 27 #include "base/threading/thread_task_runner_handle.h" |
| 28 #include "base/time/clock.h" |
28 #include "base/time/tick_clock.h" | 29 #include "base/time/tick_clock.h" |
29 #include "base/time/time.h" | 30 #include "base/time/time.h" |
30 #include "base/timer/timer.h" | 31 #include "base/timer/timer.h" |
31 #include "content/browser/service_worker/embedded_worker_instance.h" | 32 #include "content/browser/service_worker/embedded_worker_instance.h" |
32 #include "content/browser/service_worker/embedded_worker_status.h" | 33 #include "content/browser/service_worker/embedded_worker_status.h" |
33 #include "content/browser/service_worker/service_worker_context_request_handler.
h" | 34 #include "content/browser/service_worker/service_worker_context_request_handler.
h" |
34 #include "content/browser/service_worker/service_worker_metrics.h" | 35 #include "content/browser/service_worker/service_worker_metrics.h" |
35 #include "content/browser/service_worker/service_worker_script_cache_map.h" | 36 #include "content/browser/service_worker/service_worker_script_cache_map.h" |
36 #include "content/common/content_export.h" | 37 #include "content/common/content_export.h" |
37 #include "content/common/origin_trials/trial_token_validator.h" | 38 #include "content/common/origin_trials/trial_token_validator.h" |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 // to that of the ServiceWorker. | 386 // to that of the ServiceWorker. |
386 void SetMainScriptHttpResponseInfo(const net::HttpResponseInfo& http_info); | 387 void SetMainScriptHttpResponseInfo(const net::HttpResponseInfo& http_info); |
387 const net::HttpResponseInfo* GetMainScriptHttpResponseInfo(); | 388 const net::HttpResponseInfo* GetMainScriptHttpResponseInfo(); |
388 | 389 |
389 // Simulate ping timeout. Should be used for tests-only. | 390 // Simulate ping timeout. Should be used for tests-only. |
390 void SimulatePingTimeoutForTesting(); | 391 void SimulatePingTimeoutForTesting(); |
391 | 392 |
392 // Used to allow tests to change time for testing. | 393 // Used to allow tests to change time for testing. |
393 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock); | 394 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock); |
394 | 395 |
| 396 // Used to allow tests to change wall clock for testing. |
| 397 void SetClockForTesting(std::unique_ptr<base::Clock> clock); |
| 398 |
395 // Returns true if the service worker has work to do: it has pending | 399 // Returns true if the service worker has work to do: it has pending |
396 // requests, in-progress streaming URLRequestJobs, or pending start callbacks. | 400 // requests, in-progress streaming URLRequestJobs, or pending start callbacks. |
397 bool HasWork() const; | 401 bool HasWork() const; |
398 | 402 |
399 // Returns the number of pending external request count of this worker. | 403 // Returns the number of pending external request count of this worker. |
400 size_t GetExternalRequestCountForTest() const { | 404 size_t GetExternalRequestCountForTest() const { |
401 return external_request_uuid_to_request_id_.size(); | 405 return external_request_uuid_to_request_id_.size(); |
402 } | 406 } |
403 | 407 |
404 // Returns the amount of time left until the request with the latest | 408 // Returns the amount of time left until the request with the latest |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 | 791 |
788 std::unique_ptr<TrialTokenValidator::FeatureToTokensMap> origin_trial_tokens_; | 792 std::unique_ptr<TrialTokenValidator::FeatureToTokensMap> origin_trial_tokens_; |
789 | 793 |
790 // If not OK, the reason that StartWorker failed. Used for | 794 // If not OK, the reason that StartWorker failed. Used for |
791 // running |start_callbacks_|. | 795 // running |start_callbacks_|. |
792 ServiceWorkerStatusCode start_worker_status_ = SERVICE_WORKER_OK; | 796 ServiceWorkerStatusCode start_worker_status_ = SERVICE_WORKER_OK; |
793 | 797 |
794 // The clock used to vend tick time. | 798 // The clock used to vend tick time. |
795 std::unique_ptr<base::TickClock> tick_clock_; | 799 std::unique_ptr<base::TickClock> tick_clock_; |
796 | 800 |
| 801 // The clock used for actual (wall clock) time |
| 802 std::unique_ptr<base::Clock> clock_; |
| 803 |
797 std::unique_ptr<PingController> ping_controller_; | 804 std::unique_ptr<PingController> ping_controller_; |
798 | 805 |
799 // Used for recording worker activities (e.g., a ratio of handled events) | 806 // Used for recording worker activities (e.g., a ratio of handled events) |
800 // while this service worker is running (i.e., after it starts up until it | 807 // while this service worker is running (i.e., after it starts up until it |
801 // stops). | 808 // stops). |
802 std::unique_ptr<ServiceWorkerMetrics::ScopedEventRecorder> event_recorder_; | 809 std::unique_ptr<ServiceWorkerMetrics::ScopedEventRecorder> event_recorder_; |
803 | 810 |
804 bool stop_when_devtools_detached_ = false; | 811 bool stop_when_devtools_detached_ = false; |
805 | 812 |
806 // Keeps the first purpose of starting the worker for UMA. Cleared in | 813 // Keeps the first purpose of starting the worker for UMA. Cleared in |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 | 858 |
852 // At this point |this| can have been deleted, so don't do anything other | 859 // At this point |this| can have been deleted, so don't do anything other |
853 // than returning. | 860 // than returning. |
854 | 861 |
855 return true; | 862 return true; |
856 } | 863 } |
857 | 864 |
858 } // namespace content | 865 } // namespace content |
859 | 866 |
860 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 867 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
OLD | NEW |