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

Unified Diff: cc/test/test_shared_bitmap_manager.cc

Issue 761903003: Update from https://crrev.com/306655 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: 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
« no previous file with comments | « cc/test/solid_color_content_layer_client.cc ('k') | cc/test/test_web_graphics_context_3d.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/test/test_shared_bitmap_manager.cc
diff --git a/cc/test/test_shared_bitmap_manager.cc b/cc/test/test_shared_bitmap_manager.cc
index d7716ddcba855508456197509ebac421c855dfa1..933dcd25db4d8d3ce68b201c249863b7d5e93d8f 100644
--- a/cc/test/test_shared_bitmap_manager.cc
+++ b/cc/test/test_shared_bitmap_manager.cc
@@ -4,15 +4,41 @@
#include "cc/test/test_shared_bitmap_manager.h"
-#include "base/bind.h"
+#include "base/memory/shared_memory.h"
namespace cc {
-void FreeSharedBitmap(SharedBitmap* shared_bitmap) {
- delete shared_bitmap->memory();
-}
+namespace {
+class OwnedSharedBitmap : public SharedBitmap {
+ public:
+ OwnedSharedBitmap(scoped_ptr<base::SharedMemory> shared_memory,
+ const SharedBitmapId& id)
+ : SharedBitmap(static_cast<uint8*>(shared_memory->memory()), id),
+ shared_memory_(shared_memory.Pass()) {}
+
+ ~OwnedSharedBitmap() override {}
+
+ base::SharedMemory* memory() override { return shared_memory_.get(); }
+
+ private:
+ scoped_ptr<base::SharedMemory> shared_memory_;
+};
+
+class UnownedSharedBitmap : public SharedBitmap {
+ public:
+ UnownedSharedBitmap(base::SharedMemory* shared_memory,
+ const SharedBitmapId& id)
+ : SharedBitmap(static_cast<uint8*>(shared_memory->memory()), id),
+ shared_memory_(shared_memory) {}
+
+ ~UnownedSharedBitmap() override {}
+
+ base::SharedMemory* memory() override { return shared_memory_; }
-void IgnoreSharedBitmap(SharedBitmap* shared_bitmap) {}
+ private:
+ base::SharedMemory* shared_memory_;
+};
+} // namespace
TestSharedBitmapManager::TestSharedBitmapManager() {}
@@ -25,8 +51,7 @@ scoped_ptr<SharedBitmap> TestSharedBitmapManager::AllocateSharedBitmap(
memory->CreateAndMapAnonymous(size.GetArea() * 4);
SharedBitmapId id = SharedBitmap::GenerateId();
bitmap_map_[id] = memory.get();
- return make_scoped_ptr(
- new SharedBitmap(memory.release(), id, base::Bind(&FreeSharedBitmap)));
+ return make_scoped_ptr(new OwnedSharedBitmap(memory.Pass(), id));
}
scoped_ptr<SharedBitmap> TestSharedBitmapManager::GetSharedBitmapFromId(
@@ -35,8 +60,7 @@ scoped_ptr<SharedBitmap> TestSharedBitmapManager::GetSharedBitmapFromId(
base::AutoLock lock(lock_);
if (bitmap_map_.find(id) == bitmap_map_.end())
return nullptr;
- return make_scoped_ptr(
- new SharedBitmap(bitmap_map_[id], id, base::Bind(&IgnoreSharedBitmap)));
+ return make_scoped_ptr(new UnownedSharedBitmap(bitmap_map_[id], id));
}
scoped_ptr<SharedBitmap> TestSharedBitmapManager::GetBitmapForSharedMemory(
@@ -44,8 +68,7 @@ scoped_ptr<SharedBitmap> TestSharedBitmapManager::GetBitmapForSharedMemory(
base::AutoLock lock(lock_);
SharedBitmapId id = SharedBitmap::GenerateId();
bitmap_map_[id] = memory;
- return make_scoped_ptr(
- new SharedBitmap(memory, id, base::Bind(&IgnoreSharedBitmap)));
+ return make_scoped_ptr(new UnownedSharedBitmap(memory, id));
}
} // namespace cc
« no previous file with comments | « cc/test/solid_color_content_layer_client.cc ('k') | cc/test/test_web_graphics_context_3d.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698