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

Unified Diff: components/network_time/network_time_tracker.cc

Issue 2449193002: Attempt an on-demand time fetch when encountering a date invalid error (Closed)
Patch Set: Check that network time query state is as expected before triggering response 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: components/network_time/network_time_tracker.cc
diff --git a/components/network_time/network_time_tracker.cc b/components/network_time/network_time_tracker.cc
index 2be937662e8e777b846d931adaaa3aa51413a20e..2a4672e854e3bc9fd7ee523950726956ea2b0bc6 100644
--- a/components/network_time/network_time_tracker.cc
+++ b/components/network_time/network_time_tracker.cc
@@ -100,9 +100,19 @@ const char kVariationsServiceCheckTimeIntervalSeconds[] =
"CheckTimeIntervalSeconds";
const char kVariationsServiceRandomQueryProbability[] =
"RandomQueryProbability";
-// This parameter must have the value "true" in order for
-// StartTimeFetch() to start time queries on demand.
-const char kVariationsServiceEnableFetchesOnDemand[] = "EnableFetchesOnDemand";
+
+// This parameter can have three values:
+//
+// - "background-only": Time queries will be issued in the background as
+// needed (when the clock loses sync), but on-demand time queries will
+// not be issued (i.e. StartTimeFetch() will not start time queries.)
+//
+// - "on-demand-only": Time queries will not be issued except when
+// StartTimeFetch() is called.
+//
+// - "background-and-on-demand": Time queries will be issued both in the
+// background as needed and also on-demand.
+const char kVariationsServiceFetchBehavior[] = "FetchBehavior";
// This is an ECDSA prime256v1 named-curve key.
const int kKeyVersion = 1;
@@ -147,6 +157,26 @@ class SizeLimitingStringWriter : public net::URLFetcherStringWriter {
size_t limit_;
};
+bool BackgroundQueriesEnabled() {
+ if (!base::FeatureList::IsEnabled(kNetworkTimeServiceQuerying)) {
+ return false;
+ }
+
+ const std::string param = variations::GetVariationParamValueByFeature(
+ kNetworkTimeServiceQuerying, kVariationsServiceFetchBehavior);
+ return (param == "background-only" || param == "background-and-on-demand");
meacer 2016/11/08 19:39:41 minor nit: no need for parenthesis, here and blow.
estark 2016/11/08 19:46:34 Done.
+}
+
+bool OnDemandQueriesEnabled() {
+ if (!base::FeatureList::IsEnabled(kNetworkTimeServiceQuerying)) {
+ return false;
+ }
+
+ const std::string param = variations::GetVariationParamValueByFeature(
+ kNetworkTimeServiceQuerying, kVariationsServiceFetchBehavior);
+ return (param == "on-demand-only" || param == "background-and-on-demand");
+}
+
base::TimeDelta CheckTimeInterval() {
int64_t seconds;
const std::string param = variations::GetVariationParamValueByFeature(
@@ -282,6 +312,10 @@ void NetworkTimeTracker::SetTimeServerURLForTesting(const GURL& url) {
server_url_ = url;
}
+GURL NetworkTimeTracker::GetTimeServerURLForTesting() const {
+ return server_url_;
+}
+
void NetworkTimeTracker::SetMaxResponseSizeForTesting(size_t limit) {
max_response_size_ = limit;
}
@@ -302,6 +336,10 @@ void NetworkTimeTracker::WaitForFetchForTesting(uint32_t nonce) {
run_loop.Run();
}
+void NetworkTimeTracker::OverrideNonceForTesting(uint32_t nonce) {
+ query_signer_->OverrideNonceForTesting(kKeyVersion, nonce);
+}
+
base::TimeDelta NetworkTimeTracker::GetTimerDelayForTesting() const {
DCHECK(timer_.IsRunning());
return timer_.GetCurrentDelay();
@@ -374,10 +412,7 @@ NetworkTimeTracker::NetworkTimeResult NetworkTimeTracker::GetNetworkTime(
bool NetworkTimeTracker::StartTimeFetch(const base::Closure& closure) {
DCHECK(thread_checker_.CalledOnValidThread());
- // Check if the user is opted in to on-demand time fetches.
- const std::string param = variations::GetVariationParamValueByFeature(
- kNetworkTimeServiceQuerying, kVariationsServiceEnableFetchesOnDemand);
- if (param != "true") {
+ if (!OnDemandQueriesEnabled()) {
return false;
}
@@ -536,7 +571,10 @@ void NetworkTimeTracker::OnURLFetchComplete(const net::URLFetcher* source) {
}
void NetworkTimeTracker::QueueCheckTime(base::TimeDelta delay) {
- timer_.Start(FROM_HERE, delay, this, &NetworkTimeTracker::CheckTime);
+ // Check if the user is opted in to background time fetches.
+ if (BackgroundQueriesEnabled()) {
+ timer_.Start(FROM_HERE, delay, this, &NetworkTimeTracker::CheckTime);
+ }
}
bool NetworkTimeTracker::ShouldIssueTimeQuery() {

Powered by Google App Engine
This is Rietveld 408576698