Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / metrics / variations / variations_service.cc
bloba359f5c10f497ff47a53f68f42472e305e4b6d87
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
3 // found in the LICENSE file.
5 #include "chrome/browser/metrics/variations/variations_service.h"
7 #include <set>
9 #include "base/build_time.h"
10 #include "base/command_line.h"
11 #include "base/metrics/histogram.h"
12 #include "base/metrics/sparse_histogram.h"
13 #include "base/prefs/pref_registry_simple.h"
14 #include "base/prefs/pref_service.h"
15 #include "base/sys_info.h"
16 #include "base/task_runner_util.h"
17 #include "base/timer/elapsed_timer.h"
18 #include "base/version.h"
19 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/metrics/variations/generated_resources_map.h"
21 #include "chrome/common/chrome_switches.h"
22 #include "chrome/common/pref_names.h"
23 #include "components/metrics/metrics_state_manager.h"
24 #include "components/network_time/network_time_tracker.h"
25 #include "components/pref_registry/pref_registry_syncable.h"
26 #include "components/variations/proto/variations_seed.pb.h"
27 #include "components/variations/variations_seed_processor.h"
28 #include "components/variations/variations_seed_simulator.h"
29 #include "content/public/browser/browser_thread.h"
30 #include "net/base/load_flags.h"
31 #include "net/base/net_errors.h"
32 #include "net/base/network_change_notifier.h"
33 #include "net/base/url_util.h"
34 #include "net/http/http_response_headers.h"
35 #include "net/http/http_status_code.h"
36 #include "net/http/http_util.h"
37 #include "net/url_request/url_fetcher.h"
38 #include "net/url_request/url_request_status.h"
39 #include "ui/base/device_form_factor.h"
40 #include "ui/base/resource/resource_bundle.h"
41 #include "url/gurl.h"
43 #if !defined(OS_ANDROID) && !defined(OS_IOS) && !defined(OS_CHROMEOS)
44 #include "chrome/browser/upgrade_detector_impl.h"
45 #endif
47 #if defined(OS_CHROMEOS)
48 #include "chrome/browser/chromeos/settings/cros_settings.h"
49 #endif
51 namespace chrome_variations {
53 namespace {
55 // Default server of Variations seed info.
56 const char kDefaultVariationsServerURL[] =
57 "https://clients4.google.com/chrome-variations/seed";
58 const int kMaxRetrySeedFetch = 5;
60 // TODO(mad): To be removed when we stop updating the NetworkTimeTracker.
61 // For the HTTP date headers, the resolution of the server time is 1 second.
62 const int64 kServerTimeResolutionMs = 1000;
64 // Wrapper around channel checking, used to enable channel mocking for
65 // testing. If the current browser channel is not UNKNOWN, this will return
66 // that channel value. Otherwise, if the fake channel flag is provided, this
67 // will return the fake channel. Failing that, this will return the UNKNOWN
68 // channel.
69 variations::Study_Channel GetChannelForVariations() {
70 switch (chrome::VersionInfo::GetChannel()) {
71 case chrome::VersionInfo::CHANNEL_CANARY:
72 return variations::Study_Channel_CANARY;
73 case chrome::VersionInfo::CHANNEL_DEV:
74 return variations::Study_Channel_DEV;
75 case chrome::VersionInfo::CHANNEL_BETA:
76 return variations::Study_Channel_BETA;
77 case chrome::VersionInfo::CHANNEL_STABLE:
78 return variations::Study_Channel_STABLE;
79 case chrome::VersionInfo::CHANNEL_UNKNOWN:
80 break;
82 const std::string forced_channel =
83 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
84 switches::kFakeVariationsChannel);
85 if (forced_channel == "stable")
86 return variations::Study_Channel_STABLE;
87 if (forced_channel == "beta")
88 return variations::Study_Channel_BETA;
89 if (forced_channel == "dev")
90 return variations::Study_Channel_DEV;
91 if (forced_channel == "canary")
92 return variations::Study_Channel_CANARY;
93 DVLOG(1) << "Invalid channel provided: " << forced_channel;
94 return variations::Study_Channel_UNKNOWN;
97 // Returns a string that will be used for the value of the 'osname' URL param
98 // to the variations server.
99 std::string GetPlatformString() {
100 #if defined(OS_WIN)
101 return "win";
102 #elif defined(OS_IOS)
103 return "ios";
104 #elif defined(OS_MACOSX)
105 return "mac";
106 #elif defined(OS_CHROMEOS)
107 return "chromeos";
108 #elif defined(OS_ANDROID)
109 return "android";
110 #elif defined(OS_LINUX) || defined(OS_BSD) || defined(OS_SOLARIS)
111 // Default BSD and SOLARIS to Linux to not break those builds, although these
112 // platforms are not officially supported by Chrome.
113 return "linux";
114 #else
115 #error Unknown platform
116 #endif
119 // Gets the version number to use for variations seed simulation. Must be called
120 // on a thread where IO is allowed.
121 base::Version GetVersionForSimulation() {
122 #if !defined(OS_ANDROID) && !defined(OS_IOS) && !defined(OS_CHROMEOS)
123 const base::Version installed_version =
124 UpgradeDetectorImpl::GetCurrentlyInstalledVersion();
125 if (installed_version.IsValid())
126 return installed_version;
127 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) && !defined(OS_CHROMEOS)
129 // TODO(asvitkine): Get the version that will be used on restart instead of
130 // the current version on Android, iOS and ChromeOS.
131 return base::Version(chrome::VersionInfo().Version());
134 // Gets the restrict parameter from |policy_pref_service| or from Chrome OS
135 // settings in the case of that platform.
136 std::string GetRestrictParameterPref(PrefService* policy_pref_service) {
137 std::string parameter;
138 #if defined(OS_CHROMEOS)
139 chromeos::CrosSettings::Get()->GetString(
140 chromeos::kVariationsRestrictParameter, &parameter);
141 #else
142 if (policy_pref_service) {
143 parameter =
144 policy_pref_service->GetString(prefs::kVariationsRestrictParameter);
146 #endif
147 return parameter;
150 enum ResourceRequestsAllowedState {
151 RESOURCE_REQUESTS_ALLOWED,
152 RESOURCE_REQUESTS_NOT_ALLOWED,
153 RESOURCE_REQUESTS_ALLOWED_NOTIFIED,
154 RESOURCE_REQUESTS_NOT_ALLOWED_EULA_NOT_ACCEPTED,
155 RESOURCE_REQUESTS_NOT_ALLOWED_NETWORK_DOWN,
156 RESOURCE_REQUESTS_NOT_ALLOWED_COMMAND_LINE_DISABLED,
157 RESOURCE_REQUESTS_ALLOWED_ENUM_SIZE,
160 // Records UMA histogram with the current resource requests allowed state.
161 void RecordRequestsAllowedHistogram(ResourceRequestsAllowedState state) {
162 UMA_HISTOGRAM_ENUMERATION("Variations.ResourceRequestsAllowed", state,
163 RESOURCE_REQUESTS_ALLOWED_ENUM_SIZE);
166 // Converts ResourceRequestAllowedNotifier::State to the corresponding
167 // ResourceRequestsAllowedState value.
168 ResourceRequestsAllowedState ResourceRequestStateToHistogramValue(
169 web_resource::ResourceRequestAllowedNotifier::State state) {
170 using web_resource::ResourceRequestAllowedNotifier;
171 switch (state) {
172 case ResourceRequestAllowedNotifier::DISALLOWED_EULA_NOT_ACCEPTED:
173 return RESOURCE_REQUESTS_NOT_ALLOWED_EULA_NOT_ACCEPTED;
174 case ResourceRequestAllowedNotifier::DISALLOWED_NETWORK_DOWN:
175 return RESOURCE_REQUESTS_NOT_ALLOWED_NETWORK_DOWN;
176 case ResourceRequestAllowedNotifier::DISALLOWED_COMMAND_LINE_DISABLED:
177 return RESOURCE_REQUESTS_NOT_ALLOWED_COMMAND_LINE_DISABLED;
178 case ResourceRequestAllowedNotifier::ALLOWED:
179 return RESOURCE_REQUESTS_ALLOWED;
181 NOTREACHED();
182 return RESOURCE_REQUESTS_NOT_ALLOWED;
186 // Gets current form factor and converts it from enum DeviceFormFactor to enum
187 // Study_FormFactor.
188 variations::Study_FormFactor GetCurrentFormFactor() {
189 switch (ui::GetDeviceFormFactor()) {
190 case ui::DEVICE_FORM_FACTOR_PHONE:
191 return variations::Study_FormFactor_PHONE;
192 case ui::DEVICE_FORM_FACTOR_TABLET:
193 return variations::Study_FormFactor_TABLET;
194 case ui::DEVICE_FORM_FACTOR_DESKTOP:
195 return variations::Study_FormFactor_DESKTOP;
197 NOTREACHED();
198 return variations::Study_FormFactor_DESKTOP;
201 // Gets the hardware class and returns it as a string. This returns an empty
202 // string if the client is not ChromeOS.
203 std::string GetHardwareClass() {
204 #if defined(OS_CHROMEOS)
205 return base::SysInfo::GetLsbReleaseBoard();
206 #endif // OS_CHROMEOS
207 return std::string();
210 // Returns the date that should be used by the VariationsSeedProcessor to do
211 // expiry and start date checks.
212 base::Time GetReferenceDateForExpiryChecks(PrefService* local_state) {
213 const int64 date_value = local_state->GetInt64(prefs::kVariationsSeedDate);
214 const base::Time seed_date = base::Time::FromInternalValue(date_value);
215 const base::Time build_time = base::GetBuildTime();
216 // Use the build time for date checks if either the seed date is invalid or
217 // the build time is newer than the seed date.
218 base::Time reference_date = seed_date;
219 if (seed_date.is_null() || seed_date < build_time)
220 reference_date = build_time;
221 return reference_date;
224 // Overrides the string resource sepecified by |hash| with |string| in the
225 // resource bundle. Used as a callback passed to the variations seed processor.
226 void OverrideUIString(uint32_t hash, const base::string16& string) {
227 int resource_id = GetResourceIndex(hash);
228 if (resource_id == -1)
229 return;
231 ui::ResourceBundle::GetSharedInstance().OverrideLocaleStringResource(
232 resource_id, string);
235 } // namespace
237 VariationsService::VariationsService(
238 web_resource::ResourceRequestAllowedNotifier* notifier,
239 PrefService* local_state,
240 metrics::MetricsStateManager* state_manager)
241 : local_state_(local_state),
242 state_manager_(state_manager),
243 policy_pref_service_(local_state),
244 seed_store_(local_state),
245 create_trials_from_seed_called_(false),
246 initial_request_completed_(false),
247 resource_request_allowed_notifier_(notifier),
248 weak_ptr_factory_(this) {
249 resource_request_allowed_notifier_->Init(this);
252 VariationsService::~VariationsService() {
255 bool VariationsService::CreateTrialsFromSeed() {
256 create_trials_from_seed_called_ = true;
258 variations::VariationsSeed seed;
259 if (!seed_store_.LoadSeed(&seed))
260 return false;
262 const chrome::VersionInfo current_version_info;
263 const base::Version current_version(current_version_info.Version());
264 if (!current_version.IsValid())
265 return false;
267 variations::Study_Channel channel = GetChannelForVariations();
268 UMA_HISTOGRAM_SPARSE_SLOWLY("Variations.UserChannel", channel);
270 variations::VariationsSeedProcessor().CreateTrialsFromSeed(
271 seed,
272 g_browser_process->GetApplicationLocale(),
273 GetReferenceDateForExpiryChecks(local_state_),
274 current_version,
275 channel,
276 GetCurrentFormFactor(),
277 GetHardwareClass(),
278 base::Bind(&OverrideUIString));
280 const base::Time now = base::Time::Now();
282 // Log the "freshness" of the seed that was just used. The freshness is the
283 // time between the last successful seed download and now.
284 const int64 last_fetch_time_internal =
285 local_state_->GetInt64(prefs::kVariationsLastFetchTime);
286 if (last_fetch_time_internal) {
287 const base::TimeDelta delta =
288 now - base::Time::FromInternalValue(last_fetch_time_internal);
289 // Log the value in number of minutes.
290 UMA_HISTOGRAM_CUSTOM_COUNTS("Variations.SeedFreshness", delta.InMinutes(),
291 1, base::TimeDelta::FromDays(30).InMinutes(), 50);
294 // Log the skew between the seed date and the system clock/build time to
295 // analyze whether either could be used to make old variations seeds expire
296 // after some time.
297 const int64 seed_date_internal =
298 local_state_->GetInt64(prefs::kVariationsSeedDate);
299 if (seed_date_internal) {
300 const base::Time seed_date =
301 base::Time::FromInternalValue(seed_date_internal);
302 const int system_clock_delta_days = (now - seed_date).InDays();
303 if (system_clock_delta_days < 0) {
304 UMA_HISTOGRAM_COUNTS_100("Variations.SeedDateSkew.SystemClockBehindBy",
305 -system_clock_delta_days);
306 } else {
307 UMA_HISTOGRAM_COUNTS_100("Variations.SeedDateSkew.SystemClockAheadBy",
308 system_clock_delta_days);
311 const int build_time_delta_days =
312 (base::GetBuildTime() - seed_date).InDays();
313 if (build_time_delta_days < 0) {
314 UMA_HISTOGRAM_COUNTS_100("Variations.SeedDateSkew.BuildTimeBehindBy",
315 -build_time_delta_days);
316 } else {
317 UMA_HISTOGRAM_COUNTS_100("Variations.SeedDateSkew.BuildTimeAheadBy",
318 build_time_delta_days);
322 return true;
325 void VariationsService::StartRepeatedVariationsSeedFetch() {
326 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
328 // Initialize the Variations server URL.
329 variations_server_url_ =
330 GetVariationsServerURL(policy_pref_service_, restrict_mode_);
332 // Check that |CreateTrialsFromSeed| was called, which is necessary to
333 // retrieve the serial number that will be sent to the server.
334 DCHECK(create_trials_from_seed_called_);
336 DCHECK(!request_scheduler_.get());
337 // Note that the act of instantiating the scheduler will start the fetch, if
338 // the scheduler deems appropriate.
339 request_scheduler_.reset(VariationsRequestScheduler::Create(
340 base::Bind(&VariationsService::FetchVariationsSeed,
341 weak_ptr_factory_.GetWeakPtr()),
342 local_state_));
343 request_scheduler_->Start();
346 void VariationsService::AddObserver(Observer* observer) {
347 observer_list_.AddObserver(observer);
350 void VariationsService::RemoveObserver(Observer* observer) {
351 observer_list_.RemoveObserver(observer);
354 void VariationsService::OnAppEnterForeground() {
355 // On mobile platforms, initialize the fetch scheduler when we receive the
356 // first app foreground notification.
357 if (!request_scheduler_)
358 StartRepeatedVariationsSeedFetch();
359 request_scheduler_->OnAppEnterForeground();
362 #if defined(OS_WIN)
363 void VariationsService::StartGoogleUpdateRegistrySync() {
364 registry_syncer_.RequestRegistrySync();
366 #endif
368 void VariationsService::SetRestrictMode(const std::string& restrict_mode) {
369 // This should be called before the server URL has been computed.
370 DCHECK(variations_server_url_.is_empty());
371 restrict_mode_ = restrict_mode;
374 void VariationsService::SetCreateTrialsFromSeedCalledForTesting(bool called) {
375 create_trials_from_seed_called_ = called;
378 // static
379 GURL VariationsService::GetVariationsServerURL(
380 PrefService* policy_pref_service,
381 const std::string& restrict_mode_override) {
382 std::string server_url_string(
383 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
384 switches::kVariationsServerURL));
385 if (server_url_string.empty())
386 server_url_string = kDefaultVariationsServerURL;
387 GURL server_url = GURL(server_url_string);
389 const std::string restrict_param = !restrict_mode_override.empty() ?
390 restrict_mode_override : GetRestrictParameterPref(policy_pref_service);
391 if (!restrict_param.empty()) {
392 server_url = net::AppendOrReplaceQueryParameter(server_url,
393 "restrict",
394 restrict_param);
397 server_url = net::AppendOrReplaceQueryParameter(server_url, "osname",
398 GetPlatformString());
400 DCHECK(server_url.is_valid());
401 return server_url;
404 // static
405 std::string VariationsService::GetDefaultVariationsServerURLForTesting() {
406 return kDefaultVariationsServerURL;
409 // static
410 void VariationsService::RegisterPrefs(PrefRegistrySimple* registry) {
411 VariationsSeedStore::RegisterPrefs(registry);
412 registry->RegisterInt64Pref(prefs::kVariationsLastFetchTime, 0);
413 // This preference will only be written by the policy service, which will fill
414 // it according to a value stored in the User Policy.
415 registry->RegisterStringPref(prefs::kVariationsRestrictParameter,
416 std::string());
419 // static
420 void VariationsService::RegisterProfilePrefs(
421 user_prefs::PrefRegistrySyncable* registry) {
422 // This preference will only be written by the policy service, which will fill
423 // it according to a value stored in the User Policy.
424 registry->RegisterStringPref(
425 prefs::kVariationsRestrictParameter,
426 std::string(),
427 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
430 // static
431 scoped_ptr<VariationsService> VariationsService::Create(
432 PrefService* local_state,
433 metrics::MetricsStateManager* state_manager) {
434 scoped_ptr<VariationsService> result;
435 #if !defined(GOOGLE_CHROME_BUILD)
436 // Unless the URL was provided, unsupported builds should return NULL to
437 // indicate that the service should not be used.
438 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
439 switches::kVariationsServerURL)) {
440 DVLOG(1) << "Not creating VariationsService in unofficial build without --"
441 << switches::kVariationsServerURL << " specified.";
442 return result.Pass();
444 #endif
445 result.reset(new VariationsService(
446 new web_resource::ResourceRequestAllowedNotifier(
447 local_state, switches::kDisableBackgroundNetworking),
448 local_state, state_manager));
449 return result.Pass();
452 void VariationsService::DoActualFetch() {
453 pending_seed_request_.reset(net::URLFetcher::Create(
454 0, variations_server_url_, net::URLFetcher::GET, this));
455 pending_seed_request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
456 net::LOAD_DO_NOT_SAVE_COOKIES);
457 pending_seed_request_->SetRequestContext(
458 g_browser_process->system_request_context());
459 pending_seed_request_->SetMaxRetriesOn5xx(kMaxRetrySeedFetch);
460 if (!seed_store_.variations_serial_number().empty()) {
461 pending_seed_request_->AddExtraRequestHeader(
462 "If-Match:" + seed_store_.variations_serial_number());
464 pending_seed_request_->Start();
466 const base::TimeTicks now = base::TimeTicks::Now();
467 base::TimeDelta time_since_last_fetch;
468 // Record a time delta of 0 (default value) if there was no previous fetch.
469 if (!last_request_started_time_.is_null())
470 time_since_last_fetch = now - last_request_started_time_;
471 UMA_HISTOGRAM_CUSTOM_COUNTS("Variations.TimeSinceLastFetchAttempt",
472 time_since_last_fetch.InMinutes(), 0,
473 base::TimeDelta::FromDays(7).InMinutes(), 50);
474 last_request_started_time_ = now;
477 void VariationsService::StoreSeed(const std::string& seed_data,
478 const std::string& seed_signature,
479 const base::Time& date_fetched) {
480 scoped_ptr<variations::VariationsSeed> seed(new variations::VariationsSeed);
481 if (!seed_store_.StoreSeedData(seed_data, seed_signature, date_fetched,
482 seed.get())) {
483 return;
485 RecordLastFetchTime();
487 // Perform seed simulation only if |state_manager_| is not-NULL. The state
488 // manager may be NULL for some unit tests.
489 if (!state_manager_)
490 return;
492 base::PostTaskAndReplyWithResult(
493 content::BrowserThread::GetBlockingPool(),
494 FROM_HERE,
495 base::Bind(&GetVersionForSimulation),
496 base::Bind(&VariationsService::PerformSimulationWithVersion,
497 weak_ptr_factory_.GetWeakPtr(), base::Passed(&seed)));
500 void VariationsService::FetchVariationsSeed() {
501 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
503 const web_resource::ResourceRequestAllowedNotifier::State state =
504 resource_request_allowed_notifier_->GetResourceRequestsAllowedState();
505 RecordRequestsAllowedHistogram(ResourceRequestStateToHistogramValue(state));
506 if (state != web_resource::ResourceRequestAllowedNotifier::ALLOWED) {
507 DVLOG(1) << "Resource requests were not allowed. Waiting for notification.";
508 return;
511 DoActualFetch();
514 void VariationsService::NotifyObservers(
515 const variations::VariationsSeedSimulator::Result& result) {
516 if (result.kill_critical_group_change_count > 0) {
517 FOR_EACH_OBSERVER(Observer, observer_list_,
518 OnExperimentChangesDetected(Observer::CRITICAL));
519 } else if (result.kill_best_effort_group_change_count > 0) {
520 FOR_EACH_OBSERVER(Observer, observer_list_,
521 OnExperimentChangesDetected(Observer::BEST_EFFORT));
525 void VariationsService::OnURLFetchComplete(const net::URLFetcher* source) {
526 DCHECK_EQ(pending_seed_request_.get(), source);
528 const bool is_first_request = !initial_request_completed_;
529 initial_request_completed_ = true;
531 // The fetcher will be deleted when the request is handled.
532 scoped_ptr<const net::URLFetcher> request(pending_seed_request_.release());
533 const net::URLRequestStatus& request_status = request->GetStatus();
534 if (request_status.status() != net::URLRequestStatus::SUCCESS) {
535 UMA_HISTOGRAM_SPARSE_SLOWLY("Variations.FailedRequestErrorCode",
536 -request_status.error());
537 DVLOG(1) << "Variations server request failed with error: "
538 << request_status.error() << ": "
539 << net::ErrorToString(request_status.error());
540 // It's common for the very first fetch attempt to fail (e.g. the network
541 // may not yet be available). In such a case, try again soon, rather than
542 // waiting the full time interval.
543 if (is_first_request)
544 request_scheduler_->ScheduleFetchShortly();
545 return;
548 // Log the response code.
549 const int response_code = request->GetResponseCode();
550 UMA_HISTOGRAM_SPARSE_SLOWLY("Variations.SeedFetchResponseCode",
551 response_code);
553 const base::TimeDelta latency =
554 base::TimeTicks::Now() - last_request_started_time_;
556 base::Time response_date;
557 if (response_code == net::HTTP_OK ||
558 response_code == net::HTTP_NOT_MODIFIED) {
559 bool success = request->GetResponseHeaders()->GetDateValue(&response_date);
560 DCHECK(success || response_date.is_null());
562 if (!response_date.is_null()) {
563 g_browser_process->network_time_tracker()->UpdateNetworkTime(
564 response_date,
565 base::TimeDelta::FromMilliseconds(kServerTimeResolutionMs),
566 latency,
567 base::TimeTicks::Now());
571 if (response_code != net::HTTP_OK) {
572 DVLOG(1) << "Variations server request returned non-HTTP_OK response code: "
573 << response_code;
574 if (response_code == net::HTTP_NOT_MODIFIED) {
575 RecordLastFetchTime();
576 // Update the seed date value in local state (used for expiry check on
577 // next start up), since 304 is a successful response.
578 seed_store_.UpdateSeedDateAndLogDayChange(response_date);
580 return;
583 std::string seed_data;
584 bool success = request->GetResponseAsString(&seed_data);
585 DCHECK(success);
587 std::string seed_signature;
588 request->GetResponseHeaders()->EnumerateHeader(NULL,
589 "X-Seed-Signature",
590 &seed_signature);
591 StoreSeed(seed_data, seed_signature, response_date);
594 void VariationsService::OnResourceRequestsAllowed() {
595 // Note that this only attempts to fetch the seed at most once per period
596 // (kSeedFetchPeriodHours). This works because
597 // |resource_request_allowed_notifier_| only calls this method if an
598 // attempt was made earlier that fails (which implies that the period had
599 // elapsed). After a successful attempt is made, the notifier will know not
600 // to call this method again until another failed attempt occurs.
601 RecordRequestsAllowedHistogram(RESOURCE_REQUESTS_ALLOWED_NOTIFIED);
602 DVLOG(1) << "Retrying fetch.";
603 DoActualFetch();
605 // This service must have created a scheduler in order for this to be called.
606 DCHECK(request_scheduler_.get());
607 request_scheduler_->Reset();
610 void VariationsService::PerformSimulationWithVersion(
611 scoped_ptr<variations::VariationsSeed> seed,
612 const base::Version& version) {
613 if (!version.IsValid())
614 return;
616 const base::ElapsedTimer timer;
618 scoped_ptr<const base::FieldTrial::EntropyProvider> entropy_provider =
619 state_manager_->CreateEntropyProvider();
620 variations::VariationsSeedSimulator seed_simulator(*entropy_provider);
622 const variations::VariationsSeedSimulator::Result result =
623 seed_simulator.SimulateSeedStudies(
624 *seed, g_browser_process->GetApplicationLocale(),
625 GetReferenceDateForExpiryChecks(local_state_), version,
626 GetChannelForVariations(), GetCurrentFormFactor(),
627 GetHardwareClass());
629 UMA_HISTOGRAM_COUNTS_100("Variations.SimulateSeed.NormalChanges",
630 result.normal_group_change_count);
631 UMA_HISTOGRAM_COUNTS_100("Variations.SimulateSeed.KillBestEffortChanges",
632 result.kill_best_effort_group_change_count);
633 UMA_HISTOGRAM_COUNTS_100("Variations.SimulateSeed.KillCriticalChanges",
634 result.kill_critical_group_change_count);
636 UMA_HISTOGRAM_TIMES("Variations.SimulateSeed.Duration", timer.Elapsed());
638 NotifyObservers(result);
641 void VariationsService::RecordLastFetchTime() {
642 // local_state_ is NULL in tests, so check it first.
643 if (local_state_) {
644 local_state_->SetInt64(prefs::kVariationsLastFetchTime,
645 base::Time::Now().ToInternalValue());
649 std::string VariationsService::GetInvalidVariationsSeedSignature() const {
650 return seed_store_.GetInvalidSignature();
653 } // namespace chrome_variations