Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROMEOS_TIMEZONE_TIMEZONE_RESOLVER_H_ | |
| 6 #define CHROMEOS_TIMEZONE_TIMEZONE_RESOLVER_H_ | |
| 7 | |
| 8 #include "base/callback.h" | |
| 9 #include "base/macros.h" | |
| 10 #include "base/threading/thread_checker.h" | |
| 11 #include "chromeos/chromeos_export.h" | |
| 12 #include "url/gurl.h" | |
| 13 | |
| 14 class PrefRegistrySimple; | |
| 15 class PrefService; | |
| 16 | |
| 17 namespace net { | |
| 18 class URLRequestContextGetter; | |
| 19 } | |
| 20 | |
| 21 namespace chromeos { | |
| 22 | |
| 23 struct TimeZoneResponseData; | |
| 24 | |
| 25 // This class implements periodic timezone synchronization. | |
| 26 class CHROMEOS_EXPORT TimeZoneResolver { | |
| 27 public: | |
| 28 class TimeZoneResolverImpl; | |
| 29 | |
| 30 // This callback will be called when new timezone arrives. | |
| 31 typedef base::Callback<void(const TimeZoneResponseData*)> | |
| 32 ApplyTimeZoneCallback; | |
| 33 | |
| 34 // chromeos::DelayNetworkCall cannot be used directly due to link | |
| 35 // restrictions. | |
| 36 typedef base::Callback<void(const base::Closure&)> DelayNetworkCallClosure; | |
| 37 | |
| 38 // This is a LocalState preference to store base::Time value of the last | |
| 39 // request. | |
| 40 // It is used to limit request rate on browser restart. | |
| 41 static const char kLastTimeZoneRefreshTime[]; | |
| 42 | |
| 43 TimeZoneResolver(net::URLRequestContextGetter* context, | |
| 44 const GURL& url, | |
| 45 const ApplyTimeZoneCallback& apply_timezone, | |
| 46 const DelayNetworkCallClosure& delay_network_call, | |
| 47 PrefService* local_state); | |
| 48 ~TimeZoneResolver(); | |
| 49 | |
| 50 // Starts periodic timezone refresh. | |
| 51 void Start(); | |
| 52 | |
| 53 // Cancels current request and stops periodic timezone refresh. | |
| 54 void Stop(); | |
| 55 | |
| 56 // Register prefs to LocalState. | |
| 57 static void RegisterPrefs(PrefRegistrySimple* registry); | |
| 58 | |
| 59 // Expose internal fuctions for testing. | |
| 60 static int MaxRequestsCountForIntervalForTesting( | |
| 61 const double interval_seconds); | |
| 62 static int IntervalForNextRequestForTesting(const int requests); | |
| 63 | |
| 64 private: | |
| 65 net::URLRequestContextGetter* const context_; | |
|
Dmitry Polukhin
2015/01/28 12:10:10
It looks like it should be scoped_refptr<net::URLR
Alexander Alekseev
2015/01/28 17:57:55
Done.
| |
| 66 const GURL url_; | |
| 67 | |
| 68 const ApplyTimeZoneCallback apply_timezone_; | |
| 69 const DelayNetworkCallClosure delay_network_call_; | |
| 70 PrefService* local_state_; | |
|
Dmitry Polukhin
2015/01/28 12:10:10
Suggestion, I don't like having all these data mem
Alexander Alekseev
2015/01/28 17:57:55
The idea was to use RAII, so that implementation w
| |
| 71 | |
| 72 scoped_ptr<TimeZoneResolverImpl> implementation_; | |
| 73 | |
| 74 base::ThreadChecker thread_checker_; | |
| 75 | |
| 76 DISALLOW_COPY_AND_ASSIGN(TimeZoneResolver); | |
| 77 }; | |
| 78 | |
| 79 } // namespace chromeos | |
| 80 | |
| 81 #endif // CHROMEOS_TIMEZONE_TIMEZONE_RESOLVER_H_ | |
| OLD | NEW |