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

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

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, 2 months 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 #ifndef COMPONENTS_NETWORK_TIME_NETWORK_TIME_TRACKER_H_ 5 #ifndef COMPONENTS_NETWORK_TIME_NETWORK_TIME_TRACKER_H_
6 #define COMPONENTS_NETWORK_TIME_NETWORK_TIME_TRACKER_H_ 6 #define COMPONENTS_NETWORK_TIME_NETWORK_TIME_TRACKER_H_
7 7
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/threading/thread_checker.h" 9 #include "base/threading/thread_checker.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 11
12 class PrefRegistrySimple; 12 class PrefRegistrySimple;
13 class PrefService; 13 class PrefService;
14 14
15 namespace base { 15 namespace base {
16 class TickClock; 16 class TickClock;
17 } 17 }
18 18
19 namespace network_time { 19 namespace network_time {
20 20
21 // A class that receives network time updates and can provide the network time 21 // A class that receives network time updates and can provide the network time
22 // for a corresponding local time. This class is not thread safe. 22 // for a corresponding local time. This class is not thread safe.
23 class NetworkTimeTracker { 23 class NetworkTimeTracker {
24 public: 24 public:
25 static void RegisterPrefs(PrefRegistrySimple* registry); 25 static void RegisterPrefs(PrefRegistrySimple* registry);
26 26
27 NetworkTimeTracker(scoped_ptr<base::TickClock> tick_clock, 27 NetworkTimeTracker(const scoped_refptr<base::TickClock>& tick_clock,
28 PrefService* pref_service); 28 PrefService* pref_service);
29 ~NetworkTimeTracker(); 29 ~NetworkTimeTracker();
30 30
31 // Returns the network time corresponding to |time_ticks| if network time 31 // Returns the network time corresponding to |time_ticks| if network time
32 // is available. Returns false if no network time is available yet. Can also 32 // is available. Returns false if no network time is available yet. Can also
33 // return the error range if |uncertainty| isn't NULL. 33 // return the error range if |uncertainty| isn't NULL.
34 bool GetNetworkTime(base::TimeTicks time_ticks, 34 bool GetNetworkTime(base::TimeTicks time_ticks,
35 base::Time* network_time, 35 base::Time* network_time,
36 base::TimeDelta* uncertainty) const; 36 base::TimeDelta* uncertainty) const;
37 37
38 // Calculates corresponding time ticks according to the given parameters. 38 // Calculates corresponding time ticks according to the given parameters.
39 // The provided |network_time| is precise at the given |resolution| and 39 // The provided |network_time| is precise at the given |resolution| and
40 // represent the time between now and up to |latency| + (now - |post_time|) 40 // represent the time between now and up to |latency| + (now - |post_time|)
41 // ago. 41 // ago.
42 void UpdateNetworkTime(base::Time network_time, 42 void UpdateNetworkTime(base::Time network_time,
43 base::TimeDelta resolution, 43 base::TimeDelta resolution,
44 base::TimeDelta latency, 44 base::TimeDelta latency,
45 base::TimeTicks post_time); 45 base::TimeTicks post_time);
46 46
47 bool received_network_time() const { 47 bool received_network_time() const {
48 return received_network_time_; 48 return received_network_time_;
49 } 49 }
50 50
51 private: 51 private:
52 // For querying current time ticks. 52 // For querying current time ticks.
53 scoped_ptr<base::TickClock> tick_clock_; 53 scoped_refptr<base::TickClock> tick_clock_;
54 54
55 PrefService* pref_service_; 55 PrefService* pref_service_;
56 56
57 // Network time based on last call to UpdateNetworkTime(). 57 // Network time based on last call to UpdateNetworkTime().
58 base::Time network_time_; 58 base::Time network_time_;
59 59
60 // The estimated local time from |tick_clock| that corresponds with 60 // The estimated local time from |tick_clock| that corresponds with
61 // |network_time|. Assumes the actual network time measurement was performed 61 // |network_time|. Assumes the actual network time measurement was performed
62 // midway through the latency time, and does not account for suspect/resume 62 // midway through the latency time, and does not account for suspect/resume
63 // events since the network time was measured. 63 // events since the network time was measured.
64 // See UpdateNetworkTime(..) implementation for details. 64 // See UpdateNetworkTime(..) implementation for details.
65 base::TimeTicks network_time_ticks_; 65 base::TimeTicks network_time_ticks_;
66 66
67 // Uncertainty of |network_time_| based on added inaccuracies/resolution. 67 // Uncertainty of |network_time_| based on added inaccuracies/resolution.
68 // See UpdateNetworkTime(..) implementation for details. 68 // See UpdateNetworkTime(..) implementation for details.
69 base::TimeDelta network_time_uncertainty_; 69 base::TimeDelta network_time_uncertainty_;
70 70
71 base::ThreadChecker thread_checker_; 71 base::ThreadChecker thread_checker_;
72 72
73 bool received_network_time_; 73 bool received_network_time_;
74 74
75 DISALLOW_COPY_AND_ASSIGN(NetworkTimeTracker); 75 DISALLOW_COPY_AND_ASSIGN(NetworkTimeTracker);
76 }; 76 };
77 77
78 } // namespace network_time 78 } // namespace network_time
79 79
80 #endif // COMPONENTS_NETWORK_TIME_NETWORK_TIME_TRACKER_H_ 80 #endif // COMPONENTS_NETWORK_TIME_NETWORK_TIME_TRACKER_H_
OLDNEW
« no previous file with comments | « components/copresence/timed_map_unittest.cc ('k') | components/network_time/network_time_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698