| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_NETWORK_TIME_NETWORK_TIME_TRACKER_H_ | 5 #ifndef COMPONENTS_NETWORK_TIME_NETWORK_TIME_TRACKER_H_ |
| 6 #define COMPONENTS_NETWORK_TIME_NETWORK_TIME_TRACKER_H_ | 6 #define COMPONENTS_NETWORK_TIME_NETWORK_TIME_TRACKER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 void SetPublicKeyForTesting(const base::StringPiece& key); | 120 void SetPublicKeyForTesting(const base::StringPiece& key); |
| 121 | 121 |
| 122 void SetTimeServerURLForTesting(const GURL& url); | 122 void SetTimeServerURLForTesting(const GURL& url); |
| 123 | 123 |
| 124 bool QueryTimeServiceForTesting(); | 124 bool QueryTimeServiceForTesting(); |
| 125 | 125 |
| 126 void WaitForFetchForTesting(uint32_t nonce); | 126 void WaitForFetchForTesting(uint32_t nonce); |
| 127 | 127 |
| 128 base::TimeDelta GetTimerDelayForTesting() const; | 128 base::TimeDelta GetTimerDelayForTesting() const; |
| 129 | 129 |
| 130 void EnableTimeQueriesForTesting(); |
| 131 |
| 130 private: | 132 private: |
| 131 // Checks whether a network time query should be issued, and issues one if so. | 133 // Checks whether a network time query should be issued, and issues one if so. |
| 132 // Upon response, execution resumes in |OnURLFetchComplete|. | 134 // Upon response, execution resumes in |OnURLFetchComplete|. |
| 133 void CheckTime(); | 135 void CheckTime(); |
| 134 | 136 |
| 135 // Updates network time from a time server response, returning true | 137 // Updates network time from a time server response, returning true |
| 136 // if successful. | 138 // if successful. |
| 137 bool UpdateTimeFromResponse(); | 139 bool UpdateTimeFromResponse(); |
| 138 | 140 |
| 139 // net::URLFetcherDelegate: | 141 // net::URLFetcherDelegate: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 154 base::TimeDelta backoff_; | 156 base::TimeDelta backoff_; |
| 155 // Timer that runs CheckTime(). All backoff and delay is implemented by | 157 // Timer that runs CheckTime(). All backoff and delay is implemented by |
| 156 // changing the delay of this timer, with the result that CheckTime() may | 158 // changing the delay of this timer, with the result that CheckTime() may |
| 157 // assume that if it runs, it is eligible to issue a time query. | 159 // assume that if it runs, it is eligible to issue a time query. |
| 158 base::RepeatingTimer timer_; | 160 base::RepeatingTimer timer_; |
| 159 scoped_refptr<net::URLRequestContextGetter> getter_; | 161 scoped_refptr<net::URLRequestContextGetter> getter_; |
| 160 std::unique_ptr<net::URLFetcher> time_fetcher_; | 162 std::unique_ptr<net::URLFetcher> time_fetcher_; |
| 161 base::TimeTicks fetch_started_; | 163 base::TimeTicks fetch_started_; |
| 162 std::unique_ptr<client_update_protocol::Ecdsa> query_signer_; | 164 std::unique_ptr<client_update_protocol::Ecdsa> query_signer_; |
| 163 | 165 |
| 166 bool enable_time_queries_for_testing_ = false; |
| 167 |
| 164 // Run by WaitForFetchForTesting() and quit by OnURLFetchComplete(). | 168 // Run by WaitForFetchForTesting() and quit by OnURLFetchComplete(). |
| 165 base::RunLoop* run_loop_for_testing_ = nullptr; | 169 base::RunLoop* run_loop_for_testing_ = nullptr; |
| 166 | 170 |
| 167 // The |Clock| and |TickClock| are used to sanity-check one another, allowing | 171 // The |Clock| and |TickClock| are used to sanity-check one another, allowing |
| 168 // the NetworkTimeTracker to notice e.g. suspend/resume events and clock | 172 // the NetworkTimeTracker to notice e.g. suspend/resume events and clock |
| 169 // resets. | 173 // resets. |
| 170 std::unique_ptr<base::Clock> clock_; | 174 std::unique_ptr<base::Clock> clock_; |
| 171 std::unique_ptr<base::TickClock> tick_clock_; | 175 std::unique_ptr<base::TickClock> tick_clock_; |
| 172 | 176 |
| 173 PrefService* pref_service_; | 177 PrefService* pref_service_; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 192 bool time_query_completed_; | 196 bool time_query_completed_; |
| 193 | 197 |
| 194 base::ThreadChecker thread_checker_; | 198 base::ThreadChecker thread_checker_; |
| 195 | 199 |
| 196 DISALLOW_COPY_AND_ASSIGN(NetworkTimeTracker); | 200 DISALLOW_COPY_AND_ASSIGN(NetworkTimeTracker); |
| 197 }; | 201 }; |
| 198 | 202 |
| 199 } // namespace network_time | 203 } // namespace network_time |
| 200 | 204 |
| 201 #endif // COMPONENTS_NETWORK_TIME_NETWORK_TIME_TRACKER_H_ | 205 #endif // COMPONENTS_NETWORK_TIME_NETWORK_TIME_TRACKER_H_ |
| OLD | NEW |