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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 if (resource_id == -1) | 236 if (resource_id == -1) |
237 return; | 237 return; |
238 | 238 |
239 ui::ResourceBundle::GetSharedInstance().OverrideLocaleStringResource( | 239 ui::ResourceBundle::GetSharedInstance().OverrideLocaleStringResource( |
240 resource_id, string); | 240 resource_id, string); |
241 } | 241 } |
242 | 242 |
243 } // namespace | 243 } // namespace |
244 | 244 |
245 VariationsService::VariationsService( | 245 VariationsService::VariationsService( |
| 246 scoped_ptr<VariationsServiceClient> client, |
246 web_resource::ResourceRequestAllowedNotifier* notifier, | 247 web_resource::ResourceRequestAllowedNotifier* notifier, |
247 PrefService* local_state, | 248 PrefService* local_state, |
248 metrics::MetricsStateManager* state_manager) | 249 metrics::MetricsStateManager* state_manager) |
249 : local_state_(local_state), | 250 : client_(client.Pass()), |
| 251 local_state_(local_state), |
250 state_manager_(state_manager), | 252 state_manager_(state_manager), |
251 policy_pref_service_(local_state), | 253 policy_pref_service_(local_state), |
252 seed_store_(local_state), | 254 seed_store_(local_state), |
253 create_trials_from_seed_called_(false), | 255 create_trials_from_seed_called_(false), |
254 initial_request_completed_(false), | 256 initial_request_completed_(false), |
255 disable_deltas_for_next_request_(false), | 257 disable_deltas_for_next_request_(false), |
256 resource_request_allowed_notifier_(notifier), | 258 resource_request_allowed_notifier_(notifier), |
257 request_count_(0), | 259 request_count_(0), |
258 weak_ptr_factory_(this) { | 260 weak_ptr_factory_(this) { |
259 resource_request_allowed_notifier_->Init(this); | 261 resource_request_allowed_notifier_->Init(this); |
(...skipping 14 matching lines...) Expand all Loading... |
274 const base::Version current_version(version_info::GetVersionNumber()); | 276 const base::Version current_version(version_info::GetVersionNumber()); |
275 if (!current_version.IsValid()) | 277 if (!current_version.IsValid()) |
276 return false; | 278 return false; |
277 | 279 |
278 variations::Study_Channel channel = GetChannelForVariations(); | 280 variations::Study_Channel channel = GetChannelForVariations(); |
279 UMA_HISTOGRAM_SPARSE_SLOWLY("Variations.UserChannel", channel); | 281 UMA_HISTOGRAM_SPARSE_SLOWLY("Variations.UserChannel", channel); |
280 | 282 |
281 const std::string latest_country = | 283 const std::string latest_country = |
282 local_state_->GetString(prefs::kVariationsCountry); | 284 local_state_->GetString(prefs::kVariationsCountry); |
283 variations::VariationsSeedProcessor().CreateTrialsFromSeed( | 285 variations::VariationsSeedProcessor().CreateTrialsFromSeed( |
284 seed, g_browser_process->GetApplicationLocale(), | 286 seed, client_->GetApplicationLocale(), |
285 GetReferenceDateForExpiryChecks(local_state_), current_version, channel, | 287 GetReferenceDateForExpiryChecks(local_state_), current_version, channel, |
286 GetCurrentFormFactor(), GetHardwareClass(), latest_country, | 288 GetCurrentFormFactor(), GetHardwareClass(), latest_country, |
287 LoadPermanentConsistencyCountry(current_version, latest_country), | 289 LoadPermanentConsistencyCountry(current_version, latest_country), |
288 base::Bind(&OverrideUIString)); | 290 base::Bind(&OverrideUIString)); |
289 | 291 |
290 const base::Time now = base::Time::Now(); | 292 const base::Time now = base::Time::Now(); |
291 | 293 |
292 // Log the "freshness" of the seed that was just used. The freshness is the | 294 // Log the "freshness" of the seed that was just used. The freshness is the |
293 // time between the last successful seed download and now. | 295 // time between the last successful seed download and now. |
294 const int64 last_fetch_time_internal = | 296 const int64 last_fetch_time_internal = |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 void VariationsService::RegisterProfilePrefs( | 443 void VariationsService::RegisterProfilePrefs( |
442 user_prefs::PrefRegistrySyncable* registry) { | 444 user_prefs::PrefRegistrySyncable* registry) { |
443 // This preference will only be written by the policy service, which will fill | 445 // This preference will only be written by the policy service, which will fill |
444 // it according to a value stored in the User Policy. | 446 // it according to a value stored in the User Policy. |
445 registry->RegisterStringPref(prefs::kVariationsRestrictParameter, | 447 registry->RegisterStringPref(prefs::kVariationsRestrictParameter, |
446 std::string()); | 448 std::string()); |
447 } | 449 } |
448 | 450 |
449 // static | 451 // static |
450 scoped_ptr<VariationsService> VariationsService::Create( | 452 scoped_ptr<VariationsService> VariationsService::Create( |
| 453 scoped_ptr<VariationsServiceClient> client, |
451 PrefService* local_state, | 454 PrefService* local_state, |
452 metrics::MetricsStateManager* state_manager) { | 455 metrics::MetricsStateManager* state_manager) { |
453 scoped_ptr<VariationsService> result; | 456 scoped_ptr<VariationsService> result; |
454 #if !defined(GOOGLE_CHROME_BUILD) | 457 #if !defined(GOOGLE_CHROME_BUILD) |
455 // Unless the URL was provided, unsupported builds should return NULL to | 458 // Unless the URL was provided, unsupported builds should return NULL to |
456 // indicate that the service should not be used. | 459 // indicate that the service should not be used. |
457 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 460 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
458 switches::kVariationsServerURL)) { | 461 switches::kVariationsServerURL)) { |
459 DVLOG(1) << "Not creating VariationsService in unofficial build without --" | 462 DVLOG(1) << "Not creating VariationsService in unofficial build without --" |
460 << switches::kVariationsServerURL << " specified."; | 463 << switches::kVariationsServerURL << " specified."; |
461 return result.Pass(); | 464 return result.Pass(); |
462 } | 465 } |
463 #endif | 466 #endif |
464 result.reset(new VariationsService( | 467 result.reset(new VariationsService( |
465 new web_resource::ResourceRequestAllowedNotifier( | 468 client.Pass(), new web_resource::ResourceRequestAllowedNotifier( |
466 local_state, switches::kDisableBackgroundNetworking), | 469 local_state, switches::kDisableBackgroundNetworking), |
467 local_state, state_manager)); | 470 local_state, state_manager)); |
468 return result.Pass(); | 471 return result.Pass(); |
469 } | 472 } |
470 | 473 |
471 void VariationsService::DoActualFetch() { | 474 void VariationsService::DoActualFetch() { |
472 DCHECK(thread_checker_.CalledOnValidThread()); | 475 DCHECK(thread_checker_.CalledOnValidThread()); |
473 DCHECK(!pending_seed_request_); | 476 DCHECK(!pending_seed_request_); |
474 | 477 |
475 pending_seed_request_ = net::URLFetcher::Create(0, variations_server_url_, | 478 pending_seed_request_ = net::URLFetcher::Create(0, variations_server_url_, |
476 net::URLFetcher::GET, this); | 479 net::URLFetcher::GET, this); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 const base::ElapsedTimer timer; | 674 const base::ElapsedTimer timer; |
672 | 675 |
673 scoped_ptr<const base::FieldTrial::EntropyProvider> entropy_provider = | 676 scoped_ptr<const base::FieldTrial::EntropyProvider> entropy_provider = |
674 state_manager_->CreateEntropyProvider(); | 677 state_manager_->CreateEntropyProvider(); |
675 variations::VariationsSeedSimulator seed_simulator(*entropy_provider); | 678 variations::VariationsSeedSimulator seed_simulator(*entropy_provider); |
676 | 679 |
677 const std::string latest_country = | 680 const std::string latest_country = |
678 local_state_->GetString(prefs::kVariationsCountry); | 681 local_state_->GetString(prefs::kVariationsCountry); |
679 const variations::VariationsSeedSimulator::Result result = | 682 const variations::VariationsSeedSimulator::Result result = |
680 seed_simulator.SimulateSeedStudies( | 683 seed_simulator.SimulateSeedStudies( |
681 *seed, g_browser_process->GetApplicationLocale(), | 684 *seed, client_->GetApplicationLocale(), |
682 GetReferenceDateForExpiryChecks(local_state_), version, | 685 GetReferenceDateForExpiryChecks(local_state_), version, |
683 GetChannelForVariations(), GetCurrentFormFactor(), GetHardwareClass(), | 686 GetChannelForVariations(), GetCurrentFormFactor(), GetHardwareClass(), |
684 latest_country, | 687 latest_country, |
685 LoadPermanentConsistencyCountry(version, latest_country)); | 688 LoadPermanentConsistencyCountry(version, latest_country)); |
686 | 689 |
687 UMA_HISTOGRAM_COUNTS_100("Variations.SimulateSeed.NormalChanges", | 690 UMA_HISTOGRAM_COUNTS_100("Variations.SimulateSeed.NormalChanges", |
688 result.normal_group_change_count); | 691 result.normal_group_change_count); |
689 UMA_HISTOGRAM_COUNTS_100("Variations.SimulateSeed.KillBestEffortChanges", | 692 UMA_HISTOGRAM_COUNTS_100("Variations.SimulateSeed.KillBestEffortChanges", |
690 result.kill_best_effort_group_change_count); | 693 result.kill_best_effort_group_change_count); |
691 UMA_HISTOGRAM_COUNTS_100("Variations.SimulateSeed.KillCriticalChanges", | 694 UMA_HISTOGRAM_COUNTS_100("Variations.SimulateSeed.KillCriticalChanges", |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 // Otherwise, update the pref with the current Chrome version and country. | 780 // Otherwise, update the pref with the current Chrome version and country. |
778 base::ListValue new_list_value; | 781 base::ListValue new_list_value; |
779 new_list_value.AppendString(version.GetString()); | 782 new_list_value.AppendString(version.GetString()); |
780 new_list_value.AppendString(latest_country); | 783 new_list_value.AppendString(latest_country); |
781 local_state_->Set(prefs::kVariationsPermanentConsistencyCountry, | 784 local_state_->Set(prefs::kVariationsPermanentConsistencyCountry, |
782 new_list_value); | 785 new_list_value); |
783 return latest_country; | 786 return latest_country; |
784 } | 787 } |
785 | 788 |
786 } // namespace chrome_variations | 789 } // namespace chrome_variations |
OLD | NEW |