| Index: chrome/browser/metrics/variations/variations_service.cc
|
| diff --git a/chrome/browser/metrics/variations/variations_service.cc b/chrome/browser/metrics/variations/variations_service.cc
|
| index 2b95bf6e4aa1b2b0389b7f241fe50b541692edfa..cdd4364f60c5e55359e6cc09a82f9a46a6b33b5f 100644
|
| --- a/chrome/browser/metrics/variations/variations_service.cc
|
| +++ b/chrome/browser/metrics/variations/variations_service.cc
|
| @@ -11,7 +11,6 @@
|
| #include "base/command_line.h"
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/metrics/field_trial.h"
|
| -#include "base/metrics/histogram.h"
|
| #include "base/version.h"
|
| #include "chrome/browser/browser_process.h"
|
| #include "chrome/browser/metrics/proto/trials_seed.pb.h"
|
| @@ -98,14 +97,14 @@ GURL GetVariationsServerURL() {
|
| } // namespace
|
|
|
| VariationsService::VariationsService()
|
| - : variations_server_url_(GetVariationsServerURL()),
|
| - create_trials_from_seed_called_(false),
|
| - was_offline_during_last_request_attempt_(false) {
|
| - net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
|
| + : create_trials_from_seed_called_(false),
|
| + variations_server_url_(GetVariationsServerURL()),
|
| + resource_request_allowed_notifier_(new ResourceRequestAllowedNotifier) {
|
| + resource_request_allowed_notifier_->SetObserver(this);
|
| }
|
|
|
| VariationsService::~VariationsService() {
|
| - net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
|
| + resource_request_allowed_notifier_->ClearObserver();
|
| }
|
|
|
| bool VariationsService::CreateTrialsFromSeed(PrefService* local_prefs) {
|
| @@ -154,15 +153,28 @@ void VariationsService::StartRepeatedVariationsSeedFetch() {
|
| void VariationsService::FetchVariationsSeed() {
|
| DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
|
|
|
| - was_offline_during_last_request_attempt_ =
|
| - net::NetworkChangeNotifier::IsOffline();
|
| - UMA_HISTOGRAM_BOOLEAN("Variations.NetworkAvailability",
|
| - !was_offline_during_last_request_attempt_);
|
| - if (was_offline_during_last_request_attempt_) {
|
| - DVLOG(1) << "Network was offline.";
|
| + if (!resource_request_allowed_notifier_->ResourceRequestsAllowed()) {
|
| + DVLOG(1) << "Resource requests were not allowed. Waiting for notification.";
|
| return;
|
| }
|
|
|
| + DoActualFetch();
|
| +}
|
| +
|
| +void VariationsService::
|
| + RegisterForEulaAcceptedNotification(chromeos::WizardController* source) {
|
| + resource_request_allowed_notifier_->
|
| + RegisterForEulaAcceptedNotification(source);
|
| +}
|
| +
|
| +// static
|
| +void VariationsService::RegisterPrefs(PrefService* prefs) {
|
| + prefs->RegisterStringPref(prefs::kVariationsSeed, std::string());
|
| + prefs->RegisterInt64Pref(prefs::kVariationsSeedDate,
|
| + base::Time().ToInternalValue());
|
| +}
|
| +
|
| +void VariationsService::DoActualFetch() {
|
| pending_seed_request_.reset(net::URLFetcher::Create(
|
| variations_server_url_, net::URLFetcher::GET, this));
|
| pending_seed_request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
|
| @@ -177,16 +189,12 @@ void VariationsService::FetchVariationsSeed() {
|
| pending_seed_request_->Start();
|
| }
|
|
|
| -void VariationsService::SetWasOfflineDuringLastRequestAttemptForTesting(
|
| - bool offline) {
|
| - was_offline_during_last_request_attempt_ = offline;
|
| -}
|
| -
|
| -// static
|
| -void VariationsService::RegisterPrefs(PrefService* prefs) {
|
| - prefs->RegisterStringPref(prefs::kVariationsSeed, std::string());
|
| - prefs->RegisterInt64Pref(prefs::kVariationsSeedDate,
|
| - base::Time().ToInternalValue());
|
| +void VariationsService::SetResourceRequestAllowedNotifierForTesting(
|
| + ResourceRequestAllowedNotifier* notifier) {
|
| + DCHECK(notifier);
|
| + resource_request_allowed_notifier_->ClearObserver();
|
| + resource_request_allowed_notifier_.reset(notifier);
|
| + notifier->SetObserver(this);
|
| }
|
|
|
| void VariationsService::OnURLFetchComplete(const net::URLFetcher* source) {
|
| @@ -216,24 +224,17 @@ void VariationsService::OnURLFetchComplete(const net::URLFetcher* source) {
|
| StoreSeedData(seed_data, response_date, g_browser_process->local_state());
|
| }
|
|
|
| -void VariationsService::OnConnectionTypeChanged(
|
| - net::NetworkChangeNotifier::ConnectionType type) {
|
| - // If the connection type is back online, start a request if the last request
|
| - // failed due to being offline.
|
| - if (was_offline_during_last_request_attempt_ &&
|
| - type != net::NetworkChangeNotifier::CONNECTION_NONE) {
|
| - VLOG(1) << "Retrying fetch due to network reconnect.";
|
| - FetchVariationsSeed();
|
| -
|
| - // Since FetchVariationsSeed was explicitly called here, reset the timer to
|
| - // avoid retrying for a full period.
|
| - // net::NetworkChangeNotifier::IsOffline may be inconsistent with |type|, so
|
| - // we check if FetchVariationsSeed set
|
| - // |was_offline_during_last_request_attempt_| to true before we reset the
|
| - // timer.
|
| - if (!was_offline_during_last_request_attempt_ && timer_.IsRunning())
|
| - timer_.Reset();
|
| - }
|
| +void VariationsService::OnResourceRequestsAllowed() {
|
| + // Note that this only attempts to fetch the seed at most once per period
|
| + // (kSeedFetchPeriodHours). This works because
|
| + // |resource_request_allowed_notifier_| only calls this method if an
|
| + // attempt was made earlier that fails (which implies that the period had
|
| + // elapsed). After a successful attempt is made, the notifier will know not
|
| + // to call this method again until another failed attempt occurs.
|
| + DVLOG(1) << "Retrying fetch.";
|
| + FetchVariationsSeed();
|
| + if (timer_.IsRunning())
|
| + timer_.Reset();
|
| }
|
|
|
| bool VariationsService::StoreSeedData(const std::string& seed_data,
|
|
|