Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(613)

Side by Side Diff: components/network_time/network_time_tracker.cc

Issue 670623002: Change base::TickClock to a ref counted class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@audio_redesign
Patch Set: y Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « components/network_time/network_time_tracker.h ('k') | components/network_time/network_time_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698