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

Side by Side Diff: content/common/host_shared_bitmap_manager.cc

Issue 1464383004: Add lock around modification of HostSharedBitmapManagerClient::owned_bitmaps_ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 unified diff | Download patch
« no previous file with comments | « content/common/host_shared_bitmap_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/common/host_shared_bitmap_manager.h" 5 #include "content/common/host_shared_bitmap_manager.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/trace_event/process_memory_dump.h" 10 #include "base/trace_event/process_memory_dump.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 manager_->ChildDeletedSharedBitmap(id); 67 manager_->ChildDeletedSharedBitmap(id);
68 } 68 }
69 69
70 void HostSharedBitmapManagerClient::AllocateSharedBitmapForChild( 70 void HostSharedBitmapManagerClient::AllocateSharedBitmapForChild(
71 base::ProcessHandle process_handle, 71 base::ProcessHandle process_handle,
72 size_t buffer_size, 72 size_t buffer_size,
73 const cc::SharedBitmapId& id, 73 const cc::SharedBitmapId& id,
74 base::SharedMemoryHandle* shared_memory_handle) { 74 base::SharedMemoryHandle* shared_memory_handle) {
75 manager_->AllocateSharedBitmapForChild(process_handle, buffer_size, id, 75 manager_->AllocateSharedBitmapForChild(process_handle, buffer_size, id,
76 shared_memory_handle); 76 shared_memory_handle);
77 owned_bitmaps_.insert(id); 77 if (*shared_memory_handle != base::SharedMemory::NULLHandle()) {
78 base::AutoLock lock(lock_);
79 owned_bitmaps_.insert(id);
80 }
78 } 81 }
79 82
80 void HostSharedBitmapManagerClient::ChildAllocatedSharedBitmap( 83 void HostSharedBitmapManagerClient::ChildAllocatedSharedBitmap(
81 size_t buffer_size, 84 size_t buffer_size,
82 const base::SharedMemoryHandle& handle, 85 const base::SharedMemoryHandle& handle,
83 base::ProcessHandle process_handle, 86 base::ProcessHandle process_handle,
84 const cc::SharedBitmapId& id) { 87 const cc::SharedBitmapId& id) {
85 manager_->ChildAllocatedSharedBitmap(buffer_size, handle, process_handle, id); 88 if (manager_->ChildAllocatedSharedBitmap(buffer_size, handle, process_handle,
86 owned_bitmaps_.insert(id); 89 id)) {
90 base::AutoLock lock(lock_);
91 owned_bitmaps_.insert(id);
92 }
87 } 93 }
88 94
89 void HostSharedBitmapManagerClient::ChildDeletedSharedBitmap( 95 void HostSharedBitmapManagerClient::ChildDeletedSharedBitmap(
90 const cc::SharedBitmapId& id) { 96 const cc::SharedBitmapId& id) {
91 manager_->ChildDeletedSharedBitmap(id); 97 manager_->ChildDeletedSharedBitmap(id);
92 owned_bitmaps_.erase(id); 98 {
99 base::AutoLock lock(lock_);
100 owned_bitmaps_.erase(id);
101 }
93 } 102 }
94 103
95 HostSharedBitmapManager::HostSharedBitmapManager() {} 104 HostSharedBitmapManager::HostSharedBitmapManager() {}
96 HostSharedBitmapManager::~HostSharedBitmapManager() { 105 HostSharedBitmapManager::~HostSharedBitmapManager() {
97 DCHECK(handle_map_.empty()); 106 DCHECK(handle_map_.empty());
98 } 107 }
99 108
100 HostSharedBitmapManager* HostSharedBitmapManager::current() { 109 HostSharedBitmapManager* HostSharedBitmapManager::current() {
101 return g_shared_memory_manager.Pointer(); 110 return g_shared_memory_manager.Pointer();
102 } 111 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 // Generate a global GUID used to share this allocation with renderer 178 // Generate a global GUID used to share this allocation with renderer
170 // processes. 179 // processes.
171 auto guid = cc::GetSharedBitmapGUIDForTracing(bitmap.first); 180 auto guid = cc::GetSharedBitmapGUIDForTracing(bitmap.first);
172 pmd->CreateSharedGlobalAllocatorDump(guid); 181 pmd->CreateSharedGlobalAllocatorDump(guid);
173 pmd->AddOwnershipEdge(dump->guid(), guid); 182 pmd->AddOwnershipEdge(dump->guid(), guid);
174 } 183 }
175 184
176 return true; 185 return true;
177 } 186 }
178 187
179 void HostSharedBitmapManager::ChildAllocatedSharedBitmap( 188 bool HostSharedBitmapManager::ChildAllocatedSharedBitmap(
180 size_t buffer_size, 189 size_t buffer_size,
181 const base::SharedMemoryHandle& handle, 190 const base::SharedMemoryHandle& handle,
182 base::ProcessHandle process_handle, 191 base::ProcessHandle process_handle,
183 const cc::SharedBitmapId& id) { 192 const cc::SharedBitmapId& id) {
184 base::AutoLock lock(lock_); 193 base::AutoLock lock(lock_);
185 if (handle_map_.find(id) != handle_map_.end()) 194 if (handle_map_.find(id) != handle_map_.end())
186 return; 195 return false;
187 scoped_refptr<BitmapData> data( 196 scoped_refptr<BitmapData> data(
188 new BitmapData(process_handle, buffer_size)); 197 new BitmapData(process_handle, buffer_size));
189 198
190 handle_map_[id] = data; 199 handle_map_[id] = data;
191 #if defined(OS_WIN) 200 #if defined(OS_WIN)
192 data->memory = make_scoped_ptr( 201 data->memory = make_scoped_ptr(
193 new base::SharedMemory(handle, false, data->process_handle)); 202 new base::SharedMemory(handle, false, data->process_handle));
194 #else 203 #else
195 data->memory = 204 data->memory =
196 make_scoped_ptr(new base::SharedMemory(handle, false)); 205 make_scoped_ptr(new base::SharedMemory(handle, false));
197 #endif 206 #endif
198 data->memory->Map(data->buffer_size); 207 data->memory->Map(data->buffer_size);
199 data->memory->Close(); 208 data->memory->Close();
209 return true;
200 } 210 }
201 211
202 void HostSharedBitmapManager::AllocateSharedBitmapForChild( 212 void HostSharedBitmapManager::AllocateSharedBitmapForChild(
203 base::ProcessHandle process_handle, 213 base::ProcessHandle process_handle,
204 size_t buffer_size, 214 size_t buffer_size,
205 const cc::SharedBitmapId& id, 215 const cc::SharedBitmapId& id,
206 base::SharedMemoryHandle* shared_memory_handle) { 216 base::SharedMemoryHandle* shared_memory_handle) {
207 base::AutoLock lock(lock_); 217 base::AutoLock lock(lock_);
208 if (handle_map_.find(id) != handle_map_.end()) { 218 if (handle_map_.find(id) != handle_map_.end()) {
209 *shared_memory_handle = base::SharedMemory::NULLHandle(); 219 *shared_memory_handle = base::SharedMemory::NULLHandle();
(...skipping 30 matching lines...) Expand all
240 return handle_map_.size(); 250 return handle_map_.size();
241 } 251 }
242 252
243 void HostSharedBitmapManager::FreeSharedMemoryFromMap( 253 void HostSharedBitmapManager::FreeSharedMemoryFromMap(
244 const cc::SharedBitmapId& id) { 254 const cc::SharedBitmapId& id) {
245 base::AutoLock lock(lock_); 255 base::AutoLock lock(lock_);
246 handle_map_.erase(id); 256 handle_map_.erase(id);
247 } 257 }
248 258
249 } // namespace content 259 } // namespace content
OLDNEW
« no previous file with comments | « content/common/host_shared_bitmap_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698