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

Unified Diff: content/browser/service_worker/service_worker_version.h

Issue 2504663002: Added a local tick clock to ServiceWorkerVersion. (Closed)
Patch Set: Created 4 years, 1 month 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
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 8e08831ea13e2913b6ad6edf95019677315db566..bbebd9e8c9f5036bf0000d6b7aa74389f5fb10ab 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"
@@ -400,6 +401,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;
@@ -442,9 +446,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);
@@ -587,6 +591,11 @@ class CONTENT_EXPORT ServiceWorkerVersion
~ServiceWorkerVersion() override;
+ // The following methods all rely on the internal clock for the current time.
falken 2016/12/02 09:12:28 nit: add "|tick_clock_|" for clarity?
harkness 2016/12/02 10:15:33 Done.
+ 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;
@@ -809,6 +818,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;

Powered by Google App Engine
This is Rietveld 408576698