Chromium Code Reviews| 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)), |