| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 95 |
| 96 std::unique_ptr<cc::SharedBitmap> | 96 std::unique_ptr<cc::SharedBitmap> |
| 97 ChildSharedBitmapManager::AllocateSharedBitmap(const gfx::Size& size) { | 97 ChildSharedBitmapManager::AllocateSharedBitmap(const gfx::Size& size) { |
| 98 TRACE_EVENT2("renderer", | 98 TRACE_EVENT2("renderer", |
| 99 "ChildSharedBitmapManager::AllocateSharedMemoryBitmap", "width", | 99 "ChildSharedBitmapManager::AllocateSharedMemoryBitmap", "width", |
| 100 size.width(), "height", size.height()); | 100 size.width(), "height", size.height()); |
| 101 size_t memory_size; | 101 size_t memory_size; |
| 102 if (!cc::SharedBitmap::SizeInBytes(size, &memory_size)) | 102 if (!cc::SharedBitmap::SizeInBytes(size, &memory_size)) |
| 103 return std::unique_ptr<SharedMemoryBitmap>(); | 103 return std::unique_ptr<SharedMemoryBitmap>(); |
| 104 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId(); | 104 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId(); |
| 105 bool out_of_memory = false; | |
| 106 std::unique_ptr<base::SharedMemory> memory = | 105 std::unique_ptr<base::SharedMemory> memory = |
| 107 ChildThreadImpl::AllocateSharedMemory(memory_size, nullptr, | 106 ChildThreadImpl::AllocateSharedMemory(memory_size); |
| 108 &out_of_memory); | 107 if (!memory || !memory->Map(memory_size)) |
| 109 if (!memory) { | |
| 110 if (out_of_memory) { | |
| 111 CollectMemoryUsageAndDie(size, memory_size); | |
| 112 } else { | |
| 113 // Callers of this method are not prepared to handle failures during | |
| 114 // shutdown. Exit immediately. This is expected behavior during the Fast | |
| 115 // Shutdown path, so use EXIT_SUCCESS. https://crbug.com/615121. | |
| 116 exit(EXIT_SUCCESS); | |
| 117 } | |
| 118 } | |
| 119 | |
| 120 if (!memory->Map(memory_size)) | |
| 121 CollectMemoryUsageAndDie(size, memory_size); | 108 CollectMemoryUsageAndDie(size, memory_size); |
| 122 | 109 |
| 123 NotifyAllocatedSharedBitmap(memory.get(), id); | 110 NotifyAllocatedSharedBitmap(memory.get(), id); |
| 124 | 111 |
| 125 // Close the associated FD to save resources, the previously mapped memory | 112 // Close the associated FD to save resources, the previously mapped memory |
| 126 // remains available. | 113 // remains available. |
| 127 memory->Close(); | 114 memory->Close(); |
| 128 | 115 |
| 129 return base::MakeUnique<ChildSharedBitmap>(render_message_filter_ptr_, | 116 return base::MakeUnique<ChildSharedBitmap>(render_message_filter_ptr_, |
| 130 std::move(memory), id); | 117 std::move(memory), id); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 158 } | 145 } |
| 159 | 146 |
| 160 mojo::ScopedSharedBufferHandle buffer_handle = mojo::WrapSharedMemoryHandle( | 147 mojo::ScopedSharedBufferHandle buffer_handle = mojo::WrapSharedMemoryHandle( |
| 161 handle_to_send, memory->mapped_size(), true /* read_only */); | 148 handle_to_send, memory->mapped_size(), true /* read_only */); |
| 162 | 149 |
| 163 (*render_message_filter_ptr_) | 150 (*render_message_filter_ptr_) |
| 164 ->AllocatedSharedBitmap(std::move(buffer_handle), id); | 151 ->AllocatedSharedBitmap(std::move(buffer_handle), id); |
| 165 } | 152 } |
| 166 | 153 |
| 167 } // namespace content | 154 } // namespace content |
| OLD | NEW |