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 <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/i18n/time_formatting.h" | 10 #include "base/i18n/time_formatting.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 const char kPrefNetworkTime[] = "network"; | 42 const char kPrefNetworkTime[] = "network"; |
43 | 43 |
44 } // namespace | 44 } // namespace |
45 | 45 |
46 // static | 46 // static |
47 void NetworkTimeTracker::RegisterPrefs(PrefRegistrySimple* registry) { | 47 void NetworkTimeTracker::RegisterPrefs(PrefRegistrySimple* registry) { |
48 registry->RegisterDictionaryPref(prefs::kNetworkTimeMapping, | 48 registry->RegisterDictionaryPref(prefs::kNetworkTimeMapping, |
49 new base::DictionaryValue()); | 49 new base::DictionaryValue()); |
50 } | 50 } |
51 | 51 |
52 NetworkTimeTracker::NetworkTimeTracker(scoped_ptr<base::Clock> clock, | 52 NetworkTimeTracker::NetworkTimeTracker( |
53 scoped_ptr<base::TickClock> tick_clock, | 53 std::unique_ptr<base::Clock> clock, |
54 PrefService* pref_service) | 54 std::unique_ptr<base::TickClock> tick_clock, |
| 55 PrefService* pref_service) |
55 : clock_(std::move(clock)), | 56 : clock_(std::move(clock)), |
56 tick_clock_(std::move(tick_clock)), | 57 tick_clock_(std::move(tick_clock)), |
57 pref_service_(pref_service) { | 58 pref_service_(pref_service) { |
58 const base::DictionaryValue* time_mapping = | 59 const base::DictionaryValue* time_mapping = |
59 pref_service_->GetDictionary(prefs::kNetworkTimeMapping); | 60 pref_service_->GetDictionary(prefs::kNetworkTimeMapping); |
60 double time_js = 0; | 61 double time_js = 0; |
61 double ticks_js = 0; | 62 double ticks_js = 0; |
62 double network_time_js = 0; | 63 double network_time_js = 0; |
63 double uncertainty_js = 0; | 64 double uncertainty_js = 0; |
64 if (time_mapping->GetDouble(kPrefTime, &time_js) && | 65 if (time_mapping->GetDouble(kPrefTime, &time_js) && |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 return false; | 161 return false; |
161 } | 162 } |
162 *network_time = network_time_at_last_measurement_ + tick_delta; | 163 *network_time = network_time_at_last_measurement_ + tick_delta; |
163 if (uncertainty) { | 164 if (uncertainty) { |
164 *uncertainty = network_time_uncertainty_ + divergence; | 165 *uncertainty = network_time_uncertainty_ + divergence; |
165 } | 166 } |
166 return true; | 167 return true; |
167 } | 168 } |
168 | 169 |
169 } // namespace network_time | 170 } // namespace network_time |
OLD | NEW |