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

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: missed asvit nit 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_) {
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.
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) {
200 // Not implemented as VariationsService does not care about screen changes.
201 }
202
203 void VariationsService::OnSessionStart() {
204 // Not implemented as VariationsService does not care about session starts.
205 }
206
207 void VariationsService::OnEulaAccepted() {
208 // If an earlier request attempt was aborted because the EULA was not
209 // accepted, retry the request now.
210 // Note that if the EULA check succeeded earlier, this just returns.
211 if (!waiting_for_user_to_accept_eula_)
212 return;
213 DCHECK(chromeos::WizardController::IsEulaAccepted());
214 waiting_for_user_to_accept_eula_ = false;
215
216 DCHECK(chromeos::WizardController::default_controller());
217 chromeos::WizardController::default_controller()->RemoveObserver(this);
218
219 VLOG(1) << "Starting ping because the EULA was accepted.";
220 FetchVariationsSeed();
221
222 // Since FetchVariationsSeed was explicitly called here, reset the timer to
223 // avoid retrying for a full period.
224 if (timer_.IsRunning())
225 timer_.Reset();
226 }
227 #endif
228
185 // static 229 // static
186 void VariationsService::RegisterPrefs(PrefService* prefs) { 230 void VariationsService::RegisterPrefs(PrefService* prefs) {
187 prefs->RegisterStringPref(prefs::kVariationsSeed, std::string()); 231 prefs->RegisterStringPref(prefs::kVariationsSeed, std::string());
188 prefs->RegisterInt64Pref(prefs::kVariationsSeedDate, 232 prefs->RegisterInt64Pref(prefs::kVariationsSeedDate,
189 base::Time().ToInternalValue()); 233 base::Time().ToInternalValue());
190 } 234 }
191 235
192 void VariationsService::OnURLFetchComplete(const net::URLFetcher* source) { 236 void VariationsService::OnURLFetchComplete(const net::URLFetcher* source) {
193 DCHECK_EQ(pending_seed_request_.get(), source); 237 DCHECK_EQ(pending_seed_request_.get(), source);
194 // The fetcher will be deleted when the request is handled. 238 // 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); 539 variation_id);
496 } 540 }
497 } 541 }
498 542
499 trial->SetForced(); 543 trial->SetForced();
500 if (IsStudyExpired(study, reference_date)) 544 if (IsStudyExpired(study, reference_date))
501 trial->Disable(); 545 trial->Disable();
502 } 546 }
503 547
504 } // namespace chrome_variations 548 } // namespace chrome_variations
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698