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 |
| 15 class PrefService; |
| 16 class PrefRegistrySimple; |
| 17 namespace net { |
| 18 class URLRequestContextGetter; |
| 19 } |
| 20 namespace user_prefs { |
| 21 class PrefRegistrySyncable; |
| 22 } |
| 23 |
| 24 namespace gcm { |
| 25 |
| 26 class GCMChannelStatusRequest; |
| 27 class GCMDriver; |
| 28 |
| 29 class GCMChannelStatusSyncer { |
| 30 public: |
| 31 static void RegisterPrefs(PrefRegistrySimple* registry); |
| 32 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 33 |
| 34 GCMChannelStatusSyncer( |
| 35 GCMDriver* driver, |
| 36 PrefService* prefs, |
| 37 scoped_refptr<net::URLRequestContextGetter> request_context); |
| 38 ~GCMChannelStatusSyncer(); |
| 39 |
| 40 void EnsureStarted(); |
| 41 void Stop(); |
| 42 |
| 43 bool gcm_enabled() const { return gcm_enabled_; } |
| 44 |
| 45 // For testing purpose. |
| 46 void set_delay_removed_for_testing(bool delay_removed) { |
| 47 delay_removed_for_testing_ = delay_removed; |
| 48 } |
| 49 base::TimeDelta current_request_delay_interval() const { |
| 50 return current_request_delay_interval_; |
| 51 } |
| 52 static int first_time_delay_seconds(); |
| 53 |
| 54 private: |
| 55 // Called when a request is completed. |
| 56 void OnRequestCompleted(bool enabled, int poll_interval_seconds); |
| 57 |
| 58 // Schedules next request to start after appropriate delay. |
| 59 void ScheduleRequest(); |
| 60 |
| 61 // Creates and starts a request immediately. |
| 62 void StartRequest(); |
| 63 |
| 64 // Computes and returns a delay with the fuzzing variation added if needed, |
| 65 // after which the request could start. |
| 66 base::TimeDelta GetRequestDelayInterval() const; |
| 67 |
| 68 // GCMDriver owns GCMChannelStatusSyncer instance. |
| 69 GCMDriver* driver_; |
| 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 |