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/memory/ptr_util.h" |
14 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
15 #include "base/metrics/sparse_histogram.h" | 16 #include "base/metrics/sparse_histogram.h" |
16 #include "base/rand_util.h" | 17 #include "base/rand_util.h" |
17 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
18 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
19 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
20 #include "base/time/tick_clock.h" | 21 #include "base/time/tick_clock.h" |
21 #include "build/build_config.h" | 22 #include "build/build_config.h" |
22 #include "components/client_update_protocol/ecdsa.h" | 23 #include "components/client_update_protocol/ecdsa.h" |
23 #include "components/data_use_measurement/core/data_use_user_data.h" | 24 #include "components/data_use_measurement/core/data_use_user_data.h" |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 183 |
183 void RecordFetchValidHistogram(bool valid) { | 184 void RecordFetchValidHistogram(bool valid) { |
184 UMA_HISTOGRAM_BOOLEAN("NetworkTimeTracker.UpdateTimeFetchValid", valid); | 185 UMA_HISTOGRAM_BOOLEAN("NetworkTimeTracker.UpdateTimeFetchValid", valid); |
185 } | 186 } |
186 | 187 |
187 } // namespace | 188 } // namespace |
188 | 189 |
189 // static | 190 // static |
190 void NetworkTimeTracker::RegisterPrefs(PrefRegistrySimple* registry) { | 191 void NetworkTimeTracker::RegisterPrefs(PrefRegistrySimple* registry) { |
191 registry->RegisterDictionaryPref(prefs::kNetworkTimeMapping, | 192 registry->RegisterDictionaryPref(prefs::kNetworkTimeMapping, |
192 new base::DictionaryValue()); | 193 base::MakeUnique<base::DictionaryValue>()); |
193 } | 194 } |
194 | 195 |
195 NetworkTimeTracker::NetworkTimeTracker( | 196 NetworkTimeTracker::NetworkTimeTracker( |
196 std::unique_ptr<base::Clock> clock, | 197 std::unique_ptr<base::Clock> clock, |
197 std::unique_ptr<base::TickClock> tick_clock, | 198 std::unique_ptr<base::TickClock> tick_clock, |
198 PrefService* pref_service, | 199 PrefService* pref_service, |
199 scoped_refptr<net::URLRequestContextGetter> getter) | 200 scoped_refptr<net::URLRequestContextGetter> getter) |
200 : server_url_(kTimeServiceURL), | 201 : server_url_(kTimeServiceURL), |
201 max_response_size_(1024), | 202 max_response_size_(1024), |
202 backoff_(base::TimeDelta::FromMinutes(kBackoffMinutes)), | 203 backoff_(base::TimeDelta::FromMinutes(kBackoffMinutes)), |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 base::Time network_time; | 626 base::Time network_time; |
626 if (GetNetworkTime(&network_time, nullptr) != NETWORK_TIME_AVAILABLE) { | 627 if (GetNetworkTime(&network_time, nullptr) != NETWORK_TIME_AVAILABLE) { |
627 return true; | 628 return true; |
628 } | 629 } |
629 | 630 |
630 // Otherwise, make the decision at random. | 631 // Otherwise, make the decision at random. |
631 return base::RandDouble() < RandomQueryProbability(); | 632 return base::RandDouble() < RandomQueryProbability(); |
632 } | 633 } |
633 | 634 |
634 } // namespace network_time | 635 } // namespace network_time |
OLD | NEW |