Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / metrics / variations / variations_request_scheduler.h
blob7dd1a2c065b96225e19ad51aeddac9dcdd9ebfed
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_
8 #include "base/bind.h"
9 #include "base/gtest_prod_util.h"
10 #include "base/time/time.h"
11 #include "base/timer/timer.h"
13 class PrefService;
15 namespace chrome_variations {
17 // A helper class that makes VariationsService requests at the correct times.
18 class VariationsRequestScheduler {
19 public:
20 virtual ~VariationsRequestScheduler();
22 // Starts the task. This can be a repeated event or a one-off.
23 virtual void Start();
25 // Resets the scheduler if it is currently on a timer.
26 virtual void Reset();
28 // Schedules a fetch shortly, for example to re-try the initial request which
29 // may have failed.
30 void ScheduleFetchShortly();
32 // Called when the application has been foregrounded. This may fetch a new
33 // seed.
34 virtual void OnAppEnterForeground();
36 // Factory method for this class.
37 static VariationsRequestScheduler* Create(const base::Closure& task,
38 PrefService* local_state);
40 protected:
41 // |task| is the closure to call when the scheduler deems ready.
42 explicit VariationsRequestScheduler(const base::Closure& task);
44 // Getter for derived classes.
45 base::Closure task() const;
47 private:
48 FRIEND_TEST_ALL_PREFIXES(VariationsRequestSchedulerTest,
49 ScheduleFetchShortly);
51 // The task scheduled by this class.
52 base::Closure task_;
54 // The timer used to repeatedly ping the server. Keep this as an instance
55 // member so if VariationsRequestScheduler goes out of scope, the timer is
56 // automatically canceled.
57 base::RepeatingTimer<VariationsRequestScheduler> timer_;
59 // A one-shot timer used for scheduling out-of-band fetches.
60 base::OneShotTimer<VariationsRequestScheduler> one_shot_timer_;
62 DISALLOW_COPY_AND_ASSIGN(VariationsRequestScheduler);
65 } // namespace chrome_variations
67 #endif // CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_REQUEST_SCHEDULER_H_