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

Side by Side Diff: components/nacl/loader/nonsfi/nonsfi_listener.cc

Issue 2501913002: Change the NaCl loader and broker processes to use the ServiceManager. (Closed)
Patch Set: Created 4 years 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/nacl/loader/nonsfi/nonsfi_listener.h" 5 #include "components/nacl/loader/nonsfi/nonsfi_listener.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_descriptor_posix.h" 10 #include "base/file_descriptor_posix.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/posix/global_descriptors.h"
14 #include "base/rand_util.h" 13 #include "base/rand_util.h"
15 #include "base/run_loop.h" 14 #include "base/run_loop.h"
16 #include "build/build_config.h" 15 #include "build/build_config.h"
17 #include "components/nacl/common/nacl_messages.h" 16 #include "components/nacl/common/nacl_messages.h"
17 #include "components/nacl/common/nacl_service.h"
18 #include "components/nacl/common/nacl_types.h" 18 #include "components/nacl/common/nacl_types.h"
19 #include "components/nacl/loader/nacl_trusted_listener.h" 19 #include "components/nacl/loader/nacl_trusted_listener.h"
20 #include "components/nacl/loader/nonsfi/nonsfi_main.h" 20 #include "components/nacl/loader/nonsfi/nonsfi_main.h"
21 #include "content/public/common/content_descriptors.h" 21 #include "content/public/common/content_descriptors.h"
22 #include "content/public/common/mojo_channel_switches.h" 22 #include "content/public/common/mojo_channel_switches.h"
23 #include "ipc/ipc_channel.h" 23 #include "ipc/ipc_channel.h"
24 #include "ipc/ipc_channel_handle.h" 24 #include "ipc/ipc_channel_handle.h"
25 #include "ipc/ipc_sync_channel.h" 25 #include "ipc/ipc_sync_channel.h"
26 #include "mojo/edk/embedder/embedder.h"
27 #include "mojo/edk/embedder/scoped_ipc_support.h"
28 #include "native_client/src/public/nonsfi/irt_random.h" 26 #include "native_client/src/public/nonsfi/irt_random.h"
29 #include "ppapi/nacl_irt/irt_manifest.h" 27 #include "ppapi/nacl_irt/irt_manifest.h"
30 #include "ppapi/nacl_irt/plugin_startup.h" 28 #include "ppapi/nacl_irt/plugin_startup.h"
29 #include "services/service_manager/public/cpp/service_context.h"
31 30
32 #if !defined(OS_NACL_NONSFI) 31 #if !defined(OS_NACL_NONSFI)
33 #error "This file must be built for nacl_helper_nonsfi." 32 #error "This file must be built for nacl_helper_nonsfi."
34 #endif 33 #endif
35 34
36 namespace nacl { 35 namespace nacl {
37 namespace nonsfi { 36 namespace nonsfi {
38 37
39 NonSfiListener::NonSfiListener() 38 NonSfiListener::NonSfiListener()
40 : io_thread_("NaCl_IOThread"), 39 : io_thread_("NaCl_IOThread"),
41 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, 40 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL,
42 base::WaitableEvent::InitialState::NOT_SIGNALED), 41 base::WaitableEvent::InitialState::NOT_SIGNALED),
43 key_fd_map_(new std::map<std::string, int>) { 42 key_fd_map_(new std::map<std::string, int>) {
44 io_thread_.StartWithOptions( 43 io_thread_.StartWithOptions(
45 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); 44 base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
46
47 mojo_ipc_support_ =
48 base::MakeUnique<mojo::edk::ScopedIPCSupport>(io_thread_.task_runner());
49 mojo::edk::ScopedPlatformHandle platform_channel(
50 mojo::edk::PlatformHandle(
51 base::GlobalDescriptors::GetInstance()->Get(kMojoIPCChannel)));
52 DCHECK(platform_channel.is_valid());
53 mojo::edk::SetParentPipeHandle(std::move(platform_channel));
54 } 45 }
55 46
56 NonSfiListener::~NonSfiListener() { 47 NonSfiListener::~NonSfiListener() {
57 } 48 }
58 49
59 void NonSfiListener::Listen() { 50 void NonSfiListener::Listen() {
60 mojo::ScopedMessagePipeHandle handle( 51 mojo::ScopedMessagePipeHandle channel_handle;
61 mojo::edk::CreateChildMessagePipe( 52 std::unique_ptr<service_manager::ServiceContext> service_context =
62 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 53 CreateNaClServiceContext(io_thread_.task_runner(), &channel_handle);
63 switches::kMojoChannelToken))); 54 channel_ = IPC::SyncChannel::Create(channel_handle.release(),
64 DCHECK(handle.is_valid()); 55 IPC::Channel::MODE_CLIENT,
65 IPC::ChannelHandle channel_handle = IPC::ChannelHandle(handle.release()); 56 this, // As a Listener.
66 57 io_thread_.task_runner(),
67 channel_ = IPC::SyncChannel::Create( 58 true, // Create pipe now.
68 channel_handle, 59 &shutdown_event_);
69 IPC::Channel::MODE_CLIENT,
70 this, // As a Listener.
71 io_thread_.task_runner().get(),
72 true, // Create pipe now.
73 &shutdown_event_);
74 base::RunLoop().Run(); 60 base::RunLoop().Run();
75 } 61 }
76 62
77 bool NonSfiListener::OnMessageReceived(const IPC::Message& msg) { 63 bool NonSfiListener::OnMessageReceived(const IPC::Message& msg) {
78 bool handled = true; 64 bool handled = true;
79 IPC_BEGIN_MESSAGE_MAP(NonSfiListener, msg) 65 IPC_BEGIN_MESSAGE_MAP(NonSfiListener, msg)
80 IPC_MESSAGE_HANDLER(NaClProcessMsg_AddPrefetchedResource, 66 IPC_MESSAGE_HANDLER(NaClProcessMsg_AddPrefetchedResource,
81 OnAddPrefetchedResource) 67 OnAddPrefetchedResource)
82 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart) 68 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart)
83 IPC_MESSAGE_UNHANDLED(handled = false) 69 IPC_MESSAGE_UNHANDLED(handled = false)
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 CHECK(params.nexe_file != IPC::InvalidPlatformFileForTransit()); 133 CHECK(params.nexe_file != IPC::InvalidPlatformFileForTransit());
148 CHECK(params.nexe_file_path_metadata.empty()); 134 CHECK(params.nexe_file_path_metadata.empty());
149 135
150 ppapi::RegisterPreopenedDescriptorsNonSfi(key_fd_map_.release()); 136 ppapi::RegisterPreopenedDescriptorsNonSfi(key_fd_map_.release());
151 137
152 MainStart(IPC::PlatformFileForTransitToPlatformFile(params.nexe_file)); 138 MainStart(IPC::PlatformFileForTransitToPlatformFile(params.nexe_file));
153 } 139 }
154 140
155 } // namespace nonsfi 141 } // namespace nonsfi
156 } // namespace nacl 142 } // namespace nacl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698