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

Unified Diff: services/ui/public/cpp/bitmap/child_shared_bitmap_manager.cc

Issue 2717213004: Move SharedBitmapManager implementation out of content/ (Closed)
Patch Set: rebase Created 3 years, 8 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « services/ui/public/cpp/bitmap/child_shared_bitmap_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/ui/public/cpp/bitmap/child_shared_bitmap_manager.cc
diff --git a/content/child/child_shared_bitmap_manager.cc b/services/ui/public/cpp/bitmap/child_shared_bitmap_manager.cc
similarity index 68%
rename from content/child/child_shared_bitmap_manager.cc
rename to services/ui/public/cpp/bitmap/child_shared_bitmap_manager.cc
index 225c569b7690239f243bad5f6ca5c7707a044817..92fc4300b1891aba9d4cc158ca79d771fb9723b3 100644
--- a/content/child/child_shared_bitmap_manager.cc
+++ b/services/ui/public/cpp/bitmap/child_shared_bitmap_manager.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "content/child/child_shared_bitmap_manager.h"
+#include "services/ui/public/cpp/bitmap/child_shared_bitmap_manager.h"
#include <stddef.h>
@@ -12,44 +12,43 @@
#include "base/memory/ptr_util.h"
#include "base/process/memory.h"
#include "base/process/process_metrics.h"
+#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
-#include "content/child/child_thread_impl.h"
-#include "content/common/child_process_messages.h"
#include "mojo/public/cpp/system/platform_handle.h"
#include "ui/gfx/geometry/size.h"
-namespace content {
+namespace ui {
namespace {
class ChildSharedBitmap : public cc::SharedBitmap {
public:
ChildSharedBitmap(
- const scoped_refptr<mojom::ThreadSafeRenderMessageFilterAssociatedPtr>&
- render_message_filter_ptr,
+ const scoped_refptr<cc::mojom::ThreadSafeSharedBitmapManagerAssociatedPtr>
+ shared_bitmap_manager_ptr,
base::SharedMemory* shared_memory,
const cc::SharedBitmapId& id)
: cc::SharedBitmap(static_cast<uint8_t*>(shared_memory->memory()), id),
- render_message_filter_ptr_(render_message_filter_ptr) {}
+ shared_bitmap_manager_ptr_(shared_bitmap_manager_ptr) {}
ChildSharedBitmap(
- const scoped_refptr<mojom::ThreadSafeRenderMessageFilterAssociatedPtr>&
- render_message_filter_ptr,
+ const scoped_refptr<cc::mojom::ThreadSafeSharedBitmapManagerAssociatedPtr>
+ shared_bitmap_manager_ptr,
std::unique_ptr<base::SharedMemory> shared_memory_holder,
const cc::SharedBitmapId& id)
- : ChildSharedBitmap(render_message_filter_ptr,
+ : ChildSharedBitmap(shared_bitmap_manager_ptr,
shared_memory_holder.get(),
id) {
shared_memory_holder_ = std::move(shared_memory_holder);
}
~ChildSharedBitmap() override {
- (*render_message_filter_ptr_)->DeletedSharedBitmap(id());
+ (*shared_bitmap_manager_ptr_)->DidDeleteSharedBitmap(id());
}
private:
- scoped_refptr<mojom::ThreadSafeRenderMessageFilterAssociatedPtr>
- render_message_filter_ptr_;
+ scoped_refptr<cc::mojom::ThreadSafeSharedBitmapManagerAssociatedPtr>
+ shared_bitmap_manager_ptr_;
std::unique_ptr<base::SharedMemory> shared_memory_holder_;
};
@@ -77,12 +76,32 @@ void CollectMemoryUsageAndDie(const gfx::Size& size, size_t alloc_size) {
base::TerminateBecauseOutOfMemory(alloc_size);
}
+// Allocates a block of shared memory of the given size. Returns nullptr on
+// failure.
+std::unique_ptr<base::SharedMemory> AllocateSharedMemory(size_t buf_size) {
+ mojo::ScopedSharedBufferHandle mojo_buf =
+ mojo::SharedBufferHandle::Create(buf_size);
+ if (!mojo_buf->is_valid()) {
+ LOG(WARNING) << "Browser failed to allocate shared memory";
+ return nullptr;
+ }
+
+ base::SharedMemoryHandle shared_buf;
+ if (mojo::UnwrapSharedMemoryHandle(std::move(mojo_buf), &shared_buf, nullptr,
+ nullptr) != MOJO_RESULT_OK) {
+ LOG(WARNING) << "Browser failed to allocate shared memory";
+ return nullptr;
+ }
+
+ return base::MakeUnique<base::SharedMemory>(shared_buf, false);
+}
+
} // namespace
ChildSharedBitmapManager::ChildSharedBitmapManager(
- const scoped_refptr<mojom::ThreadSafeRenderMessageFilterAssociatedPtr>&
- render_message_filter_ptr)
- : render_message_filter_ptr_(render_message_filter_ptr) {}
+ const scoped_refptr<cc::mojom::ThreadSafeSharedBitmapManagerAssociatedPtr>&
+ shared_bitmap_manager_ptr)
+ : shared_bitmap_manager_ptr_(shared_bitmap_manager_ptr) {}
ChildSharedBitmapManager::~ChildSharedBitmapManager() {}
@@ -95,7 +114,7 @@ ChildSharedBitmapManager::AllocateSharedBitmap(const gfx::Size& size) {
return nullptr;
cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
std::unique_ptr<base::SharedMemory> memory =
- ChildThreadImpl::AllocateSharedMemory(memory_size);
+ AllocateSharedMemory(memory_size);
if (!memory || !memory->Map(memory_size))
CollectMemoryUsageAndDie(size, memory_size);
@@ -105,7 +124,7 @@ ChildSharedBitmapManager::AllocateSharedBitmap(const gfx::Size& size) {
// remains available.
memory->Close();
- return base::MakeUnique<ChildSharedBitmap>(render_message_filter_ptr_,
+ return base::MakeUnique<ChildSharedBitmap>(shared_bitmap_manager_ptr_,
std::move(memory), id);
}
@@ -120,7 +139,7 @@ std::unique_ptr<cc::SharedBitmap>
ChildSharedBitmapManager::GetBitmapForSharedMemory(base::SharedMemory* mem) {
cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
NotifyAllocatedSharedBitmap(mem, cc::SharedBitmap::GenerateId());
- return base::MakeUnique<ChildSharedBitmap>(render_message_filter_ptr_,
+ return base::MakeUnique<ChildSharedBitmap>(shared_bitmap_manager_ptr_,
std::move(mem), id);
}
@@ -139,8 +158,8 @@ void ChildSharedBitmapManager::NotifyAllocatedSharedBitmap(
mojo::ScopedSharedBufferHandle buffer_handle = mojo::WrapSharedMemoryHandle(
handle_to_send, memory->mapped_size(), true /* read_only */);
- (*render_message_filter_ptr_)
- ->AllocatedSharedBitmap(std::move(buffer_handle), id);
+ (*shared_bitmap_manager_ptr_)
+ ->DidAllocateSharedBitmap(std::move(buffer_handle), id);
}
-} // namespace content
+} // namespace ui
« no previous file with comments | « services/ui/public/cpp/bitmap/child_shared_bitmap_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698