• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "chrome/browser/metrics/variations/variations_request_scheduler.h"
6 
7 namespace chrome_variations {
8 
VariationsRequestScheduler(const base::Closure & task)9 VariationsRequestScheduler::VariationsRequestScheduler(
10     const base::Closure& task) : task_(task) {
11 }
12 
~VariationsRequestScheduler()13 VariationsRequestScheduler::~VariationsRequestScheduler() {
14 }
15 
Start()16 void VariationsRequestScheduler::Start() {
17   // Time between regular seed fetches, in hours.
18   const int kFetchPeriodHours = 5;
19   task_.Run();
20   timer_.Start(FROM_HERE, base::TimeDelta::FromHours(kFetchPeriodHours), task_);
21 }
22 
Reset()23 void VariationsRequestScheduler::Reset() {
24   if (timer_.IsRunning())
25     timer_.Reset();
26   one_shot_timer_.Stop();
27 }
28 
ScheduleFetchShortly()29 void VariationsRequestScheduler::ScheduleFetchShortly() {
30   // Reset the regular timer to avoid it triggering soon after.
31   Reset();
32   // The delay before attempting a fetch shortly, in minutes.
33   const int kFetchShortlyDelayMinutes = 5;
34   one_shot_timer_.Start(FROM_HERE,
35                         base::TimeDelta::FromMinutes(kFetchShortlyDelayMinutes),
36                         task_);
37 }
38 
OnAppEnterForeground()39 void VariationsRequestScheduler::OnAppEnterForeground() {
40   NOTREACHED() << "Attempted to OnAppEnterForeground on non-mobile device";
41 }
42 
task() const43 base::Closure VariationsRequestScheduler::task() const {
44   return task_;
45 }
46 
47 #if !defined(OS_ANDROID) && !defined(OS_IOS)
48 // static
Create(const base::Closure & task,PrefService * local_state)49 VariationsRequestScheduler* VariationsRequestScheduler::Create(
50     const base::Closure& task,
51     PrefService* local_state) {
52   return new VariationsRequestScheduler(task);
53 }
54 #endif  // !defined(OS_ANDROID) && !defined(OS_IOS)
55 
56 }  // namespace chrome_variations
57