| 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/i18n/time_formatting.h" | 8 #include "base/i18n/time_formatting.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 const int kNumTimeMeasurements = 5; | 28 const int kNumTimeMeasurements = 5; |
| 29 | 29 |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 // static | 32 // static |
| 33 void NetworkTimeTracker::RegisterPrefs(PrefRegistrySimple* registry) { | 33 void NetworkTimeTracker::RegisterPrefs(PrefRegistrySimple* registry) { |
| 34 registry->RegisterDictionaryPref(prefs::kNetworkTimeMapping, | 34 registry->RegisterDictionaryPref(prefs::kNetworkTimeMapping, |
| 35 new base::DictionaryValue()); | 35 new base::DictionaryValue()); |
| 36 } | 36 } |
| 37 | 37 |
| 38 NetworkTimeTracker::NetworkTimeTracker(scoped_ptr<base::TickClock> tick_clock, | 38 NetworkTimeTracker::NetworkTimeTracker( |
| 39 PrefService* pref_service) | 39 const scoped_refptr<base::TickClock>& tick_clock, |
| 40 : tick_clock_(tick_clock.Pass()), | 40 PrefService* pref_service) |
| 41 : tick_clock_(tick_clock), |
| 41 pref_service_(pref_service), | 42 pref_service_(pref_service), |
| 42 received_network_time_(false) { | 43 received_network_time_(false) { |
| 43 const base::DictionaryValue* time_mapping = | 44 const base::DictionaryValue* time_mapping = |
| 44 pref_service_->GetDictionary(prefs::kNetworkTimeMapping); | 45 pref_service_->GetDictionary(prefs::kNetworkTimeMapping); |
| 45 double local_time_js = 0; | 46 double local_time_js = 0; |
| 46 double network_time_js = 0; | 47 double network_time_js = 0; |
| 47 if (time_mapping->GetDouble("local", &local_time_js) && | 48 if (time_mapping->GetDouble("local", &local_time_js) && |
| 48 time_mapping->GetDouble("network", &network_time_js)) { | 49 time_mapping->GetDouble("network", &network_time_js)) { |
| 49 base::Time local_time_saved = base::Time::FromJsTime(local_time_js); | 50 base::Time local_time_saved = base::Time::FromJsTime(local_time_js); |
| 50 base::Time local_time_now = base::Time::Now(); | 51 base::Time local_time_now = base::Time::Now(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 if (network_time_.is_null()) | 117 if (network_time_.is_null()) |
| 117 return false; | 118 return false; |
| 118 DCHECK(!network_time_ticks_.is_null()); | 119 DCHECK(!network_time_ticks_.is_null()); |
| 119 *network_time = network_time_ + (time_ticks - network_time_ticks_); | 120 *network_time = network_time_ + (time_ticks - network_time_ticks_); |
| 120 if (uncertainty) | 121 if (uncertainty) |
| 121 *uncertainty = network_time_uncertainty_; | 122 *uncertainty = network_time_uncertainty_; |
| 122 return true; | 123 return true; |
| 123 } | 124 } |
| 124 | 125 |
| 125 } // namespace network_time | 126 } // namespace network_time |
| OLD | NEW |