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

Unified Diff: chrome/browser/metrics/variations/variations_service.cc

Issue 10917120: Activate the VariationsService for ChromeOS and ensure that it does not ping the server until the E… (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Refactored to use ResourceRequestAllowedNotifier Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
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..8a14b231e4d63a0f6b2966ab15e9f7762973f0ce 100644
--- a/chrome/browser/metrics/variations/variations_service.cc
+++ b/chrome/browser/metrics/variations/variations_service.cc
@@ -100,12 +100,15 @@ GURL GetVariationsServerURL() {
VariationsService::VariationsService()
: variations_server_url_(GetVariationsServerURL()),
create_trials_from_seed_called_(false),
+#if defined(OS_CHROMEOS)
+ waiting_for_user_to_accept_eula_(false),
+#endif
was_offline_during_last_request_attempt_(false) {
- net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
+ resource_request_allowed_notifier_.AddObserver(this);
}
VariationsService::~VariationsService() {
- net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
+ resource_request_allowed_notifier_.RemoveObserver(this);
}
bool VariationsService::CreateTrialsFromSeed(PrefService* local_prefs) {
@@ -163,6 +166,16 @@ void VariationsService::FetchVariationsSeed() {
return;
}
+#if defined(OS_CHROMEOS)
+ if (!ResourceRequestAllowedNotifier::IsEulaAccepted()) {
+ // The ResourceRequestAllowedNotifier should notify this class when the EULA
+ // has been accepted.
+ VLOG(1) << "EULA was not accepted.";
+ waiting_for_user_to_accept_eula_ = true;
+ return;
+ }
+#endif
+
pending_seed_request_.reset(net::URLFetcher::Create(
variations_server_url_, net::URLFetcher::GET, this));
pending_seed_request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
@@ -182,6 +195,44 @@ void VariationsService::SetWasOfflineDuringLastRequestAttemptForTesting(
was_offline_during_last_request_attempt_ = offline;
}
+void VariationsService::OnNetworkChangedToActiveConnection() {
+ // 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_) {
+ 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.
+ // ResourceRequestAllowedNotifier::IsNetworkOffline may be inconsistent with
+ // calls to OnNetworkChangedToActiveConnection, 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();
+ }
+}
+
+#if defined(OS_CHROMEOS)
+void VariationsService::OnEulaAccepted() {
+ // If an earlier request attempt was aborted because the EULA was not
+ // accepted, retry the request now.
+ // Note that if the EULA check succeeded earlier, this just returns.
+ if (!waiting_for_user_to_accept_eula_)
+ return;
+ DCHECK(ResourceRequestAllowedNotifier::IsEulaAccepted());
+ waiting_for_user_to_accept_eula_ = false;
+
+ VLOG(1) << "Starting ping because the EULA was accepted.";
+ FetchVariationsSeed();
+
+ // Since FetchVariationsSeed was explicitly called here, reset the timer to
+ // avoid retrying for a full period.
+ if (timer_.IsRunning())
+ timer_.Reset();
+}
+#endif
+
// static
void VariationsService::RegisterPrefs(PrefService* prefs) {
prefs->RegisterStringPref(prefs::kVariationsSeed, std::string());
@@ -216,26 +267,6 @@ 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();
- }
-}
-
bool VariationsService::StoreSeedData(const std::string& seed_data,
const base::Time& seed_date,
PrefService* local_prefs) {

Powered by Google App Engine
This is Rietveld 408576698