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

Side by Side 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: nikita nits 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/metrics/variations/variations_service.h" 5 #include "chrome/browser/metrics/variations/variations_service.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/build_time.h" 10 #include "base/build_time.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 GURL url_as_gurl = GURL(server_url); 93 GURL url_as_gurl = GURL(server_url);
94 DCHECK(url_as_gurl.is_valid()); 94 DCHECK(url_as_gurl.is_valid());
95 return url_as_gurl; 95 return url_as_gurl;
96 } 96 }
97 97
98 } // namespace 98 } // namespace
99 99
100 VariationsService::VariationsService() 100 VariationsService::VariationsService()
101 : variations_server_url_(GetVariationsServerURL()), 101 : variations_server_url_(GetVariationsServerURL()),
102 create_trials_from_seed_called_(false), 102 create_trials_from_seed_called_(false),
103 #if defined(OS_CHROMEOS)
104 waiting_for_user_to_accept_eula_(false),
105 #endif
103 was_offline_during_last_request_attempt_(false) { 106 was_offline_during_last_request_attempt_(false) {
104 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); 107 net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
105 } 108 }
106 109
107 VariationsService::~VariationsService() { 110 VariationsService::~VariationsService() {
108 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); 111 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
109 } 112 }
110 113
111 bool VariationsService::CreateTrialsFromSeed(PrefService* local_prefs) { 114 bool VariationsService::CreateTrialsFromSeed(PrefService* local_prefs) {
112 create_trials_from_seed_called_ = true; 115 create_trials_from_seed_called_ = true;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 this, &VariationsService::FetchVariationsSeed); 154 this, &VariationsService::FetchVariationsSeed);
152 } 155 }
153 156
154 void VariationsService::FetchVariationsSeed() { 157 void VariationsService::FetchVariationsSeed() {
155 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 158 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
156 159
157 was_offline_during_last_request_attempt_ = 160 was_offline_during_last_request_attempt_ =
158 net::NetworkChangeNotifier::IsOffline(); 161 net::NetworkChangeNotifier::IsOffline();
159 UMA_HISTOGRAM_BOOLEAN("Variations.NetworkAvailability", 162 UMA_HISTOGRAM_BOOLEAN("Variations.NetworkAvailability",
160 !was_offline_during_last_request_attempt_); 163 !was_offline_during_last_request_attempt_);
161 if (was_offline_during_last_request_attempt_) { 164 if (was_offline_during_last_request_attempt_) {
Alexei Svitkine (slow) 2012/09/10 16:50:11 I feel like it would better to have a helper class
SteveT 2012/09/10 17:25:28 So you're suggesting that I extract the Observer b
MAD 2012/09/10 17:35:03 Maybe we could share code with the translate manag
Alexei Svitkine (slow) 2012/09/10 17:38:39 The benefits is that variations_service will not h
SteveT 2012/09/10 19:33:52 I am convinced by these arguments and will do the
Alexei Svitkine (slow) 2012/09/10 21:47:35 Maybe NetworkAllowedNotifier or something variatio
SteveT 2012/09/10 21:57:07 It's a bit more like a ResourceRequestAllowedNotif
162 DVLOG(1) << "Network was offline."; 165 DVLOG(1) << "Network was offline.";
163 return; 166 return;
164 } 167 }
165 168
169 #if defined(OS_CHROMEOS)
170 if (!chromeos::WizardController::IsEulaAccepted()) {
171 // The WizardController should notify this class when the EULA has been
172 // accepted.
Alexei Svitkine (slow) 2012/09/10 16:50:11 What about the case of a second start up when ther
SteveT 2012/09/10 17:25:28 Comment added below to explain how we NO-OP if the
173 VLOG(1) << "EULA was not accepted.";
174 waiting_for_user_to_accept_eula_ = true;
175 return;
176 }
177 #endif
178
166 pending_seed_request_.reset(net::URLFetcher::Create( 179 pending_seed_request_.reset(net::URLFetcher::Create(
167 variations_server_url_, net::URLFetcher::GET, this)); 180 variations_server_url_, net::URLFetcher::GET, this));
168 pending_seed_request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | 181 pending_seed_request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
169 net::LOAD_DO_NOT_SAVE_COOKIES); 182 net::LOAD_DO_NOT_SAVE_COOKIES);
170 pending_seed_request_->SetRequestContext( 183 pending_seed_request_->SetRequestContext(
171 g_browser_process->system_request_context()); 184 g_browser_process->system_request_context());
172 pending_seed_request_->SetMaxRetries(kMaxRetrySeedFetch); 185 pending_seed_request_->SetMaxRetries(kMaxRetrySeedFetch);
173 if (!variations_serial_number_.empty()) { 186 if (!variations_serial_number_.empty()) {
174 pending_seed_request_->AddExtraRequestHeader("If-Match:" + 187 pending_seed_request_->AddExtraRequestHeader("If-Match:" +
175 variations_serial_number_); 188 variations_serial_number_);
176 } 189 }
177 pending_seed_request_->Start(); 190 pending_seed_request_->Start();
178 } 191 }
179 192
180 void VariationsService::SetWasOfflineDuringLastRequestAttemptForTesting( 193 void VariationsService::SetWasOfflineDuringLastRequestAttemptForTesting(
181 bool offline) { 194 bool offline) {
182 was_offline_during_last_request_attempt_ = offline; 195 was_offline_during_last_request_attempt_ = offline;
183 } 196 }
184 197
198 #if defined(OS_CHROMEOS)
199 void VariationsService::OnScreenChanged(chromeos::WizardScreen* next_screen) {
Alexei Svitkine (slow) 2012/09/10 16:50:11 Don't indent these. Please add a comment to the no
SteveT 2012/09/10 17:25:28 Done and done. Let me know if the comments are fin
200 }
201
202 void VariationsService::OnSessionStart() {
203 }
204
205 void VariationsService::OnEulaAccepted() {
206 // If an earlier request attempt was aborted because the EULA was not
207 // accepted, retry the request now.
208 if (!waiting_for_user_to_accept_eula_)
209 return;
210 DCHECK(chromeos::WizardController::IsEulaAccepted());
211 waiting_for_user_to_accept_eula_ = false;
212
213 DCHECK(chromeos::WizardController::default_controller());
214 chromeos::WizardController::default_controller()->RemoveObserver(this);
215
216 VLOG(1) << "Starting ping because the EULA was accepted.";
217 FetchVariationsSeed();
218
219 // Since FetchVariationsSeed was explicitly called here, reset the timer to
220 // avoid retrying for a full period.
221 if (timer_.IsRunning())
222 timer_.Reset();
223 }
224 #endif
225
185 // static 226 // static
186 void VariationsService::RegisterPrefs(PrefService* prefs) { 227 void VariationsService::RegisterPrefs(PrefService* prefs) {
187 prefs->RegisterStringPref(prefs::kVariationsSeed, std::string()); 228 prefs->RegisterStringPref(prefs::kVariationsSeed, std::string());
188 prefs->RegisterInt64Pref(prefs::kVariationsSeedDate, 229 prefs->RegisterInt64Pref(prefs::kVariationsSeedDate,
189 base::Time().ToInternalValue()); 230 base::Time().ToInternalValue());
190 } 231 }
191 232
192 void VariationsService::OnURLFetchComplete(const net::URLFetcher* source) { 233 void VariationsService::OnURLFetchComplete(const net::URLFetcher* source) {
193 DCHECK_EQ(pending_seed_request_.get(), source); 234 DCHECK_EQ(pending_seed_request_.get(), source);
194 // The fetcher will be deleted when the request is handled. 235 // The fetcher will be deleted when the request is handled.
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 variation_id); 536 variation_id);
496 } 537 }
497 } 538 }
498 539
499 trial->SetForced(); 540 trial->SetForced();
500 if (IsStudyExpired(study, reference_date)) 541 if (IsStudyExpired(study, reference_date))
501 trial->Disable(); 542 trial->Disable();
502 } 543 }
503 544
504 } // namespace chrome_variations 545 } // namespace chrome_variations
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698