| 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 71223e0e7a7965e9156a21da35ead17a2d5eecbe..d5b146ab3a9a265646ef93654a55cb78b2087309 100644
|
| --- a/components/network_time/network_time_tracker.cc
|
| +++ b/components/network_time/network_time_tracker.cc
|
| @@ -188,7 +188,8 @@ NetworkTimeTracker::NetworkTimeTracker(
|
| getter_(std::move(getter)),
|
| clock_(std::move(clock)),
|
| tick_clock_(std::move(tick_clock)),
|
| - pref_service_(pref_service) {
|
| + pref_service_(pref_service),
|
| + time_query_failed_(false) {
|
| const base::DictionaryValue* time_mapping =
|
| pref_service_->GetDictionary(prefs::kNetworkTimeMapping);
|
| double time_js = 0;
|
| @@ -310,7 +311,22 @@ NetworkTimeTracker::NetworkTimeResult NetworkTimeTracker::GetNetworkTime(
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| DCHECK(network_time);
|
| if (network_time_at_last_measurement_.is_null()) {
|
| - return NETWORK_TIME_NO_SYNC;
|
| + if (time_query_failed_) {
|
| + // Time query attempts have been made in the past and failed.
|
| + if (time_fetcher_) {
|
| + // A fetch (not the first attempt) is in progress.
|
| + return NETWORK_TIME_SUBSEQUENT_SYNC_PENDING;
|
| + } else {
|
| + return NETWORK_TIME_NO_SUCCESSFUL_SYNC;
|
| + }
|
| + } else {
|
| + // No time queries have happened yet.
|
| + if (time_fetcher_) {
|
| + return NETWORK_TIME_FIRST_SYNC_PENDING;
|
| + } else {
|
| + return NETWORK_TIME_NO_SYNC_ATTEMPT;
|
| + }
|
| + }
|
| }
|
| DCHECK(!ticks_at_last_measurement_.is_null());
|
| DCHECK(!time_at_last_measurement_.is_null());
|
| @@ -400,6 +416,7 @@ void NetworkTimeTracker::CheckTime() {
|
| bool NetworkTimeTracker::UpdateTimeFromResponse() {
|
| if (time_fetcher_->GetStatus().status() != net::URLRequestStatus::SUCCESS ||
|
| time_fetcher_->GetResponseCode() != 200) {
|
| + time_query_failed_ = true;
|
| DVLOG(1) << "fetch failed, status=" << time_fetcher_->GetStatus().status()
|
| << ",code=" << time_fetcher_->GetResponseCode();
|
| // The error code is negated because net errors are negative, but
|
| @@ -412,12 +429,14 @@ bool NetworkTimeTracker::UpdateTimeFromResponse() {
|
| std::string response_body;
|
| if (!time_fetcher_->GetResponseAsString(&response_body)) {
|
| DVLOG(1) << "failed to get response";
|
| + time_query_failed_ = true;
|
| return false;
|
| }
|
| DCHECK(query_signer_);
|
| if (!query_signer_->ValidateResponse(response_body,
|
| GetServerProof(time_fetcher_.get()))) {
|
| DVLOG(1) << "invalid signature";
|
| + time_query_failed_ = true;
|
| RecordFetchValidHistogram(false);
|
| return false;
|
| }
|
| @@ -425,18 +444,21 @@ bool NetworkTimeTracker::UpdateTimeFromResponse() {
|
| std::unique_ptr<base::Value> value = base::JSONReader::Read(response_body);
|
| if (!value) {
|
| DVLOG(1) << "bad JSON";
|
| + time_query_failed_ = true;
|
| RecordFetchValidHistogram(false);
|
| return false;
|
| }
|
| const base::DictionaryValue* dict;
|
| if (!value->GetAsDictionary(&dict)) {
|
| DVLOG(1) << "not a dictionary";
|
| + time_query_failed_ = true;
|
| RecordFetchValidHistogram(false);
|
| return false;
|
| }
|
| double current_time_millis;
|
| if (!dict->GetDouble("current_time_millis", ¤t_time_millis)) {
|
| DVLOG(1) << "no current_time_millis";
|
| + time_query_failed_ = true;
|
| RecordFetchValidHistogram(false);
|
| return false;
|
| }
|
| @@ -450,6 +472,7 @@ bool NetworkTimeTracker::UpdateTimeFromResponse() {
|
| base::TimeDelta::FromMilliseconds(1) +
|
| base::TimeDelta::FromSeconds(kTimeServerMaxSkewSeconds);
|
| base::TimeDelta latency = tick_clock_->NowTicks() - fetch_started_;
|
| + UMA_HISTOGRAM_TIMES("NetworkTimeTracker.TimeQueryLatency", latency);
|
| UpdateNetworkTime(current_time, resolution, latency, tick_clock_->NowTicks());
|
| return true;
|
| }
|
|
|