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

Side by Side Diff: chromeos/timezone/timezone_resolver.h

Issue 1837893003: ChromeOS: Refactor TimeZoneResolver, add TimeZoneResolverManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROMEOS_TIMEZONE_TIMEZONE_RESOLVER_H_ 5 #ifndef CHROMEOS_TIMEZONE_TIMEZONE_RESOLVER_H_
6 #define CHROMEOS_TIMEZONE_TIMEZONE_RESOLVER_H_ 6 #define CHROMEOS_TIMEZONE_TIMEZONE_RESOLVER_H_
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/threading/thread_checker.h" 10 #include "base/threading/thread_checker.h"
(...skipping 14 matching lines...) Expand all
25 class TimeZoneResolverImpl; 25 class TimeZoneResolverImpl;
26 26
27 // This callback will be called when new timezone arrives. 27 // This callback will be called when new timezone arrives.
28 using ApplyTimeZoneCallback = 28 using ApplyTimeZoneCallback =
29 base::Callback<void(const TimeZoneResponseData*)>; 29 base::Callback<void(const TimeZoneResponseData*)>;
30 30
31 // chromeos::DelayNetworkCall cannot be used directly due to link 31 // chromeos::DelayNetworkCall cannot be used directly due to link
32 // restrictions. 32 // restrictions.
33 using DelayNetworkCallClosure = base::Callback<void(const base::Closure&)>; 33 using DelayNetworkCallClosure = base::Callback<void(const base::Closure&)>;
34 34
35 class Delegate {
36 public:
37 Delegate();
38 virtual ~Delegate();
39
40 // Returns true if TimeZoneResolver should include WiFi data in request.
41 virtual bool ShouldSendWiFiGeolocationData() = 0;
42
43 private:
44 DISALLOW_COPY_AND_ASSIGN(Delegate);
45 };
46
35 // This is a LocalState preference to store base::Time value of the last 47 // This is a LocalState preference to store base::Time value of the last
36 // request. It is used to limit request rate on browser restart. 48 // request. It is used to limit request rate on browser restart.
37 static const char kLastTimeZoneRefreshTime[]; 49 static const char kLastTimeZoneRefreshTime[];
38 50
39 TimeZoneResolver(scoped_refptr<net::URLRequestContextGetter> context, 51 TimeZoneResolver(Delegate* delegate,
52 scoped_refptr<net::URLRequestContextGetter> context,
40 const GURL& url, 53 const GURL& url,
41 const ApplyTimeZoneCallback& apply_timezone, 54 const ApplyTimeZoneCallback& apply_timezone,
42 const DelayNetworkCallClosure& delay_network_call, 55 const DelayNetworkCallClosure& delay_network_call,
43 PrefService* local_state); 56 PrefService* local_state);
44 ~TimeZoneResolver(); 57 ~TimeZoneResolver();
45 58
46 // Starts periodic timezone refresh. 59 // Starts periodic timezone refresh.
47 void Start(); 60 void Start();
48 61
49 // Cancels current request and stops periodic timezone refresh. 62 // Cancels current request and stops periodic timezone refresh.
50 void Stop(); 63 void Stop();
51 64
52 // Register prefs to LocalState. 65 // Register prefs to LocalState.
53 static void RegisterPrefs(PrefRegistrySimple* registry); 66 static void RegisterPrefs(PrefRegistrySimple* registry);
54 67
55 scoped_refptr<net::URLRequestContextGetter> context() const { 68 scoped_refptr<net::URLRequestContextGetter> context() const {
56 return context_; 69 return context_;
57 } 70 }
58 71
59 DelayNetworkCallClosure delay_network_call() const { 72 DelayNetworkCallClosure delay_network_call() const {
60 return delay_network_call_; 73 return delay_network_call_;
61 } 74 }
62 75
63 ApplyTimeZoneCallback apply_timezone() const { return apply_timezone_; } 76 ApplyTimeZoneCallback apply_timezone() const { return apply_timezone_; }
64 77
65 PrefService* local_state() const { return local_state_; } 78 PrefService* local_state() const { return local_state_; }
66 79
80 // Proxy call to Delegate::ShouldSendWiFiGeolocationData().
81 bool ShouldSendWiFiGeolocationData() const;
82
67 // Expose internal fuctions for testing. 83 // Expose internal fuctions for testing.
68 static int MaxRequestsCountForIntervalForTesting( 84 static int MaxRequestsCountForIntervalForTesting(
69 const double interval_seconds); 85 const double interval_seconds);
70 static int IntervalForNextRequestForTesting(const int requests); 86 static int IntervalForNextRequestForTesting(const int requests);
71 87
72 private: 88 private:
89 Delegate* delegate_;
90
73 scoped_refptr<net::URLRequestContextGetter> context_; 91 scoped_refptr<net::URLRequestContextGetter> context_;
74 const GURL url_; 92 const GURL url_;
75 93
76 const ApplyTimeZoneCallback apply_timezone_; 94 const ApplyTimeZoneCallback apply_timezone_;
77 const DelayNetworkCallClosure delay_network_call_; 95 const DelayNetworkCallClosure delay_network_call_;
78 PrefService* local_state_; 96 PrefService* local_state_;
79 97
80 scoped_ptr<TimeZoneResolverImpl> implementation_; 98 scoped_ptr<TimeZoneResolverImpl> implementation_;
81 99
82 bool send_wifi_data_to_geolocation_api_; 100 bool send_wifi_data_to_geolocation_api_;
83 101
84 base::ThreadChecker thread_checker_; 102 base::ThreadChecker thread_checker_;
85 103
86 DISALLOW_COPY_AND_ASSIGN(TimeZoneResolver); 104 DISALLOW_COPY_AND_ASSIGN(TimeZoneResolver);
87 }; 105 };
88 106
89 } // namespace chromeos 107 } // namespace chromeos
90 108
91 #endif // CHROMEOS_TIMEZONE_TIMEZONE_RESOLVER_H_ 109 #endif // CHROMEOS_TIMEZONE_TIMEZONE_RESOLVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698