Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(618)

Side by Side Diff: chrome/browser/chrome_browser_field_trials.cc

Issue 2938263002: Put BrowserMetrics with embedded profiles into subdir for auto-upload. (Closed)
Patch Set: rebased Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 // Desktop may have to restore a lot of tabs so give it more time before doing 48 // Desktop may have to restore a lot of tabs so give it more time before doing
49 // non-essential work. The spare file is still a performance boost but not as 49 // non-essential work. The spare file is still a performance boost but not as
50 // significant of one so it's not required. 50 // significant of one so it's not required.
51 constexpr bool kSpareFileRequired = false; 51 constexpr bool kSpareFileRequired = false;
52 constexpr int kSpareFileCreateDelaySeconds = 90; 52 constexpr int kSpareFileCreateDelaySeconds = 90;
53 #endif 53 #endif
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.
Alexei Svitkine (slow) 2017/06/28 17:30:35 Friendly ping on this! (Separate CL, but please le
bcwhite 2017/06/28 18:52:08 Acknowledged.
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 base::FilePath upload_file;
65 base::FilePath active_file; 85 base::FilePath active_file;
66 base::FilePath spare_file; 86 base::FilePath spare_file;
67 base::GlobalHistogramAllocator::ConstructFilePaths( 87 base::GlobalHistogramAllocator::ConstructFilePathsForUploadDir(
68 metrics_dir, ChromeMetricsServiceClient::kBrowserMetricsName, 88 metrics_dir, upload_dir, ChromeMetricsServiceClient::kBrowserMetricsName,
Alexei Svitkine (slow) 2017/06/28 17:30:35 Can you add a comment about expected file location
bcwhite 2017/06/28 18:52:08 Done.
69 &metrics_file, &active_file, &spare_file); 89 &upload_file, &active_file, &spare_file);
70 90
71 // Move any existing "active" file to the final name from which it will be 91 // 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 92 // read when reporting initial stability metrics. If there is no file to
73 // move, remove any old, existing file from before the previous session. 93 // move, remove any old, existing file from before the previous session.
74 if (!base::ReplaceFile(active_file, metrics_file, nullptr)) 94 if (!base::ReplaceFile(active_file, upload_file, nullptr))
75 base::DeleteFile(metrics_file, /*recursive=*/false); 95 base::DeleteFile(active_file, /*recursive=*/false);
76 96
77 // This is used to report results to an UMA histogram. 97 // This is used to report results to an UMA histogram.
78 enum InitResult { 98 enum InitResult {
79 LOCAL_MEMORY_SUCCESS, 99 LOCAL_MEMORY_SUCCESS,
80 LOCAL_MEMORY_FAILED, 100 LOCAL_MEMORY_FAILED,
81 MAPPED_FILE_SUCCESS, 101 MAPPED_FILE_SUCCESS,
82 MAPPED_FILE_FAILED, 102 MAPPED_FILE_FAILED,
83 MAPPED_FILE_EXISTS, 103 MAPPED_FILE_EXISTS,
84 NO_SPARE_FILE, 104 NO_SPARE_FILE,
85 INIT_RESULT_MAX 105 INIT_RESULT_MAX
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 bool has_seed, 226 bool has_seed,
207 base::FeatureList* feature_list) { 227 base::FeatureList* feature_list) {
208 CreateFallbackSamplingTrialIfNeeded(has_seed, feature_list); 228 CreateFallbackSamplingTrialIfNeeded(has_seed, feature_list);
209 } 229 }
210 230
211 void ChromeBrowserFieldTrials::InstantiateDynamicTrials() { 231 void ChromeBrowserFieldTrials::InstantiateDynamicTrials() {
212 // Persistent histograms must be enabled as soon as possible. 232 // Persistent histograms must be enabled as soon as possible.
213 InstantiatePersistentHistograms(); 233 InstantiatePersistentHistograms();
214 tracing::SetupBackgroundTracingFieldTrial(); 234 tracing::SetupBackgroundTracingFieldTrial();
215 } 235 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698