Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: content/browser/service_worker/service_worker_version.h

Issue 2504663002: Added a local tick clock to ServiceWorkerVersion. (Closed)
Patch Set: Fix test issues and rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_version.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/containers/scoped_ptr_hash_map.h" 20 #include "base/containers/scoped_ptr_hash_map.h"
21 #include "base/gtest_prod_util.h" 21 #include "base/gtest_prod_util.h"
22 #include "base/id_map.h" 22 #include "base/id_map.h"
23 #include "base/macros.h" 23 #include "base/macros.h"
24 #include "base/memory/ptr_util.h" 24 #include "base/memory/ptr_util.h"
25 #include "base/memory/ref_counted.h" 25 #include "base/memory/ref_counted.h"
26 #include "base/observer_list.h" 26 #include "base/observer_list.h"
27 #include "base/optional.h" 27 #include "base/optional.h"
28 #include "base/threading/thread_task_runner_handle.h" 28 #include "base/threading/thread_task_runner_handle.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_metrics.h" 34 #include "content/browser/service_worker/service_worker_metrics.h"
34 #include "content/browser/service_worker/service_worker_script_cache_map.h" 35 #include "content/browser/service_worker/service_worker_script_cache_map.h"
35 #include "content/common/content_export.h" 36 #include "content/common/content_export.h"
36 #include "content/common/origin_trials/trial_token_validator.h" 37 #include "content/common/origin_trials/trial_token_validator.h"
37 #include "content/common/service_worker/service_worker_event_dispatcher.mojom.h" 38 #include "content/common/service_worker/service_worker_event_dispatcher.mojom.h"
38 #include "content/common/service_worker/service_worker_status_code.h" 39 #include "content/common/service_worker/service_worker_status_code.h"
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 // Sets the HttpResponseInfo used to load the main script. 391 // Sets the HttpResponseInfo used to load the main script.
391 // This HttpResponseInfo will be used for all responses sent back from the 392 // This HttpResponseInfo will be used for all responses sent back from the
392 // service worker, as the effective security of these responses is equivalent 393 // service worker, as the effective security of these responses is equivalent
393 // to that of the ServiceWorker. 394 // to that of the ServiceWorker.
394 void SetMainScriptHttpResponseInfo(const net::HttpResponseInfo& http_info); 395 void SetMainScriptHttpResponseInfo(const net::HttpResponseInfo& http_info);
395 const net::HttpResponseInfo* GetMainScriptHttpResponseInfo(); 396 const net::HttpResponseInfo* GetMainScriptHttpResponseInfo();
396 397
397 // Simulate ping timeout. Should be used for tests-only. 398 // Simulate ping timeout. Should be used for tests-only.
398 void SimulatePingTimeoutForTesting(); 399 void SimulatePingTimeoutForTesting();
399 400
401 // Used to allow tests to change time for testing.
402 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock);
403
400 // Returns true if the service worker has work to do: it has pending 404 // Returns true if the service worker has work to do: it has pending
401 // requests, in-progress streaming URLRequestJobs, or pending start callbacks. 405 // requests, in-progress streaming URLRequestJobs, or pending start callbacks.
402 bool HasWork() const; 406 bool HasWork() const;
403 407
404 // Returns the number of pending external request count of this worker. 408 // Returns the number of pending external request count of this worker.
405 size_t GetExternalRequestCountForTest() const { 409 size_t GetExternalRequestCountForTest() const {
406 return external_request_uuid_to_request_id_.size(); 410 return external_request_uuid_to_request_id_.size();
407 } 411 }
408 412
409 private: 413 private:
(...skipping 22 matching lines...) Expand all
432 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTestP, RequestTimeout); 436 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTestP, RequestTimeout);
433 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerFailToStartTest, Timeout); 437 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerFailToStartTest, Timeout);
434 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest, 438 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest,
435 TimeoutStartingWorker); 439 TimeoutStartingWorker);
436 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest, 440 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest,
437 TimeoutWorkerInEvent); 441 TimeoutWorkerInEvent);
438 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStallInStoppingTest, DetachThenStart); 442 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStallInStoppingTest, DetachThenStart);
439 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStallInStoppingTest, DetachThenRestart); 443 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStallInStoppingTest, DetachThenRestart);
440 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTestP, 444 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTestP,
441 RegisterForeignFetchScopes); 445 RegisterForeignFetchScopes);
446 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTestP, RequestNowTimeout);
447 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTestP, RequestNowTimeoutKill);
442 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTestP, RequestCustomizedTimeout); 448 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTestP, RequestCustomizedTimeout);
443 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTestP,
444 RequestCustomizedTimeoutKill);
445 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTestP, MixedRequestTimeouts); 449 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTestP, MixedRequestTimeouts);
446 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerURLRequestJobTest, EarlyResponse); 450 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerURLRequestJobTest, EarlyResponse);
447 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerURLRequestJobTest, CancelRequest); 451 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerURLRequestJobTest, CancelRequest);
448 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerActivationTest, SkipWaiting); 452 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerActivationTest, SkipWaiting);
449 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerActivationTest, 453 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerActivationTest,
450 SkipWaitingWithInflightRequest); 454 SkipWaitingWithInflightRequest);
451 455
452 class Metrics; 456 class Metrics;
453 class PingController; 457 class PingController;
454 458
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 static const int kStartInstalledWorkerTimeoutSeconds; 581 static const int kStartInstalledWorkerTimeoutSeconds;
578 // Timeout for a new worker to start. 582 // Timeout for a new worker to start.
579 static const int kStartNewWorkerTimeoutMinutes; 583 static const int kStartNewWorkerTimeoutMinutes;
580 // Timeout for a request to be handled. 584 // Timeout for a request to be handled.
581 static const int kRequestTimeoutMinutes; 585 static const int kRequestTimeoutMinutes;
582 // Timeout for the worker to stop. 586 // Timeout for the worker to stop.
583 static const int kStopWorkerTimeoutSeconds; 587 static const int kStopWorkerTimeoutSeconds;
584 588
585 ~ServiceWorkerVersion() override; 589 ~ServiceWorkerVersion() override;
586 590
591 // The following methods all rely on the internal |tick_clock_| for the
592 // current time.
593 void RestartTick(base::TimeTicks* time) const;
594 bool RequestExpired(const base::TimeTicks& expiration) const;
595 base::TimeDelta GetTickDuration(const base::TimeTicks& time) const;
596
587 // EmbeddedWorkerInstance::Listener overrides: 597 // EmbeddedWorkerInstance::Listener overrides:
588 void OnThreadStarted() override; 598 void OnThreadStarted() override;
589 void OnStarting() override; 599 void OnStarting() override;
590 void OnStarted() override; 600 void OnStarted() override;
591 void OnStopping() override; 601 void OnStopping() override;
592 void OnStopped(EmbeddedWorkerStatus old_status) override; 602 void OnStopped(EmbeddedWorkerStatus old_status) override;
593 void OnDetached(EmbeddedWorkerStatus old_status) override; 603 void OnDetached(EmbeddedWorkerStatus old_status) override;
594 void OnScriptLoaded() override; 604 void OnScriptLoaded() override;
595 void OnScriptLoadFailed() override; 605 void OnScriptLoadFailed() override;
596 void OnRegisteredToDevToolsManager() override; 606 void OnRegisteredToDevToolsManager() override;
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 804
795 std::vector<int> pending_skip_waiting_requests_; 805 std::vector<int> pending_skip_waiting_requests_;
796 std::unique_ptr<net::HttpResponseInfo> main_script_http_info_; 806 std::unique_ptr<net::HttpResponseInfo> main_script_http_info_;
797 807
798 std::unique_ptr<TrialTokenValidator::FeatureToTokensMap> origin_trial_tokens_; 808 std::unique_ptr<TrialTokenValidator::FeatureToTokensMap> origin_trial_tokens_;
799 809
800 // If not OK, the reason that StartWorker failed. Used for 810 // If not OK, the reason that StartWorker failed. Used for
801 // running |start_callbacks_|. 811 // running |start_callbacks_|.
802 ServiceWorkerStatusCode start_worker_status_ = SERVICE_WORKER_OK; 812 ServiceWorkerStatusCode start_worker_status_ = SERVICE_WORKER_OK;
803 813
814 // The clock used to vend tick time.
815 std::unique_ptr<base::TickClock> tick_clock_;
816
804 std::unique_ptr<PingController> ping_controller_; 817 std::unique_ptr<PingController> ping_controller_;
805 std::unique_ptr<Metrics> metrics_; 818 std::unique_ptr<Metrics> metrics_;
806 const bool should_exclude_from_uma_ = false; 819 const bool should_exclude_from_uma_ = false;
807 820
808 bool stop_when_devtools_detached_ = false; 821 bool stop_when_devtools_detached_ = false;
809 822
810 // Keeps the first purpose of starting the worker for UMA. Cleared in 823 // Keeps the first purpose of starting the worker for UMA. Cleared in
811 // FinishStartWorker(). 824 // FinishStartWorker().
812 base::Optional<ServiceWorkerMetrics::EventType> start_worker_first_purpose_; 825 base::Optional<ServiceWorkerMetrics::EventType> start_worker_first_purpose_;
813 826
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 875
863 // At this point |this| can have been deleted, so don't do anything other 876 // At this point |this| can have been deleted, so don't do anything other
864 // than returning. 877 // than returning.
865 878
866 return true; 879 return true;
867 } 880 }
868 881
869 } // namespace content 882 } // namespace content
870 883
871 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ 884 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_version.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698