| 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/chrome_browser_field_trials.h" | 5 #include "chrome/browser/chrome_browser_field_trials.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/feature_list.h" | 10 #include "base/feature_list.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
| 13 #include "base/metrics/histogram_base.h" | 13 #include "base/metrics/histogram_base.h" |
| 14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/metrics/persistent_histogram_allocator.h" | 15 #include "base/metrics/persistent_histogram_allocator.h" |
| 16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 20 #include "chrome/browser/metrics/chrome_metrics_service_client.h" | 20 #include "chrome/browser/metrics/chrome_metrics_service_client.h" |
| 21 #include "chrome/browser/metrics/chrome_metrics_services_manager_client.h" |
| 21 #include "chrome/browser/tracing/background_tracing_field_trial.h" | 22 #include "chrome/browser/tracing/background_tracing_field_trial.h" |
| 23 #include "chrome/common/channel_info.h" |
| 22 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
| 23 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 24 #include "components/metrics/metrics_pref_names.h" | 26 #include "components/metrics/metrics_pref_names.h" |
| 25 #include "components/variations/variations_associated_data.h" | 27 #include "components/variations/variations_associated_data.h" |
| 28 #include "components/version_info/version_info.h" |
| 26 | 29 |
| 27 #if defined(OS_ANDROID) | 30 #if defined(OS_ANDROID) |
| 28 #include "chrome/browser/chrome_browser_field_trials_mobile.h" | 31 #include "chrome/browser/chrome_browser_field_trials_mobile.h" |
| 29 #else | 32 #else |
| 30 #include "chrome/browser/chrome_browser_field_trials_desktop.h" | 33 #include "chrome/browser/chrome_browser_field_trials_desktop.h" |
| 31 #endif | 34 #endif |
| 32 | 35 |
| 33 namespace { | 36 namespace { |
| 34 | 37 |
| 35 // Check for feature enabling the use of persistent histogram storage and | 38 // Check for feature enabling the use of persistent histogram storage and |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 CREATE_ALLOCATOR_RESULTS); | 107 CREATE_ALLOCATOR_RESULTS); |
| 105 if (!allocator) | 108 if (!allocator) |
| 106 return; | 109 return; |
| 107 | 110 |
| 108 // Create tracking histograms for the allocator and record storage file. | 111 // Create tracking histograms for the allocator and record storage file. |
| 109 allocator->CreateTrackingHistograms( | 112 allocator->CreateTrackingHistograms( |
| 110 ChromeMetricsServiceClient::kBrowserMetricsName); | 113 ChromeMetricsServiceClient::kBrowserMetricsName); |
| 111 allocator->SetPersistentLocation(active_file); | 114 allocator->SetPersistentLocation(active_file); |
| 112 } | 115 } |
| 113 | 116 |
| 117 // Create a field trial to control metrics/crash sampling for Stable on |
| 118 // Windows/Android if no variations seed was applied. |
| 119 void CreateFallbackSamplingTrialIfNeeded(bool has_seed, |
| 120 base::FeatureList* feature_list) { |
| 121 #if defined(OS_WIN) || defined(OS_ANDROID) |
| 122 // Only create the fallback trial if there isn't already a variations seed |
| 123 // being applied. This should occur during first run when first-run variations |
| 124 // isn't supported. It's assumed that, if there is a seed, then it either |
| 125 // contains the relavent study, or is intentionally omitted, so no fallback is |
| 126 // needed. |
| 127 if (has_seed) |
| 128 return; |
| 129 |
| 130 // Sampling is only supported on Stable. |
| 131 if (chrome::GetChannel() != version_info::Channel::STABLE) |
| 132 return; |
| 133 |
| 134 ChromeMetricsServicesManagerClient::CreateFallbackSamplingTrial(feature_list); |
| 135 #endif // defined(OS_WIN) || defined(OS_ANDROID) |
| 136 } |
| 137 |
| 114 } // namespace | 138 } // namespace |
| 115 | 139 |
| 116 ChromeBrowserFieldTrials::ChromeBrowserFieldTrials( | 140 ChromeBrowserFieldTrials::ChromeBrowserFieldTrials( |
| 117 const base::CommandLine& parsed_command_line) | 141 const base::CommandLine& parsed_command_line) |
| 118 : parsed_command_line_(parsed_command_line) { | 142 : parsed_command_line_(parsed_command_line) { |
| 119 } | 143 } |
| 120 | 144 |
| 121 ChromeBrowserFieldTrials::~ChromeBrowserFieldTrials() { | 145 ChromeBrowserFieldTrials::~ChromeBrowserFieldTrials() { |
| 122 } | 146 } |
| 123 | 147 |
| 124 void ChromeBrowserFieldTrials::SetupFieldTrials() { | 148 void ChromeBrowserFieldTrials::SetupFieldTrials() { |
| 125 // Field trials that are shared by all platforms. | 149 // Field trials that are shared by all platforms. |
| 126 InstantiateDynamicTrials(); | 150 InstantiateDynamicTrials(); |
| 127 | 151 |
| 128 #if defined(OS_ANDROID) | 152 #if defined(OS_ANDROID) |
| 129 chrome::SetupMobileFieldTrials(parsed_command_line_); | 153 chrome::SetupMobileFieldTrials(parsed_command_line_); |
| 130 #else | 154 #else |
| 131 chrome::SetupDesktopFieldTrials(parsed_command_line_); | 155 chrome::SetupDesktopFieldTrials(parsed_command_line_); |
| 132 #endif | 156 #endif |
| 133 } | 157 } |
| 134 | 158 |
| 159 void ChromeBrowserFieldTrials::SetupFeatureControllingFieldTrials( |
| 160 bool has_seed, |
| 161 base::FeatureList* feature_list) { |
| 162 CreateFallbackSamplingTrialIfNeeded(has_seed, feature_list); |
| 163 } |
| 164 |
| 135 void ChromeBrowserFieldTrials::InstantiateDynamicTrials() { | 165 void ChromeBrowserFieldTrials::InstantiateDynamicTrials() { |
| 136 // Persistent histograms must be enabled as soon as possible. | 166 // Persistent histograms must be enabled as soon as possible. |
| 137 InstantiatePersistentHistograms(); | 167 InstantiatePersistentHistograms(); |
| 138 tracing::SetupBackgroundTracingFieldTrial(); | 168 tracing::SetupBackgroundTracingFieldTrial(); |
| 139 } | 169 } |
| OLD | NEW |