OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_REQUEST_SCHEDULER_H_ | 5 #ifndef CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_REQUEST_SCHEDULER_H_ |
6 #define CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_REQUEST_SCHEDULER_H_ | 6 #define CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_REQUEST_SCHEDULER_H_ |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/gtest_prod_util.h" | 9 #include "base/gtest_prod_util.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
11 #include "base/timer/timer.h" | 11 #include "base/timer/timer.h" |
12 | 12 |
13 class PrefService; | 13 class PrefService; |
14 | 14 |
15 namespace chrome_variations { | 15 namespace chrome_variations { |
16 | 16 |
17 // A helper class that makes VariationsService requests at the correct times. | 17 // A helper class that makes VariationsService requests at the correct times. |
18 class VariationsRequestScheduler { | 18 class VariationsRequestScheduler { |
19 public: | 19 public: |
20 virtual ~VariationsRequestScheduler(); | 20 virtual ~VariationsRequestScheduler(); |
21 | 21 |
22 // Starts the task on a schedule. | 22 // Starts the task. This can be a repeated event or a one-off. |
23 virtual void Start(); | 23 virtual void Start(); |
24 | 24 |
25 // Resets the scheduler if it is currently on a timer. | 25 // Resets the scheduler if it is currently on a timer. |
26 virtual void Reset(); | 26 virtual void Reset(); |
27 | 27 |
28 // Schedules a fetch shortly, for example to re-try the initial request which | 28 // Schedules a fetch shortly, for example to re-try the initial request which |
29 // may have failed. | 29 // may have failed. |
30 void ScheduleFetchShortly(); | 30 void ForceFetch(); |
Alexei Svitkine (slow)
2014/02/13 16:13:08
Why did you rename this? I found the previous name
rkaplow
2014/02/13 16:55:59
Renaming was required when I had ScheduleFetch nam
| |
31 | |
32 // Potentially fetch a new seed, depending on implementation. This may only | |
33 // fetch if there has not been one recently. | |
34 virtual void ScheduleFetch(); | |
Alexei Svitkine (slow)
2014/02/13 16:13:08
Actually, I'd prefer if this was also named OnAppE
rkaplow
2014/02/13 16:55:59
Done.
| |
31 | 35 |
32 // Factory method for this class. | 36 // Factory method for this class. |
33 static VariationsRequestScheduler* Create(const base::Closure& task, | 37 static VariationsRequestScheduler* Create(const base::Closure& task, |
34 PrefService* local_state); | 38 PrefService* local_state); |
35 | 39 |
36 protected: | 40 protected: |
37 // |task| is the closure to call when the scheduler deems ready. | 41 // |task| is the closure to call when the scheduler deems ready. |
38 explicit VariationsRequestScheduler(const base::Closure& task); | 42 explicit VariationsRequestScheduler(const base::Closure& task); |
39 | 43 |
40 // Getter for derived classes. | 44 // Getter for derived classes. |
41 base::Closure task() const; | 45 base::Closure task() const; |
42 | 46 |
43 private: | 47 private: |
44 FRIEND_TEST_ALL_PREFIXES(VariationsRequestSchedulerTest, | 48 FRIEND_TEST_ALL_PREFIXES(VariationsRequestSchedulerTest, |
45 ScheduleFetchShortly); | 49 ForceFetch); |
46 | 50 |
47 // The task scheduled by this class. | 51 // The task scheduled by this class. |
48 base::Closure task_; | 52 base::Closure task_; |
49 | 53 |
50 // The timer used to repeatedly ping the server. Keep this as an instance | 54 // The timer used to repeatedly ping the server. Keep this as an instance |
51 // member so if VariationsRequestScheduler goes out of scope, the timer is | 55 // member so if VariationsRequestScheduler goes out of scope, the timer is |
52 // automatically canceled. | 56 // automatically canceled. |
53 base::RepeatingTimer<VariationsRequestScheduler> timer_; | 57 base::RepeatingTimer<VariationsRequestScheduler> timer_; |
54 | 58 |
55 // A one-shot timer used for scheduling out-of-band fetches. | 59 // A one-shot timer used for scheduling out-of-band fetches. |
56 base::OneShotTimer<VariationsRequestScheduler> one_shot_timer_; | 60 base::OneShotTimer<VariationsRequestScheduler> one_shot_timer_; |
57 | 61 |
58 DISALLOW_COPY_AND_ASSIGN(VariationsRequestScheduler); | 62 DISALLOW_COPY_AND_ASSIGN(VariationsRequestScheduler); |
59 }; | 63 }; |
60 | 64 |
61 } // namespace chrome_variations | 65 } // namespace chrome_variations |
62 | 66 |
63 #endif // CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_REQUEST_SCHEDULER_H_ | 67 #endif // CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_REQUEST_SCHEDULER_H_ |
OLD | NEW |