Chromium Code Reviews| Index: base/metrics/persistent_memory_allocator.h |
| diff --git a/base/metrics/persistent_memory_allocator.h b/base/metrics/persistent_memory_allocator.h |
| index 65d5a0eccbe7c26a350d7b7da2c6268aaf49d1d6..42bff8499bae4f66125806cfbe2369bda4cfb4d5 100644 |
| --- a/base/metrics/persistent_memory_allocator.h |
| +++ b/base/metrics/persistent_memory_allocator.h |
| @@ -19,6 +19,7 @@ namespace base { |
| class HistogramBase; |
| class MemoryMappedFile; |
| +class SharedMemory; |
| // Simple allocator for pieces of a memory block that may be persistent |
| // to some storage or shared across multiple processes. This class resides |
| @@ -308,19 +309,42 @@ class BASE_EXPORT LocalPersistentMemoryAllocator |
| }; |
| +// This allocator takes a shared-memory object and performs allocation from |
| +// it. The memory must be previously mapped via Map() or MapAt(). The allocator |
| +// takes ownership of the memory object. |
| +class BASE_EXPORT SharedPersistentMemoryAllocator |
| + : public PersistentMemoryAllocator { |
| + public: |
| + SharedPersistentMemoryAllocator(scoped_ptr<SharedMemory> mem, uint64_t id, |
|
Alexei Svitkine (slow)
2016/02/05 21:54:02
Nit: 1 param per line.
|mem| -> |memory|
bcwhite
2016/02/06 04:26:11
Done.
|
| + const std::string& name, bool read_only); |
| + ~SharedPersistentMemoryAllocator() override; |
| + |
| + SharedMemory* GetSharedMemory() { return shared_memory_.get(); } |
|
Alexei Svitkine (slow)
2016/02/05 21:54:02
Nit: Either a method is trivial and should be name
bcwhite
2016/02/06 04:26:11
Done.
|
| + |
| + // Ensure that the memory isn't so invalid that it won't crash when passing it |
| + // to the allocator. This doesn't guarantee the data is valid, just that it |
| + // won't cause the program to abort. The existing IsCorrupt() call will handle |
| + // the rest. |
| + static bool IsSharedMemoryAcceptable(const SharedMemory& mem); |
|
Alexei Svitkine (slow)
2016/02/05 21:54:02
Hmm, it's hard to understand Acceptable without re
bcwhite
2016/02/06 04:26:11
It doesn't check that it's valid, just that it's a
|
| + |
| + private: |
| + scoped_ptr<SharedMemory> shared_memory_; |
|
Alexei Svitkine (slow)
2016/02/05 21:54:02
DISALLOW_COPY_AND_ASSIGN()
bcwhite
2016/02/06 04:26:11
I always forget that... below, too.
|
| +}; |
| + |
| + |
| // This allocator takes a memory-mapped file object and performs allocation |
| // from it. The allocator takes ownership of the file object. Only read access |
| // is provided due to limitions of the MemoryMappedFile class. |
| class BASE_EXPORT FilePersistentMemoryAllocator |
| : public PersistentMemoryAllocator { |
| public: |
| - FilePersistentMemoryAllocator(MemoryMappedFile* file, uint64_t id, |
| + FilePersistentMemoryAllocator(scoped_ptr<MemoryMappedFile> file, uint64_t id, |
| const std::string& name); |
| ~FilePersistentMemoryAllocator() override; |
| // Ensure that the file isn't so invalid that it won't crash when passing it |
| // to the allocator. This doesn't guarantee the file is valid, just that it |
| - // won't cause program to abort. The existing IsCorrupt() call will handle |
| + // won't cause the program to abort. The existing IsCorrupt() call will handle |
| // the rest. |
| static bool IsFileAcceptable(const MemoryMappedFile& file); |