Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(331)

Side by Side Diff: chrome/browser/metrics/variations/variations_request_scheduler.cc

Issue 1119893003: Parametrize variations server ping period. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/metrics/variations/variations_request_scheduler.h" 5 #include "chrome/browser/metrics/variations/variations_request_scheduler.h"
6 6
7 #include "base/strings/string_number_conversions.h"
8 #include "components/variations/variations_associated_data.h"
9
7 namespace chrome_variations { 10 namespace chrome_variations {
8 11
12 namespace {
13
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);
23
24 // The default fetch interval is every 5 hours.
25 return base::TimeDelta::FromHours(5);
26 }
27
28 } // namespace
29
9 VariationsRequestScheduler::VariationsRequestScheduler( 30 VariationsRequestScheduler::VariationsRequestScheduler(
10 const base::Closure& task) : task_(task) { 31 const base::Closure& task) : task_(task) {
11 } 32 }
12 33
13 VariationsRequestScheduler::~VariationsRequestScheduler() { 34 VariationsRequestScheduler::~VariationsRequestScheduler() {
14 } 35 }
15 36
16 void VariationsRequestScheduler::Start() { 37 void VariationsRequestScheduler::Start() {
17 // Time between regular seed fetches, in hours.
18 const int kFetchPeriodHours = 5;
19 task_.Run(); 38 task_.Run();
20 timer_.Start(FROM_HERE, base::TimeDelta::FromHours(kFetchPeriodHours), task_); 39 timer_.Start(FROM_HERE, GetFetchPeriod(), task_);
21 } 40 }
22 41
23 void VariationsRequestScheduler::Reset() { 42 void VariationsRequestScheduler::Reset() {
24 if (timer_.IsRunning()) 43 if (timer_.IsRunning())
25 timer_.Reset(); 44 timer_.Reset();
26 one_shot_timer_.Stop(); 45 one_shot_timer_.Stop();
27 } 46 }
28 47
29 void VariationsRequestScheduler::ScheduleFetchShortly() { 48 void VariationsRequestScheduler::ScheduleFetchShortly() {
30 // Reset the regular timer to avoid it triggering soon after. 49 // Reset the regular timer to avoid it triggering soon after.
(...skipping 16 matching lines...) Expand all
47 #if !defined(OS_ANDROID) && !defined(OS_IOS) 66 #if !defined(OS_ANDROID) && !defined(OS_IOS)
48 // static 67 // static
49 VariationsRequestScheduler* VariationsRequestScheduler::Create( 68 VariationsRequestScheduler* VariationsRequestScheduler::Create(
50 const base::Closure& task, 69 const base::Closure& task,
51 PrefService* local_state) { 70 PrefService* local_state) {
52 return new VariationsRequestScheduler(task); 71 return new VariationsRequestScheduler(task);
53 } 72 }
54 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) 73 #endif // !defined(OS_ANDROID) && !defined(OS_IOS)
55 74
56 } // namespace chrome_variations 75 } // namespace chrome_variations
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698