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. |
245 variations::VariationsSeedProcessor().CreateTrialsFromSeed( | 247 variations::VariationsSeedProcessor().CreateTrialsFromSeed( |
246 seed, client_->GetApplicationLocale(), | 248 seed, client_->GetApplicationLocale(), |
247 GetReferenceDateForExpiryChecks(local_state_), current_version, channel, | 249 GetReferenceDateForExpiryChecks(local_state_), current_version, channel, |
248 GetCurrentFormFactor(), GetHardwareClass(), latest_country, | 250 GetCurrentFormFactor(), GetHardwareClass(), latest_country, |
249 LoadPermanentConsistencyCountry(current_version, latest_country), | 251 LoadPermanentConsistencyCountry(current_version, latest_country), |
250 base::Bind(&VariationsServiceClient::OverrideUIString, | 252 base::Bind(&UIStringOverrider::OverrideUIString, |
251 base::Unretained(client_.get()))); | 253 base::Unretained(&ui_string_overrider_))); |
Alexei Svitkine (slow)
2015/09/24 21:51:23
Can this pass a ref to the object instead of a cal
blundell
2015/09/25 13:06:56
//components/variations can't depend on //ui/base,
Alexei Svitkine (slow)
2015/09/25 14:45:56
Gotcha. Maybe worth mentioning that in the comment
sdefresne
2015/09/28 08:57:32
Acknowledged and added a comment.
| |
252 | 254 |
253 const base::Time now = base::Time::Now(); | 255 const base::Time now = base::Time::Now(); |
254 | 256 |
255 // Log the "freshness" of the seed that was just used. The freshness is the | 257 // Log the "freshness" of the seed that was just used. The freshness is the |
256 // time between the last successful seed download and now. | 258 // time between the last successful seed download and now. |
257 const int64 last_fetch_time_internal = | 259 const int64 last_fetch_time_internal = |
258 local_state_->GetInt64(prefs::kVariationsLastFetchTime); | 260 local_state_->GetInt64(prefs::kVariationsLastFetchTime); |
259 if (last_fetch_time_internal) { | 261 if (last_fetch_time_internal) { |
260 const base::TimeDelta delta = | 262 const base::TimeDelta delta = |
261 now - base::Time::FromInternalValue(last_fetch_time_internal); | 263 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. | 410 // it according to a value stored in the User Policy. |
409 registry->RegisterStringPref(prefs::kVariationsRestrictParameter, | 411 registry->RegisterStringPref(prefs::kVariationsRestrictParameter, |
410 std::string()); | 412 std::string()); |
411 } | 413 } |
412 | 414 |
413 // static | 415 // static |
414 scoped_ptr<VariationsService> VariationsService::Create( | 416 scoped_ptr<VariationsService> VariationsService::Create( |
415 scoped_ptr<VariationsServiceClient> client, | 417 scoped_ptr<VariationsServiceClient> client, |
416 PrefService* local_state, | 418 PrefService* local_state, |
417 metrics::MetricsStateManager* state_manager, | 419 metrics::MetricsStateManager* state_manager, |
418 const char* disable_network_switch) { | 420 const char* disable_network_switch, |
421 const UIStringOverrider& ui_string_overrider) { | |
419 scoped_ptr<VariationsService> result; | 422 scoped_ptr<VariationsService> result; |
420 #if !defined(GOOGLE_CHROME_BUILD) | 423 #if !defined(GOOGLE_CHROME_BUILD) |
421 // Unless the URL was provided, unsupported builds should return NULL to | 424 // Unless the URL was provided, unsupported builds should return NULL to |
422 // indicate that the service should not be used. | 425 // indicate that the service should not be used. |
423 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 426 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
424 switches::kVariationsServerURL)) { | 427 switches::kVariationsServerURL)) { |
425 DVLOG(1) << "Not creating VariationsService in unofficial build without --" | 428 DVLOG(1) << "Not creating VariationsService in unofficial build without --" |
426 << switches::kVariationsServerURL << " specified."; | 429 << switches::kVariationsServerURL << " specified."; |
427 return result.Pass(); | 430 return result.Pass(); |
428 } | 431 } |
429 #endif | 432 #endif |
430 result.reset(new VariationsService( | 433 result.reset(new VariationsService( |
431 client.Pass(), | 434 client.Pass(), |
432 make_scoped_ptr(new web_resource::ResourceRequestAllowedNotifier( | 435 make_scoped_ptr(new web_resource::ResourceRequestAllowedNotifier( |
433 local_state, disable_network_switch)), | 436 local_state, disable_network_switch)), |
434 local_state, state_manager)); | 437 local_state, state_manager, ui_string_overrider)); |
435 return result.Pass(); | 438 return result.Pass(); |
436 } | 439 } |
437 | 440 |
438 // static | 441 // static |
439 scoped_ptr<VariationsService> VariationsService::CreateForTesting( | 442 scoped_ptr<VariationsService> VariationsService::CreateForTesting( |
440 scoped_ptr<VariationsServiceClient> client, | 443 scoped_ptr<VariationsServiceClient> client, |
441 PrefService* local_state) { | 444 PrefService* local_state) { |
442 return make_scoped_ptr(new VariationsService( | 445 return make_scoped_ptr(new VariationsService( |
443 client.Pass(), | 446 client.Pass(), |
444 make_scoped_ptr(new web_resource::ResourceRequestAllowedNotifier( | 447 make_scoped_ptr(new web_resource::ResourceRequestAllowedNotifier( |
445 local_state, nullptr)), | 448 local_state, nullptr)), |
446 local_state, nullptr)); | 449 local_state, nullptr, UIStringOverrider())); |
447 } | 450 } |
448 | 451 |
449 void VariationsService::DoActualFetch() { | 452 void VariationsService::DoActualFetch() { |
450 DCHECK(thread_checker_.CalledOnValidThread()); | 453 DCHECK(thread_checker_.CalledOnValidThread()); |
451 DCHECK(!pending_seed_request_); | 454 DCHECK(!pending_seed_request_); |
452 | 455 |
453 pending_seed_request_ = net::URLFetcher::Create(0, variations_server_url_, | 456 pending_seed_request_ = net::URLFetcher::Create(0, variations_server_url_, |
454 net::URLFetcher::GET, this); | 457 net::URLFetcher::GET, this); |
455 data_use_measurement::DataUseUserData::AttachToFetcher( | 458 data_use_measurement::DataUseUserData::AttachToFetcher( |
456 pending_seed_request_.get(), | 459 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. | 758 // Otherwise, update the pref with the current Chrome version and country. |
756 base::ListValue new_list_value; | 759 base::ListValue new_list_value; |
757 new_list_value.AppendString(version.GetString()); | 760 new_list_value.AppendString(version.GetString()); |
758 new_list_value.AppendString(latest_country); | 761 new_list_value.AppendString(latest_country); |
759 local_state_->Set(prefs::kVariationsPermanentConsistencyCountry, | 762 local_state_->Set(prefs::kVariationsPermanentConsistencyCountry, |
760 new_list_value); | 763 new_list_value); |
761 return latest_country; | 764 return latest_country; |
762 } | 765 } |
763 | 766 |
764 } // namespace variations | 767 } // namespace variations |
OLD | NEW |