| 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 "components/variations/service/variations_service.h" | 5 #include "components/variations/service/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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 headers->EnumerateHeader(NULL, name, &value); | 196 headers->EnumerateHeader(NULL, name, &value); |
| 197 return value; | 197 return value; |
| 198 } | 198 } |
| 199 | 199 |
| 200 } // namespace | 200 } // namespace |
| 201 | 201 |
| 202 VariationsService::VariationsService( | 202 VariationsService::VariationsService( |
| 203 scoped_ptr<VariationsServiceClient> client, | 203 scoped_ptr<VariationsServiceClient> client, |
| 204 scoped_ptr<web_resource::ResourceRequestAllowedNotifier> notifier, | 204 scoped_ptr<web_resource::ResourceRequestAllowedNotifier> notifier, |
| 205 PrefService* local_state, | 205 PrefService* local_state, |
| 206 metrics::MetricsStateManager* state_manager) | 206 metrics::MetricsStateManager* state_manager, |
| 207 const UIStringOverrider& ui_string_overrider) |
| 207 : client_(client.Pass()), | 208 : client_(client.Pass()), |
| 209 ui_string_overrider_(ui_string_overrider), |
| 208 local_state_(local_state), | 210 local_state_(local_state), |
| 209 state_manager_(state_manager), | 211 state_manager_(state_manager), |
| 210 policy_pref_service_(local_state), | 212 policy_pref_service_(local_state), |
| 211 seed_store_(local_state), | 213 seed_store_(local_state), |
| 212 create_trials_from_seed_called_(false), | 214 create_trials_from_seed_called_(false), |
| 213 initial_request_completed_(false), | 215 initial_request_completed_(false), |
| 214 disable_deltas_for_next_request_(false), | 216 disable_deltas_for_next_request_(false), |
| 215 resource_request_allowed_notifier_(notifier.Pass()), | 217 resource_request_allowed_notifier_(notifier.Pass()), |
| 216 request_count_(0), | 218 request_count_(0), |
| 217 weak_ptr_factory_(this) { | 219 weak_ptr_factory_(this) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 233 const base::Version current_version(version_info::GetVersionNumber()); | 235 const base::Version current_version(version_info::GetVersionNumber()); |
| 234 if (!current_version.IsValid()) | 236 if (!current_version.IsValid()) |
| 235 return false; | 237 return false; |
| 236 | 238 |
| 237 variations::Study_Channel channel = | 239 variations::Study_Channel channel = |
| 238 GetChannelForVariations(client_->GetChannel()); | 240 GetChannelForVariations(client_->GetChannel()); |
| 239 UMA_HISTOGRAM_SPARSE_SLOWLY("Variations.UserChannel", channel); | 241 UMA_HISTOGRAM_SPARSE_SLOWLY("Variations.UserChannel", channel); |
| 240 | 242 |
| 241 const std::string latest_country = | 243 const std::string latest_country = |
| 242 local_state_->GetString(prefs::kVariationsCountry); | 244 local_state_->GetString(prefs::kVariationsCountry); |
| 243 // Note that passing |client_| via base::Unretained below is safe because | 245 // Note that passing |&ui_string_overrider_| via base::Unretained below is |
| 244 // the callback is executed synchronously. | 246 // safe because the callback is executed synchronously. It is not possible |
| 247 // to pass UIStringOverrider itself to VariationSeedProcesor as variations |
| 248 // components should not depends on //ui/base. |
| 245 variations::VariationsSeedProcessor().CreateTrialsFromSeed( | 249 variations::VariationsSeedProcessor().CreateTrialsFromSeed( |
| 246 seed, client_->GetApplicationLocale(), | 250 seed, client_->GetApplicationLocale(), |
| 247 GetReferenceDateForExpiryChecks(local_state_), current_version, channel, | 251 GetReferenceDateForExpiryChecks(local_state_), current_version, channel, |
| 248 GetCurrentFormFactor(), GetHardwareClass(), latest_country, | 252 GetCurrentFormFactor(), GetHardwareClass(), latest_country, |
| 249 LoadPermanentConsistencyCountry(current_version, latest_country), | 253 LoadPermanentConsistencyCountry(current_version, latest_country), |
| 250 base::Bind(&VariationsServiceClient::OverrideUIString, | 254 base::Bind(&UIStringOverrider::OverrideUIString, |
| 251 base::Unretained(client_.get()))); | 255 base::Unretained(&ui_string_overrider_))); |
| 252 | 256 |
| 253 const base::Time now = base::Time::Now(); | 257 const base::Time now = base::Time::Now(); |
| 254 | 258 |
| 255 // Log the "freshness" of the seed that was just used. The freshness is the | 259 // Log the "freshness" of the seed that was just used. The freshness is the |
| 256 // time between the last successful seed download and now. | 260 // time between the last successful seed download and now. |
| 257 const int64 last_fetch_time_internal = | 261 const int64 last_fetch_time_internal = |
| 258 local_state_->GetInt64(prefs::kVariationsLastFetchTime); | 262 local_state_->GetInt64(prefs::kVariationsLastFetchTime); |
| 259 if (last_fetch_time_internal) { | 263 if (last_fetch_time_internal) { |
| 260 const base::TimeDelta delta = | 264 const base::TimeDelta delta = |
| 261 now - base::Time::FromInternalValue(last_fetch_time_internal); | 265 now - base::Time::FromInternalValue(last_fetch_time_internal); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 // it according to a value stored in the User Policy. | 412 // it according to a value stored in the User Policy. |
| 409 registry->RegisterStringPref(prefs::kVariationsRestrictParameter, | 413 registry->RegisterStringPref(prefs::kVariationsRestrictParameter, |
| 410 std::string()); | 414 std::string()); |
| 411 } | 415 } |
| 412 | 416 |
| 413 // static | 417 // static |
| 414 scoped_ptr<VariationsService> VariationsService::Create( | 418 scoped_ptr<VariationsService> VariationsService::Create( |
| 415 scoped_ptr<VariationsServiceClient> client, | 419 scoped_ptr<VariationsServiceClient> client, |
| 416 PrefService* local_state, | 420 PrefService* local_state, |
| 417 metrics::MetricsStateManager* state_manager, | 421 metrics::MetricsStateManager* state_manager, |
| 418 const char* disable_network_switch) { | 422 const char* disable_network_switch, |
| 423 const UIStringOverrider& ui_string_overrider) { |
| 419 scoped_ptr<VariationsService> result; | 424 scoped_ptr<VariationsService> result; |
| 420 #if !defined(GOOGLE_CHROME_BUILD) | 425 #if !defined(GOOGLE_CHROME_BUILD) |
| 421 // Unless the URL was provided, unsupported builds should return NULL to | 426 // Unless the URL was provided, unsupported builds should return NULL to |
| 422 // indicate that the service should not be used. | 427 // indicate that the service should not be used. |
| 423 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 428 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 424 switches::kVariationsServerURL)) { | 429 switches::kVariationsServerURL)) { |
| 425 DVLOG(1) << "Not creating VariationsService in unofficial build without --" | 430 DVLOG(1) << "Not creating VariationsService in unofficial build without --" |
| 426 << switches::kVariationsServerURL << " specified."; | 431 << switches::kVariationsServerURL << " specified."; |
| 427 return result.Pass(); | 432 return result.Pass(); |
| 428 } | 433 } |
| 429 #endif | 434 #endif |
| 430 result.reset(new VariationsService( | 435 result.reset(new VariationsService( |
| 431 client.Pass(), | 436 client.Pass(), |
| 432 make_scoped_ptr(new web_resource::ResourceRequestAllowedNotifier( | 437 make_scoped_ptr(new web_resource::ResourceRequestAllowedNotifier( |
| 433 local_state, disable_network_switch)), | 438 local_state, disable_network_switch)), |
| 434 local_state, state_manager)); | 439 local_state, state_manager, ui_string_overrider)); |
| 435 return result.Pass(); | 440 return result.Pass(); |
| 436 } | 441 } |
| 437 | 442 |
| 438 // static | 443 // static |
| 439 scoped_ptr<VariationsService> VariationsService::CreateForTesting( | 444 scoped_ptr<VariationsService> VariationsService::CreateForTesting( |
| 440 scoped_ptr<VariationsServiceClient> client, | 445 scoped_ptr<VariationsServiceClient> client, |
| 441 PrefService* local_state) { | 446 PrefService* local_state) { |
| 442 return make_scoped_ptr(new VariationsService( | 447 return make_scoped_ptr(new VariationsService( |
| 443 client.Pass(), | 448 client.Pass(), |
| 444 make_scoped_ptr(new web_resource::ResourceRequestAllowedNotifier( | 449 make_scoped_ptr(new web_resource::ResourceRequestAllowedNotifier( |
| 445 local_state, nullptr)), | 450 local_state, nullptr)), |
| 446 local_state, nullptr)); | 451 local_state, nullptr, UIStringOverrider())); |
| 447 } | 452 } |
| 448 | 453 |
| 449 void VariationsService::DoActualFetch() { | 454 void VariationsService::DoActualFetch() { |
| 450 DCHECK(thread_checker_.CalledOnValidThread()); | 455 DCHECK(thread_checker_.CalledOnValidThread()); |
| 451 DCHECK(!pending_seed_request_); | 456 DCHECK(!pending_seed_request_); |
| 452 | 457 |
| 453 pending_seed_request_ = net::URLFetcher::Create(0, variations_server_url_, | 458 pending_seed_request_ = net::URLFetcher::Create(0, variations_server_url_, |
| 454 net::URLFetcher::GET, this); | 459 net::URLFetcher::GET, this); |
| 455 data_use_measurement::DataUseUserData::AttachToFetcher( | 460 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 456 pending_seed_request_.get(), | 461 pending_seed_request_.get(), |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 // Otherwise, update the pref with the current Chrome version and country. | 760 // Otherwise, update the pref with the current Chrome version and country. |
| 756 base::ListValue new_list_value; | 761 base::ListValue new_list_value; |
| 757 new_list_value.AppendString(version.GetString()); | 762 new_list_value.AppendString(version.GetString()); |
| 758 new_list_value.AppendString(latest_country); | 763 new_list_value.AppendString(latest_country); |
| 759 local_state_->Set(prefs::kVariationsPermanentConsistencyCountry, | 764 local_state_->Set(prefs::kVariationsPermanentConsistencyCountry, |
| 760 new_list_value); | 765 new_list_value); |
| 761 return latest_country; | 766 return latest_country; |
| 762 } | 767 } |
| 763 | 768 |
| 764 } // namespace variations | 769 } // namespace variations |
| OLD | NEW |