Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / metrics / variations / variations_request_scheduler_mobile.cc
blob77148617bfcb9747711027767e5da2ae427bdca2
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_mobile.h"
7 #include "base/prefs/pref_service.h"
8 #include "chrome/common/pref_names.h"
10 namespace chrome_variations {
12 namespace {
14 // Time between seed fetches, in hours.
15 const int kSeedFetchPeriodHours = 5;
17 } // namespace
19 VariationsRequestSchedulerMobile::VariationsRequestSchedulerMobile(
20 const base::Closure& task,
21 PrefService* local_state) :
22 VariationsRequestScheduler(task), local_state_(local_state) {
25 VariationsRequestSchedulerMobile::~VariationsRequestSchedulerMobile() {
28 void VariationsRequestSchedulerMobile::Start() {
29 // Check the time of the last request. If it has been longer than the fetch
30 // period, run the task. Otherwise, do nothing. Note that no future requests
31 // are scheduled since it is unlikely that the mobile process would live long
32 // enough for the timer to fire.
33 const base::Time last_fetch_time = base::Time::FromInternalValue(
34 local_state_->GetInt64(prefs::kVariationsLastFetchTime));
35 if (base::Time::Now() >
36 last_fetch_time + base::TimeDelta::FromHours(kSeedFetchPeriodHours)) {
37 task().Run();
41 void VariationsRequestSchedulerMobile::Reset() {
44 // static
45 VariationsRequestScheduler* VariationsRequestScheduler::Create(
46 const base::Closure& task,
47 PrefService* local_state) {
48 return new VariationsRequestSchedulerMobile(task, local_state);
51 } // namespace chrome_variations