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

Unified Diff: content/child/child_thread_impl.cc

Issue 2478343002: Removing the ChildProcessHostMsg_SyncAllocateSharedMemory IPC message. (Closed)
Patch Set: Synced Created 4 years, 1 month 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 | « content/browser/renderer_host/render_message_filter.cc ('k') | content/common/child_process_host_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/child_thread_impl.cc
diff --git a/content/child/child_thread_impl.cc b/content/child/child_thread_impl.cc
index 927427d2d59ebb1036ed206723f3800312d0f9f4..8d8b6bd84e9bc028b154724304b00e3cc21589e7 100644
--- a/content/child/child_thread_impl.cc
+++ b/content/child/child_thread_impl.cc
@@ -65,6 +65,8 @@
#include "mojo/edk/embedder/named_platform_channel_pair.h"
#include "mojo/edk/embedder/platform_channel_pair.h"
#include "mojo/edk/embedder/scoped_ipc_support.h"
+#include "mojo/public/cpp/system/buffer.h"
+#include "mojo/public/cpp/system/platform_handle.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/interface_factory.h"
#include "services/service_manager/public/cpp/interface_provider.h"
@@ -729,27 +731,23 @@ std::unique_ptr<base::SharedMemory> ChildThreadImpl::AllocateSharedMemory(
size_t buf_size,
IPC::Sender* sender,
bool* out_of_memory) {
- std::unique_ptr<base::SharedMemory> shared_buf;
- // Ask the browser to create the shared memory, since this is blocked by the
- // sandbox on most platforms.
- base::SharedMemoryHandle shared_mem_handle;
- if (sender->Send(new ChildProcessHostMsg_SyncAllocateSharedMemory(
- buf_size, &shared_mem_handle))) {
- if (base::SharedMemory::IsHandleValid(shared_mem_handle)) {
- shared_buf.reset(new base::SharedMemory(shared_mem_handle, false));
- } else {
- LOG(WARNING) << "Browser failed to allocate shared memory";
- if (out_of_memory)
- *out_of_memory = true;
- return nullptr;
- }
- } else {
- // Send is allowed to fail during shutdown. Return null in this case.
+ mojo::ScopedSharedBufferHandle mojo_buf =
+ mojo::SharedBufferHandle::Create(buf_size);
+ if (!mojo_buf->is_valid()) {
+ LOG(WARNING) << "Browser failed to allocate shared memory";
if (out_of_memory)
- *out_of_memory = false;
+ *out_of_memory = true;
return nullptr;
}
- return shared_buf;
+
+ 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);
}
#if defined(OS_LINUX)
« no previous file with comments | « content/browser/renderer_host/render_message_filter.cc ('k') | content/common/child_process_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698