Commit 82b5c239 authored by jbauman's avatar jbauman Committed by Commit bot

Add lock around modification of HostSharedBitmapManagerClient::owned_bitmaps_

This can be modified from both the FILE and IO threads.

BUG=559865

Review URL: https://codereview.chromium.org/1464383004

Cr-Commit-Position: refs/heads/master@{#361272}
parent cf536a3c
...@@ -74,7 +74,10 @@ void HostSharedBitmapManagerClient::AllocateSharedBitmapForChild( ...@@ -74,7 +74,10 @@ void HostSharedBitmapManagerClient::AllocateSharedBitmapForChild(
base::SharedMemoryHandle* shared_memory_handle) { base::SharedMemoryHandle* shared_memory_handle) {
manager_->AllocateSharedBitmapForChild(process_handle, buffer_size, id, manager_->AllocateSharedBitmapForChild(process_handle, buffer_size, id,
shared_memory_handle); shared_memory_handle);
owned_bitmaps_.insert(id); if (*shared_memory_handle != base::SharedMemory::NULLHandle()) {
base::AutoLock lock(lock_);
owned_bitmaps_.insert(id);
}
} }
void HostSharedBitmapManagerClient::ChildAllocatedSharedBitmap( void HostSharedBitmapManagerClient::ChildAllocatedSharedBitmap(
...@@ -82,14 +85,20 @@ void HostSharedBitmapManagerClient::ChildAllocatedSharedBitmap( ...@@ -82,14 +85,20 @@ void HostSharedBitmapManagerClient::ChildAllocatedSharedBitmap(
const base::SharedMemoryHandle& handle, const base::SharedMemoryHandle& handle,
base::ProcessHandle process_handle, base::ProcessHandle process_handle,
const cc::SharedBitmapId& id) { const cc::SharedBitmapId& id) {
manager_->ChildAllocatedSharedBitmap(buffer_size, handle, process_handle, id); if (manager_->ChildAllocatedSharedBitmap(buffer_size, handle, process_handle,
owned_bitmaps_.insert(id); id)) {
base::AutoLock lock(lock_);
owned_bitmaps_.insert(id);
}
} }
void HostSharedBitmapManagerClient::ChildDeletedSharedBitmap( void HostSharedBitmapManagerClient::ChildDeletedSharedBitmap(
const cc::SharedBitmapId& id) { const cc::SharedBitmapId& id) {
manager_->ChildDeletedSharedBitmap(id); manager_->ChildDeletedSharedBitmap(id);
owned_bitmaps_.erase(id); {
base::AutoLock lock(lock_);
owned_bitmaps_.erase(id);
}
} }
HostSharedBitmapManager::HostSharedBitmapManager() {} HostSharedBitmapManager::HostSharedBitmapManager() {}
...@@ -176,14 +185,14 @@ bool HostSharedBitmapManager::OnMemoryDump( ...@@ -176,14 +185,14 @@ bool HostSharedBitmapManager::OnMemoryDump(
return true; return true;
} }
void HostSharedBitmapManager::ChildAllocatedSharedBitmap( bool HostSharedBitmapManager::ChildAllocatedSharedBitmap(
size_t buffer_size, size_t buffer_size,
const base::SharedMemoryHandle& handle, const base::SharedMemoryHandle& handle,
base::ProcessHandle process_handle, base::ProcessHandle process_handle,
const cc::SharedBitmapId& id) { const cc::SharedBitmapId& id) {
base::AutoLock lock(lock_); base::AutoLock lock(lock_);
if (handle_map_.find(id) != handle_map_.end()) if (handle_map_.find(id) != handle_map_.end())
return; return false;
scoped_refptr<BitmapData> data( scoped_refptr<BitmapData> data(
new BitmapData(process_handle, buffer_size)); new BitmapData(process_handle, buffer_size));
...@@ -195,8 +204,9 @@ void HostSharedBitmapManager::ChildAllocatedSharedBitmap( ...@@ -195,8 +204,9 @@ void HostSharedBitmapManager::ChildAllocatedSharedBitmap(
data->memory = data->memory =
make_scoped_ptr(new base::SharedMemory(handle, false)); make_scoped_ptr(new base::SharedMemory(handle, false));
#endif #endif
data->memory->Map(data->buffer_size); data->memory->Map(data->buffer_size);
data->memory->Close(); data->memory->Close();
return true;
} }
void HostSharedBitmapManager::AllocateSharedBitmapForChild( void HostSharedBitmapManager::AllocateSharedBitmapForChild(
......
...@@ -51,6 +51,9 @@ class CONTENT_EXPORT HostSharedBitmapManagerClient { ...@@ -51,6 +51,9 @@ class CONTENT_EXPORT HostSharedBitmapManagerClient {
private: private:
HostSharedBitmapManager* manager_; HostSharedBitmapManager* manager_;
// Lock must be held around access to owned_bitmaps_.
base::Lock lock_;
base::hash_set<cc::SharedBitmapId> owned_bitmaps_; base::hash_set<cc::SharedBitmapId> owned_bitmaps_;
DISALLOW_COPY_AND_ASSIGN(HostSharedBitmapManagerClient); DISALLOW_COPY_AND_ASSIGN(HostSharedBitmapManagerClient);
...@@ -88,7 +91,7 @@ class CONTENT_EXPORT HostSharedBitmapManager ...@@ -88,7 +91,7 @@ class CONTENT_EXPORT HostSharedBitmapManager
size_t buffer_size, size_t buffer_size,
const cc::SharedBitmapId& id, const cc::SharedBitmapId& id,
base::SharedMemoryHandle* shared_memory_handle); base::SharedMemoryHandle* shared_memory_handle);
void ChildAllocatedSharedBitmap(size_t buffer_size, bool ChildAllocatedSharedBitmap(size_t buffer_size,
const base::SharedMemoryHandle& handle, const base::SharedMemoryHandle& handle,
base::ProcessHandle process_handle, base::ProcessHandle process_handle,
const cc::SharedBitmapId& id); const cc::SharedBitmapId& id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment