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

Side by Side 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 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"
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 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 size_t buf_size) { 724 size_t buf_size) {
723 DCHECK(message_loop_->task_runner()->BelongsToCurrentThread()); 725 DCHECK(message_loop_->task_runner()->BelongsToCurrentThread());
724 return AllocateSharedMemory(buf_size, this, nullptr); 726 return AllocateSharedMemory(buf_size, this, nullptr);
725 } 727 }
726 728
727 // static 729 // static
728 std::unique_ptr<base::SharedMemory> ChildThreadImpl::AllocateSharedMemory( 730 std::unique_ptr<base::SharedMemory> ChildThreadImpl::AllocateSharedMemory(
729 size_t buf_size, 731 size_t buf_size,
730 IPC::Sender* sender, 732 IPC::Sender* sender,
731 bool* out_of_memory) { 733 bool* out_of_memory) {
732 std::unique_ptr<base::SharedMemory> shared_buf; 734 mojo::ScopedSharedBufferHandle mojo_buf =
733 // Ask the browser to create the shared memory, since this is blocked by the 735 mojo::SharedBufferHandle::Create(buf_size);
734 // sandbox on most platforms. 736 if (!mojo_buf->is_valid()) {
735 base::SharedMemoryHandle shared_mem_handle; 737 LOG(WARNING) << "Browser failed to allocate shared memory";
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.
748 if (out_of_memory) 738 if (out_of_memory)
749 *out_of_memory = false; 739 *out_of_memory = true;
750 return nullptr; 740 return nullptr;
751 } 741 }
752 return shared_buf; 742
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);
753 } 751 }
754 752
755 #if defined(OS_LINUX) 753 #if defined(OS_LINUX)
756 void ChildThreadImpl::SetThreadPriority(base::PlatformThreadId id, 754 void ChildThreadImpl::SetThreadPriority(base::PlatformThreadId id,
757 base::ThreadPriority priority) { 755 base::ThreadPriority priority) {
758 Send(new ChildProcessHostMsg_SetThreadPriority(id, priority)); 756 Send(new ChildProcessHostMsg_SetThreadPriority(id, priority));
759 } 757 }
760 #endif 758 #endif
761 759
762 bool ChildThreadImpl::OnMessageReceived(const IPC::Message& msg) { 760 bool ChildThreadImpl::OnMessageReceived(const IPC::Message& msg) {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 connected_to_browser_ = true; 915 connected_to_browser_ = true;
918 child_info_ = local_info; 916 child_info_ = local_info;
919 browser_info_ = remote_info; 917 browser_info_ = remote_info;
920 } 918 }
921 919
922 bool ChildThreadImpl::IsInBrowserProcess() const { 920 bool ChildThreadImpl::IsInBrowserProcess() const {
923 return static_cast<bool>(browser_process_io_runner_); 921 return static_cast<bool>(browser_process_io_runner_);
924 } 922 }
925 923
926 } // namespace content 924 } // 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