| 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" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 // Check for feature enabling the use of persistent histogram storage and | 37 // Check for feature enabling the use of persistent histogram storage and |
| 38 // enable the global allocator if so. | 38 // enable the global allocator if so. |
| 39 // TODO(bcwhite): Move this and CreateInstallerFileMetricsProvider into a new | 39 // TODO(bcwhite): Move this and CreateInstallerFileMetricsProvider into a new |
| 40 // file and make kBrowserMetricsName local to that file. | 40 // file and make kBrowserMetricsName local to that file. |
| 41 void InstantiatePersistentHistograms() { | 41 void InstantiatePersistentHistograms() { |
| 42 base::FilePath metrics_dir; | 42 base::FilePath metrics_dir; |
| 43 if (!base::PathService::Get(chrome::DIR_USER_DATA, &metrics_dir)) | 43 if (!base::PathService::Get(chrome::DIR_USER_DATA, &metrics_dir)) |
| 44 return; | 44 return; |
| 45 | 45 |
| 46 base::FilePath metrics_file = | 46 base::FilePath metrics_file, active_file; |
| 47 metrics_dir | 47 base::GlobalHistogramAllocator::ConstructFilePaths( |
| 48 .AppendASCII(ChromeMetricsServiceClient::kBrowserMetricsName) | 48 metrics_dir, ChromeMetricsServiceClient::kBrowserMetricsName, |
| 49 .AddExtension(base::PersistentMemoryAllocator::kFileExtension); | 49 &metrics_file, &active_file); |
| 50 base::FilePath active_file = | |
| 51 metrics_dir | |
| 52 .AppendASCII( | |
| 53 std::string(ChromeMetricsServiceClient::kBrowserMetricsName) + | |
| 54 "-active") | |
| 55 .AddExtension(base::PersistentMemoryAllocator::kFileExtension); | |
| 56 | 50 |
| 57 // Move any existing "active" file to the final name from which it will be | 51 // Move any existing "active" file to the final name from which it will be |
| 58 // read when reporting initial stability metrics. If there is no file to | 52 // read when reporting initial stability metrics. If there is no file to |
| 59 // move, remove any old, existing file from before the previous session. | 53 // move, remove any old, existing file from before the previous session. |
| 60 if (!base::ReplaceFile(active_file, metrics_file, nullptr)) | 54 if (!base::ReplaceFile(active_file, metrics_file, nullptr)) |
| 61 base::DeleteFile(metrics_file, /*recursive=*/false); | 55 base::DeleteFile(metrics_file, /*recursive=*/false); |
| 62 | 56 |
| 63 // This is used to report results to an UMA histogram. It's an int because | 57 // This is used to report results to an UMA histogram. It's an int because |
| 64 // arithmetic is done on the value. The corresponding "failed" case must | 58 // arithmetic is done on the value. The corresponding "failed" case must |
| 65 // always appear directly after the "success" case. | 59 // always appear directly after the "success" case. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 base::GlobalHistogramAllocator::Get(); | 97 base::GlobalHistogramAllocator::Get(); |
| 104 UMA_HISTOGRAM_ENUMERATION("UMA.PersistentHistograms.InitResult", | 98 UMA_HISTOGRAM_ENUMERATION("UMA.PersistentHistograms.InitResult", |
| 105 result + (allocator ? 0 : 1), | 99 result + (allocator ? 0 : 1), |
| 106 CREATE_ALLOCATOR_RESULTS); | 100 CREATE_ALLOCATOR_RESULTS); |
| 107 if (!allocator) | 101 if (!allocator) |
| 108 return; | 102 return; |
| 109 | 103 |
| 110 // Create tracking histograms for the allocator and record storage file. | 104 // Create tracking histograms for the allocator and record storage file. |
| 111 allocator->CreateTrackingHistograms( | 105 allocator->CreateTrackingHistograms( |
| 112 ChromeMetricsServiceClient::kBrowserMetricsName); | 106 ChromeMetricsServiceClient::kBrowserMetricsName); |
| 113 allocator->SetPersistentLocation(active_file); | |
| 114 } | 107 } |
| 115 | 108 |
| 116 // Create a field trial to control metrics/crash sampling for Stable on | 109 // Create a field trial to control metrics/crash sampling for Stable on |
| 117 // Windows/Android if no variations seed was applied. | 110 // Windows/Android if no variations seed was applied. |
| 118 void CreateFallbackSamplingTrialIfNeeded(bool has_seed, | 111 void CreateFallbackSamplingTrialIfNeeded(bool has_seed, |
| 119 base::FeatureList* feature_list) { | 112 base::FeatureList* feature_list) { |
| 120 #if defined(OS_WIN) || defined(OS_ANDROID) | 113 #if defined(OS_WIN) || defined(OS_ANDROID) |
| 121 // Only create the fallback trial if there isn't already a variations seed | 114 // Only create the fallback trial if there isn't already a variations seed |
| 122 // being applied. This should occur during first run when first-run variations | 115 // being applied. This should occur during first run when first-run variations |
| 123 // isn't supported. It's assumed that, if there is a seed, then it either | 116 // isn't supported. It's assumed that, if there is a seed, then it either |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 bool has_seed, | 149 bool has_seed, |
| 157 base::FeatureList* feature_list) { | 150 base::FeatureList* feature_list) { |
| 158 CreateFallbackSamplingTrialIfNeeded(has_seed, feature_list); | 151 CreateFallbackSamplingTrialIfNeeded(has_seed, feature_list); |
| 159 } | 152 } |
| 160 | 153 |
| 161 void ChromeBrowserFieldTrials::InstantiateDynamicTrials() { | 154 void ChromeBrowserFieldTrials::InstantiateDynamicTrials() { |
| 162 // Persistent histograms must be enabled as soon as possible. | 155 // Persistent histograms must be enabled as soon as possible. |
| 163 InstantiatePersistentHistograms(); | 156 InstantiatePersistentHistograms(); |
| 164 tracing::SetupBackgroundTracingFieldTrial(); | 157 tracing::SetupBackgroundTracingFieldTrial(); |
| 165 } | 158 } |
| OLD | NEW |