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. 4 5#include "chrome/browser/metrics/variations/variations_request_scheduler_mobile.h" 6 7#include "base/prefs/pref_service.h" 8#include "chrome/common/pref_names.h" 9 10namespace chrome_variations { 11 12namespace { 13 14// Time between seed fetches, in hours. 15const int kSeedFetchPeriodHours = 5; 16 17} // namespace 18 19VariationsRequestSchedulerMobile::VariationsRequestSchedulerMobile( 20 const base::Closure& task, 21 PrefService* local_state) : 22 VariationsRequestScheduler(task), local_state_(local_state) { 23} 24 25VariationsRequestSchedulerMobile::~VariationsRequestSchedulerMobile() { 26} 27 28void 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(); 38 } 39} 40 41void VariationsRequestSchedulerMobile::Reset() { 42} 43 44// static 45VariationsRequestScheduler* VariationsRequestScheduler::Create( 46 const base::Closure& task, 47 PrefService* local_state) { 48 return new VariationsRequestSchedulerMobile(task, local_state); 49} 50 51} // namespace chrome_variations 52