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

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: rebase 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 8b9157f583adde720a7412510979a7a99ac7a5df..fdd68673420e84eafe67c5cfc4a90b955eea5714 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:
- scoped_ptr<DiscardableSharedMemory> AllocateLockedDiscardableSharedMemory(
- size_t size) override {
+ scoped_ptr<DiscardableMemoryShmemChunk>
+ AllocateLockedDiscardableMemory(size_t size) override {
scoped_ptr<DiscardableSharedMemory> memory(new DiscardableSharedMemory);
if (!memory->CreateAndMap(size))
- return scoped_ptr<DiscardableSharedMemory>();
+ return nullptr;
- return memory.Pass();
+ return make_scoped_ptr(new DiscardableMemoryShmemChunkImpl(memory.Pass()));
}
};
« no previous file with comments | « base/memory/discardable_memory_shmem_allocator.h ('k') | content/child/child_discardable_shared_memory_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698