Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / metrics / variations / variations_request_scheduler.cc
blobff437a8c9d450aa7a78fac1127e4e05bc15b1048
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 #include "chrome/browser/metrics/variations/variations_request_scheduler.h"
7 namespace chrome_variations {
9 VariationsRequestScheduler::VariationsRequestScheduler(
10 const base::Closure& task) : task_(task) {
13 VariationsRequestScheduler::~VariationsRequestScheduler() {
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_);
23 void VariationsRequestScheduler::Reset() {
24 if (timer_.IsRunning())
25 timer_.Reset();
26 one_shot_timer_.Stop();
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_);
39 base::Closure VariationsRequestScheduler::task() const {
40 return task_;
43 #if !defined(OS_ANDROID) && !defined(OS_IOS)
44 // static
45 VariationsRequestScheduler* VariationsRequestScheduler::Create(
46 const base::Closure& task,
47 PrefService* local_state) {
48 return new VariationsRequestScheduler(task);
50 #endif // !defined(OS_ANDROID) && !defined(OS_IOS)
52 } // namespace chrome_variations