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 7f2eb8792031d2cf56c13c17dda1b49909a0e000..340df5fe8c6ea6c38ddfaf7652f0bf28e44fa4f3 100644 |
--- a/components/network_time/network_time_tracker.h |
+++ b/components/network_time/network_time_tracker.h |
@@ -7,17 +7,30 @@ |
#include <memory> |
+#include "base/gtest_prod_util.h" |
#include "base/macros.h" |
#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" |
+#include "net/url_request/url_request_context_getter.h" |
class PrefRegistrySimple; |
class PrefService; |
namespace base { |
class TickClock; |
-} |
+} // namespace base |
+ |
+namespace client_update_protocol { |
+class Ecdsa; |
+} // namespace client_udpate_protocol |
+ |
+namespace net { |
+class URLFetcher; |
+class URLRequestContextGetter; |
+} // namespace net |
namespace network_time { |
@@ -30,14 +43,18 @@ const int64_t kTicksResolutionMs = 1; // Assume 1ms for non-windows platforms. |
// 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(std::unique_ptr<base::Clock> clock, |
std::unique_ptr<base::TickClock> tick_clock, |
- PrefService* pref_service); |
- ~NetworkTimeTracker(); |
+ PrefService* pref_service, |
+ scoped_refptr<net::URLRequestContextGetter>& getter); |
mmenke
2016/04/28 15:17:09
Bug: Passing by non-const ref is not allowed.
Th
mab
2016/04/29 19:42:07
I think this is moot. Looking more closely, I see
Ryan Sleevi
2016/04/29 21:16:29
If you're going to take a reference, the recommend
mab
2016/04/29 21:35:36
Fair enough, done.
|
+ ~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 |
@@ -62,6 +79,27 @@ class NetworkTimeTracker { |
base::TimeTicks post_time); |
private: |
+ friend class NetworkTimeTrackerTest; |
+ FRIEND_TEST_ALL_PREFIXES(NetworkTimeTrackerTest, UpdateFromNetwork); |
+ FRIEND_TEST_ALL_PREFIXES(NetworkTimeTrackerTest, NoNetworkQueryWhileSynced); |
+ FRIEND_TEST_ALL_PREFIXES(NetworkTimeTrackerTest, |
+ UpdateFromNetworkBadSignature); |
+ |
+ // If synchronization has been lost, sends a query to the secure time service. |
+ // Upon response, execution resumes in |OnURLFetchComplete|. |
+ void QueryTimeService(); |
+ |
+ // net::URLFetcherDelegate: |
+ // Called to process responses from the secure time service. |
+ void OnURLFetchComplete(const net::URLFetcher* source) override; |
+ |
+ // State variables for internally-managed secure time service queries. |
+ base::RepeatingTimer query_timer_; |
+ scoped_refptr<net::URLRequestContextGetter> getter_; |
+ std::unique_ptr<net::URLFetcher> time_fetcher_; |
+ base::TimeTicks fetch_started_; |
+ std::unique_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. |