Index: chrome/browser/network_time/network_time_tracker.h |
diff --git a/chrome/browser/network_time/network_time_tracker.h b/chrome/browser/network_time/network_time_tracker.h |
index f7603516cafcf0d5d8df00c2a4d783025924117f..caed3fc78f8658562f2b02dff035721eff357f11 100644 |
--- a/chrome/browser/network_time/network_time_tracker.h |
+++ b/chrome/browser/network_time/network_time_tracker.h |
@@ -5,40 +5,21 @@ |
#ifndef CHROME_BROWSER_NETWORK_TIME_NETWORK_TIME_TRACKER_H_ |
#define CHROME_BROWSER_NETWORK_TIME_NETWORK_TIME_TRACKER_H_ |
-#include "base/callback.h" |
-#include "base/memory/weak_ptr.h" |
+#include "base/memory/scoped_ptr.h" |
#include "base/threading/thread_checker.h" |
#include "base/time/time.h" |
-#include "net/base/network_time_notifier.h" |
-class IOThread; |
-class NetworkTimeTrackerTest; |
+namespace base { |
+class TickClock; |
+} |
// A class that receives network time updates and can provide the network time |
-// for a corresponding local time. This class is not thread safe, but may live |
-// on any thread. |
-// Note that all NetworkTimeTracker instances interact with a |
-// NetworkTimeNotifier singleton that lives on the IO thread. This class |
-// enables arbitrary threads to maintain their own network time source without |
-// having to deal with the details of the Notifier's implementation. |
+// for a corresponding local time. This class is not thread safe. |
class NetworkTimeTracker { |
public: |
- // Callback for updating network time based on http responses. This callback |
- // is thread safe and should be called directly without posting to any thread. |
- // The parameters are: |
- // const base::Time& network_time - the actual time. |
- // const base::TimeDelta& resolution - how precise the reading is. |
- // const base::TimeDelta& latency - the http request's latency. |
- typedef base::Callback<void(const base::Time&, |
- const base::TimeDelta&, |
- const base::TimeDelta&)> UpdateCallback; |
- |
- NetworkTimeTracker(); |
+ explicit NetworkTimeTracker(scoped_ptr<base::TickClock> tick_clock); |
~NetworkTimeTracker(); |
- // Starts tracking network time. |
- void Start(); |
- |
struct TimeMapping { |
TimeMapping(base::Time local_time, base::Time network_time); |
base::Time local_time; |
@@ -52,44 +33,41 @@ class NetworkTimeTracker { |
// Returns the network time corresponding to |time_ticks| if network time |
// is available. Returns false if no network time is available yet. Can also |
// return the error range if |uncertainty| isn't NULL. |
- bool GetNetworkTime(const base::TimeTicks& time_ticks, |
+ bool GetNetworkTime(base::TimeTicks time_ticks, |
base::Time* network_time, |
base::TimeDelta* uncertainty) const; |
- // Build a callback for use in updating the network time notifier. |
- // This method must be called on the UI thread, while the callback can be |
- // called from any thread. |
- static UpdateCallback BuildNotifierUpdateCallback(); |
+ // Calculates corresponding time ticks according to the given parameters. |
+ // The provided |network_time| is precise at the given |resolution| and |
+ // represent the time between now and up to |latency| + (now - |post_time|) |
+ // ago. |
+ void UpdateNetworkTime(base::Time network_time, |
+ base::TimeDelta resolution, |
+ base::TimeDelta latency, |
+ base::TimeTicks post_time); |
bool received_network_time() const { |
return received_network_time_; |
} |
private: |
- friend class NetworkTimeTrackerTest; |
- |
- // Returns the callback used to register for time updates from the network |
- // time notifier on the IO thread. |
- net::NetworkTimeNotifier::ObserverCallback BuildObserverCallback(); |
- |
- // net::NetworkTimeNotifier::ObserverCallback implementation. |
- void OnNetworkTimeUpdate( |
- const base::Time& network_time, |
- const base::TimeTicks& network_time_ticks, |
- const base::TimeDelta& network_time_uncertainty); |
+ // For querying current time ticks. |
+ scoped_ptr<base::TickClock> tick_clock_; |
// Network time based on last call to UpdateNetworkTime(). |
base::Time network_time_; |
- // The estimated ticks count from when |network_time_| was set based on the |
- // system's tick count. |
+ // The estimated local time from |tick_clock| that corresponds with |
+ // |network_time|. Assumes the actual network time measurement was performed |
+ // midway through the latency time, and does not account for suspect/resume |
+ // events since the network time was measured. |
+ // See UpdateNetworkTime(..) implementation for details. |
base::TimeTicks network_time_ticks_; |
// Uncertainty of |network_time_| based on added inaccuracies/resolution. |
+ // See UpdateNetworkTime(..) implementation for details. |
base::TimeDelta network_time_uncertainty_; |
- base::WeakPtrFactory<NetworkTimeTracker> weak_ptr_factory_; |
- |
base::ThreadChecker thread_checker_; |
bool received_network_time_; |