OLD | NEW |
---|---|
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 | 56 |
57 base::LazyInstance<HostSharedBitmapManager> g_shared_memory_manager = | 57 base::LazyInstance<HostSharedBitmapManager> g_shared_memory_manager = |
58 LAZY_INSTANCE_INITIALIZER; | 58 LAZY_INSTANCE_INITIALIZER; |
59 | 59 |
60 HostSharedBitmapManagerClient::HostSharedBitmapManagerClient( | 60 HostSharedBitmapManagerClient::HostSharedBitmapManagerClient( |
61 HostSharedBitmapManager* manager) | 61 HostSharedBitmapManager* manager) |
62 : manager_(manager) { | 62 : manager_(manager) { |
63 } | 63 } |
64 | 64 |
65 HostSharedBitmapManagerClient::~HostSharedBitmapManagerClient() { | 65 HostSharedBitmapManagerClient::~HostSharedBitmapManagerClient() { |
66 base::AutoLock lock(lock_); | |
piman
2015/11/24 03:00:37
nit: I think you don't need this one (only 1 threa
| |
66 for (const auto& id : owned_bitmaps_) | 67 for (const auto& id : owned_bitmaps_) |
67 manager_->ChildDeletedSharedBitmap(id); | 68 manager_->ChildDeletedSharedBitmap(id); |
68 } | 69 } |
69 | 70 |
70 void HostSharedBitmapManagerClient::AllocateSharedBitmapForChild( | 71 void HostSharedBitmapManagerClient::AllocateSharedBitmapForChild( |
71 base::ProcessHandle process_handle, | 72 base::ProcessHandle process_handle, |
72 size_t buffer_size, | 73 size_t buffer_size, |
73 const cc::SharedBitmapId& id, | 74 const cc::SharedBitmapId& id, |
74 base::SharedMemoryHandle* shared_memory_handle) { | 75 base::SharedMemoryHandle* shared_memory_handle) { |
75 manager_->AllocateSharedBitmapForChild(process_handle, buffer_size, id, | 76 manager_->AllocateSharedBitmapForChild(process_handle, buffer_size, id, |
76 shared_memory_handle); | 77 shared_memory_handle); |
77 owned_bitmaps_.insert(id); | 78 if (*shared_memory_handle != base::SharedMemory::NULLHandle()) { |
79 base::AutoLock lock(lock_); | |
80 owned_bitmaps_.insert(id); | |
81 } | |
78 } | 82 } |
79 | 83 |
80 void HostSharedBitmapManagerClient::ChildAllocatedSharedBitmap( | 84 void HostSharedBitmapManagerClient::ChildAllocatedSharedBitmap( |
81 size_t buffer_size, | 85 size_t buffer_size, |
82 const base::SharedMemoryHandle& handle, | 86 const base::SharedMemoryHandle& handle, |
83 base::ProcessHandle process_handle, | 87 base::ProcessHandle process_handle, |
84 const cc::SharedBitmapId& id) { | 88 const cc::SharedBitmapId& id) { |
85 manager_->ChildAllocatedSharedBitmap(buffer_size, handle, process_handle, id); | 89 if (manager_->ChildAllocatedSharedBitmap(buffer_size, handle, process_handle, |
86 owned_bitmaps_.insert(id); | 90 id)) { |
91 base::AutoLock lock(lock_); | |
92 owned_bitmaps_.insert(id); | |
93 } | |
87 } | 94 } |
88 | 95 |
89 void HostSharedBitmapManagerClient::ChildDeletedSharedBitmap( | 96 void HostSharedBitmapManagerClient::ChildDeletedSharedBitmap( |
90 const cc::SharedBitmapId& id) { | 97 const cc::SharedBitmapId& id) { |
91 manager_->ChildDeletedSharedBitmap(id); | 98 manager_->ChildDeletedSharedBitmap(id); |
92 owned_bitmaps_.erase(id); | 99 { |
100 base::AutoLock lock(lock_); | |
101 owned_bitmaps_.erase(id); | |
102 } | |
93 } | 103 } |
94 | 104 |
95 HostSharedBitmapManager::HostSharedBitmapManager() {} | 105 HostSharedBitmapManager::HostSharedBitmapManager() {} |
96 HostSharedBitmapManager::~HostSharedBitmapManager() { | 106 HostSharedBitmapManager::~HostSharedBitmapManager() { |
97 DCHECK(handle_map_.empty()); | 107 DCHECK(handle_map_.empty()); |
98 } | 108 } |
99 | 109 |
100 HostSharedBitmapManager* HostSharedBitmapManager::current() { | 110 HostSharedBitmapManager* HostSharedBitmapManager::current() { |
101 return g_shared_memory_manager.Pointer(); | 111 return g_shared_memory_manager.Pointer(); |
102 } | 112 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 // Generate a global GUID used to share this allocation with renderer | 179 // Generate a global GUID used to share this allocation with renderer |
170 // processes. | 180 // processes. |
171 auto guid = cc::GetSharedBitmapGUIDForTracing(bitmap.first); | 181 auto guid = cc::GetSharedBitmapGUIDForTracing(bitmap.first); |
172 pmd->CreateSharedGlobalAllocatorDump(guid); | 182 pmd->CreateSharedGlobalAllocatorDump(guid); |
173 pmd->AddOwnershipEdge(dump->guid(), guid); | 183 pmd->AddOwnershipEdge(dump->guid(), guid); |
174 } | 184 } |
175 | 185 |
176 return true; | 186 return true; |
177 } | 187 } |
178 | 188 |
179 void HostSharedBitmapManager::ChildAllocatedSharedBitmap( | 189 bool HostSharedBitmapManager::ChildAllocatedSharedBitmap( |
180 size_t buffer_size, | 190 size_t buffer_size, |
181 const base::SharedMemoryHandle& handle, | 191 const base::SharedMemoryHandle& handle, |
182 base::ProcessHandle process_handle, | 192 base::ProcessHandle process_handle, |
183 const cc::SharedBitmapId& id) { | 193 const cc::SharedBitmapId& id) { |
184 base::AutoLock lock(lock_); | 194 base::AutoLock lock(lock_); |
185 if (handle_map_.find(id) != handle_map_.end()) | 195 if (handle_map_.find(id) != handle_map_.end()) |
186 return; | 196 return false; |
187 scoped_refptr<BitmapData> data( | 197 scoped_refptr<BitmapData> data( |
188 new BitmapData(process_handle, buffer_size)); | 198 new BitmapData(process_handle, buffer_size)); |
189 | 199 |
190 handle_map_[id] = data; | 200 handle_map_[id] = data; |
191 #if defined(OS_WIN) | 201 #if defined(OS_WIN) |
192 data->memory = make_scoped_ptr( | 202 data->memory = make_scoped_ptr( |
193 new base::SharedMemory(handle, false, data->process_handle)); | 203 new base::SharedMemory(handle, false, data->process_handle)); |
194 #else | 204 #else |
195 data->memory = | 205 data->memory = |
196 make_scoped_ptr(new base::SharedMemory(handle, false)); | 206 make_scoped_ptr(new base::SharedMemory(handle, false)); |
197 #endif | 207 #endif |
198 data->memory->Map(data->buffer_size); | 208 data->memory->Map(data->buffer_size); |
199 data->memory->Close(); | 209 data->memory->Close(); |
210 return true; | |
200 } | 211 } |
201 | 212 |
202 void HostSharedBitmapManager::AllocateSharedBitmapForChild( | 213 void HostSharedBitmapManager::AllocateSharedBitmapForChild( |
203 base::ProcessHandle process_handle, | 214 base::ProcessHandle process_handle, |
204 size_t buffer_size, | 215 size_t buffer_size, |
205 const cc::SharedBitmapId& id, | 216 const cc::SharedBitmapId& id, |
206 base::SharedMemoryHandle* shared_memory_handle) { | 217 base::SharedMemoryHandle* shared_memory_handle) { |
207 base::AutoLock lock(lock_); | 218 base::AutoLock lock(lock_); |
208 if (handle_map_.find(id) != handle_map_.end()) { | 219 if (handle_map_.find(id) != handle_map_.end()) { |
209 *shared_memory_handle = base::SharedMemory::NULLHandle(); | 220 *shared_memory_handle = base::SharedMemory::NULLHandle(); |
(...skipping 30 matching lines...) Expand all Loading... | |
240 return handle_map_.size(); | 251 return handle_map_.size(); |
241 } | 252 } |
242 | 253 |
243 void HostSharedBitmapManager::FreeSharedMemoryFromMap( | 254 void HostSharedBitmapManager::FreeSharedMemoryFromMap( |
244 const cc::SharedBitmapId& id) { | 255 const cc::SharedBitmapId& id) { |
245 base::AutoLock lock(lock_); | 256 base::AutoLock lock(lock_); |
246 handle_map_.erase(id); | 257 handle_map_.erase(id); |
247 } | 258 } |
248 | 259 |
249 } // namespace content | 260 } // namespace content |
OLD | NEW |