summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorasvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-11 17:24:23 +0000
committerasvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-11 17:24:23 +0000
commit348201f40150e7a6b754c03dfb358614eb180b06 (patch)
treee45644986715b533e358d6a41030c7220c406151
parentd3b59bcf4b7cff259d59643b98004f9ab80e5cfd (diff)
downloadchromium_src-348201f40150e7a6b754c03dfb358614eb180b06.zip
chromium_src-348201f40150e7a6b754c03dfb358614eb180b06.tar.gz
chromium_src-348201f40150e7a6b754c03dfb358614eb180b06.tar.bz2
Re-try variations seed fetch earlier if it fails the first time.
Makes it so that if a variations seed fetch fails the first time due to an error in the network stack (not a bad response from the server), that we'll re-try again after 5 minutes instead of waiting for the full fetch interval to elapse (5 hours). Also applies to mobile platforms, where we'll also re-try in 5 minutes in such cases, rather than on the next browser startup. BUG=247820 Review URL: https://chromiumcodereview.appspot.com/15675019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@205575 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/metrics/variations/variations_request_scheduler.cc24
-rw-r--r--chrome/browser/metrics/variations/variations_request_scheduler.h8
-rw-r--r--chrome/browser/metrics/variations/variations_service.cc11
-rw-r--r--chrome/browser/metrics/variations/variations_service.h3
4 files changed, 36 insertions, 10 deletions
diff --git a/chrome/browser/metrics/variations/variations_request_scheduler.cc b/chrome/browser/metrics/variations/variations_request_scheduler.cc
index 0eac6b7..091e522 100644
--- a/chrome/browser/metrics/variations/variations_request_scheduler.cc
+++ b/chrome/browser/metrics/variations/variations_request_scheduler.cc
@@ -6,13 +6,6 @@
namespace chrome_variations {
-namespace {
-
-// Time between seed fetches, in hours.
-const int kSeedFetchPeriodHours = 5;
-
-} // namespace
-
VariationsRequestScheduler::VariationsRequestScheduler(
const base::Closure& task) : task_(task) {
}
@@ -21,15 +14,26 @@ VariationsRequestScheduler::~VariationsRequestScheduler() {
}
void VariationsRequestScheduler::Start() {
- // Call the task and repeat it periodically.
+ // Time between regular seed fetches, in hours.
+ const int kFetchPeriodHours = 5;
task_.Run();
- timer_.Start(FROM_HERE, base::TimeDelta::FromHours(kSeedFetchPeriodHours),
- task_);
+ timer_.Start(FROM_HERE, base::TimeDelta::FromHours(kFetchPeriodHours), task_);
}
void VariationsRequestScheduler::Reset() {
if (timer_.IsRunning())
timer_.Reset();
+ one_shot_timer_.Stop();
+}
+
+void VariationsRequestScheduler::ScheduleFetchShortly() {
+ // The delay before attempting a fetch shortly, in minutes.
+ const int kFetchShortlyDelayMinutes = 5;
+ one_shot_timer_.Start(FROM_HERE,
+ base::TimeDelta::FromMinutes(kFetchShortlyDelayMinutes),
+ task_);
+ // Reset the regular timer to avoid it triggering soon after.
+ Reset();
}
base::Closure VariationsRequestScheduler::task() const {
diff --git a/chrome/browser/metrics/variations/variations_request_scheduler.h b/chrome/browser/metrics/variations/variations_request_scheduler.h
index 897983c..e6113ed 100644
--- a/chrome/browser/metrics/variations/variations_request_scheduler.h
+++ b/chrome/browser/metrics/variations/variations_request_scheduler.h
@@ -6,6 +6,7 @@
#define CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_REQUEST_SCHEDULER_H_
#include "base/bind.h"
+#include "base/time.h"
#include "base/timer.h"
class PrefService;
@@ -23,6 +24,10 @@ class VariationsRequestScheduler {
// Resets the scheduler if it is currently on a timer.
virtual void Reset();
+ // Schedules a fetch shortly, for example to re-try the initial request which
+ // may have failed.
+ void ScheduleFetchShortly();
+
// Factory method for this class.
static VariationsRequestScheduler* Create(const base::Closure& task,
PrefService* local_state);
@@ -43,6 +48,9 @@ class VariationsRequestScheduler {
// automatically canceled.
base::RepeatingTimer<VariationsRequestScheduler> timer_;
+ // A one-shot timer used for scheduling out-of-band fetches.
+ base::OneShotTimer<VariationsRequestScheduler> one_shot_timer_;
+
DISALLOW_COPY_AND_ASSIGN(VariationsRequestScheduler);
};
diff --git a/chrome/browser/metrics/variations/variations_service.cc b/chrome/browser/metrics/variations/variations_service.cc
index 24f74ca..2b1bb3b 100644
--- a/chrome/browser/metrics/variations/variations_service.cc
+++ b/chrome/browser/metrics/variations/variations_service.cc
@@ -176,6 +176,7 @@ VariationsService::VariationsService(PrefService* local_state)
: local_state_(local_state),
variations_server_url_(GetVariationsServerURL(local_state)),
create_trials_from_seed_called_(false),
+ initial_request_completed_(false),
resource_request_allowed_notifier_(
new ResourceRequestAllowedNotifier) {
resource_request_allowed_notifier_->Init(this);
@@ -186,6 +187,7 @@ VariationsService::VariationsService(ResourceRequestAllowedNotifier* notifier,
: local_state_(local_state),
variations_server_url_(GetVariationsServerURL(NULL)),
create_trials_from_seed_called_(false),
+ initial_request_completed_(false),
resource_request_allowed_notifier_(notifier) {
resource_request_allowed_notifier_->Init(this);
}
@@ -357,6 +359,10 @@ void VariationsService::FetchVariationsSeed() {
void VariationsService::OnURLFetchComplete(const net::URLFetcher* source) {
DCHECK_EQ(pending_seed_request_.get(), source);
+
+ const bool is_first_request = !initial_request_completed_;
+ initial_request_completed_ = true;
+
// The fetcher will be deleted when the request is handled.
scoped_ptr<const net::URLFetcher> request(pending_seed_request_.release());
const net::URLRequestStatus& request_status = request->GetStatus();
@@ -366,6 +372,11 @@ void VariationsService::OnURLFetchComplete(const net::URLFetcher* source) {
DVLOG(1) << "Variations server request failed with error: "
<< request_status.error() << ": "
<< net::ErrorToString(request_status.error());
+ // It's common for the very first fetch attempt to fail (e.g. the network
+ // may not yet be available). In such a case, try again soon, rather than
+ // waiting the full time interval.
+ if (is_first_request)
+ request_scheduler_->ScheduleFetchShortly();
return;
}
diff --git a/chrome/browser/metrics/variations/variations_service.h b/chrome/browser/metrics/variations/variations_service.h
index 4392337..35c2723 100644
--- a/chrome/browser/metrics/variations/variations_service.h
+++ b/chrome/browser/metrics/variations/variations_service.h
@@ -196,6 +196,9 @@ class VariationsService
// it gets called prior to |StartRepeatedVariationsSeedFetch|.
bool create_trials_from_seed_called_;
+ // Tracks whether the initial request to the variations server had completed.
+ bool initial_request_completed_;
+
// Helper class used to tell this service if it's allowed to make network
// resource requests.
scoped_ptr<ResourceRequestAllowedNotifier> resource_request_allowed_notifier_;