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..1c9d890d5292777c79d46b5f6e9df9bc458ae789 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; |
@@ -302,6 +312,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(); |
@@ -376,8 +390,8 @@ 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") { |
+ kNetworkTimeServiceQuerying, kVariationsServiceFetchBehavior); |
+ if (param == "background-only") { |
return false; |
} |
@@ -536,7 +550,13 @@ 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. |
+ const std::string param = variations::GetVariationParamValueByFeature( |
+ kNetworkTimeServiceQuerying, kVariationsServiceFetchBehavior); |
+ if (base::FeatureList::IsEnabled(kNetworkTimeServiceQuerying) && |
+ param != "on-demand-only") { |
+ timer_.Start(FROM_HERE, delay, this, &NetworkTimeTracker::CheckTime); |
+ } |
} |
bool NetworkTimeTracker::ShouldIssueTimeQuery() { |