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 //------------------------------------------------------------------------------ | 5 //------------------------------------------------------------------------------ |
6 // Description of the life cycle of a instance of MetricsService. | 6 // Description of the life cycle of a instance of MetricsService. |
7 // | 7 // |
8 // OVERVIEW | 8 // OVERVIEW |
9 // | 9 // |
10 // A MetricsService instance is typically created at application startup. It is | 10 // A MetricsService instance is typically created at application startup. It is |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
514 | 514 |
515 local_state->ClearPref(prefs::kMetricsInitialLogs); | 515 local_state->ClearPref(prefs::kMetricsInitialLogs); |
516 local_state->ClearPref(prefs::kMetricsOngoingLogs); | 516 local_state->ClearPref(prefs::kMetricsOngoingLogs); |
517 | 517 |
518 #if defined(OS_ANDROID) | 518 #if defined(OS_ANDROID) |
519 DiscardOldStabilityStatsAndroid(local_state); | 519 DiscardOldStabilityStatsAndroid(local_state); |
520 #endif // defined(OS_ANDROID) | 520 #endif // defined(OS_ANDROID) |
521 } | 521 } |
522 | 522 |
523 MetricsService::MetricsService() | 523 MetricsService::MetricsService() |
524 : recording_active_(false), | 524 : variations_state_initialized_(false), |
525 recording_active_(false), | |
525 reporting_active_(false), | 526 reporting_active_(false), |
526 test_mode_active_(false), | 527 test_mode_active_(false), |
527 state_(INITIALIZED), | 528 state_(INITIALIZED), |
528 has_initial_stability_log_(false), | 529 has_initial_stability_log_(false), |
529 low_entropy_source_(kLowEntropySourceNotSet), | 530 low_entropy_source_(kLowEntropySourceNotSet), |
530 idle_since_last_transmission_(false), | 531 idle_since_last_transmission_(false), |
531 session_id_(-1), | 532 session_id_(-1), |
532 next_window_id_(0), | 533 next_window_id_(0), |
533 self_ptr_factory_(this), | 534 self_ptr_factory_(this), |
534 state_saver_factory_(this), | 535 state_saver_factory_(this), |
(...skipping 16 matching lines...) Expand all Loading... | |
551 | 552 |
552 void MetricsService::InitializeMetricsRecordingState( | 553 void MetricsService::InitializeMetricsRecordingState( |
553 ReportingState reporting_state) { | 554 ReportingState reporting_state) { |
554 InitializeMetricsState(reporting_state); | 555 InitializeMetricsState(reporting_state); |
555 | 556 |
556 base::Closure callback = base::Bind(&MetricsService::StartScheduledUpload, | 557 base::Closure callback = base::Bind(&MetricsService::StartScheduledUpload, |
557 self_ptr_factory_.GetWeakPtr()); | 558 self_ptr_factory_.GetWeakPtr()); |
558 scheduler_.reset(new MetricsReportingScheduler(callback)); | 559 scheduler_.reset(new MetricsReportingScheduler(callback)); |
559 } | 560 } |
560 | 561 |
562 void MetricsService::InitializeVariationsState(bool recording_enabled) { | |
563 if (!variations_state_initialized_) { | |
564 variations_state_initialized_ = true; | |
565 | |
566 if (g_browser_process->local_state()->GetBoolean( | |
567 prefs::kMetricsCloneDetected)) | |
568 ResetVariationsState(); | |
569 } | |
570 | |
571 GetLowEntropySource(); | |
572 | |
573 if (recording_enabled) | |
Alexei Svitkine (slow)
2014/03/28 15:00:17
Hmm, this requires the caller to know this, which
jwd
2014/03/28 16:23:50
Done.
| |
574 ForceClientIdCreation(); | |
575 } | |
576 | |
561 void MetricsService::Start() { | 577 void MetricsService::Start() { |
562 HandleIdleSinceLastTransmission(false); | 578 HandleIdleSinceLastTransmission(false); |
563 EnableRecording(); | 579 EnableRecording(); |
564 EnableReporting(); | 580 EnableReporting(); |
565 } | 581 } |
566 | 582 |
567 void MetricsService::StartRecordingForTests() { | 583 void MetricsService::StartRecordingForTests() { |
568 test_mode_active_ = true; | 584 test_mode_active_ = true; |
569 EnableRecording(); | 585 EnableRecording(); |
570 DisableReporting(); | 586 DisableReporting(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
626 #else | 642 #else |
627 return scoped_ptr<const base::FieldTrial::EntropyProvider>( | 643 return scoped_ptr<const base::FieldTrial::EntropyProvider>( |
628 new metrics::PermutedEntropyProvider(low_entropy_source_value, | 644 new metrics::PermutedEntropyProvider(low_entropy_source_value, |
629 kMaxLowEntropySize)); | 645 kMaxLowEntropySize)); |
630 #endif | 646 #endif |
631 } | 647 } |
632 | 648 |
633 void MetricsService::ForceClientIdCreation() { | 649 void MetricsService::ForceClientIdCreation() { |
634 if (!client_id_.empty()) | 650 if (!client_id_.empty()) |
635 return; | 651 return; |
652 | |
636 PrefService* pref = g_browser_process->local_state(); | 653 PrefService* pref = g_browser_process->local_state(); |
637 client_id_ = pref->GetString(prefs::kMetricsClientID); | 654 client_id_ = pref->GetString(prefs::kMetricsClientID); |
638 if (!client_id_.empty()) | 655 if (!client_id_.empty()) |
639 return; | 656 return; |
640 | 657 |
641 client_id_ = GenerateClientID(); | 658 client_id_ = GenerateClientID(); |
642 pref->SetString(prefs::kMetricsClientID, client_id_); | 659 pref->SetString(prefs::kMetricsClientID, client_id_); |
643 | 660 |
644 // Might as well make a note of how long this ID has existed | 661 // Might as well make a note of how long this ID has existed |
645 pref->SetString(prefs::kMetricsClientIDTimestamp, | 662 pref->SetString(prefs::kMetricsClientIDTimestamp, |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1185 } | 1202 } |
1186 } | 1203 } |
1187 | 1204 |
1188 int MetricsService::GetLowEntropySource() { | 1205 int MetricsService::GetLowEntropySource() { |
1189 // Note that the default value for the low entropy source and the default pref | 1206 // Note that the default value for the low entropy source and the default pref |
1190 // value are both kLowEntropySourceNotSet, which is used to identify if the | 1207 // value are both kLowEntropySourceNotSet, which is used to identify if the |
1191 // value has been set or not. | 1208 // value has been set or not. |
1192 if (low_entropy_source_ != kLowEntropySourceNotSet) | 1209 if (low_entropy_source_ != kLowEntropySourceNotSet) |
1193 return low_entropy_source_; | 1210 return low_entropy_source_; |
1194 | 1211 |
1212 ResetVariationsState(); | |
Alexei Svitkine (slow)
2014/03/28 15:00:17
Why is this called from here? Did you mean Initial
jwd
2014/03/28 16:23:50
Done.
| |
1213 | |
1195 PrefService* local_state = g_browser_process->local_state(); | 1214 PrefService* local_state = g_browser_process->local_state(); |
1196 const CommandLine* command_line(CommandLine::ForCurrentProcess()); | 1215 const CommandLine* command_line(CommandLine::ForCurrentProcess()); |
1197 // Only try to load the value from prefs if the user did not request a reset. | 1216 // Only try to load the value from prefs if the user did not request a reset. |
1198 // Otherwise, skip to generating a new value. | 1217 // Otherwise, skip to generating a new value. |
1199 if (!command_line->HasSwitch(switches::kResetVariationState)) { | 1218 if (!command_line->HasSwitch(switches::kResetVariationState)) { |
1200 int value = local_state->GetInteger(prefs::kMetricsLowEntropySource); | 1219 int value = local_state->GetInteger(prefs::kMetricsLowEntropySource); |
1201 // Old versions of the code would generate values in the range of [1, 8192], | 1220 // Old versions of the code would generate values in the range of [1, 8192], |
1202 // before the range was switched to [0, 8191] and then to [0, 7999]. Map | 1221 // before the range was switched to [0, 8191] and then to [0, 7999]. Map |
1203 // 8192 to 0, so that the 0th bucket remains uniform, while re-generating | 1222 // 8192 to 0, so that the 0th bucket remains uniform, while re-generating |
1204 // the low entropy source for old values in the [8000, 8191] range. | 1223 // the low entropy source for old values in the [8000, 8191] range. |
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1855 return; | 1874 return; |
1856 } | 1875 } |
1857 } | 1876 } |
1858 | 1877 |
1859 SyntheticTrialGroup trial_group = trial; | 1878 SyntheticTrialGroup trial_group = trial; |
1860 trial_group.start_time = base::TimeTicks::Now(); | 1879 trial_group.start_time = base::TimeTicks::Now(); |
1861 synthetic_trial_groups_.push_back(trial_group); | 1880 synthetic_trial_groups_.push_back(trial_group); |
1862 } | 1881 } |
1863 | 1882 |
1864 void MetricsService::CheckForClonedInstall() { | 1883 void MetricsService::CheckForClonedInstall() { |
1884 DVLOG(2) << "\n\nChecking for cloned installs\n\n"; | |
1865 DCHECK(!cloned_install_detector_); | 1885 DCHECK(!cloned_install_detector_); |
1866 | 1886 |
1867 metrics::MachineIdProvider* provider = | 1887 metrics::MachineIdProvider* provider = |
1868 metrics::MachineIdProvider::CreateInstance(); | 1888 metrics::MachineIdProvider::CreateInstance(); |
1869 if (!provider) | 1889 if (!provider) |
1870 return; | 1890 return; |
1871 | 1891 |
1872 cloned_install_detector_.reset( | 1892 cloned_install_detector_.reset( |
1873 new metrics::ClonedInstallDetector(provider)); | 1893 new metrics::ClonedInstallDetector(provider)); |
1874 | 1894 |
1875 PrefService* local_state = g_browser_process->local_state(); | 1895 PrefService* local_state = g_browser_process->local_state(); |
1876 cloned_install_detector_->CheckForClonedInstall(local_state); | 1896 cloned_install_detector_->CheckForClonedInstall(local_state); |
1877 } | 1897 } |
1878 | 1898 |
1899 void MetricsService::ResetVariationsState() { | |
1900 PrefService* local_state = g_browser_process->local_state(); | |
1901 DCHECK(local_state->GetBoolean(prefs::kMetricsCloneDetected)); | |
1902 DCHECK(client_id_.empty()); | |
1903 DCHECK(low_entropy_source_ == kLowEntropySourceNotSet); | |
1904 | |
1905 DVLOG(2) << "\n\nresetting variatinos state\n\n"; | |
1906 | |
1907 local_state->ClearPref(prefs::kMetricsClientID); | |
1908 local_state->ClearPref(prefs::kMetricsLowEntropySource); | |
1909 local_state->SetBoolean(prefs::kMetricsCloneDetected, false); | |
1910 } | |
1911 | |
1879 void MetricsService::GetCurrentSyntheticFieldTrials( | 1912 void MetricsService::GetCurrentSyntheticFieldTrials( |
1880 std::vector<chrome_variations::ActiveGroupId>* synthetic_trials) { | 1913 std::vector<chrome_variations::ActiveGroupId>* synthetic_trials) { |
1881 DCHECK(synthetic_trials); | 1914 DCHECK(synthetic_trials); |
1882 synthetic_trials->clear(); | 1915 synthetic_trials->clear(); |
1883 const MetricsLog* current_log = | 1916 const MetricsLog* current_log = |
1884 static_cast<const MetricsLog*>(log_manager_.current_log()); | 1917 static_cast<const MetricsLog*>(log_manager_.current_log()); |
1885 for (size_t i = 0; i < synthetic_trial_groups_.size(); ++i) { | 1918 for (size_t i = 0; i < synthetic_trial_groups_.size(); ++i) { |
1886 if (synthetic_trial_groups_[i].start_time <= current_log->creation_time()) | 1919 if (synthetic_trial_groups_[i].start_time <= current_log->creation_time()) |
1887 synthetic_trials->push_back(synthetic_trial_groups_[i].id); | 1920 synthetic_trials->push_back(synthetic_trial_groups_[i].id); |
1888 } | 1921 } |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2098 // Android has its own settings for metrics / crash uploading. | 2131 // Android has its own settings for metrics / crash uploading. |
2099 const PrefService* prefs = g_browser_process->local_state(); | 2132 const PrefService* prefs = g_browser_process->local_state(); |
2100 return prefs->GetBoolean(prefs::kCrashReportingEnabled); | 2133 return prefs->GetBoolean(prefs::kCrashReportingEnabled); |
2101 #else | 2134 #else |
2102 return MetricsServiceHelper::IsMetricsReportingEnabled(); | 2135 return MetricsServiceHelper::IsMetricsReportingEnabled(); |
2103 #endif | 2136 #endif |
2104 #else | 2137 #else |
2105 return false; | 2138 return false; |
2106 #endif | 2139 #endif |
2107 } | 2140 } |
OLD | NEW |