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

Unified Diff: content/common/host_shared_bitmap_manager.cc

Issue 955523005: Add HostSharedBitmapManagerClient to organize bitmaps coming from renderers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months 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 | « content/common/host_shared_bitmap_manager.h ('k') | content/common/host_shared_bitmap_manager_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/host_shared_bitmap_manager.cc
diff --git a/content/common/host_shared_bitmap_manager.cc b/content/common/host_shared_bitmap_manager.cc
index 778260b0f7ef96d4b76b5ce99b74ca92cc46f900..b95820c2f32c44867d7b3abba5f2b05d70f1d00d 100644
--- a/content/common/host_shared_bitmap_manager.cc
+++ b/content/common/host_shared_bitmap_manager.cc
@@ -55,6 +55,41 @@ class HostSharedBitmap : public cc::SharedBitmap {
base::LazyInstance<HostSharedBitmapManager> g_shared_memory_manager =
LAZY_INSTANCE_INITIALIZER;
+HostSharedBitmapManagerClient::HostSharedBitmapManagerClient(
+ HostSharedBitmapManager* manager)
+ : manager_(manager) {
+}
+
+HostSharedBitmapManagerClient::~HostSharedBitmapManagerClient() {
+ for (const auto& id : owned_bitmaps_)
+ manager_->ChildDeletedSharedBitmap(id);
+}
+
+void HostSharedBitmapManagerClient::AllocateSharedBitmapForChild(
+ base::ProcessHandle process_handle,
+ size_t buffer_size,
+ const cc::SharedBitmapId& id,
+ base::SharedMemoryHandle* shared_memory_handle) {
+ manager_->AllocateSharedBitmapForChild(process_handle, buffer_size, id,
+ shared_memory_handle);
+ owned_bitmaps_.insert(id);
+}
+
+void HostSharedBitmapManagerClient::ChildAllocatedSharedBitmap(
+ size_t buffer_size,
+ const base::SharedMemoryHandle& handle,
+ base::ProcessHandle process_handle,
+ const cc::SharedBitmapId& id) {
+ manager_->ChildAllocatedSharedBitmap(buffer_size, handle, process_handle, id);
+ owned_bitmaps_.insert(id);
+}
+
+void HostSharedBitmapManagerClient::ChildDeletedSharedBitmap(
+ const cc::SharedBitmapId& id) {
+ manager_->ChildDeletedSharedBitmap(id);
+ owned_bitmaps_.erase(id);
+}
+
HostSharedBitmapManager::HostSharedBitmapManager() {}
HostSharedBitmapManager::~HostSharedBitmapManager() {
DCHECK(handle_map_.empty());
@@ -123,7 +158,6 @@ void HostSharedBitmapManager::ChildAllocatedSharedBitmap(
new BitmapData(process_handle, buffer_size));
handle_map_[id] = data;
- process_map_[process_handle].insert(id);
#if defined(OS_WIN)
data->memory = make_scoped_ptr(
new base::SharedMemory(handle, false, data->process_handle));
@@ -157,7 +191,6 @@ void HostSharedBitmapManager::AllocateSharedBitmapForChild(
data->memory = shared_memory.Pass();
handle_map_[id] = data;
- process_map_[process_handle].insert(id);
if (!data->memory->ShareToProcess(process_handle, shared_memory_handle)) {
LOG(ERROR) << "Cannot share shared memory buffer";
*shared_memory_handle = base::SharedMemory::NULLHandle();
@@ -169,29 +202,7 @@ void HostSharedBitmapManager::AllocateSharedBitmapForChild(
void HostSharedBitmapManager::ChildDeletedSharedBitmap(
const cc::SharedBitmapId& id) {
base::AutoLock lock(lock_);
- BitmapMap::iterator it = handle_map_.find(id);
- if (it == handle_map_.end())
- return;
- base::hash_set<cc::SharedBitmapId>& res =
- process_map_[it->second->process_handle];
- res.erase(id);
- handle_map_.erase(it);
-}
-
-void HostSharedBitmapManager::ProcessRemoved(
- base::ProcessHandle process_handle) {
- base::AutoLock lock(lock_);
- ProcessMap::iterator proc_it = process_map_.find(process_handle);
- if (proc_it == process_map_.end())
- return;
- base::hash_set<cc::SharedBitmapId>& res = proc_it->second;
-
- for (base::hash_set<cc::SharedBitmapId>::iterator it = res.begin();
- it != res.end();
- ++it) {
- handle_map_.erase(*it);
- }
- process_map_.erase(proc_it);
+ handle_map_.erase(id);
}
size_t HostSharedBitmapManager::AllocatedBitmapCount() const {
« no previous file with comments | « content/common/host_shared_bitmap_manager.h ('k') | content/common/host_shared_bitmap_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698