OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 NET_BASE_NETWORK_TIME_NOTIFIER_H_ | 5 #ifndef NET_BASE_NETWORK_TIME_NOTIFIER_H_ |
6 #define NET_BASE_NETWORK_TIME_NOTIFIER_H_ | 6 #define NET_BASE_NETWORK_TIME_NOTIFIER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 // consumers can register as observers. This class is not thread-safe. | 23 // consumers can register as observers. This class is not thread-safe. |
24 class NET_EXPORT NetworkTimeNotifier { | 24 class NET_EXPORT NetworkTimeNotifier { |
25 public: | 25 public: |
26 // Callback for observers to receive network time updates. | 26 // Callback for observers to receive network time updates. |
27 // The parameters are: | 27 // The parameters are: |
28 // const base::Time& network_time - the new network time. | 28 // const base::Time& network_time - the new network time. |
29 // const base::TimeTicks& network_time_ticks - the ticks time that corresponds | 29 // const base::TimeTicks& network_time_ticks - the ticks time that corresponds |
30 // with |network_time|. | 30 // with |network_time|. |
31 // const base::TimeDelta& network_time_uncertainty - the uncertainty | 31 // const base::TimeDelta& network_time_uncertainty - the uncertainty |
32 // associated with the new network time. | 32 // associated with the new network time. |
33 typedef base::Callback<void(const base::Time&, | 33 typedef base::Callback< |
34 const base::TimeTicks&, | 34 void(const base::Time&, const base::TimeTicks&, const base::TimeDelta&)> |
35 const base::TimeDelta&)> ObserverCallback; | 35 ObserverCallback; |
36 | 36 |
37 // Takes ownership of |tick_clock|. | 37 // Takes ownership of |tick_clock|. |
38 explicit NetworkTimeNotifier(scoped_ptr<base::TickClock> tick_clock); | 38 explicit NetworkTimeNotifier(scoped_ptr<base::TickClock> tick_clock); |
39 ~NetworkTimeNotifier(); | 39 ~NetworkTimeNotifier(); |
40 | 40 |
41 // Calculates corresponding time ticks according to the given parameters and | 41 // Calculates corresponding time ticks according to the given parameters and |
42 // notifies observers. The provided |network_time| is precise at the given | 42 // notifies observers. The provided |network_time| is precise at the given |
43 // |resolution| and represent the time between now and up to |latency| + | 43 // |resolution| and represent the time between now and up to |latency| + |
44 // (now - |post_time|) ago. | 44 // (now - |post_time|) ago. |
45 void UpdateNetworkTime(const base::Time& network_time, | 45 void UpdateNetworkTime(const base::Time& network_time, |
(...skipping 29 matching lines...) Expand all Loading... |
75 // A vector of callbacks is used, rather than an ObserverList, so that the | 75 // A vector of callbacks is used, rather than an ObserverList, so that the |
76 // lifetime of the observer can be bound to the callback. | 76 // lifetime of the observer can be bound to the callback. |
77 std::vector<ObserverCallback> observers_; | 77 std::vector<ObserverCallback> observers_; |
78 | 78 |
79 DISALLOW_COPY_AND_ASSIGN(NetworkTimeNotifier); | 79 DISALLOW_COPY_AND_ASSIGN(NetworkTimeNotifier); |
80 }; | 80 }; |
81 | 81 |
82 } // namespace net | 82 } // namespace net |
83 | 83 |
84 #endif // NET_BASE_NETWORK_TIME_NOTIFIER_H_ | 84 #endif // NET_BASE_NETWORK_TIME_NOTIFIER_H_ |
OLD | NEW |