Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(600)

Unified Diff: base/memory/discardable_memory_shmem_allocator.cc

Issue 807303002: base: Add free list implementation to browser-wide discardable memory system. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@discardable-shared-memory-ashmem
Patch Set: fix nits Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/memory/discardable_memory_shmem_allocator.cc
diff --git a/base/memory/discardable_memory_shmem_allocator.cc b/base/memory/discardable_memory_shmem_allocator.cc
index 78d15c1031e7713bc9e80915dd894942c4d755b6..1277c1a45cf226921791c3d96a694049ca7d2c2b 100644
--- a/base/memory/discardable_memory_shmem_allocator.cc
+++ b/base/memory/discardable_memory_shmem_allocator.cc
@@ -11,19 +11,39 @@
namespace base {
namespace {
+class DiscardableMemoryShmemChunkImpl : public DiscardableMemoryShmemChunk {
+ public:
+ explicit DiscardableMemoryShmemChunkImpl(
+ scoped_ptr<DiscardableSharedMemory> shared_memory)
+ : shared_memory_(shared_memory.Pass()) {}
+
+ // Overridden from DiscardableMemoryShmemChunk:
+ bool Lock() override { return shared_memory_->Lock(0, 0); }
+ void Unlock() override { shared_memory_->Unlock(0, 0); }
+ void* Memory() const override { return shared_memory_->memory(); }
+ bool IsMemoryResident() const override {
+ return shared_memory_->IsMemoryResident();
+ }
+
+ private:
+ scoped_ptr<DiscardableSharedMemory> shared_memory_;
+
+ DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryShmemChunkImpl);
+};
+
// Default allocator implementation that allocates in-process
// DiscardableSharedMemory instances.
class DiscardableMemoryShmemAllocatorImpl
: public DiscardableMemoryShmemAllocator {
public:
// Overridden from DiscardableMemoryShmemAllocator:
- virtual scoped_ptr<DiscardableSharedMemory>
- AllocateLockedDiscardableSharedMemory(size_t size) override {
+ virtual scoped_ptr<DiscardableMemoryShmemChunk>
+ AllocateLockedDiscardableMemory(size_t size) override {
scoped_ptr<DiscardableSharedMemory> memory(new DiscardableSharedMemory);
if (!memory->CreateAndMap(size))
- return scoped_ptr<DiscardableSharedMemory>();
+ return scoped_ptr<DiscardableMemoryShmemChunk>();
danakj 2014/12/18 21:40:50 return nullptr
reveman 2014/12/19 00:49:54 Done. Here and a few other places.
- return memory.Pass();
+ return make_scoped_ptr(new DiscardableMemoryShmemChunkImpl(memory.Pass()));
}
};

Powered by Google App Engine
This is Rietveld 408576698