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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_version.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/service_worker/service_worker_version.h
diff --git a/content/browser/service_worker/service_worker_version.h b/content/browser/service_worker/service_worker_version.h
index 314f18d94b44f47c1c11fe74be1ad14307a9a3f2..f1839424f73f2cd482100ad44d80e02bba17fc90 100644
--- a/content/browser/service_worker/service_worker_version.h
+++ b/content/browser/service_worker/service_worker_version.h
@@ -26,6 +26,7 @@
#include "base/observer_list.h"
#include "base/optional.h"
#include "base/threading/thread_task_runner_handle.h"
+#include "base/time/tick_clock.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "content/browser/service_worker/embedded_worker_instance.h"
@@ -397,6 +398,9 @@ class CONTENT_EXPORT ServiceWorkerVersion
// Simulate ping timeout. Should be used for tests-only.
void SimulatePingTimeoutForTesting();
+ // Used to allow tests to change time for testing.
+ void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock);
+
// Returns true if the service worker has work to do: it has pending
// requests, in-progress streaming URLRequestJobs, or pending start callbacks.
bool HasWork() const;
@@ -439,9 +443,9 @@ class CONTENT_EXPORT ServiceWorkerVersion
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStallInStoppingTest, DetachThenRestart);
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTestP,
RegisterForeignFetchScopes);
+ FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTestP, RequestNowTimeout);
+ FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTestP, RequestNowTimeoutKill);
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTestP, RequestCustomizedTimeout);
- FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTestP,
- RequestCustomizedTimeoutKill);
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTestP, MixedRequestTimeouts);
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerURLRequestJobTest, EarlyResponse);
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerURLRequestJobTest, CancelRequest);
@@ -584,6 +588,12 @@ class CONTENT_EXPORT ServiceWorkerVersion
~ServiceWorkerVersion() override;
+ // The following methods all rely on the internal |tick_clock_| for the
+ // current time.
+ void RestartTick(base::TimeTicks* time) const;
+ bool RequestExpired(const base::TimeTicks& expiration) const;
+ base::TimeDelta GetTickDuration(const base::TimeTicks& time) const;
+
// EmbeddedWorkerInstance::Listener overrides:
void OnThreadStarted() override;
void OnStarting() override;
@@ -801,6 +811,9 @@ class CONTENT_EXPORT ServiceWorkerVersion
// running |start_callbacks_|.
ServiceWorkerStatusCode start_worker_status_ = SERVICE_WORKER_OK;
+ // The clock used to vend tick time.
+ std::unique_ptr<base::TickClock> tick_clock_;
+
std::unique_ptr<PingController> ping_controller_;
std::unique_ptr<Metrics> metrics_;
const bool should_exclude_from_uma_ = false;
« 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