| OLD | NEW |
| 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 "base/build_time.h" | 7 #include "base/build_time.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/metrics/sparse_histogram.h" | 10 #include "base/metrics/sparse_histogram.h" |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 const base::StringPiece& name) { | 203 const base::StringPiece& name) { |
| 204 std::string value; | 204 std::string value; |
| 205 headers->EnumerateHeader(NULL, name, &value); | 205 headers->EnumerateHeader(NULL, name, &value); |
| 206 return value; | 206 return value; |
| 207 } | 207 } |
| 208 | 208 |
| 209 } // namespace | 209 } // namespace |
| 210 | 210 |
| 211 VariationsService::VariationsService( | 211 VariationsService::VariationsService( |
| 212 scoped_ptr<VariationsServiceClient> client, | 212 scoped_ptr<VariationsServiceClient> client, |
| 213 scoped_ptr<web_resource::ResourceRequestAllowedNotifier> notifier, | 213 web_resource::ResourceRequestAllowedNotifier* notifier, |
| 214 PrefService* local_state, | 214 PrefService* local_state, |
| 215 metrics::MetricsStateManager* state_manager) | 215 metrics::MetricsStateManager* state_manager) |
| 216 : client_(client.Pass()), | 216 : client_(client.Pass()), |
| 217 local_state_(local_state), | 217 local_state_(local_state), |
| 218 state_manager_(state_manager), | 218 state_manager_(state_manager), |
| 219 policy_pref_service_(local_state), | 219 policy_pref_service_(local_state), |
| 220 seed_store_(local_state), | 220 seed_store_(local_state), |
| 221 create_trials_from_seed_called_(false), | 221 create_trials_from_seed_called_(false), |
| 222 initial_request_completed_(false), | 222 initial_request_completed_(false), |
| 223 disable_deltas_for_next_request_(false), | 223 disable_deltas_for_next_request_(false), |
| 224 resource_request_allowed_notifier_(notifier.Pass()), | 224 resource_request_allowed_notifier_(notifier), |
| 225 request_count_(0), | 225 request_count_(0), |
| 226 weak_ptr_factory_(this) { | 226 weak_ptr_factory_(this) { |
| 227 resource_request_allowed_notifier_->Init(this); | 227 resource_request_allowed_notifier_->Init(this); |
| 228 } | 228 } |
| 229 | 229 |
| 230 VariationsService::~VariationsService() { | 230 VariationsService::~VariationsService() { |
| 231 } | 231 } |
| 232 | 232 |
| 233 bool VariationsService::CreateTrialsFromSeed() { | 233 bool VariationsService::CreateTrialsFromSeed() { |
| 234 DCHECK(thread_checker_.CalledOnValidThread()); | 234 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 // This should be called before the server URL has been computed. | 358 // This should be called before the server URL has been computed. |
| 359 DCHECK(variations_server_url_.is_empty()); | 359 DCHECK(variations_server_url_.is_empty()); |
| 360 restrict_mode_ = restrict_mode; | 360 restrict_mode_ = restrict_mode; |
| 361 } | 361 } |
| 362 | 362 |
| 363 void VariationsService::SetCreateTrialsFromSeedCalledForTesting(bool called) { | 363 void VariationsService::SetCreateTrialsFromSeedCalledForTesting(bool called) { |
| 364 DCHECK(thread_checker_.CalledOnValidThread()); | 364 DCHECK(thread_checker_.CalledOnValidThread()); |
| 365 create_trials_from_seed_called_ = called; | 365 create_trials_from_seed_called_ = called; |
| 366 } | 366 } |
| 367 | 367 |
| 368 // static |
| 368 GURL VariationsService::GetVariationsServerURL( | 369 GURL VariationsService::GetVariationsServerURL( |
| 369 PrefService* policy_pref_service, | 370 PrefService* policy_pref_service, |
| 370 const std::string& restrict_mode_override) { | 371 const std::string& restrict_mode_override) { |
| 371 std::string server_url_string( | 372 std::string server_url_string( |
| 372 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 373 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 373 switches::kVariationsServerURL)); | 374 switches::kVariationsServerURL)); |
| 374 if (server_url_string.empty()) | 375 if (server_url_string.empty()) |
| 375 server_url_string = kDefaultServerUrl; | 376 server_url_string = kDefaultServerUrl; |
| 376 GURL server_url = GURL(server_url_string); | 377 GURL server_url = GURL(server_url_string); |
| 377 | 378 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 // Unless the URL was provided, unsupported builds should return NULL to | 429 // Unless the URL was provided, unsupported builds should return NULL to |
| 429 // indicate that the service should not be used. | 430 // indicate that the service should not be used. |
| 430 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 431 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 431 switches::kVariationsServerURL)) { | 432 switches::kVariationsServerURL)) { |
| 432 DVLOG(1) << "Not creating VariationsService in unofficial build without --" | 433 DVLOG(1) << "Not creating VariationsService in unofficial build without --" |
| 433 << switches::kVariationsServerURL << " specified."; | 434 << switches::kVariationsServerURL << " specified."; |
| 434 return result.Pass(); | 435 return result.Pass(); |
| 435 } | 436 } |
| 436 #endif | 437 #endif |
| 437 result.reset(new VariationsService( | 438 result.reset(new VariationsService( |
| 438 client.Pass(), | 439 client.Pass(), new web_resource::ResourceRequestAllowedNotifier( |
| 439 make_scoped_ptr(new web_resource::ResourceRequestAllowedNotifier( | 440 local_state, disable_network_switch), |
| 440 local_state, disable_network_switch)), | |
| 441 local_state, state_manager)); | 441 local_state, state_manager)); |
| 442 return result.Pass(); | 442 return result.Pass(); |
| 443 } | 443 } |
| 444 | 444 |
| 445 // static | |
| 446 scoped_ptr<VariationsService> VariationsService::CreateForTesting( | |
| 447 scoped_ptr<VariationsServiceClient> client, | |
| 448 PrefService* local_state) { | |
| 449 return Create(client.Pass(), local_state, nullptr, nullptr); | |
| 450 } | |
| 451 | |
| 452 void VariationsService::DoActualFetch() { | 445 void VariationsService::DoActualFetch() { |
| 453 DCHECK(thread_checker_.CalledOnValidThread()); | 446 DCHECK(thread_checker_.CalledOnValidThread()); |
| 454 DCHECK(!pending_seed_request_); | 447 DCHECK(!pending_seed_request_); |
| 455 | 448 |
| 456 pending_seed_request_ = net::URLFetcher::Create(0, variations_server_url_, | 449 pending_seed_request_ = net::URLFetcher::Create(0, variations_server_url_, |
| 457 net::URLFetcher::GET, this); | 450 net::URLFetcher::GET, this); |
| 458 pending_seed_request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 451 pending_seed_request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 459 net::LOAD_DO_NOT_SAVE_COOKIES); | 452 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 460 pending_seed_request_->SetRequestContext(client_->GetURLRequestContext()); | 453 pending_seed_request_->SetRequestContext(client_->GetURLRequestContext()); |
| 461 pending_seed_request_->SetMaxRetriesOn5xx(kMaxRetrySeedFetch); | 454 pending_seed_request_->SetMaxRetriesOn5xx(kMaxRetrySeedFetch); |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 // Otherwise, update the pref with the current Chrome version and country. | 748 // Otherwise, update the pref with the current Chrome version and country. |
| 756 base::ListValue new_list_value; | 749 base::ListValue new_list_value; |
| 757 new_list_value.AppendString(version.GetString()); | 750 new_list_value.AppendString(version.GetString()); |
| 758 new_list_value.AppendString(latest_country); | 751 new_list_value.AppendString(latest_country); |
| 759 local_state_->Set(prefs::kVariationsPermanentConsistencyCountry, | 752 local_state_->Set(prefs::kVariationsPermanentConsistencyCountry, |
| 760 new_list_value); | 753 new_list_value); |
| 761 return latest_country; | 754 return latest_country; |
| 762 } | 755 } |
| 763 | 756 |
| 764 } // namespace chrome_variations | 757 } // namespace chrome_variations |
| OLD | NEW |