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 13b51b1dba641af0a59078aa763bbe5546aba198..a81a3a052a3834679a50c2cf3f357e420d85264e 100644 |
| --- a/base/metrics/persistent_histogram_allocator.cc |
| +++ b/base/metrics/persistent_histogram_allocator.cc |
| @@ -21,6 +21,7 @@ |
| #include "base/metrics/sparse_histogram.h" |
| #include "base/metrics/statistics_recorder.h" |
| #include "base/pickle.h" |
| +#include "base/strings/stringprintf.h" |
| #include "base/synchronization/lock.h" |
| namespace base { |
| @@ -819,19 +820,43 @@ void GlobalHistogramAllocator::ConstructFilePaths(const FilePath& dir, |
| FilePath* out_base_path, |
| FilePath* out_active_path, |
| FilePath* out_spare_path) { |
| - if (out_base_path) { |
| - *out_base_path = dir.AppendASCII(name).AddExtension( |
| - PersistentMemoryAllocator::kFileExtension); |
| + if (out_base_path) |
| + *out_base_path = MakeMetricsFilePath(dir, name); |
| + |
| + if (out_active_path) { |
| + *out_active_path = |
| + MakeMetricsFilePath(dir, name.as_string() + std::string("-active")); |
| } |
| + |
| + if (out_spare_path) { |
| + *out_spare_path = |
| + MakeMetricsFilePath(dir, name.as_string() + std::string("-spare")); |
| + } |
| +} |
| + |
| +// static |
| +void GlobalHistogramAllocator::ConstructFilePathsForUploadDir( |
| + const FilePath& active_dir, |
| + const FilePath& upload_dir, |
| + const std::string& name, |
| + FilePath* out_upload_path, |
| + FilePath* out_active_path, |
| + FilePath* out_spare_path) { |
| + if (out_upload_path) { |
| + std::string name_stamp = |
| + StringPrintf("%s-%X", name.c_str(), |
| + static_cast<unsigned int>(Time::Now().ToTimeT())); |
| + *out_upload_path = MakeMetricsFilePath(upload_dir, name_stamp); |
| + } |
| + |
| if (out_active_path) { |
| *out_active_path = |
| - dir.AppendASCII(name.as_string() + std::string("-active")) |
| - .AddExtension(PersistentMemoryAllocator::kFileExtension); |
| + MakeMetricsFilePath(active_dir, name + std::string("-active")); |
|
Alexei Svitkine (slow)
2017/06/28 19:19:09
Nit: I think name.append("-active") might be more
bcwhite
2017/06/28 19:29:51
I can't append() because |name| is a "const" ref.
Alexei Svitkine (slow)
2017/06/28 19:33:00
Ah right, it doesn't work in this case. It should
bcwhite
2017/06/28 19:46:15
Done.
|
| } |
| + |
| if (out_spare_path) { |
| *out_spare_path = |
| - dir.AppendASCII(name.as_string() + std::string("-spare")) |
| - .AddExtension(PersistentMemoryAllocator::kFileExtension); |
| + MakeMetricsFilePath(active_dir, name + std::string("-spare")); |
| } |
| } |
| @@ -1021,4 +1046,11 @@ void GlobalHistogramAllocator::ImportHistogramsToStatisticsRecorder() { |
| } |
| } |
| +// static |
| +FilePath GlobalHistogramAllocator::MakeMetricsFilePath(const FilePath& dir, |
| + StringPiece name) { |
| + return dir.AppendASCII(name).AddExtension( |
| + PersistentMemoryAllocator::kFileExtension); |
| +} |
| + |
| } // namespace base |