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

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: rebase 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
« no previous file with comments | « components/nacl/loader/nonsfi/nonsfi_listener.h ('k') | content/BUILD.gn » ('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 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.mojom.h" 16 #include "components/nacl/common/nacl.mojom.h"
18 #include "components/nacl/common/nacl_messages.h" 17 #include "components/nacl/common/nacl_messages.h"
18 #include "components/nacl/common/nacl_service.h"
19 #include "components/nacl/common/nacl_types.h" 19 #include "components/nacl/common/nacl_types.h"
20 #include "components/nacl/loader/nacl_trusted_listener.h" 20 #include "components/nacl/loader/nacl_trusted_listener.h"
21 #include "components/nacl/loader/nonsfi/nonsfi_main.h" 21 #include "components/nacl/loader/nonsfi/nonsfi_main.h"
22 #include "content/public/common/content_descriptors.h" 22 #include "content/public/common/content_descriptors.h"
23 #include "content/public/common/mojo_channel_switches.h" 23 #include "content/public/common/mojo_channel_switches.h"
24 #include "ipc/ipc_channel.h" 24 #include "ipc/ipc_channel.h"
25 #include "ipc/ipc_channel_handle.h" 25 #include "ipc/ipc_channel_handle.h"
26 #include "ipc/ipc_sync_channel.h" 26 #include "ipc/ipc_sync_channel.h"
27 #include "mojo/edk/embedder/embedder.h"
28 #include "mojo/edk/embedder/scoped_ipc_support.h"
29 #include "native_client/src/public/nonsfi/irt_random.h" 27 #include "native_client/src/public/nonsfi/irt_random.h"
30 #include "ppapi/nacl_irt/irt_manifest.h" 28 #include "ppapi/nacl_irt/irt_manifest.h"
31 #include "ppapi/nacl_irt/plugin_startup.h" 29 #include "ppapi/nacl_irt/plugin_startup.h"
30 #include "services/service_manager/public/cpp/service_context.h"
32 31
33 #if !defined(OS_NACL_NONSFI) 32 #if !defined(OS_NACL_NONSFI)
34 #error "This file must be built for nacl_helper_nonsfi." 33 #error "This file must be built for nacl_helper_nonsfi."
35 #endif 34 #endif
36 35
37 namespace nacl { 36 namespace nacl {
38 namespace nonsfi { 37 namespace nonsfi {
39 38
40 NonSfiListener::NonSfiListener() 39 NonSfiListener::NonSfiListener()
41 : io_thread_("NaCl_IOThread"), 40 : io_thread_("NaCl_IOThread"),
42 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, 41 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL,
43 base::WaitableEvent::InitialState::NOT_SIGNALED), 42 base::WaitableEvent::InitialState::NOT_SIGNALED),
44 key_fd_map_(new std::map<std::string, int>) { 43 key_fd_map_(new std::map<std::string, int>) {
45 io_thread_.StartWithOptions( 44 io_thread_.StartWithOptions(
46 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); 45 base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
47
48 mojo_ipc_support_ =
49 base::MakeUnique<mojo::edk::ScopedIPCSupport>(io_thread_.task_runner());
50 mojo::edk::ScopedPlatformHandle platform_channel(
51 mojo::edk::PlatformHandle(
52 base::GlobalDescriptors::GetInstance()->Get(kMojoIPCChannel)));
53 DCHECK(platform_channel.is_valid());
54 mojo::edk::SetParentPipeHandle(std::move(platform_channel));
55 } 46 }
56 47
57 NonSfiListener::~NonSfiListener() { 48 NonSfiListener::~NonSfiListener() {
58 } 49 }
59 50
60 void NonSfiListener::Listen() { 51 void NonSfiListener::Listen() {
61 mojo::ScopedMessagePipeHandle handle( 52 mojo::ScopedMessagePipeHandle channel_handle;
62 mojo::edk::CreateChildMessagePipe( 53 std::unique_ptr<service_manager::ServiceContext> service_context =
63 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 54 CreateNaClServiceContext(io_thread_.task_runner(), &channel_handle);
64 switches::kMojoChannelToken))); 55 channel_ = IPC::SyncChannel::Create(channel_handle.release(),
65 DCHECK(handle.is_valid()); 56 IPC::Channel::MODE_CLIENT,
66 IPC::ChannelHandle channel_handle = IPC::ChannelHandle(handle.release()); 57 this, // As a Listener.
67 58 io_thread_.task_runner(),
68 channel_ = IPC::SyncChannel::Create( 59 true, // Create pipe now.
69 channel_handle, 60 &shutdown_event_);
70 IPC::Channel::MODE_CLIENT,
71 this, // As a Listener.
72 io_thread_.task_runner().get(),
73 true, // Create pipe now.
74 &shutdown_event_);
75 base::RunLoop().Run(); 61 base::RunLoop().Run();
76 } 62 }
77 63
78 bool NonSfiListener::OnMessageReceived(const IPC::Message& msg) { 64 bool NonSfiListener::OnMessageReceived(const IPC::Message& msg) {
79 bool handled = true; 65 bool handled = true;
80 IPC_BEGIN_MESSAGE_MAP(NonSfiListener, msg) 66 IPC_BEGIN_MESSAGE_MAP(NonSfiListener, msg)
81 IPC_MESSAGE_HANDLER(NaClProcessMsg_AddPrefetchedResource, 67 IPC_MESSAGE_HANDLER(NaClProcessMsg_AddPrefetchedResource,
82 OnAddPrefetchedResource) 68 OnAddPrefetchedResource)
83 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart) 69 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart)
84 IPC_MESSAGE_UNHANDLED(handled = false) 70 IPC_MESSAGE_UNHANDLED(handled = false)
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 CHECK(params.nexe_file != IPC::InvalidPlatformFileForTransit()); 134 CHECK(params.nexe_file != IPC::InvalidPlatformFileForTransit());
149 CHECK(params.nexe_file_path_metadata.empty()); 135 CHECK(params.nexe_file_path_metadata.empty());
150 136
151 ppapi::RegisterPreopenedDescriptorsNonSfi(key_fd_map_.release()); 137 ppapi::RegisterPreopenedDescriptorsNonSfi(key_fd_map_.release());
152 138
153 MainStart(IPC::PlatformFileForTransitToPlatformFile(params.nexe_file)); 139 MainStart(IPC::PlatformFileForTransitToPlatformFile(params.nexe_file));
154 } 140 }
155 141
156 } // namespace nonsfi 142 } // namespace nonsfi
157 } // namespace nacl 143 } // namespace nacl
OLDNEW
« no previous file with comments | « components/nacl/loader/nonsfi/nonsfi_listener.h ('k') | content/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698