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 <set> | 7 #include <set> |
8 | 8 |
9 #include "base/build_time.h" | 9 #include "base/build_time.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/metrics/sparse_histogram.h" | 12 #include "base/metrics/sparse_histogram.h" |
13 #include "base/prefs/pref_registry_simple.h" | 13 #include "base/prefs/pref_registry_simple.h" |
14 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
| 15 #include "base/timer/elapsed_timer.h" |
15 #include "base/version.h" | 16 #include "base/version.h" |
16 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/network_time/network_time_tracker.h" | 18 #include "chrome/browser/network_time/network_time_tracker.h" |
18 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
20 #include "components/user_prefs/pref_registry_syncable.h" | 21 #include "components/user_prefs/pref_registry_syncable.h" |
21 #include "components/variations/proto/variations_seed.pb.h" | 22 #include "components/variations/proto/variations_seed.pb.h" |
22 #include "components/variations/variations_seed_processor.h" | 23 #include "components/variations/variations_seed_processor.h" |
| 24 #include "components/variations/variations_seed_simulator.h" |
23 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
24 #include "net/base/load_flags.h" | 26 #include "net/base/load_flags.h" |
25 #include "net/base/net_errors.h" | 27 #include "net/base/net_errors.h" |
26 #include "net/base/network_change_notifier.h" | 28 #include "net/base/network_change_notifier.h" |
27 #include "net/base/url_util.h" | 29 #include "net/base/url_util.h" |
28 #include "net/http/http_response_headers.h" | 30 #include "net/http/http_response_headers.h" |
29 #include "net/http/http_status_code.h" | 31 #include "net/http/http_status_code.h" |
30 #include "net/http/http_util.h" | 32 #include "net/http/http_util.h" |
31 #include "net/url_request/url_fetcher.h" | 33 #include "net/url_request/url_fetcher.h" |
32 #include "net/url_request/url_request_status.h" | 34 #include "net/url_request/url_request_status.h" |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 time_since_last_fetch = now - last_request_started_time_; | 376 time_since_last_fetch = now - last_request_started_time_; |
375 UMA_HISTOGRAM_CUSTOM_COUNTS("Variations.TimeSinceLastFetchAttempt", | 377 UMA_HISTOGRAM_CUSTOM_COUNTS("Variations.TimeSinceLastFetchAttempt", |
376 time_since_last_fetch.InMinutes(), 0, | 378 time_since_last_fetch.InMinutes(), 0, |
377 base::TimeDelta::FromDays(7).InMinutes(), 50); | 379 base::TimeDelta::FromDays(7).InMinutes(), 50); |
378 last_request_started_time_ = now; | 380 last_request_started_time_ = now; |
379 } | 381 } |
380 | 382 |
381 void VariationsService::StoreSeed(const std::string& seed_data, | 383 void VariationsService::StoreSeed(const std::string& seed_data, |
382 const std::string& seed_signature, | 384 const std::string& seed_signature, |
383 const base::Time& date_fetched) { | 385 const base::Time& date_fetched) { |
384 if (!seed_store_.StoreSeedData(seed_data, seed_signature, date_fetched)) | 386 VariationsSeed seed; |
| 387 if (!seed_store_.StoreSeedData(seed_data, seed_signature, date_fetched, |
| 388 &seed)) { |
385 return; | 389 return; |
| 390 } |
386 RecordLastFetchTime(); | 391 RecordLastFetchTime(); |
| 392 |
| 393 const base::ElapsedTimer timer; |
| 394 |
| 395 // TODO(asvitkine): Get the version that will be used on restart instead of |
| 396 // the current version (i.e. if an update has been downloaded). |
| 397 const chrome::VersionInfo current_version_info; |
| 398 if (!current_version_info.is_valid()) |
| 399 return; |
| 400 |
| 401 const base::Version current_version(current_version_info.Version()); |
| 402 if (!current_version.IsValid()) |
| 403 return; |
| 404 |
| 405 const base::FieldTrial::EntropyProvider* entropy_provider = |
| 406 base::FieldTrialList::GetEntropyProviderForOneTimeRandomization(); |
| 407 // One-time randomization should be supported by the global FieldTrialList in |
| 408 // the process the VariationService is running in, so |entropy_provider| must |
| 409 // be non-NULL. |
| 410 DCHECK(entropy_provider); |
| 411 VariationsSeedSimulator seed_simulator(*entropy_provider); |
| 412 |
| 413 VariationsSeedSimulator::Result result = seed_simulator.SimulateSeedStudies( |
| 414 seed, g_browser_process->GetApplicationLocale(), |
| 415 GetReferenceDateForExpiryChecks(local_state_), current_version, |
| 416 GetChannelForVariations(), GetCurrentFormFactor()); |
| 417 |
| 418 UMA_HISTOGRAM_COUNTS_100("Variations.SimulateSeed.NormalChanges", |
| 419 result.normal_group_change_count); |
| 420 UMA_HISTOGRAM_COUNTS_100("Variations.SimulateSeed.KillBestEffortChanges", |
| 421 result.kill_best_effort_group_change_count); |
| 422 UMA_HISTOGRAM_COUNTS_100("Variations.SimulateSeed.KillCriticalChanges", |
| 423 result.kill_critical_group_change_count); |
| 424 |
| 425 UMA_HISTOGRAM_TIMES("Variations.SimulateSeed.Duration", timer.Elapsed()); |
387 } | 426 } |
388 | 427 |
389 void VariationsService::FetchVariationsSeed() { | 428 void VariationsService::FetchVariationsSeed() { |
390 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 429 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
391 | 430 |
392 const ResourceRequestAllowedNotifier::State state = | 431 const ResourceRequestAllowedNotifier::State state = |
393 resource_request_allowed_notifier_->GetResourceRequestsAllowedState(); | 432 resource_request_allowed_notifier_->GetResourceRequestsAllowedState(); |
394 RecordRequestsAllowedHistogram(ResourceRequestStateToHistogramValue(state)); | 433 RecordRequestsAllowedHistogram(ResourceRequestStateToHistogramValue(state)); |
395 if (state != ResourceRequestAllowedNotifier::ALLOWED) { | 434 if (state != ResourceRequestAllowedNotifier::ALLOWED) { |
396 DVLOG(1) << "Resource requests were not allowed. Waiting for notification."; | 435 DVLOG(1) << "Resource requests were not allowed. Waiting for notification."; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 | 525 |
487 void VariationsService::RecordLastFetchTime() { | 526 void VariationsService::RecordLastFetchTime() { |
488 // local_state_ is NULL in tests, so check it first. | 527 // local_state_ is NULL in tests, so check it first. |
489 if (local_state_) { | 528 if (local_state_) { |
490 local_state_->SetInt64(prefs::kVariationsLastFetchTime, | 529 local_state_->SetInt64(prefs::kVariationsLastFetchTime, |
491 base::Time::Now().ToInternalValue()); | 530 base::Time::Now().ToInternalValue()); |
492 } | 531 } |
493 } | 532 } |
494 | 533 |
495 } // namespace chrome_variations | 534 } // namespace chrome_variations |
OLD | NEW |