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.cc
blob932bf6664620bf4eeffd8455dcd35541afb20da2
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 #include "base/strings/string_number_conversions.h"
8 #include "components/variations/variations_associated_data.h"
10 namespace chrome_variations {
12 namespace {
14 // Returns the time interval between variations seed fetches.
15 base::TimeDelta GetFetchPeriod() {
16 // The fetch interval can be overridden by a variation param.
17 std::string period_min_str =
18 variations::GetVariationParamValue("VarationsServiceControl",
19 "fetch_period_min");
20 size_t period_min;
21 if (base::StringToSizeT(period_min_str, &period_min))
22 return base::TimeDelta::FromMinutes(period_min);
24 // The default fetch interval is every 5 hours.
25 return base::TimeDelta::FromHours(5);
28 } // namespace
30 VariationsRequestScheduler::VariationsRequestScheduler(
31 const base::Closure& task) : task_(task) {
34 VariationsRequestScheduler::~VariationsRequestScheduler() {
37 void VariationsRequestScheduler::Start() {
38 task_.Run();
39 timer_.Start(FROM_HERE, GetFetchPeriod(), task_);
42 void VariationsRequestScheduler::Reset() {
43 if (timer_.IsRunning())
44 timer_.Reset();
45 one_shot_timer_.Stop();
48 void VariationsRequestScheduler::ScheduleFetchShortly() {
49 // Reset the regular timer to avoid it triggering soon after.
50 Reset();
51 // The delay before attempting a fetch shortly, in minutes.
52 const int kFetchShortlyDelayMinutes = 5;
53 one_shot_timer_.Start(FROM_HERE,
54 base::TimeDelta::FromMinutes(kFetchShortlyDelayMinutes),
55 task_);
58 void VariationsRequestScheduler::OnAppEnterForeground() {
59 NOTREACHED() << "Attempted to OnAppEnterForeground on non-mobile device";
62 base::Closure VariationsRequestScheduler::task() const {
63 return task_;
66 #if !defined(OS_ANDROID) && !defined(OS_IOS)
67 // static
68 VariationsRequestScheduler* VariationsRequestScheduler::Create(
69 const base::Closure& task,
70 PrefService* local_state) {
71 return new VariationsRequestScheduler(task);
73 #endif // !defined(OS_ANDROID) && !defined(OS_IOS)
75 } // namespace chrome_variations