| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/child/child_shared_bitmap_manager.h" | 5 #include "content/child/child_shared_bitmap_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 base::SharedMemoryHandle handle; | 110 base::SharedMemoryHandle handle; |
| 111 bool send_success = | 111 bool send_success = |
| 112 sender_->Send(new ChildProcessHostMsg_SyncAllocateSharedBitmap( | 112 sender_->Send(new ChildProcessHostMsg_SyncAllocateSharedBitmap( |
| 113 memory_size, id, &handle)); | 113 memory_size, id, &handle)); |
| 114 if (!send_success) { | 114 if (!send_success) { |
| 115 // Callers of this method are not prepared to handle failures during | 115 // Callers of this method are not prepared to handle failures during |
| 116 // shutdown. Exit immediately. This is expected behavior during the Fast | 116 // shutdown. Exit immediately. This is expected behavior during the Fast |
| 117 // Shutdown path, so use EXIT_SUCCESS. https://crbug.com/615121. | 117 // Shutdown path, so use EXIT_SUCCESS. https://crbug.com/615121. |
| 118 exit(EXIT_SUCCESS); | 118 exit(EXIT_SUCCESS); |
| 119 } | 119 } |
| 120 memory = base::WrapUnique(new base::SharedMemory(handle, false)); | 120 memory = base::MakeUnique<base::SharedMemory>(handle, false); |
| 121 if (!memory->Map(memory_size)) | 121 if (!memory->Map(memory_size)) |
| 122 CollectMemoryUsageAndDie(size, memory_size); | 122 CollectMemoryUsageAndDie(size, memory_size); |
| 123 #else | 123 #else |
| 124 bool out_of_memory; | 124 bool out_of_memory; |
| 125 memory = ChildThreadImpl::AllocateSharedMemory(memory_size, sender_.get(), | 125 memory = ChildThreadImpl::AllocateSharedMemory(memory_size, sender_.get(), |
| 126 &out_of_memory); | 126 &out_of_memory); |
| 127 if (!memory) { | 127 if (!memory) { |
| 128 if (out_of_memory) { | 128 if (out_of_memory) { |
| 129 CollectMemoryUsageAndDie(size, memory_size); | 129 CollectMemoryUsageAndDie(size, memory_size); |
| 130 } else { | 130 } else { |
| 131 // Callers of this method are not prepared to handle failures during | 131 // Callers of this method are not prepared to handle failures during |
| 132 // shutdown. Exit immediately. This is expected behavior during the Fast | 132 // shutdown. Exit immediately. This is expected behavior during the Fast |
| 133 // Shutdown path, so use EXIT_SUCCESS. https://crbug.com/615121. | 133 // Shutdown path, so use EXIT_SUCCESS. https://crbug.com/615121. |
| 134 exit(EXIT_SUCCESS); | 134 exit(EXIT_SUCCESS); |
| 135 } | 135 } |
| 136 } | 136 } |
| 137 | 137 |
| 138 if (!memory->Map(memory_size)) | 138 if (!memory->Map(memory_size)) |
| 139 CollectMemoryUsageAndDie(size, memory_size); | 139 CollectMemoryUsageAndDie(size, memory_size); |
| 140 | 140 |
| 141 base::SharedMemoryHandle handle_to_send = memory->handle(); | 141 base::SharedMemoryHandle handle_to_send = memory->handle(); |
| 142 sender_->Send(new ChildProcessHostMsg_AllocatedSharedBitmap( | 142 sender_->Send(new ChildProcessHostMsg_AllocatedSharedBitmap( |
| 143 memory_size, handle_to_send, id)); | 143 memory_size, handle_to_send, id)); |
| 144 #endif | 144 #endif |
| 145 return base::WrapUnique( | 145 return base::MakeUnique<ChildSharedBitmap>(sender_, std::move(memory), id); |
| 146 new ChildSharedBitmap(sender_, std::move(memory), id)); | |
| 147 } | 146 } |
| 148 | 147 |
| 149 std::unique_ptr<cc::SharedBitmap> | 148 std::unique_ptr<cc::SharedBitmap> |
| 150 ChildSharedBitmapManager::GetSharedBitmapFromId(const gfx::Size&, | 149 ChildSharedBitmapManager::GetSharedBitmapFromId(const gfx::Size&, |
| 151 const cc::SharedBitmapId&) { | 150 const cc::SharedBitmapId&) { |
| 152 NOTREACHED(); | 151 NOTREACHED(); |
| 153 return std::unique_ptr<cc::SharedBitmap>(); | 152 return std::unique_ptr<cc::SharedBitmap>(); |
| 154 } | 153 } |
| 155 | 154 |
| 156 std::unique_ptr<cc::SharedBitmap> | 155 std::unique_ptr<cc::SharedBitmap> |
| 157 ChildSharedBitmapManager::GetBitmapForSharedMemory(base::SharedMemory* mem) { | 156 ChildSharedBitmapManager::GetBitmapForSharedMemory(base::SharedMemory* mem) { |
| 158 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId(); | 157 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId(); |
| 159 base::SharedMemoryHandle handle_to_send = mem->handle(); | 158 base::SharedMemoryHandle handle_to_send = mem->handle(); |
| 160 #if defined(OS_POSIX) | 159 #if defined(OS_POSIX) |
| 161 if (!mem->ShareToProcess(base::GetCurrentProcessHandle(), &handle_to_send)) | 160 if (!mem->ShareToProcess(base::GetCurrentProcessHandle(), &handle_to_send)) |
| 162 return std::unique_ptr<cc::SharedBitmap>(); | 161 return std::unique_ptr<cc::SharedBitmap>(); |
| 163 #endif | 162 #endif |
| 164 sender_->Send(new ChildProcessHostMsg_AllocatedSharedBitmap( | 163 sender_->Send(new ChildProcessHostMsg_AllocatedSharedBitmap( |
| 165 mem->mapped_size(), handle_to_send, id)); | 164 mem->mapped_size(), handle_to_send, id)); |
| 166 | 165 |
| 167 return base::WrapUnique(new ChildSharedBitmap(sender_, mem, id)); | 166 return base::MakeUnique<ChildSharedBitmap>(sender_, mem, id); |
| 168 } | 167 } |
| 169 | 168 |
| 170 } // namespace content | 169 } // namespace content |
| OLD | NEW |