Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(819)

Unified Diff: components/network_time/network_time_tracker.h

Issue 2453523002: Add NetworkTimeTracker::StartTimeFetch() for on-demand time queries (Closed)
Patch Set: meacer comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 5e31411d16257b3e1b4b34cc30c5f5d9852f5336..fb9aa4ef7a023f6f1d163b8884639e2a13ad7821 100644
--- a/components/network_time/network_time_tracker.h
+++ b/components/network_time/network_time_tracker.h
@@ -23,7 +23,6 @@ class PrefRegistrySimple;
class PrefService;
namespace base {
-class RunLoop;
class TickClock;
} // namespace base
@@ -106,6 +105,16 @@ class NetworkTimeTracker : public net::URLFetcherDelegate {
NetworkTimeResult GetNetworkTime(base::Time* network_time,
base::TimeDelta* uncertainty) const;
+ // Starts a network time query if network time isn't already available
+ // and if there isn't already a time query in progress. If a new query
+ // is started or if there is one already in progress, |callback| will
+ // run when the query completes.
+ //
+ // Returns true if a time query is started or was already in progress,
+ // and false otherwise. For example, this method may return false if
+ // time queries are disabled or if network time is already available.
+ bool StartTimeFetch(const base::Closure& callback);
+
// 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|)
@@ -161,9 +170,6 @@ class NetworkTimeTracker : public net::URLFetcherDelegate {
base::TimeTicks fetch_started_;
std::unique_ptr<client_update_protocol::Ecdsa> query_signer_;
- // Run by WaitForFetchForTesting() and quit by OnURLFetchComplete().
- base::RunLoop* run_loop_for_testing_ = nullptr;
-
// The |Clock| and |TickClock| are used to sanity-check one another, allowing
// the NetworkTimeTracker to notice e.g. suspend/resume events and clock
// resets.
@@ -191,6 +197,9 @@ class NetworkTimeTracker : public net::URLFetcherDelegate {
// this NetworkTimeTracker's lifetime.
bool time_query_completed_;
+ // Callbacks to run when the in-progress time fetch completes.
+ std::vector<base::Closure> fetch_completion_callbacks_;
+
base::ThreadChecker thread_checker_;
DISALLOW_COPY_AND_ASSIGN(NetworkTimeTracker);
« no previous file with comments | « no previous file | components/network_time/network_time_tracker.cc » ('j') | components/network_time/network_time_tracker.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698