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 "net/url_request/url_request_context_getter.h" | |
13 #include "url/gurl.h" | |
14 | |
15 class PrefRegistrySimple; | |
16 class PrefService; | |
17 | |
18 namespace chromeos { | |
19 | |
20 struct TimeZoneResponseData; | |
21 | |
22 // This class implements periodic timezone synchronization. | |
23 class CHROMEOS_EXPORT TimeZoneResolver { | |
24 public: | |
25 class TimeZoneResolverImpl; | |
26 | |
27 // This callback will be called when new timezone arrives. | |
28 typedef base::Callback<void(const TimeZoneResponseData*)> | |
29 ApplyTimeZoneCallback; | |
stevenjb
2015/01/29 18:29:20
using ApplyTimeZoneCallback = base::Callback<void(
Alexander Alekseev
2015/01/29 19:51:08
Done.
| |
30 | |
31 // chromeos::DelayNetworkCall cannot be used directly due to link | |
32 // restrictions. | |
33 typedef base::Callback<void(const base::Closure&)> DelayNetworkCallClosure; | |
stevenjb
2015/01/29 18:29:20
ditto
Alexander Alekseev
2015/01/29 19:51:08
Done.
| |
34 | |
35 // This is a LocalState preference to store base::Time value of the last | |
36 // request. | |
37 // It is used to limit request rate on browser restart. | |
stevenjb
2015/01/29 18:29:20
Combine lines
Alexander Alekseev
2015/01/29 19:51:08
Done.
| |
38 static const char kLastTimeZoneRefreshTime[]; | |
39 | |
40 TimeZoneResolver(scoped_refptr<net::URLRequestContextGetter> context, | |
41 const GURL& url, | |
42 const ApplyTimeZoneCallback& apply_timezone, | |
43 const DelayNetworkCallClosure& delay_network_call, | |
44 PrefService* local_state); | |
45 ~TimeZoneResolver(); | |
46 | |
47 // Starts periodic timezone refresh. | |
48 void Start(); | |
49 | |
50 // Cancels current request and stops periodic timezone refresh. | |
51 void Stop(); | |
52 | |
53 // Register prefs to LocalState. | |
54 static void RegisterPrefs(PrefRegistrySimple* registry); | |
55 | |
56 scoped_refptr<net::URLRequestContextGetter> context() const { | |
57 return context_; | |
58 } | |
59 | |
60 DelayNetworkCallClosure delay_network_call() const { | |
61 return delay_network_call_; | |
62 } | |
63 | |
64 ApplyTimeZoneCallback apply_timezone() const { return apply_timezone_; } | |
65 | |
66 PrefService* local_state() const { return local_state_; } | |
67 | |
68 // Expose internal fuctions for testing. | |
69 static int MaxRequestsCountForIntervalForTesting( | |
70 const double interval_seconds); | |
71 static int IntervalForNextRequestForTesting(const int requests); | |
72 | |
73 private: | |
74 scoped_refptr<net::URLRequestContextGetter> context_; | |
75 const GURL url_; | |
76 | |
77 const ApplyTimeZoneCallback apply_timezone_; | |
78 const DelayNetworkCallClosure delay_network_call_; | |
79 PrefService* local_state_; | |
80 | |
81 scoped_ptr<TimeZoneResolverImpl> implementation_; | |
82 | |
83 base::ThreadChecker thread_checker_; | |
84 | |
85 DISALLOW_COPY_AND_ASSIGN(TimeZoneResolver); | |
86 }; | |
87 | |
88 } // namespace chromeos | |
89 | |
90 #endif // CHROMEOS_TIMEZONE_TIMEZONE_RESOLVER_H_ | |
OLD | NEW |