Chromium Code Reviews| Index: components/network_time/network_time_tracker.h |
| diff --git a/components/network_time/network_time_tracker.h b/components/network_time/network_time_tracker.h |
| index dc7524a58302b2748c33941bc40938a73f792392..cc1d7d807bbb225c6783179c989b3f445cf580ce 100644 |
| --- a/components/network_time/network_time_tracker.h |
| +++ b/components/network_time/network_time_tracker.h |
| @@ -10,6 +10,8 @@ |
| #include "base/threading/thread_checker.h" |
| #include "base/time/clock.h" |
| #include "base/time/time.h" |
| +#include "base/timer/timer.h" |
| +#include "net/url_request/url_fetcher_delegate.h" |
| class PrefRegistrySimple; |
| class PrefService; |
| @@ -18,6 +20,15 @@ namespace base { |
| class TickClock; |
| } |
| +namespace client_update_protocol { |
| +class Ecdsa; |
| +} |
| + |
| +namespace net { |
| +class URLFetcher; |
| +class URLRequestContextGetter; |
| +} |
| + |
| namespace network_time { |
| // Clock resolution is platform dependent. |
| @@ -27,16 +38,22 @@ const int64_t kTicksResolutionMs = base::Time::kMinLowResolutionThresholdMs; |
| const int64_t kTicksResolutionMs = 1; // Assume 1ms for non-windows platforms. |
| #endif |
| +struct NetworkTimeTrackerPeer; |
| + |
| // A class that receives network time updates and can provide the network time |
| // for a corresponding local time. This class is not thread safe. |
| -class NetworkTimeTracker { |
| +class NetworkTimeTracker : public net::URLFetcherDelegate { |
| public: |
| static void RegisterPrefs(PrefRegistrySimple* registry); |
| + // Constructor. Arguments may be stubbed out for tests. |getter|, if not |
| + // null, will cause automatic queries to a time server. Otherwise, time is |
| + // available only if |UpdateNetworkTime| is called. |
| NetworkTimeTracker(scoped_ptr<base::Clock> clock, |
| scoped_ptr<base::TickClock> tick_clock, |
| - PrefService* pref_service); |
| - ~NetworkTimeTracker(); |
| + PrefService* pref_service, |
| + net::URLRequestContextGetter* getter = nullptr); |
| + ~NetworkTimeTracker() override; |
| // Sets |network_time| to an estimate of the true time. Returns true if time |
| // is available, and false otherwise. If |uncertainty| is non-NULL, it will |
| @@ -61,6 +78,22 @@ class NetworkTimeTracker { |
| base::TimeTicks post_time); |
| private: |
| + friend struct NetworkTimeTrackerPeer; |
| + |
| + // Sends a query to the secure time service. Upon response, execution resumes |
| + // in |OnURLFetchComplete|. |
| + void QueryTimeService(); |
| + |
| + // Called to process responses from the secure time service. |
|
estark
2016/03/28 17:35:10
Preface this section with
// net::URLFetcherDeleg
mab
2016/03/28 19:56:26
Done.
|
| + void OnURLFetchComplete(const net::URLFetcher* source) override; |
| + |
| + // State variables for internally-managed secure time service queries. |
| + base::RepeatingTimer query_timer_; |
| + net::URLRequestContextGetter* getter_; |
| + scoped_ptr<net::URLFetcher> time_fetcher_; |
| + base::TimeTicks fetch_started_; |
| + scoped_ptr<client_update_protocol::Ecdsa> query_signer_; |
| + |
| // The |Clock| and |TickClock| are used to sanity-check one another, allowing |
| // the NetworkTimeTracker to notice e.g. suspend/resume events and clock |
| // resets. |