| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/network_time/network_time_tracker.h" | 5 #include "components/network_time/network_time_tracker.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 } | 527 } |
| 528 | 528 |
| 529 RecordFetchValidHistogram(true); | 529 RecordFetchValidHistogram(true); |
| 530 | 530 |
| 531 // There is a "server_nonce" key here too, but it serves no purpose other than | 531 // There is a "server_nonce" key here too, but it serves no purpose other than |
| 532 // to make the server's response unpredictable. | 532 // to make the server's response unpredictable. |
| 533 base::Time current_time = base::Time::FromJsTime(current_time_millis); | 533 base::Time current_time = base::Time::FromJsTime(current_time_millis); |
| 534 base::TimeDelta resolution = | 534 base::TimeDelta resolution = |
| 535 base::TimeDelta::FromMilliseconds(1) + | 535 base::TimeDelta::FromMilliseconds(1) + |
| 536 base::TimeDelta::FromSeconds(kTimeServerMaxSkewSeconds); | 536 base::TimeDelta::FromSeconds(kTimeServerMaxSkewSeconds); |
| 537 |
| 538 // Record histograms for the latency of the time query and the time delta |
| 539 // between time fetches. |
| 537 base::TimeDelta latency = tick_clock_->NowTicks() - fetch_started_; | 540 base::TimeDelta latency = tick_clock_->NowTicks() - fetch_started_; |
| 538 UMA_HISTOGRAM_TIMES("NetworkTimeTracker.TimeQueryLatency", latency); | 541 UMA_HISTOGRAM_TIMES("NetworkTimeTracker.TimeQueryLatency", latency); |
| 542 if (!last_fetched_time_.is_null()) { |
| 543 UMA_HISTOGRAM_CUSTOM_TIMES("NetworkTimeTracker.TimeBetweenFetches", |
| 544 current_time - last_fetched_time_, |
| 545 base::TimeDelta::FromHours(1), |
| 546 base::TimeDelta::FromDays(7), 50); |
| 547 } |
| 548 last_fetched_time_ = current_time; |
| 549 |
| 539 UpdateNetworkTime(current_time, resolution, latency, tick_clock_->NowTicks()); | 550 UpdateNetworkTime(current_time, resolution, latency, tick_clock_->NowTicks()); |
| 540 return true; | 551 return true; |
| 541 } | 552 } |
| 542 | 553 |
| 543 void NetworkTimeTracker::OnURLFetchComplete(const net::URLFetcher* source) { | 554 void NetworkTimeTracker::OnURLFetchComplete(const net::URLFetcher* source) { |
| 544 DCHECK(thread_checker_.CalledOnValidThread()); | 555 DCHECK(thread_checker_.CalledOnValidThread()); |
| 545 DCHECK(time_fetcher_); | 556 DCHECK(time_fetcher_); |
| 546 DCHECK_EQ(source, time_fetcher_.get()); | 557 DCHECK_EQ(source, time_fetcher_.get()); |
| 547 | 558 |
| 548 time_query_completed_ = true; | 559 time_query_completed_ = true; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 base::Time network_time; | 600 base::Time network_time; |
| 590 if (GetNetworkTime(&network_time, nullptr) != NETWORK_TIME_AVAILABLE) { | 601 if (GetNetworkTime(&network_time, nullptr) != NETWORK_TIME_AVAILABLE) { |
| 591 return true; | 602 return true; |
| 592 } | 603 } |
| 593 | 604 |
| 594 // Otherwise, make the decision at random. | 605 // Otherwise, make the decision at random. |
| 595 return base::RandDouble() < RandomQueryProbability(); | 606 return base::RandDouble() < RandomQueryProbability(); |
| 596 } | 607 } |
| 597 | 608 |
| 598 } // namespace network_time | 609 } // namespace network_time |
| OLD | NEW |