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..8a70d644000267c31f31cff395d1d2552831cff1 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,24 +309,49 @@ 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> memory, uint64_t id, |
+ const std::string& name, bool read_only); |
+ ~SharedPersistentMemoryAllocator() override; |
+ |
+ SharedMemory* shared_memory() { return shared_memory_.get(); } |
+ |
+ // 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& memory); |
Alexei Svitkine (slow)
2016/02/09 19:58:44
I understand why you don't want to use IsValid() b
bcwhite
2016/02/10 16:43:53
Acknowledged.
|
+ |
+ private: |
+ scoped_ptr<SharedMemory> shared_memory_; |
+ DISALLOW_COPY_AND_ASSIGN(SharedPersistentMemoryAllocator); |
+}; |
+ |
+ |
// 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); |
private: |
scoped_ptr<MemoryMappedFile> mapped_file_; |
+ DISALLOW_COPY_AND_ASSIGN(FilePersistentMemoryAllocator); |
Alexei Svitkine (slow)
2016/02/09 19:58:44
Nit: Put an empty line above these lines.
bcwhite
2016/02/10 16:43:53
Done.
|
}; |
} // namespace base |