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 private: | |
50 net::URLRequestContextGetter* const context_; | |
51 const GURL url_; | |
52 | |
53 const ApplyTimeZoneCallback apply_timezone_; | |
54 const DelayNetworkCallClosure delay_network_call_; | |
55 | |
56 scoped_ptr<TimeZoneResolverImpl> implementation_; | |
57 | |
58 base::ThreadChecker thread_checker_; | |
59 | |
60 DISALLOW_COPY_AND_ASSIGN(TimeZoneResolver); | |
61 }; | |
62 | |
63 // Expose internal fuctions for testing. | |
64 unsigned int CHROMEOS_EXPORT | |
Bernhard Bauer
2015/01/16 09:25:05
Per the style guide, we usually use just plain int
Alexander Alekseev
2015/01/16 20:42:45
Done.
| |
65 MaxRequestsCountForIntervalForTesting(const double interval_seconds); | |
Bernhard Bauer
2015/01/16 09:25:05
Could you make these methods static class methods?
Alexander Alekseev
2015/01/16 20:42:44
Done.
| |
66 | |
67 unsigned int CHROMEOS_EXPORT | |
68 IntervalForNextRequestForTesting(const unsigned int requests); | |
69 | |
70 } // namespace chromeos | |
71 | |
72 #endif // CHROMEOS_TIMEZONE_TIMEZONE_RESOLVER_H_ | |
OLD | NEW |