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 | 9 |
9 #include "base/i18n/time_formatting.h" | 10 #include "base/i18n/time_formatting.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/prefs/pref_registry_simple.h" | 12 #include "base/prefs/pref_registry_simple.h" |
12 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
14 #include "base/time/tick_clock.h" | 15 #include "base/time/tick_clock.h" |
15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
16 #include "components/network_time/network_time_pref_names.h" | 17 #include "components/network_time/network_time_pref_names.h" |
17 | 18 |
(...skipping 14 matching lines...) Expand all Loading... |
32 } // namespace | 33 } // namespace |
33 | 34 |
34 // static | 35 // static |
35 void NetworkTimeTracker::RegisterPrefs(PrefRegistrySimple* registry) { | 36 void NetworkTimeTracker::RegisterPrefs(PrefRegistrySimple* registry) { |
36 registry->RegisterDictionaryPref(prefs::kNetworkTimeMapping, | 37 registry->RegisterDictionaryPref(prefs::kNetworkTimeMapping, |
37 new base::DictionaryValue()); | 38 new base::DictionaryValue()); |
38 } | 39 } |
39 | 40 |
40 NetworkTimeTracker::NetworkTimeTracker(scoped_ptr<base::TickClock> tick_clock, | 41 NetworkTimeTracker::NetworkTimeTracker(scoped_ptr<base::TickClock> tick_clock, |
41 PrefService* pref_service) | 42 PrefService* pref_service) |
42 : tick_clock_(tick_clock.Pass()), | 43 : tick_clock_(std::move(tick_clock)), |
43 pref_service_(pref_service), | 44 pref_service_(pref_service), |
44 received_network_time_(false) { | 45 received_network_time_(false) { |
45 const base::DictionaryValue* time_mapping = | 46 const base::DictionaryValue* time_mapping = |
46 pref_service_->GetDictionary(prefs::kNetworkTimeMapping); | 47 pref_service_->GetDictionary(prefs::kNetworkTimeMapping); |
47 double local_time_js = 0; | 48 double local_time_js = 0; |
48 double network_time_js = 0; | 49 double network_time_js = 0; |
49 if (time_mapping->GetDouble("local", &local_time_js) && | 50 if (time_mapping->GetDouble("local", &local_time_js) && |
50 time_mapping->GetDouble("network", &network_time_js)) { | 51 time_mapping->GetDouble("network", &network_time_js)) { |
51 base::Time local_time_saved = base::Time::FromJsTime(local_time_js); | 52 base::Time local_time_saved = base::Time::FromJsTime(local_time_js); |
52 base::Time local_time_now = base::Time::Now(); | 53 base::Time local_time_now = base::Time::Now(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 if (network_time_.is_null()) | 119 if (network_time_.is_null()) |
119 return false; | 120 return false; |
120 DCHECK(!network_time_ticks_.is_null()); | 121 DCHECK(!network_time_ticks_.is_null()); |
121 *network_time = network_time_ + (time_ticks - network_time_ticks_); | 122 *network_time = network_time_ + (time_ticks - network_time_ticks_); |
122 if (uncertainty) | 123 if (uncertainty) |
123 *uncertainty = network_time_uncertainty_; | 124 *uncertainty = network_time_uncertainty_; |
124 return true; | 125 return true; |
125 } | 126 } |
126 | 127 |
127 } // namespace network_time | 128 } // namespace network_time |
OLD | NEW |