OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_METRICS_VARIATIONS_NETWORK_TIME_TRACKER_H_ | |
6 #define CHROME_BROWSER_METRICS_VARIATIONS_NETWORK_TIME_TRACKER_H_ | |
7 | |
8 #include "base/time.h" | |
9 | |
10 // A class that tracks time based on a provided network time, using system's | |
11 // tick time to properly offset it, and also provide uncertainty. | |
12 class NetworkTimeTracker { | |
13 public: | |
14 NetworkTimeTracker(); | |
15 virtual ~NetworkTimeTracker(); | |
16 | |
17 // Returns a network time based on values provided to UpdateNetworkTime and | |
18 // CPU ticks count since then. Returns false if no network time is available | |
19 // yet. Can also return the error range if |uncertainty| isn't NULL. | |
20 bool GetNetworkTime(base::Time* network_time, | |
21 base::TimeDelta* uncertainty) const; | |
22 | |
23 // The provided |network_time| is precise at the given |resolution| and | |
24 // represent the time between now and up to |latency| ago. | |
25 void UpdateNetworkTime(const base::Time& network_time, | |
26 const base::TimeDelta& resolution, | |
27 const base::TimeDelta& latency); | |
28 protected: | |
29 // Used for a derviced test class to mock the current CPU ticks time. | |
30 virtual base::TimeTicks GetTicksNow() const; | |
31 | |
32 private: | |
33 // Returns true in NDEBUG, and validate time tracking when NDEBUG isn't | |
34 // defined, returning FALSE if the network time has drifted too far. | |
35 bool ValidateTimeTracking(const base::Time& new_network_time, | |
36 const base::TimeDelta& resolution, | |
37 const base::TimeDelta& latency); | |
38 // Remember the network time based on last call to UpdateNetworkTime(). | |
Alexei Svitkine (slow)
2013/02/05 02:29:07
Nit: blank line before this
MAD
2013/02/05 15:56:00
Done.
| |
39 base::Time network_time_; | |
40 | |
41 // The estimated ticks count when |network_time_| was set based on the | |
42 // system's tick count. | |
43 base::TimeTicks network_time_ticks_; | |
44 | |
45 // Uncertainty of |network_time_| based on added inaccuracies/resolution. | |
46 base::TimeDelta network_time_uncertainty_; | |
47 | |
48 DISALLOW_COPY_AND_ASSIGN(NetworkTimeTracker); | |
49 }; | |
50 | |
51 #endif // CHROME_BROWSER_METRICS_VARIATIONS_NETWORK_TIME_TRACKER_H_ | |
OLD | NEW |