| 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 |
| 11 #include "base/i18n/time_formatting.h" | 11 #include "base/i18n/time_formatting.h" |
| 12 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/metrics/sparse_histogram.h" | 15 #include "base/metrics/sparse_histogram.h" |
| 16 #include "base/rand_util.h" | 16 #include "base/rand_util.h" |
| 17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/time/tick_clock.h" | 20 #include "base/time/tick_clock.h" |
| 21 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 22 #include "components/client_update_protocol/ecdsa.h" | 22 #include "components/client_update_protocol/ecdsa.h" |
| 23 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 23 #include "components/network_time/network_time_pref_names.h" | 24 #include "components/network_time/network_time_pref_names.h" |
| 24 #include "components/prefs/pref_registry_simple.h" | 25 #include "components/prefs/pref_registry_simple.h" |
| 25 #include "components/prefs/pref_service.h" | 26 #include "components/prefs/pref_service.h" |
| 26 #include "components/variations/variations_associated_data.h" | 27 #include "components/variations/variations_associated_data.h" |
| 27 #include "net/base/load_flags.h" | 28 #include "net/base/load_flags.h" |
| 28 #include "net/base/net_errors.h" | 29 #include "net/base/net_errors.h" |
| 29 #include "net/http/http_response_headers.h" | 30 #include "net/http/http_response_headers.h" |
| 30 #include "net/url_request/url_fetcher.h" | 31 #include "net/url_request/url_fetcher.h" |
| 31 #include "net/url_request/url_fetcher_response_writer.h" | 32 #include "net/url_request/url_fetcher_response_writer.h" |
| 32 #include "net/url_request/url_request_context_getter.h" | 33 #include "net/url_request/url_request_context_getter.h" |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 GURL::Replacements replacements; | 458 GURL::Replacements replacements; |
| 458 replacements.SetQueryStr(query_string); | 459 replacements.SetQueryStr(query_string); |
| 459 url = url.ReplaceComponents(replacements); | 460 url = url.ReplaceComponents(replacements); |
| 460 | 461 |
| 461 // This cancels any outstanding fetch. | 462 // This cancels any outstanding fetch. |
| 462 time_fetcher_ = net::URLFetcher::Create(url, net::URLFetcher::GET, this); | 463 time_fetcher_ = net::URLFetcher::Create(url, net::URLFetcher::GET, this); |
| 463 if (!time_fetcher_) { | 464 if (!time_fetcher_) { |
| 464 DVLOG(1) << "tried to make fetch happen; failed"; | 465 DVLOG(1) << "tried to make fetch happen; failed"; |
| 465 return; | 466 return; |
| 466 } | 467 } |
| 468 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 469 time_fetcher_.get(), |
| 470 data_use_measurement::DataUseUserData::NETWORK_TIME_TRACKER); |
| 467 time_fetcher_->SaveResponseWithWriter( | 471 time_fetcher_->SaveResponseWithWriter( |
| 468 std::unique_ptr<net::URLFetcherResponseWriter>( | 472 std::unique_ptr<net::URLFetcherResponseWriter>( |
| 469 new SizeLimitingStringWriter(max_response_size_))); | 473 new SizeLimitingStringWriter(max_response_size_))); |
| 470 DCHECK(getter_); | 474 DCHECK(getter_); |
| 471 time_fetcher_->SetRequestContext(getter_.get()); | 475 time_fetcher_->SetRequestContext(getter_.get()); |
| 472 // Not expecting any cookies, but just in case. | 476 // Not expecting any cookies, but just in case. |
| 473 time_fetcher_->SetLoadFlags(net::LOAD_BYPASS_CACHE | net::LOAD_DISABLE_CACHE | | 477 time_fetcher_->SetLoadFlags(net::LOAD_BYPASS_CACHE | net::LOAD_DISABLE_CACHE | |
| 474 net::LOAD_DO_NOT_SAVE_COOKIES | | 478 net::LOAD_DO_NOT_SAVE_COOKIES | |
| 475 net::LOAD_DO_NOT_SEND_COOKIES | | 479 net::LOAD_DO_NOT_SEND_COOKIES | |
| 476 net::LOAD_DO_NOT_SEND_AUTH_DATA); | 480 net::LOAD_DO_NOT_SEND_AUTH_DATA); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 base::Time network_time; | 604 base::Time network_time; |
| 601 if (GetNetworkTime(&network_time, nullptr) != NETWORK_TIME_AVAILABLE) { | 605 if (GetNetworkTime(&network_time, nullptr) != NETWORK_TIME_AVAILABLE) { |
| 602 return true; | 606 return true; |
| 603 } | 607 } |
| 604 | 608 |
| 605 // Otherwise, make the decision at random. | 609 // Otherwise, make the decision at random. |
| 606 return base::RandDouble() < RandomQueryProbability(); | 610 return base::RandDouble() < RandomQueryProbability(); |
| 607 } | 611 } |
| 608 | 612 |
| 609 } // namespace network_time | 613 } // namespace network_time |
| OLD | NEW |