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 COMPONENTS_GCM_DRIVER_GCM_CHANNEL_STATUS_SYNCER_H_ | |
6 #define COMPONENTS_GCM_DRIVER_GCM_CHANNEL_STATUS_SYNCER_H_ | |
7 | |
8 #include "base/compiler_specific.h" | |
9 #include "base/macros.h" | |
10 #include "base/memory/ref_counted.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/memory/weak_ptr.h" | |
13 #include "base/time/time.h" | |
14 #include "components/pref_registry/pref_registry_syncable.h" | |
fgorski
2014/09/11 18:24:35
you are also forward declaring it before. I think
jianli
2014/09/11 21:04:31
Done.
| |
15 | |
16 class PrefService; | |
17 class PrefRegistrySimple; | |
18 namespace net { | |
19 class URLRequestContextGetter; | |
20 } | |
21 namespace user_prefs { | |
22 class PrefRegistrySyncable; | |
23 } | |
24 | |
25 namespace gcm { | |
26 | |
27 class GCMChannelStatusRequest; | |
28 class GCMDriver; | |
29 | |
30 class GCMChannelStatusSyncer { | |
31 public: | |
32 static void RegisterPrefs(PrefRegistrySimple* registry); | |
33 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | |
34 | |
35 GCMChannelStatusSyncer( | |
36 GCMDriver* driver, | |
37 PrefService* prefs, | |
38 scoped_refptr<net::URLRequestContextGetter> request_context); | |
39 ~GCMChannelStatusSyncer(); | |
40 | |
41 void EnsureStarted(); | |
42 void Stop(); | |
43 | |
44 bool gcm_enabled() const { return gcm_enabled_; } | |
45 | |
46 // For testing purpose. | |
47 void set_delay_removed_for_testing(bool delay_removed) { | |
48 delay_removed_for_testing_ = delay_removed; | |
49 } | |
50 base::TimeDelta current_request_delay_interval() const { | |
51 return current_request_delay_interval_; | |
52 } | |
53 static int first_time_delay_seconds(); | |
54 | |
55 private: | |
56 // Called when a request is completed. | |
57 void OnRequestCompleted(bool enabled, int poll_interval_seconds); | |
58 | |
59 // Schedules to start next request. | |
fgorski
2014/09/11 18:24:35
nit: remove "to start"
jianli
2014/09/11 21:04:31
Done.
| |
60 void ScheduleRequest(); | |
61 | |
62 // Creates and starts a request immediately. | |
63 void StartRequest(); | |
64 | |
65 // Computes and returns a delay with the fuzzing variation added if needed, | |
66 // after which the request could start. | |
67 base::TimeDelta GetRequestDelayInterval() const; | |
68 | |
69 GCMDriver* driver_; // GCMDriver owns GCMChannelStatusSyncer instance. | |
fgorski
2014/09/11 18:24:35
nit: why not putting comment above?
jianli
2014/09/11 21:04:30
Done.
| |
70 PrefService* prefs_; | |
71 | |
72 scoped_refptr<net::URLRequestContextGetter> request_context_; | |
73 scoped_ptr<GCMChannelStatusRequest> request_; | |
74 | |
75 bool gcm_enabled_; | |
76 int poll_interval_seconds_; | |
77 base::Time last_check_time_; | |
78 | |
79 // The flag that indicates if the delay, including fuzzing variation and poll | |
80 // interval, is removed for testing purpose. | |
81 bool delay_removed_for_testing_; | |
82 | |
83 // Tracked for testing purpose. | |
84 base::TimeDelta current_request_delay_interval_; | |
85 | |
86 // Used to pass a weak pointer to a task. | |
87 base::WeakPtrFactory<GCMChannelStatusSyncer> weak_ptr_factory_; | |
88 | |
89 DISALLOW_COPY_AND_ASSIGN(GCMChannelStatusSyncer); | |
90 }; | |
91 | |
92 } // namespace gcm | |
93 | |
94 #endif // COMPONENTS_GCM_DRIVER_GCM_CHANNEL_STATUS_SYNCER_H_ | |
OLD | NEW |