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

Unified Diff: components/network_time/network_time_tracker.cc

Issue 2254433003: When network time is unavailable, record the reason in UMA (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix maximums to not overflow, and fix unit tests Created 4 years, 4 months 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 5ce5e24a42cc4b252e7c9af84a7eaf725f352498..a9f9f82c89a7837939f59d6c977295bad32edfac 100644
--- a/components/network_time/network_time_tracker.cc
+++ b/components/network_time/network_time_tracker.cc
@@ -306,12 +306,13 @@ base::TimeDelta NetworkTimeTracker::GetTimerDelayForTesting() const {
return timer_.GetCurrentDelay();
}
-bool NetworkTimeTracker::GetNetworkTime(base::Time* network_time,
- base::TimeDelta* uncertainty) const {
+NetworkTimeTracker::NetworkTimeResult NetworkTimeTracker::GetNetworkTime(
+ base::Time* network_time,
+ base::TimeDelta* uncertainty) const {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(network_time);
if (network_time_at_last_measurement_.is_null()) {
- return false;
+ return NETWORK_TIME_NO_SYNC;
}
DCHECK(!ticks_at_last_measurement_.is_null());
DCHECK(!time_at_last_measurement_.is_null());
@@ -320,23 +321,41 @@ bool NetworkTimeTracker::GetNetworkTime(base::Time* network_time,
base::TimeDelta time_delta = clock_->Now() - time_at_last_measurement_;
if (time_delta.InMilliseconds() < 0) { // Has wall clock run backward?
DVLOG(1) << "Discarding network time due to wall clock running backward";
+ UMA_HISTOGRAM_CUSTOM_TIMES(
+ "NetworkTimeTracker.WallClockRanBackwards", time_delta.magnitude(),
+ base::TimeDelta::FromSeconds(1), base::TimeDelta::FromDays(7), 50);
network_time_at_last_measurement_ = base::Time();
- return false;
+ return NETWORK_TIME_SYNC_LOST;
}
// Now we know that both |tick_delta| and |time_delta| are positive.
- base::TimeDelta divergence = (tick_delta - time_delta).magnitude();
- if (divergence > base::TimeDelta::FromSeconds(kClockDivergenceSeconds)) {
+ base::TimeDelta divergence = tick_delta - time_delta;
+ if (divergence.magnitude() >
+ base::TimeDelta::FromSeconds(kClockDivergenceSeconds)) {
// Most likely either the machine has suspended, or the wall clock has been
// reset.
DVLOG(1) << "Discarding network time due to clocks diverging";
+
+ // The below histograms do not use |kClockDivergenceSeconds| as the
+ // lower-bound, so that |kClockDivergenceSeconds| can be changed
+ // without causing the buckets to change and making data from
+ // old/new clients incompatible.
+ if (divergence.InMilliseconds() < 0) {
+ UMA_HISTOGRAM_CUSTOM_TIMES(
+ "NetworkTimeTracker.ClockDivergence.Negative", divergence.magnitude(),
+ base::TimeDelta::FromSeconds(60), base::TimeDelta::FromDays(7), 50);
+ } else {
+ UMA_HISTOGRAM_CUSTOM_TIMES(
+ "NetworkTimeTracker.ClockDivergence.Positive", divergence.magnitude(),
+ base::TimeDelta::FromSeconds(60), base::TimeDelta::FromDays(7), 50);
+ }
network_time_at_last_measurement_ = base::Time();
- return false;
+ return NETWORK_TIME_SYNC_LOST;
}
*network_time = network_time_at_last_measurement_ + tick_delta;
if (uncertainty) {
*uncertainty = network_time_uncertainty_ + divergence;
}
- return true;
+ return NETWORK_TIME_AVAILABLE;
}
void NetworkTimeTracker::CheckTime() {
@@ -469,10 +488,10 @@ bool NetworkTimeTracker::ShouldIssueTimeQuery() {
return false;
}
- // If GetNetworkTime() returns false, synchronization has been lost
- // and a query is needed.
+ // If GetNetworkTime() does not return NETWORK_TIME_AVAILABLE,
+ // synchronization has been lost and a query is needed.
base::Time network_time;
- if (!GetNetworkTime(&network_time, nullptr)) {
+ if (GetNetworkTime(&network_time, nullptr) != NETWORK_TIME_AVAILABLE) {
return true;
}
« no previous file with comments | « components/network_time/network_time_tracker.h ('k') | components/network_time/network_time_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698