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..f77b2195323b80b4a03c7de5e9cd29e562349b98 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 != "on-demand-only" && param != "background-and-on-demand") { |
return false; |
} |
@@ -536,6 +550,13 @@ void NetworkTimeTracker::OnURLFetchComplete(const net::URLFetcher* source) { |
} |
void NetworkTimeTracker::QueueCheckTime(base::TimeDelta delay) { |
+ // Check if the user is opted in to background time fetches. |
+ const std::string param = variations::GetVariationParamValueByFeature( |
+ kNetworkTimeServiceQuerying, kVariationsServiceFetchBehavior); |
+ if (param != "background-only" && param != "background-and-on-demand") { |
+ return; |
meacer
2016/11/01 22:20:18
nit: Maybe revert the condition? It's a bit more r
estark
2016/11/02 19:58:13
Done.
|
+ } |
+ |
timer_.Start(FROM_HERE, delay, this, &NetworkTimeTracker::CheckTime); |
} |