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/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 | 54 |
55 // Check for feature enabling the use of persistent histogram storage and | 55 // Check for feature enabling the use of persistent histogram storage and |
56 // enable the global allocator if so. | 56 // enable the global allocator if so. |
57 // TODO(bcwhite): Move this and CreateInstallerFileMetricsProvider into a new | 57 // TODO(bcwhite): Move this and CreateInstallerFileMetricsProvider into a new |
58 // file and make kBrowserMetricsName local to that file. | 58 // file and make kBrowserMetricsName local to that file. |
59 void InstantiatePersistentHistograms() { | 59 void InstantiatePersistentHistograms() { |
60 base::FilePath metrics_dir; | 60 base::FilePath metrics_dir; |
61 if (!base::PathService::Get(chrome::DIR_USER_DATA, &metrics_dir)) | 61 if (!base::PathService::Get(chrome::DIR_USER_DATA, &metrics_dir)) |
62 return; | 62 return; |
63 | 63 |
64 base::FilePath metrics_file; | 64 // Remove any existing file from its legacy location. |
| 65 // TODO(bcwhite): Remove this block of code in M62 or later. |
| 66 base::FilePath legacy_file; |
| 67 base::GlobalHistogramAllocator::ConstructFilePaths( |
| 68 metrics_dir, ChromeMetricsServiceClient::kBrowserMetricsName, |
| 69 &legacy_file, nullptr, nullptr); |
| 70 base::PostTaskWithTraits( |
| 71 FROM_HERE, |
| 72 {base::MayBlock(), base::TaskPriority::BACKGROUND, |
| 73 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}, |
| 74 base::BindOnce(base::IgnoreResult(&base::DeleteFile), |
| 75 base::Passed(&legacy_file), /*recursive=*/false)); |
| 76 |
| 77 // Create a directory for storing completed metrics files. Files in this |
| 78 // directory must have embedded system profiles. If the directory can't be |
| 79 // created, the file will just be deleted below. |
| 80 base::FilePath upload_dir = |
| 81 metrics_dir.AppendASCII(ChromeMetricsServiceClient::kBrowserMetricsName); |
| 82 base::CreateDirectory(upload_dir); |
| 83 |
| 84 // Metrics files are typically created as a |spare_file| in the profile |
| 85 // directory (e.g. "BrowserMetrics-spare.pma") and are then rotated into |
| 86 // the |active_file| (e.g. "BrowserMetrics-active.pma") location for use |
| 87 // during the browser run. It is then moved to a time-stamped file in a |
| 88 // subdirectory (e.g. "BrowserMetrics/BrowserMetrics-1234ABCD.pma") for |
| 89 // upload when convenient. |
| 90 base::FilePath upload_file; |
65 base::FilePath active_file; | 91 base::FilePath active_file; |
66 base::FilePath spare_file; | 92 base::FilePath spare_file; |
67 base::GlobalHistogramAllocator::ConstructFilePaths( | 93 base::GlobalHistogramAllocator::ConstructFilePathsForUploadDir( |
68 metrics_dir, ChromeMetricsServiceClient::kBrowserMetricsName, | 94 metrics_dir, upload_dir, ChromeMetricsServiceClient::kBrowserMetricsName, |
69 &metrics_file, &active_file, &spare_file); | 95 &upload_file, &active_file, &spare_file); |
70 | 96 |
71 // Move any existing "active" file to the final name from which it will be | 97 // Move any existing "active" file to the final name from which it will be |
72 // read when reporting initial stability metrics. If there is no file to | 98 // read when reporting initial stability metrics. If there is no file to |
73 // move, remove any old, existing file from before the previous session. | 99 // move, remove any old, existing file from before the previous session. |
74 if (!base::ReplaceFile(active_file, metrics_file, nullptr)) | 100 if (!base::ReplaceFile(active_file, upload_file, nullptr)) |
75 base::DeleteFile(metrics_file, /*recursive=*/false); | 101 base::DeleteFile(active_file, /*recursive=*/false); |
76 | 102 |
77 // This is used to report results to an UMA histogram. | 103 // This is used to report results to an UMA histogram. |
78 enum InitResult { | 104 enum InitResult { |
79 LOCAL_MEMORY_SUCCESS, | 105 LOCAL_MEMORY_SUCCESS, |
80 LOCAL_MEMORY_FAILED, | 106 LOCAL_MEMORY_FAILED, |
81 MAPPED_FILE_SUCCESS, | 107 MAPPED_FILE_SUCCESS, |
82 MAPPED_FILE_FAILED, | 108 MAPPED_FILE_FAILED, |
83 MAPPED_FILE_EXISTS, | 109 MAPPED_FILE_EXISTS, |
84 NO_SPARE_FILE, | 110 NO_SPARE_FILE, |
85 INIT_RESULT_MAX | 111 INIT_RESULT_MAX |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 bool has_seed, | 232 bool has_seed, |
207 base::FeatureList* feature_list) { | 233 base::FeatureList* feature_list) { |
208 CreateFallbackSamplingTrialIfNeeded(has_seed, feature_list); | 234 CreateFallbackSamplingTrialIfNeeded(has_seed, feature_list); |
209 } | 235 } |
210 | 236 |
211 void ChromeBrowserFieldTrials::InstantiateDynamicTrials() { | 237 void ChromeBrowserFieldTrials::InstantiateDynamicTrials() { |
212 // Persistent histograms must be enabled as soon as possible. | 238 // Persistent histograms must be enabled as soon as possible. |
213 InstantiatePersistentHistograms(); | 239 InstantiatePersistentHistograms(); |
214 tracing::SetupBackgroundTracingFieldTrial(); | 240 tracing::SetupBackgroundTracingFieldTrial(); |
215 } | 241 } |
OLD | NEW |