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

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: init 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 10 matching lines...) Expand all
21 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
22 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
23 #include "content/public/common/url_fetcher.h" 23 #include "content/public/common/url_fetcher.h"
24 #include "googleurl/src/gurl.h" 24 #include "googleurl/src/gurl.h"
25 #include "net/base/load_flags.h" 25 #include "net/base/load_flags.h"
26 #include "net/base/network_change_notifier.h" 26 #include "net/base/network_change_notifier.h"
27 #include "net/http/http_response_headers.h" 27 #include "net/http/http_response_headers.h"
28 #include "net/url_request/url_fetcher.h" 28 #include "net/url_request/url_fetcher.h"
29 #include "net/url_request/url_request_status.h" 29 #include "net/url_request/url_request_status.h"
30 30
31 #if defined(OS_CHROMEOS)
32 #include "chrome/browser/chromeos/login/wizard_controller.h"
Nikita (slow) 2012/09/10 14:48:55 nit: Should be removed as already included in the
SteveT 2012/09/10 16:33:02 Done.
33 #endif
34
31 namespace chrome_variations { 35 namespace chrome_variations {
32 36
33 namespace { 37 namespace {
34 38
35 // Default server of Variations seed info. 39 // Default server of Variations seed info.
36 const char kDefaultVariationsServerURL[] = 40 const char kDefaultVariationsServerURL[] =
37 "https://clients4.google.com/chrome-variations/seed"; 41 "https://clients4.google.com/chrome-variations/seed";
38 const int kMaxRetrySeedFetch = 5; 42 const int kMaxRetrySeedFetch = 5;
39 43
40 // Time between seed fetches, in hours. 44 // Time between seed fetches, in hours.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 GURL url_as_gurl = GURL(server_url); 97 GURL url_as_gurl = GURL(server_url);
94 DCHECK(url_as_gurl.is_valid()); 98 DCHECK(url_as_gurl.is_valid());
95 return url_as_gurl; 99 return url_as_gurl;
96 } 100 }
97 101
98 } // namespace 102 } // namespace
99 103
100 VariationsService::VariationsService() 104 VariationsService::VariationsService()
101 : variations_server_url_(GetVariationsServerURL()), 105 : variations_server_url_(GetVariationsServerURL()),
102 create_trials_from_seed_called_(false), 106 create_trials_from_seed_called_(false),
107 #if defined(OS_CHROMEOS)
108 waiting_for_user_to_accept_eula_(false),
109 #endif
103 was_offline_during_last_request_attempt_(false) { 110 was_offline_during_last_request_attempt_(false) {
104 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); 111 net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
105 } 112 }
106 113
107 VariationsService::~VariationsService() { 114 VariationsService::~VariationsService() {
108 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); 115 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
109 } 116 }
110 117
111 bool VariationsService::CreateTrialsFromSeed(PrefService* local_prefs) { 118 bool VariationsService::CreateTrialsFromSeed(PrefService* local_prefs) {
112 create_trials_from_seed_called_ = true; 119 create_trials_from_seed_called_ = true;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 163
157 was_offline_during_last_request_attempt_ = 164 was_offline_during_last_request_attempt_ =
158 net::NetworkChangeNotifier::IsOffline(); 165 net::NetworkChangeNotifier::IsOffline();
159 UMA_HISTOGRAM_BOOLEAN("Variations.NetworkAvailability", 166 UMA_HISTOGRAM_BOOLEAN("Variations.NetworkAvailability",
160 !was_offline_during_last_request_attempt_); 167 !was_offline_during_last_request_attempt_);
161 if (was_offline_during_last_request_attempt_) { 168 if (was_offline_during_last_request_attempt_) {
162 DVLOG(1) << "Network was offline."; 169 DVLOG(1) << "Network was offline.";
163 return; 170 return;
164 } 171 }
165 172
173 #if defined(OS_CHROMEOS)
174 if (!chromeos::WizardController::IsEulaAccepted()) {
175 // The WizardController should notify this class when the EULA has been
176 // accepted.
177 VLOG(1) << "EULA was not accepted.";
178 waiting_for_user_to_accept_eula_ = true;
179 return;
180 }
181 #endif
182
166 pending_seed_request_.reset(net::URLFetcher::Create( 183 pending_seed_request_.reset(net::URLFetcher::Create(
167 variations_server_url_, net::URLFetcher::GET, this)); 184 variations_server_url_, net::URLFetcher::GET, this));
168 pending_seed_request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | 185 pending_seed_request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
169 net::LOAD_DO_NOT_SAVE_COOKIES); 186 net::LOAD_DO_NOT_SAVE_COOKIES);
170 pending_seed_request_->SetRequestContext( 187 pending_seed_request_->SetRequestContext(
171 g_browser_process->system_request_context()); 188 g_browser_process->system_request_context());
172 pending_seed_request_->SetMaxRetries(kMaxRetrySeedFetch); 189 pending_seed_request_->SetMaxRetries(kMaxRetrySeedFetch);
173 if (!variations_serial_number_.empty()) { 190 if (!variations_serial_number_.empty()) {
174 pending_seed_request_->AddExtraRequestHeader("If-Match:" + 191 pending_seed_request_->AddExtraRequestHeader("If-Match:" +
175 variations_serial_number_); 192 variations_serial_number_);
176 } 193 }
177 pending_seed_request_->Start(); 194 pending_seed_request_->Start();
178 } 195 }
179 196
180 void VariationsService::SetWasOfflineDuringLastRequestAttemptForTesting( 197 void VariationsService::SetWasOfflineDuringLastRequestAttemptForTesting(
181 bool offline) { 198 bool offline) {
182 was_offline_during_last_request_attempt_ = offline; 199 was_offline_during_last_request_attempt_ = offline;
183 } 200 }
184 201
202 #if defined(OS_CHROMEOS)
203 void VariationsService::OnScreenChanged(chromeos::WizardScreen* next_screen) {
204 }
205
206 void VariationsService::OnSessionStart() {
207 }
208
209 void VariationsService::OnEulaAccepted() {
210 // If an earlier request attempt was aborted because the EULA was not
211 // accepted, retry the request now.
212 if (!waiting_for_user_to_accept_eula_)
213 return;
214 DCHECK(chromeos::WizardController::IsEulaAccepted());
215 waiting_for_user_to_accept_eula_ = false;
216
217 DCHECK(chromeos::WizardController::default_controller());
218 chromeos::WizardController::default_controller()->RemoveObserver(this);
219
220 VLOG(1) << "Starting ping because the EULA was accepted.";
221 FetchVariationsSeed();
222
223 // Since FetchVariationsSeed was explicitly called here, reset the timer to
224 // avoid retrying for a full period.
225 if (timer_.IsRunning())
226 timer_.Reset();
227 }
228 #endif
229
185 // static 230 // static
186 void VariationsService::RegisterPrefs(PrefService* prefs) { 231 void VariationsService::RegisterPrefs(PrefService* prefs) {
187 prefs->RegisterStringPref(prefs::kVariationsSeed, std::string()); 232 prefs->RegisterStringPref(prefs::kVariationsSeed, std::string());
188 prefs->RegisterInt64Pref(prefs::kVariationsSeedDate, 233 prefs->RegisterInt64Pref(prefs::kVariationsSeedDate,
189 base::Time().ToInternalValue()); 234 base::Time().ToInternalValue());
190 } 235 }
191 236
192 void VariationsService::OnURLFetchComplete(const net::URLFetcher* source) { 237 void VariationsService::OnURLFetchComplete(const net::URLFetcher* source) {
193 DCHECK_EQ(pending_seed_request_.get(), source); 238 DCHECK_EQ(pending_seed_request_.get(), source);
194 // The fetcher will be deleted when the request is handled. 239 // 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); 540 variation_id);
496 } 541 }
497 } 542 }
498 543
499 trial->SetForced(); 544 trial->SetForced();
500 if (IsStudyExpired(study, reference_date)) 545 if (IsStudyExpired(study, reference_date))
501 trial->Disable(); 546 trial->Disable();
502 } 547 }
503 548
504 } // namespace chrome_variations 549 } // namespace chrome_variations
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698