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

Side by Side Diff: content/child/child_thread_impl.cc

Issue 2491763003: Revert of Removing the ChildProcessHostMsg_SyncAllocateSharedMemory IPC message. (Closed)
Patch Set: 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_thread_impl.h" 5 #include "content/child/child_thread_impl.h"
6 6
7 #include <signal.h> 7 #include <signal.h>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 #include "content/public/common/service_names.h" 58 #include "content/public/common/service_names.h"
59 #include "ipc/ipc_channel_mojo.h" 59 #include "ipc/ipc_channel_mojo.h"
60 #include "ipc/ipc_logging.h" 60 #include "ipc/ipc_logging.h"
61 #include "ipc/ipc_platform_file.h" 61 #include "ipc/ipc_platform_file.h"
62 #include "ipc/ipc_sync_channel.h" 62 #include "ipc/ipc_sync_channel.h"
63 #include "ipc/ipc_sync_message_filter.h" 63 #include "ipc/ipc_sync_message_filter.h"
64 #include "mojo/edk/embedder/embedder.h" 64 #include "mojo/edk/embedder/embedder.h"
65 #include "mojo/edk/embedder/named_platform_channel_pair.h" 65 #include "mojo/edk/embedder/named_platform_channel_pair.h"
66 #include "mojo/edk/embedder/platform_channel_pair.h" 66 #include "mojo/edk/embedder/platform_channel_pair.h"
67 #include "mojo/edk/embedder/scoped_ipc_support.h" 67 #include "mojo/edk/embedder/scoped_ipc_support.h"
68 #include "mojo/public/cpp/system/buffer.h"
69 #include "mojo/public/cpp/system/platform_handle.h"
70 #include "services/service_manager/public/cpp/connector.h" 68 #include "services/service_manager/public/cpp/connector.h"
71 #include "services/service_manager/public/cpp/interface_factory.h" 69 #include "services/service_manager/public/cpp/interface_factory.h"
72 #include "services/service_manager/public/cpp/interface_provider.h" 70 #include "services/service_manager/public/cpp/interface_provider.h"
73 #include "services/service_manager/public/cpp/interface_registry.h" 71 #include "services/service_manager/public/cpp/interface_registry.h"
74 #include "services/service_manager/runner/common/client_util.h" 72 #include "services/service_manager/runner/common/client_util.h"
75 73
76 #if defined(OS_POSIX) 74 #if defined(OS_POSIX)
77 #include "base/posix/global_descriptors.h" 75 #include "base/posix/global_descriptors.h"
78 #include "content/public/common/content_descriptors.h" 76 #include "content/public/common/content_descriptors.h"
79 #endif 77 #endif
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 size_t buf_size) { 722 size_t buf_size) {
725 DCHECK(message_loop_->task_runner()->BelongsToCurrentThread()); 723 DCHECK(message_loop_->task_runner()->BelongsToCurrentThread());
726 return AllocateSharedMemory(buf_size, this, nullptr); 724 return AllocateSharedMemory(buf_size, this, nullptr);
727 } 725 }
728 726
729 // static 727 // static
730 std::unique_ptr<base::SharedMemory> ChildThreadImpl::AllocateSharedMemory( 728 std::unique_ptr<base::SharedMemory> ChildThreadImpl::AllocateSharedMemory(
731 size_t buf_size, 729 size_t buf_size,
732 IPC::Sender* sender, 730 IPC::Sender* sender,
733 bool* out_of_memory) { 731 bool* out_of_memory) {
734 mojo::ScopedSharedBufferHandle mojo_buf = 732 std::unique_ptr<base::SharedMemory> shared_buf;
735 mojo::SharedBufferHandle::Create(buf_size); 733 // Ask the browser to create the shared memory, since this is blocked by the
736 if (!mojo_buf->is_valid()) { 734 // sandbox on most platforms.
737 LOG(WARNING) << "Browser failed to allocate shared memory"; 735 base::SharedMemoryHandle shared_mem_handle;
736 if (sender->Send(new ChildProcessHostMsg_SyncAllocateSharedMemory(
737 buf_size, &shared_mem_handle))) {
738 if (base::SharedMemory::IsHandleValid(shared_mem_handle)) {
739 shared_buf.reset(new base::SharedMemory(shared_mem_handle, false));
740 } else {
741 LOG(WARNING) << "Browser failed to allocate shared memory";
742 if (out_of_memory)
743 *out_of_memory = true;
744 return nullptr;
745 }
746 } else {
747 // Send is allowed to fail during shutdown. Return null in this case.
738 if (out_of_memory) 748 if (out_of_memory)
739 *out_of_memory = true; 749 *out_of_memory = false;
740 return nullptr; 750 return nullptr;
741 } 751 }
742 752 return shared_buf;
743 base::SharedMemoryHandle shared_buf;
744 if (mojo::UnwrapSharedMemoryHandle(std::move(mojo_buf), &shared_buf,
745 nullptr, nullptr) != MOJO_RESULT_OK) {
746 LOG(WARNING) << "Browser failed to allocate shared memory";
747 return nullptr;
748 }
749
750 return base::MakeUnique<base::SharedMemory>(shared_buf, false);
751 } 753 }
752 754
753 #if defined(OS_LINUX) 755 #if defined(OS_LINUX)
754 void ChildThreadImpl::SetThreadPriority(base::PlatformThreadId id, 756 void ChildThreadImpl::SetThreadPriority(base::PlatformThreadId id,
755 base::ThreadPriority priority) { 757 base::ThreadPriority priority) {
756 Send(new ChildProcessHostMsg_SetThreadPriority(id, priority)); 758 Send(new ChildProcessHostMsg_SetThreadPriority(id, priority));
757 } 759 }
758 #endif 760 #endif
759 761
760 bool ChildThreadImpl::OnMessageReceived(const IPC::Message& msg) { 762 bool ChildThreadImpl::OnMessageReceived(const IPC::Message& msg) {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 connected_to_browser_ = true; 917 connected_to_browser_ = true;
916 child_info_ = local_info; 918 child_info_ = local_info;
917 browser_info_ = remote_info; 919 browser_info_ = remote_info;
918 } 920 }
919 921
920 bool ChildThreadImpl::IsInBrowserProcess() const { 922 bool ChildThreadImpl::IsInBrowserProcess() const {
921 return static_cast<bool>(browser_process_io_runner_); 923 return static_cast<bool>(browser_process_io_runner_);
922 } 924 }
923 925
924 } // namespace content 926 } // namespace content
OLDNEW
« 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