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 c4d8c95d68da1bf7f36eba9c8538e3d790728486..8bb09cc9055d3d979a68ca36fe708cde38c993b1 100644 |
| --- a/base/metrics/persistent_histogram_allocator.cc |
| +++ b/base/metrics/persistent_histogram_allocator.cc |
| @@ -686,7 +686,7 @@ void GlobalHistogramAllocator::CreateWithLocalMemory( |
| #if !defined(OS_NACL) |
| // static |
| -void GlobalHistogramAllocator::CreateWithFile( |
| +bool GlobalHistogramAllocator::CreateWithFile( |
| const FilePath& file_path, |
| size_t size, |
| uint64_t id, |
| @@ -706,14 +706,53 @@ void GlobalHistogramAllocator::CreateWithFile( |
| if (!mmfile->IsValid() || |
| !FilePersistentMemoryAllocator::IsFileAcceptable(*mmfile, true)) { |
| NOTREACHED(); |
| - return; |
| + return false; |
| } |
| Set(WrapUnique( |
| new GlobalHistogramAllocator(MakeUnique<FilePersistentMemoryAllocator>( |
| std::move(mmfile), size, id, name, false)))); |
| + Get()->SetPersistentLocation(file_path); |
| + return true; |
| +} |
| + |
| +// static |
| +bool GlobalHistogramAllocator::CreateWithActiveFile(const FilePath& base_path, |
| + const FilePath& active_path, |
| + size_t size, |
| + uint64_t id, |
| + StringPiece name) { |
| + if (!base::ReplaceFile(active_path, base_path, nullptr)) |
| + base::DeleteFile(base_path, /*recursive=*/false); |
| + |
| + return base::GlobalHistogramAllocator::CreateWithFile(active_path, size, id, |
| + name); |
| } |
| -#endif |
| + |
| +// static |
| +bool GlobalHistogramAllocator::CreateWithActiveFileInDir(const FilePath& dir, |
| + size_t size, |
| + uint64_t id, |
| + StringPiece name) { |
| + FilePath base_path, active_path; |
| + ConstructFilePaths(dir, name, &base_path, &active_path); |
| + return CreateWithActiveFile(base_path, active_path, size, id, name); |
| +} |
| + |
| +// static |
| +void GlobalHistogramAllocator::ConstructFilePaths(const FilePath& dir, |
| + StringPiece name, |
| + FilePath* out_base_path, |
| + FilePath* out_active_path) { |
| + *out_base_path = dir.AppendASCII(name) |
|
Alexei Svitkine (slow)
2016/09/15 16:49:44
Nit: I'd prefer to wrap after the =
But you can k
scottmg
2016/09/15 17:41:13
Yeah, this is clang-format output. It doesn't quit
|
| + .AddExtension(PersistentMemoryAllocator::kFileExtension); |
| + if (out_active_path) { |
| + *out_active_path = |
| + dir.AppendASCII(name.as_string() + std::string("-active")) |
| + .AddExtension(PersistentMemoryAllocator::kFileExtension); |
| + } |
| +} |
| +#endif // !OS_NACL |
|
Alexei Svitkine (slow)
2016/09/15 16:49:44
Nit: !defined(OS_NACL)
scottmg
2016/09/15 17:41:13
Done.
|
| // static |
| void GlobalHistogramAllocator::CreateWithSharedMemory( |
| @@ -837,6 +876,18 @@ bool GlobalHistogramAllocator::WriteToPersistentLocation() { |
| #endif |
| } |
| +void GlobalHistogramAllocator::DeletePersistentLocation() { |
| + if (persistent_location_.empty()) |
| + return; |
| + |
| + // Open (with delete) and then immediately close the file by going out of |
| + // scope. This is the only cross-platform safe way to delete a file that may |
| + // be open elsewhere. Open handles will continue to operate normally but |
| + // new opens will not be possible. |
| + File file(persistent_location_, |
|
Alexei Svitkine (slow)
2016/09/15 16:49:44
Is this supported for NACL builds? Seems like it s
bcwhite
2016/09/15 17:07:48
Heh. I told him to move it in here along-side Wri
scottmg
2016/09/15 17:41:13
#ifdef'd for now to match and fix the build. As Br
Alexei Svitkine (slow)
2016/09/15 17:49:16
Sure, I'm ok with that being explored in a separat
bcwhite
2016/09/15 17:56:33
If I remember correctly, it's only the .cc file th
|
| + File::FLAG_OPEN | File::FLAG_READ | File::FLAG_DELETE_ON_CLOSE); |
| +} |
| + |
| GlobalHistogramAllocator::GlobalHistogramAllocator( |
| std::unique_ptr<PersistentMemoryAllocator> memory) |
| : PersistentHistogramAllocator(std::move(memory)), |