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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_REQUEST_SCHEDULER_H_
6 #define CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_REQUEST_SCHEDULER_H_
9 #include "base/gtest_prod_util.h"
10 #include "base/time/time.h"
11 #include "base/timer/timer.h"
15 namespace chrome_variations
{
17 // A helper class that makes VariationsService requests at the correct times.
18 class VariationsRequestScheduler
{
20 virtual ~VariationsRequestScheduler();
22 // Starts the task on a schedule.
25 // Resets the scheduler if it is currently on a timer.
28 // Schedules a fetch shortly, for example to re-try the initial request which
30 void ScheduleFetchShortly();
32 // Factory method for this class.
33 static VariationsRequestScheduler
* Create(const base::Closure
& task
,
34 PrefService
* local_state
);
37 // |task| is the closure to call when the scheduler deems ready.
38 explicit VariationsRequestScheduler(const base::Closure
& task
);
40 // Getter for derived classes.
41 base::Closure
task() const;
44 FRIEND_TEST_ALL_PREFIXES(VariationsRequestSchedulerTest
,
45 ScheduleFetchShortly
);
47 // The task scheduled by this class.
50 // 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
52 // automatically canceled.
53 base::RepeatingTimer
<VariationsRequestScheduler
> timer_
;
55 // A one-shot timer used for scheduling out-of-band fetches.
56 base::OneShotTimer
<VariationsRequestScheduler
> one_shot_timer_
;
58 DISALLOW_COPY_AND_ASSIGN(VariationsRequestScheduler
);
61 } // namespace chrome_variations
63 #endif // CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_REQUEST_SCHEDULER_H_