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 1d5c0ef0e1c5d90175f8456469b67502f34e1d28..36dcb20eef9d6ab3fb8d43241623d32afa434515 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" |
| @@ -563,6 +564,32 @@ GlobalHistogramAllocator::ReleaseForTesting() { |
| return WrapUnique(histogram_allocator); |
| }; |
| +void GlobalHistogramAllocator::SetPersistentLocation(FilePath location) { |
| + persistent_location_ = std::move(location); |
| +} |
| + |
| +bool GlobalHistogramAllocator::WritePersistentLocation() { |
| +#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()) |
| + return false; |
|
Ilya Sherman
2016/04/19 00:57:46
Hmm. Could this be a DCHECK instead? That is, ar
bcwhite
2016/04/19 16:33:37
Right now, it's mostly unset because the experimen
|
| + |
| + 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)), |