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

Unified Diff: base/metrics/persistent_histogram_allocator.cc

Issue 1891913002: Support saving browser metrics to disk and reading them during next run. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: back-out PrepareDifference change Created 4 years, 8 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: base/metrics/persistent_histogram_allocator.cc
diff --git a/base/metrics/persistent_histogram_allocator.cc b/base/metrics/persistent_histogram_allocator.cc
index 62e8cd6d68baa4ca567e97f3c095ce093969eb1c..87c3b192cb3b89ad54c2fd03262e7bcc0b1ac572 100644
--- a/base/metrics/persistent_histogram_allocator.cc
+++ b/base/metrics/persistent_histogram_allocator.cc
@@ -6,6 +6,7 @@
#include <memory>
+#include "base/files/important_file_writer.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
@@ -704,6 +705,32 @@ GlobalHistogramAllocator::ReleaseForTesting() {
return WrapUnique(histogram_allocator);
};
+void GlobalHistogramAllocator::SetPersistentLocation(const FilePath& location) {
+ persistent_location_ = location;
+}
+
+bool GlobalHistogramAllocator::WriteToPersistentLocation() {
+#if defined(OS_NACL)
+ // NACL doesn't support file operations, including ImportantFileWriter.
+ NOTREACHED();
+ return false;
+#else
+ // Stop if no destination is set, perhaps because it has not been enabled.
+ if (persistent_location_.empty())
Ilya Sherman 2016/04/20 17:10:33 I'd still prefer the location to be guaranteed to
bcwhite 2016/04/22 15:18:04 Enable/Disable: Done.
+ return false;
+
+ StringPiece contents(static_cast<const char*>(data()), used());
+ if (!ImportantFileWriter::WriteFileAtomically(persistent_location_,
+ contents)) {
+ LOG(ERROR) << "Could not write persistent histograms to file: "
+ << persistent_location_.value();
+ return false;
+ }
+
+ return true;
+#endif
+}
+
GlobalHistogramAllocator::GlobalHistogramAllocator(
std::unique_ptr<PersistentMemoryAllocator> memory)
: PersistentHistogramAllocator(std::move(memory)),

Powered by Google App Engine
This is Rietveld 408576698