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

Unified 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, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/metrics/chrome_metrics_service_client.cc
diff --git a/chrome/browser/metrics/chrome_metrics_service_client.cc b/chrome/browser/metrics/chrome_metrics_service_client.cc
index c867c27f30fc36fd14ce8270a654f4d426cd6ec4..20f1afd71ac9cd0f3487c60bd17931ddc4f8aaae 100644
--- a/chrome/browser/metrics/chrome_metrics_service_client.cc
+++ b/chrome/browser/metrics/chrome_metrics_service_client.cc
@@ -180,6 +180,27 @@ CreateInstallerFileMetricsProvider(bool metrics_reporting_enabled) {
return file_metrics_provider;
}
+void CleanUpGlobalPersistentHistogramStorage() {
+ // If there is a global metrics file being updated on disk, mark it to be
+ // deleted when the process exits. A normal shutdown is almost complete
+ // so there is no benefit in keeping a file with no new data to be processed
+ // 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.
+ base::GlobalHistogramAllocator* allocator =
+ base::GlobalHistogramAllocator::Get();
+ if (!allocator)
+ return;
+
+ const base::FilePath& path = allocator->GetPersistentLocation();
+ if (path.empty())
+ return;
+
+ // 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.
+ // of scope. This is the only cross-platform safe way to delete a file
+ // 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.
+ base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ |
+ base::File::FLAG_DELETE_ON_CLOSE);
+}
+
} // namespace
@@ -211,6 +232,7 @@ ChromeMetricsServiceClient::ChromeMetricsServiceClient(
ChromeMetricsServiceClient::~ChromeMetricsServiceClient() {
DCHECK(thread_checker_.CalledOnValidThread());
+ CleanUpGlobalPersistentHistogramStorage();
}
// static

Powered by Google App Engine
This is Rietveld 408576698