| 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 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 std::unique_ptr<net::URLFetcherResponseWriter>( | 367 std::unique_ptr<net::URLFetcherResponseWriter>( |
| 368 new SizeLimitingStringWriter(max_response_size_))); | 368 new SizeLimitingStringWriter(max_response_size_))); |
| 369 DCHECK(getter_); | 369 DCHECK(getter_); |
| 370 time_fetcher_->SetRequestContext(getter_.get()); | 370 time_fetcher_->SetRequestContext(getter_.get()); |
| 371 // Not expecting any cookies, but just in case. | 371 // Not expecting any cookies, but just in case. |
| 372 time_fetcher_->SetLoadFlags(net::LOAD_BYPASS_CACHE | net::LOAD_DISABLE_CACHE | | 372 time_fetcher_->SetLoadFlags(net::LOAD_BYPASS_CACHE | net::LOAD_DISABLE_CACHE | |
| 373 net::LOAD_DO_NOT_SAVE_COOKIES | | 373 net::LOAD_DO_NOT_SAVE_COOKIES | |
| 374 net::LOAD_DO_NOT_SEND_COOKIES | | 374 net::LOAD_DO_NOT_SEND_COOKIES | |
| 375 net::LOAD_DO_NOT_SEND_AUTH_DATA); | 375 net::LOAD_DO_NOT_SEND_AUTH_DATA); |
| 376 | 376 |
| 377 UMA_HISTOGRAM_BOOLEAN("NetworkTimeTracker.UpdateTimeFetchAttempted", true); | |
| 378 | |
| 379 time_fetcher_->Start(); | 377 time_fetcher_->Start(); |
| 380 fetch_started_ = tick_clock_->NowTicks(); | 378 fetch_started_ = tick_clock_->NowTicks(); |
| 381 | 379 |
| 382 timer_.Stop(); // Restarted in OnURLFetchComplete(). | 380 timer_.Stop(); // Restarted in OnURLFetchComplete(). |
| 383 } | 381 } |
| 384 | 382 |
| 385 bool NetworkTimeTracker::UpdateTimeFromResponse() { | 383 bool NetworkTimeTracker::UpdateTimeFromResponse() { |
| 386 if (time_fetcher_->GetStatus().status() != net::URLRequestStatus::SUCCESS || | 384 if (time_fetcher_->GetStatus().status() != net::URLRequestStatus::SUCCESS || |
| 387 time_fetcher_->GetResponseCode() != 200) { | 385 time_fetcher_->GetResponseCode() != 200) { |
| 388 DVLOG(1) << "fetch failed, status=" << time_fetcher_->GetStatus().status() | 386 DVLOG(1) << "fetch failed, status=" << time_fetcher_->GetStatus().status() |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 base::Time network_time; | 474 base::Time network_time; |
| 477 if (!GetNetworkTime(&network_time, nullptr)) { | 475 if (!GetNetworkTime(&network_time, nullptr)) { |
| 478 return true; | 476 return true; |
| 479 } | 477 } |
| 480 | 478 |
| 481 // Otherwise, make the decision at random. | 479 // Otherwise, make the decision at random. |
| 482 return base::RandDouble() < RandomQueryProbability(); | 480 return base::RandDouble() < RandomQueryProbability(); |
| 483 } | 481 } |
| 484 | 482 |
| 485 } // namespace network_time | 483 } // namespace network_time |
| OLD | NEW |