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

Side by Side Diff: chrome/browser/metrics/chrome_metrics_service_client.cc

Issue 2010173005: Support experiment to store persistent metrics in memory-mapped file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed review comments by Alexei Created 4 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/metrics/chrome_metrics_service_client.h" 5 #include "chrome/browser/metrics/chrome_metrics_service_client.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 file_metrics_provider->RegisterSource( 173 file_metrics_provider->RegisterSource(
174 program_dir.AppendASCII(installer::kSetupHistogramAllocatorName), 174 program_dir.AppendASCII(installer::kSetupHistogramAllocatorName),
175 metrics::FileMetricsProvider::SOURCE_HISTOGRAMS_ATOMIC_DIR, 175 metrics::FileMetricsProvider::SOURCE_HISTOGRAMS_ATOMIC_DIR,
176 metrics::FileMetricsProvider::ASSOCIATE_CURRENT_RUN, 176 metrics::FileMetricsProvider::ASSOCIATE_CURRENT_RUN,
177 installer::kSetupHistogramAllocatorName); 177 installer::kSetupHistogramAllocatorName);
178 #endif 178 #endif
179 179
180 return file_metrics_provider; 180 return file_metrics_provider;
181 } 181 }
182 182
183 void CleanUpGlobalPersistentHistogramStorage() {
184 // If there is a global metrics file being updated on disk, mark it to be
185 // deleted when the process exits. A normal shutdown is almost complete
186 // so there is no benefit in keeping a file with no new data to be processed
187 // during the next startup sequence.
Ilya Sherman 2016/06/29 20:41:38 nit: I'd move this comment to be just above the fu
bcwhite 2016/06/30 22:56:12 Done.
188 base::GlobalHistogramAllocator* allocator =
189 base::GlobalHistogramAllocator::Get();
190 if (!allocator)
191 return;
192
193 const base::FilePath& path = allocator->GetPersistentLocation();
194 if (path.empty())
195 return;
196
197 // Open (with delete) and then immediately close the file by going out
Alexei Svitkine (slow) 2016/06/29 19:13:43 Nit: Wrapping is off? I think some words below sho
bcwhite 2016/06/30 22:56:12 One word.
198 // of scope. This is the only cross-platform safe way to delete a file
199 // that may be open elsewhere.
Ilya Sherman 2016/06/29 20:41:38 If the file is open elsewhere, is there anything t
bcwhite 2016/06/30 22:56:12 None. Existing opens will continue to operate nor
Ilya Sherman 2016/06/30 23:16:48 Ah, nice. I think this would be great to document
bcwhite 2016/07/11 18:06:39 Will do.
200 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ |
201 base::File::FLAG_DELETE_ON_CLOSE);
202 }
203
183 } // namespace 204 } // namespace
184 205
185 206
186 const char ChromeMetricsServiceClient::kBrowserMetricsName[] = "BrowserMetrics"; 207 const char ChromeMetricsServiceClient::kBrowserMetricsName[] = "BrowserMetrics";
187 208
188 ChromeMetricsServiceClient::ChromeMetricsServiceClient( 209 ChromeMetricsServiceClient::ChromeMetricsServiceClient(
189 metrics::MetricsStateManager* state_manager) 210 metrics::MetricsStateManager* state_manager)
190 : metrics_state_manager_(state_manager), 211 : metrics_state_manager_(state_manager),
191 #if defined(OS_CHROMEOS) 212 #if defined(OS_CHROMEOS)
192 chromeos_metrics_provider_(nullptr), 213 chromeos_metrics_provider_(nullptr),
(...skipping 11 matching lines...) Expand all
204 start_time_(base::TimeTicks::Now()), 225 start_time_(base::TimeTicks::Now()),
205 has_uploaded_profiler_data_(false), 226 has_uploaded_profiler_data_(false),
206 weak_ptr_factory_(this) { 227 weak_ptr_factory_(this) {
207 DCHECK(thread_checker_.CalledOnValidThread()); 228 DCHECK(thread_checker_.CalledOnValidThread());
208 RecordCommandLineMetrics(); 229 RecordCommandLineMetrics();
209 RegisterForNotifications(); 230 RegisterForNotifications();
210 } 231 }
211 232
212 ChromeMetricsServiceClient::~ChromeMetricsServiceClient() { 233 ChromeMetricsServiceClient::~ChromeMetricsServiceClient() {
213 DCHECK(thread_checker_.CalledOnValidThread()); 234 DCHECK(thread_checker_.CalledOnValidThread());
235 CleanUpGlobalPersistentHistogramStorage();
214 } 236 }
215 237
216 // static 238 // static
217 std::unique_ptr<ChromeMetricsServiceClient> ChromeMetricsServiceClient::Create( 239 std::unique_ptr<ChromeMetricsServiceClient> ChromeMetricsServiceClient::Create(
218 metrics::MetricsStateManager* state_manager, 240 metrics::MetricsStateManager* state_manager,
219 PrefService* local_state) { 241 PrefService* local_state) {
220 // Perform two-phase initialization so that |client->metrics_service_| only 242 // Perform two-phase initialization so that |client->metrics_service_| only
221 // receives pointers to fully constructed objects. 243 // receives pointers to fully constructed objects.
222 std::unique_ptr<ChromeMetricsServiceClient> client( 244 std::unique_ptr<ChromeMetricsServiceClient> client(
223 new ChromeMetricsServiceClient(state_manager)); 245 new ChromeMetricsServiceClient(state_manager));
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 } 732 }
711 } 733 }
712 734
713 void ChromeMetricsServiceClient::OnURLOpenedFromOmnibox(OmniboxLog* log) { 735 void ChromeMetricsServiceClient::OnURLOpenedFromOmnibox(OmniboxLog* log) {
714 metrics_service_->OnApplicationNotIdle(); 736 metrics_service_->OnApplicationNotIdle();
715 } 737 }
716 738
717 bool ChromeMetricsServiceClient::IsUMACellularUploadLogicEnabled() { 739 bool ChromeMetricsServiceClient::IsUMACellularUploadLogicEnabled() {
718 return metrics::IsCellularLogicEnabled(); 740 return metrics::IsCellularLogicEnabled();
719 } 741 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698