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..3b142e4dca4b7db36775b28dee85d6b2718077a2 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"; |
+} |
+ |
+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() { |