Chromium Code Reviews| 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..9c4a1df02716149896da4fe906d53665c22fa0f0 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,28 @@ 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_SPARSE_SLOWLY("NetworkTimeTracker.WallClockRanBackwards", |
| + time_delta.InSeconds()); |
| 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"; |
| + UMA_HISTOGRAM_SPARSE_SLOWLY("NetworkTimeTracker.ClockDivergence", |
|
Steven Holte
2016/08/19 19:24:52
Using sparse histogram here seems a little surpris
|
| + divergence.InSeconds()); |
| 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 +475,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; |
| } |