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

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

Issue 2499743002: Removing 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 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 "device/power_monitor/public/cpp/power_monitor_broadcast_source.h" 58 #include "device/power_monitor/public/cpp/power_monitor_broadcast_source.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"
68 #include "services/service_manager/public/cpp/connector.h" 70 #include "services/service_manager/public/cpp/connector.h"
69 #include "services/service_manager/public/cpp/interface_factory.h" 71 #include "services/service_manager/public/cpp/interface_factory.h"
70 #include "services/service_manager/public/cpp/interface_provider.h" 72 #include "services/service_manager/public/cpp/interface_provider.h"
71 #include "services/service_manager/public/cpp/interface_registry.h" 73 #include "services/service_manager/public/cpp/interface_registry.h"
72 #include "services/service_manager/runner/common/client_util.h" 74 #include "services/service_manager/runner/common/client_util.h"
73 75
74 #if defined(OS_POSIX) 76 #if defined(OS_POSIX)
75 #include "base/posix/global_descriptors.h" 77 #include "base/posix/global_descriptors.h"
76 #include "content/public/common/content_descriptors.h" 78 #include "content/public/common/content_descriptors.h"
77 #endif 79 #endif
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 size_t buf_size) { 725 size_t buf_size) {
724 DCHECK(message_loop_->task_runner()->BelongsToCurrentThread()); 726 DCHECK(message_loop_->task_runner()->BelongsToCurrentThread());
725 return AllocateSharedMemory(buf_size, this, nullptr); 727 return AllocateSharedMemory(buf_size, this, nullptr);
726 } 728 }
727 729
728 // static 730 // static
729 std::unique_ptr<base::SharedMemory> ChildThreadImpl::AllocateSharedMemory( 731 std::unique_ptr<base::SharedMemory> ChildThreadImpl::AllocateSharedMemory(
730 size_t buf_size, 732 size_t buf_size,
731 IPC::Sender* sender, 733 IPC::Sender* sender,
732 bool* out_of_memory) { 734 bool* out_of_memory) {
733 std::unique_ptr<base::SharedMemory> shared_buf; 735 mojo::ScopedSharedBufferHandle mojo_buf =
734 // Ask the browser to create the shared memory, since this is blocked by the 736 mojo::SharedBufferHandle::Create(buf_size);
735 // sandbox on most platforms. 737 if (!mojo_buf->is_valid()) {
736 base::SharedMemoryHandle shared_mem_handle; 738 LOG(WARNING) << "Browser failed to allocate shared memory";
737 if (sender->Send(new ChildProcessHostMsg_SyncAllocateSharedMemory(
738 buf_size, &shared_mem_handle))) {
739 if (base::SharedMemory::IsHandleValid(shared_mem_handle)) {
740 shared_buf.reset(new base::SharedMemory(shared_mem_handle, false));
741 } else {
742 LOG(WARNING) << "Browser failed to allocate shared memory";
743 if (out_of_memory)
744 *out_of_memory = true;
745 return nullptr;
746 }
747 } else {
748 // Send is allowed to fail during shutdown. Return null in this case.
749 if (out_of_memory) 739 if (out_of_memory)
750 *out_of_memory = false; 740 *out_of_memory = true;
751 return nullptr; 741 return nullptr;
752 } 742 }
753 return shared_buf; 743
744 base::SharedMemoryHandle shared_buf;
745 if (mojo::UnwrapSharedMemoryHandle(std::move(mojo_buf), &shared_buf,
746 nullptr, nullptr) != MOJO_RESULT_OK) {
747 LOG(WARNING) << "Browser failed to allocate shared memory";
748 return nullptr;
749 }
750
751 return base::MakeUnique<base::SharedMemory>(shared_buf, false);
754 } 752 }
755 753
756 #if defined(OS_LINUX) 754 #if defined(OS_LINUX)
757 void ChildThreadImpl::SetThreadPriority(base::PlatformThreadId id, 755 void ChildThreadImpl::SetThreadPriority(base::PlatformThreadId id,
758 base::ThreadPriority priority) { 756 base::ThreadPriority priority) {
759 Send(new ChildProcessHostMsg_SetThreadPriority(id, priority)); 757 Send(new ChildProcessHostMsg_SetThreadPriority(id, priority));
760 } 758 }
761 #endif 759 #endif
762 760
763 bool ChildThreadImpl::OnMessageReceived(const IPC::Message& msg) { 761 bool ChildThreadImpl::OnMessageReceived(const IPC::Message& msg) {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 connected_to_browser_ = true; 916 connected_to_browser_ = true;
919 child_info_ = local_info; 917 child_info_ = local_info;
920 browser_info_ = remote_info; 918 browser_info_ = remote_info;
921 } 919 }
922 920
923 bool ChildThreadImpl::IsInBrowserProcess() const { 921 bool ChildThreadImpl::IsInBrowserProcess() const {
924 return static_cast<bool>(browser_process_io_runner_); 922 return static_cast<bool>(browser_process_io_runner_);
925 } 923 }
926 924
927 } // namespace content 925 } // 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