| 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 web_resource::ResourceRequestAllowedNotifier* notifier, | 213 scoped_ptr<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), | 224 resource_request_allowed_notifier_(notifier.Pass()), |
| 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 | |
| 369 GURL VariationsService::GetVariationsServerURL( | 368 GURL VariationsService::GetVariationsServerURL( |
| 370 PrefService* policy_pref_service, | 369 PrefService* policy_pref_service, |
| 371 const std::string& restrict_mode_override) { | 370 const std::string& restrict_mode_override) { |
| 372 std::string server_url_string( | 371 std::string server_url_string( |
| 373 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 372 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 374 switches::kVariationsServerURL)); | 373 switches::kVariationsServerURL)); |
| 375 if (server_url_string.empty()) | 374 if (server_url_string.empty()) |
| 376 server_url_string = kDefaultServerUrl; | 375 server_url_string = kDefaultServerUrl; |
| 377 GURL server_url = GURL(server_url_string); | 376 GURL server_url = GURL(server_url_string); |
| 378 | 377 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 // Unless the URL was provided, unsupported builds should return NULL to | 428 // Unless the URL was provided, unsupported builds should return NULL to |
| 430 // indicate that the service should not be used. | 429 // indicate that the service should not be used. |
| 431 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 430 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 432 switches::kVariationsServerURL)) { | 431 switches::kVariationsServerURL)) { |
| 433 DVLOG(1) << "Not creating VariationsService in unofficial build without --" | 432 DVLOG(1) << "Not creating VariationsService in unofficial build without --" |
| 434 << switches::kVariationsServerURL << " specified."; | 433 << switches::kVariationsServerURL << " specified."; |
| 435 return result.Pass(); | 434 return result.Pass(); |
| 436 } | 435 } |
| 437 #endif | 436 #endif |
| 438 result.reset(new VariationsService( | 437 result.reset(new VariationsService( |
| 439 client.Pass(), new web_resource::ResourceRequestAllowedNotifier( | 438 client.Pass(), |
| 440 local_state, disable_network_switch), | 439 make_scoped_ptr(new web_resource::ResourceRequestAllowedNotifier( |
| 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 |
| 445 void VariationsService::DoActualFetch() { | 452 void VariationsService::DoActualFetch() { |
| 446 DCHECK(thread_checker_.CalledOnValidThread()); | 453 DCHECK(thread_checker_.CalledOnValidThread()); |
| 447 DCHECK(!pending_seed_request_); | 454 DCHECK(!pending_seed_request_); |
| 448 | 455 |
| 449 pending_seed_request_ = net::URLFetcher::Create(0, variations_server_url_, | 456 pending_seed_request_ = net::URLFetcher::Create(0, variations_server_url_, |
| 450 net::URLFetcher::GET, this); | 457 net::URLFetcher::GET, this); |
| 451 pending_seed_request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 458 pending_seed_request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 452 net::LOAD_DO_NOT_SAVE_COOKIES); | 459 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 453 pending_seed_request_->SetRequestContext(client_->GetURLRequestContext()); | 460 pending_seed_request_->SetRequestContext(client_->GetURLRequestContext()); |
| 454 pending_seed_request_->SetMaxRetriesOn5xx(kMaxRetrySeedFetch); | 461 pending_seed_request_->SetMaxRetriesOn5xx(kMaxRetrySeedFetch); |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 // Otherwise, update the pref with the current Chrome version and country. | 755 // Otherwise, update the pref with the current Chrome version and country. |
| 749 base::ListValue new_list_value; | 756 base::ListValue new_list_value; |
| 750 new_list_value.AppendString(version.GetString()); | 757 new_list_value.AppendString(version.GetString()); |
| 751 new_list_value.AppendString(latest_country); | 758 new_list_value.AppendString(latest_country); |
| 752 local_state_->Set(prefs::kVariationsPermanentConsistencyCountry, | 759 local_state_->Set(prefs::kVariationsPermanentConsistencyCountry, |
| 753 new_list_value); | 760 new_list_value); |
| 754 return latest_country; | 761 return latest_country; |
| 755 } | 762 } |
| 756 | 763 |
| 757 } // namespace chrome_variations | 764 } // namespace chrome_variations |
| OLD | NEW |