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

Side by Side Diff: components/nacl/loader/nacl_listener.cc

Issue 2081183005: Use ChannelMojo from the browser to NaCl loader process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-ipc-channel-handle
Patch Set: rebase Created 4 years, 5 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 unified diff | Download patch
« no previous file with comments | « components/nacl/loader/nacl_listener.h ('k') | components/nacl/loader/nonsfi/nonsfi_listener.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/run_loop.h" 5 #include "base/run_loop.h"
6 #include "components/nacl/loader/nacl_listener.h" 6 #include "components/nacl/loader/nacl_listener.h"
7 7
8 #include <errno.h> 8 #include <errno.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <stdlib.h> 10 #include <stdlib.h>
(...skipping 11 matching lines...) Expand all
22 #include "base/run_loop.h" 22 #include "base/run_loop.h"
23 #include "base/single_thread_task_runner.h" 23 #include "base/single_thread_task_runner.h"
24 #include "base/threading/thread_task_runner_handle.h" 24 #include "base/threading/thread_task_runner_handle.h"
25 #include "build/build_config.h" 25 #include "build/build_config.h"
26 #include "components/nacl/common/nacl_messages.h" 26 #include "components/nacl/common/nacl_messages.h"
27 #include "components/nacl/common/nacl_renderer_messages.h" 27 #include "components/nacl/common/nacl_renderer_messages.h"
28 #include "components/nacl/common/nacl_switches.h" 28 #include "components/nacl/common/nacl_switches.h"
29 #include "components/nacl/loader/nacl_ipc_adapter.h" 29 #include "components/nacl/loader/nacl_ipc_adapter.h"
30 #include "components/nacl/loader/nacl_validation_db.h" 30 #include "components/nacl/loader/nacl_validation_db.h"
31 #include "components/nacl/loader/nacl_validation_query.h" 31 #include "components/nacl/loader/nacl_validation_query.h"
32 #include "content/public/common/mojo_channel_switches.h"
32 #include "ipc/attachment_broker_unprivileged.h" 33 #include "ipc/attachment_broker_unprivileged.h"
33 #include "ipc/ipc_channel_handle.h" 34 #include "ipc/ipc_channel_handle.h"
34 #include "ipc/ipc_switches.h" 35 #include "ipc/ipc_switches.h"
35 #include "ipc/ipc_sync_channel.h" 36 #include "ipc/ipc_sync_channel.h"
36 #include "ipc/ipc_sync_message_filter.h" 37 #include "ipc/ipc_sync_message_filter.h"
38 #include "mojo/edk/embedder/embedder.h"
39 #include "mojo/edk/embedder/scoped_ipc_support.h"
37 #include "native_client/src/public/chrome_main.h" 40 #include "native_client/src/public/chrome_main.h"
38 #include "native_client/src/public/nacl_app.h" 41 #include "native_client/src/public/nacl_app.h"
39 #include "native_client/src/public/nacl_desc.h" 42 #include "native_client/src/public/nacl_desc.h"
40 43
41 #if defined(OS_POSIX) 44 #if defined(OS_POSIX)
42 #include "base/file_descriptor_posix.h" 45 #include "base/file_descriptor_posix.h"
46 #include "base/posix/global_descriptors.h"
47 #include "content/public/common/content_descriptors.h"
43 #endif 48 #endif
44 49
45 #if defined(OS_LINUX) 50 #if defined(OS_LINUX)
46 #include "content/public/common/child_process_sandbox_support_linux.h" 51 #include "content/public/common/child_process_sandbox_support_linux.h"
47 #endif 52 #endif
48 53
49 #if defined(OS_WIN) 54 #if defined(OS_WIN)
50 #include <io.h> 55 #include <io.h>
51 56
52 #include "content/public/common/sandbox_init.h" 57 #include "content/public/common/sandbox_init.h"
58 #include "mojo/edk/embedder/platform_channel_pair.h"
53 #endif 59 #endif
54 60
55 namespace { 61 namespace {
56 62
57 NaClListener* g_listener; 63 NaClListener* g_listener;
58 64
59 void FatalLogHandler(const char* data, size_t bytes) { 65 void FatalLogHandler(const char* data, size_t bytes) {
60 // We use uint32_t rather than size_t for the case when the browser and NaCl 66 // We use uint32_t rather than size_t for the case when the browser and NaCl
61 // processes are a mix of 32-bit and 64-bit processes. 67 // processes are a mix of 32-bit and 64-bit processes.
62 uint32_t copy_bytes = std::min<uint32_t>(static_cast<uint32_t>(bytes), 68 uint32_t copy_bytes = std::min<uint32_t>(static_cast<uint32_t>(bytes),
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 #endif 172 #endif
167 #if defined(OS_POSIX) 173 #if defined(OS_POSIX)
168 number_of_cores_(-1), // unknown/error 174 number_of_cores_(-1), // unknown/error
169 #endif 175 #endif
170 is_started_(false) { 176 is_started_(false) {
171 IPC::AttachmentBrokerUnprivileged::CreateBrokerIfNeeded(); 177 IPC::AttachmentBrokerUnprivileged::CreateBrokerIfNeeded();
172 io_thread_.StartWithOptions( 178 io_thread_.StartWithOptions(
173 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); 179 base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
174 DCHECK(g_listener == NULL); 180 DCHECK(g_listener == NULL);
175 g_listener = this; 181 g_listener = this;
182
183 mojo_ipc_support_.reset(new mojo::edk::ScopedIPCSupport(
184 io_thread_.task_runner().get()));
185 #if defined(OS_WIN)
186 mojo::edk::ScopedPlatformHandle platform_channel(
187 mojo::edk::PlatformChannelPair::PassClientHandleFromParentProcess(
188 *base::CommandLine::ForCurrentProcess()));
189 #else
190 mojo::edk::ScopedPlatformHandle platform_channel(
191 mojo::edk::PlatformHandle(
192 base::GlobalDescriptors::GetInstance()->Get(kMojoIPCChannel)));
193 #endif
194 DCHECK(platform_channel.is_valid());
195 mojo::edk::SetParentPipeHandle(std::move(platform_channel));
176 } 196 }
177 197
178 NaClListener::~NaClListener() { 198 NaClListener::~NaClListener() {
179 NOTREACHED(); 199 NOTREACHED();
180 shutdown_event_.Signal(); 200 shutdown_event_.Signal();
181 g_listener = NULL; 201 g_listener = NULL;
182 } 202 }
183 203
184 bool NaClListener::Send(IPC::Message* msg) { 204 bool NaClListener::Send(IPC::Message* msg) {
185 DCHECK(!!main_task_runner_); 205 DCHECK(!!main_task_runner_);
(...skipping 28 matching lines...) Expand all
214 IPC::PlatformFileForTransit ipc_fd, 234 IPC::PlatformFileForTransit ipc_fd,
215 base::FilePath file_path) { 235 base::FilePath file_path) {
216 CHECK(g_listener); 236 CHECK(g_listener);
217 g_listener->OnFileTokenResolved(token_lo, token_hi, ipc_fd, file_path); 237 g_listener->OnFileTokenResolved(token_lo, token_hi, ipc_fd, file_path);
218 } 238 }
219 private: 239 private:
220 ~FileTokenMessageFilter() override {} 240 ~FileTokenMessageFilter() override {}
221 }; 241 };
222 242
223 void NaClListener::Listen() { 243 void NaClListener::Listen() {
224 std::string channel_name = 244 mojo::ScopedMessagePipeHandle handle(
225 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 245 mojo::edk::CreateChildMessagePipe(
226 switches::kProcessChannelID); 246 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
247 switches::kMojoChannelToken)));
248 DCHECK(handle.is_valid());
249 IPC::ChannelHandle channel_handle(handle.release());
250
227 channel_ = IPC::SyncChannel::Create(this, io_thread_.task_runner().get(), 251 channel_ = IPC::SyncChannel::Create(this, io_thread_.task_runner().get(),
228 &shutdown_event_); 252 &shutdown_event_);
229 filter_ = channel_->CreateSyncMessageFilter(); 253 filter_ = channel_->CreateSyncMessageFilter();
230 channel_->AddFilter(new FileTokenMessageFilter()); 254 channel_->AddFilter(new FileTokenMessageFilter());
231 IPC::AttachmentBroker* global = IPC::AttachmentBroker::GetGlobal(); 255 IPC::AttachmentBroker* global = IPC::AttachmentBroker::GetGlobal();
232 if (global && !global->IsPrivilegedBroker()) 256 if (global && !global->IsPrivilegedBroker())
233 global->RegisterBrokerCommunicationChannel(channel_.get()); 257 global->RegisterBrokerCommunicationChannel(channel_.get());
234 channel_->Init(channel_name, IPC::Channel::MODE_CLIENT, true); 258 channel_->Init(channel_handle, IPC::Channel::MODE_CLIENT, true);
235 main_task_runner_ = base::ThreadTaskRunnerHandle::Get(); 259 main_task_runner_ = base::ThreadTaskRunnerHandle::Get();
236 base::RunLoop().Run(); 260 base::RunLoop().Run();
237 } 261 }
238 262
239 bool NaClListener::OnMessageReceived(const IPC::Message& msg) { 263 bool NaClListener::OnMessageReceived(const IPC::Message& msg) {
240 bool handled = true; 264 bool handled = true;
241 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg) 265 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg)
242 IPC_MESSAGE_HANDLER(NaClProcessMsg_AddPrefetchedResource, 266 IPC_MESSAGE_HANDLER(NaClProcessMsg_AddPrefetchedResource,
243 OnAddPrefetchedResource) 267 OnAddPrefetchedResource)
244 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart) 268 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart)
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 } 474 }
451 475
452 void NaClListener::OnFileTokenResolved( 476 void NaClListener::OnFileTokenResolved(
453 uint64_t token_lo, 477 uint64_t token_lo,
454 uint64_t token_hi, 478 uint64_t token_hi,
455 IPC::PlatformFileForTransit ipc_fd, 479 IPC::PlatformFileForTransit ipc_fd,
456 base::FilePath file_path) { 480 base::FilePath file_path) {
457 resolved_cb_.Run(ipc_fd, file_path); 481 resolved_cb_.Run(ipc_fd, file_path);
458 resolved_cb_.Reset(); 482 resolved_cb_.Reset();
459 } 483 }
OLDNEW
« no previous file with comments | « components/nacl/loader/nacl_listener.h ('k') | components/nacl/loader/nonsfi/nonsfi_listener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698