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 |
| 16 namespace net { |
| 17 class URLRequestContextGetter; |
| 18 } |
| 19 |
| 20 namespace chromeos { |
| 21 |
| 22 struct TimeZoneResponseData; |
| 23 |
| 24 // This class implements periodic timezone synchronization. |
| 25 class CHROMEOS_EXPORT TimeZoneResolver { |
| 26 public: |
| 27 class TimeZoneResolverImpl; |
| 28 |
| 29 // This callback will be called when new timezone arrives. |
| 30 typedef base::Callback<void(const TimeZoneResponseData*)> |
| 31 ApplyTimeZoneCallback; |
| 32 |
| 33 // chromeos::DelayNetworkCall cannot be used directly due to link |
| 34 // restrictions. |
| 35 typedef base::Callback<void(const base::Closure&)> DelayNetworkCallClosure; |
| 36 |
| 37 TimeZoneResolver(net::URLRequestContextGetter* context, |
| 38 const GURL& url, |
| 39 const ApplyTimeZoneCallback& apply_timezone, |
| 40 const DelayNetworkCallClosure& delay_network_call); |
| 41 ~TimeZoneResolver(); |
| 42 |
| 43 // Starts periodic timezone refresh. |
| 44 void Start(); |
| 45 |
| 46 // Cancels current request and stops periodic timezone refresh. |
| 47 void Stop(); |
| 48 |
| 49 // Expose internal fuctions for testing. |
| 50 static int MaxRequestsCountForIntervalForTesting( |
| 51 const double interval_seconds); |
| 52 static int IntervalForNextRequestForTesting(const int requests); |
| 53 |
| 54 private: |
| 55 net::URLRequestContextGetter* const context_; |
| 56 const GURL url_; |
| 57 |
| 58 const ApplyTimeZoneCallback apply_timezone_; |
| 59 const DelayNetworkCallClosure delay_network_call_; |
| 60 |
| 61 scoped_ptr<TimeZoneResolverImpl> implementation_; |
| 62 |
| 63 base::ThreadChecker thread_checker_; |
| 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(TimeZoneResolver); |
| 66 }; |
| 67 |
| 68 } // namespace chromeos |
| 69 |
| 70 #endif // CHROMEOS_TIMEZONE_TIMEZONE_RESOLVER_H_ |
OLD | NEW |