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

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

Issue 147723010: Expose a method in VariationsService to trigger a seed fetch. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 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
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 namespace chrome_variations { 7 namespace chrome_variations {
8 8
9 VariationsRequestScheduler::VariationsRequestScheduler( 9 VariationsRequestScheduler::VariationsRequestScheduler(
10 const base::Closure& task) : task_(task) { 10 const base::Closure& task) : task_(task) {
11 } 11 }
12 12
13 VariationsRequestScheduler::~VariationsRequestScheduler() { 13 VariationsRequestScheduler::~VariationsRequestScheduler() {
14 } 14 }
15 15
16 void VariationsRequestScheduler::Start() { 16 void VariationsRequestScheduler::Start() {
17 // Time between regular seed fetches, in hours. 17 // Time between regular seed fetches, in hours.
18 const int kFetchPeriodHours = 5; 18 const int kFetchPeriodHours = 5;
19 task_.Run(); 19 task_.Run();
20 timer_.Start(FROM_HERE, base::TimeDelta::FromHours(kFetchPeriodHours), task_); 20 timer_.Start(FROM_HERE, base::TimeDelta::FromHours(kFetchPeriodHours), task_);
21 } 21 }
22 22
23 void VariationsRequestScheduler::Reset() { 23 void VariationsRequestScheduler::Reset() {
24 if (timer_.IsRunning()) 24 if (timer_.IsRunning())
25 timer_.Reset(); 25 timer_.Reset();
26 one_shot_timer_.Stop(); 26 one_shot_timer_.Stop();
27 } 27 }
28 28
29 void VariationsRequestScheduler::ScheduleFetchShortly() { 29 void VariationsRequestScheduler::ForceFetch() {
30 // Reset the regular timer to avoid it triggering soon after. 30 // Reset the regular timer to avoid it triggering soon after.
31 Reset(); 31 Reset();
32 // The delay before attempting a fetch shortly, in minutes. 32 // The delay before attempting a fetch shortly, in minutes.
33 const int kFetchShortlyDelayMinutes = 5; 33 const int kFetchShortlyDelayMinutes = 5;
34 one_shot_timer_.Start(FROM_HERE, 34 one_shot_timer_.Start(FROM_HERE,
35 base::TimeDelta::FromMinutes(kFetchShortlyDelayMinutes), 35 base::TimeDelta::FromMinutes(kFetchShortlyDelayMinutes),
36 task_); 36 task_);
37 } 37 }
38 38
39 void VariationsRequestScheduler::ScheduleFetch() {
40 // By default (non-mobile) we can reuse ForceFetch.
41 ForceFetch();
42 }
43
39 base::Closure VariationsRequestScheduler::task() const { 44 base::Closure VariationsRequestScheduler::task() const {
40 return task_; 45 return task_;
41 } 46 }
42 47
43 #if !defined(OS_ANDROID) && !defined(OS_IOS) 48 #if !defined(OS_ANDROID) && !defined(OS_IOS)
44 // static 49 // static
45 VariationsRequestScheduler* VariationsRequestScheduler::Create( 50 VariationsRequestScheduler* VariationsRequestScheduler::Create(
46 const base::Closure& task, 51 const base::Closure& task,
47 PrefService* local_state) { 52 PrefService* local_state) {
48 return new VariationsRequestScheduler(task); 53 return new VariationsRequestScheduler(task);
49 } 54 }
50 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) 55 #endif // !defined(OS_ANDROID) && !defined(OS_IOS)
51 56
52 } // namespace chrome_variations 57 } // namespace chrome_variations
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698