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

Side by Side Diff: components/nacl/loader/nacl_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
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 "components/nacl/loader/nacl_listener.h" 5 #include "components/nacl/loader/nacl_listener.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <string.h> 10 #include <string.h>
11 11
12 #include <memory> 12 #include <memory>
13 #include <utility> 13 #include <utility>
14 14
15 #if defined(OS_POSIX) 15 #if defined(OS_POSIX)
16 #include <unistd.h> 16 #include <unistd.h>
17 #endif 17 #endif
18 18
19 #include "base/command_line.h" 19 #include "base/command_line.h"
20 #include "base/logging.h" 20 #include "base/logging.h"
21 #include "base/memory/ptr_util.h" 21 #include "base/memory/ptr_util.h"
22 #include "base/rand_util.h" 22 #include "base/rand_util.h"
23 #include "base/run_loop.h" 23 #include "base/run_loop.h"
24 #include "base/single_thread_task_runner.h" 24 #include "base/single_thread_task_runner.h"
25 #include "base/threading/thread_task_runner_handle.h" 25 #include "base/threading/thread_task_runner_handle.h"
26 #include "build/build_config.h" 26 #include "build/build_config.h"
27 #include "components/nacl/common/nacl.mojom.h" 27 #include "components/nacl/common/nacl.mojom.h"
28 #include "components/nacl/common/nacl_messages.h" 28 #include "components/nacl/common/nacl_messages.h"
29 #include "components/nacl/common/nacl_service.h"
29 #include "components/nacl/common/nacl_switches.h" 30 #include "components/nacl/common/nacl_switches.h"
30 #include "components/nacl/loader/nacl_ipc_adapter.h" 31 #include "components/nacl/loader/nacl_ipc_adapter.h"
31 #include "components/nacl/loader/nacl_validation_db.h" 32 #include "components/nacl/loader/nacl_validation_db.h"
32 #include "components/nacl/loader/nacl_validation_query.h" 33 #include "components/nacl/loader/nacl_validation_query.h"
33 #include "content/public/common/mojo_channel_switches.h" 34 #include "content/public/common/mojo_channel_switches.h"
34 #include "ipc/ipc_channel_handle.h" 35 #include "ipc/ipc_channel_handle.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"
37 #include "mojo/edk/embedder/embedder.h"
38 #include "mojo/edk/embedder/scoped_ipc_support.h"
39 #include "native_client/src/public/chrome_main.h" 38 #include "native_client/src/public/chrome_main.h"
40 #include "native_client/src/public/nacl_app.h" 39 #include "native_client/src/public/nacl_app.h"
41 #include "native_client/src/public/nacl_desc.h" 40 #include "native_client/src/public/nacl_desc.h"
42 41 #include "services/service_manager/public/cpp/service_context.h"
43 #if defined(OS_POSIX)
44 #include "base/posix/global_descriptors.h"
45 #include "content/public/common/content_descriptors.h"
46 #endif
47 42
48 #if defined(OS_LINUX) 43 #if defined(OS_LINUX)
49 #include "content/public/common/child_process_sandbox_support_linux.h" 44 #include "content/public/common/child_process_sandbox_support_linux.h"
50 #endif 45 #endif
51 46
52 #if defined(OS_WIN) 47 #if defined(OS_WIN)
53 #include <io.h> 48 #include <io.h>
54 49
55 #include "content/public/common/sandbox_init.h" 50 #include "content/public/common/sandbox_init.h"
56 #include "mojo/edk/embedder/platform_channel_pair.h"
57 #endif 51 #endif
58 52
59 namespace { 53 namespace {
60 54
61 NaClListener* g_listener; 55 NaClListener* g_listener;
62 56
63 void FatalLogHandler(const char* data, size_t bytes) { 57 void FatalLogHandler(const char* data, size_t bytes) {
64 // We use uint32_t rather than size_t for the case when the browser and NaCl 58 // We use uint32_t rather than size_t for the case when the browser and NaCl
65 // processes are a mix of 32-bit and 64-bit processes. 59 // processes are a mix of 32-bit and 64-bit processes.
66 uint32_t copy_bytes = std::min<uint32_t>(static_cast<uint32_t>(bytes), 60 uint32_t copy_bytes = std::min<uint32_t>(static_cast<uint32_t>(bytes),
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 prereserved_sandbox_size_(0), 161 prereserved_sandbox_size_(0),
168 #endif 162 #endif
169 #if defined(OS_POSIX) 163 #if defined(OS_POSIX)
170 number_of_cores_(-1), // unknown/error 164 number_of_cores_(-1), // unknown/error
171 #endif 165 #endif
172 is_started_(false) { 166 is_started_(false) {
173 io_thread_.StartWithOptions( 167 io_thread_.StartWithOptions(
174 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); 168 base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
175 DCHECK(g_listener == NULL); 169 DCHECK(g_listener == NULL);
176 g_listener = this; 170 g_listener = this;
177
178 mojo_ipc_support_ =
179 base::MakeUnique<mojo::edk::ScopedIPCSupport>(io_thread_.task_runner());
180 #if defined(OS_WIN)
181 mojo::edk::ScopedPlatformHandle platform_channel(
182 mojo::edk::PlatformChannelPair::PassClientHandleFromParentProcess(
183 *base::CommandLine::ForCurrentProcess()));
184 #else
185 mojo::edk::ScopedPlatformHandle platform_channel(
186 mojo::edk::PlatformHandle(
187 base::GlobalDescriptors::GetInstance()->Get(kMojoIPCChannel)));
188 #endif
189 DCHECK(platform_channel.is_valid());
190 mojo::edk::SetParentPipeHandle(std::move(platform_channel));
191 } 171 }
192 172
193 NaClListener::~NaClListener() { 173 NaClListener::~NaClListener() {
194 NOTREACHED(); 174 NOTREACHED();
195 shutdown_event_.Signal(); 175 shutdown_event_.Signal();
196 g_listener = NULL; 176 g_listener = NULL;
197 } 177 }
198 178
199 bool NaClListener::Send(IPC::Message* msg) { 179 bool NaClListener::Send(IPC::Message* msg) {
200 DCHECK(!!main_task_runner_); 180 DCHECK(!!main_task_runner_);
(...skipping 28 matching lines...) Expand all
229 IPC::PlatformFileForTransit ipc_fd, 209 IPC::PlatformFileForTransit ipc_fd,
230 base::FilePath file_path) { 210 base::FilePath file_path) {
231 CHECK(g_listener); 211 CHECK(g_listener);
232 g_listener->OnFileTokenResolved(token_lo, token_hi, ipc_fd, file_path); 212 g_listener->OnFileTokenResolved(token_lo, token_hi, ipc_fd, file_path);
233 } 213 }
234 private: 214 private:
235 ~FileTokenMessageFilter() override {} 215 ~FileTokenMessageFilter() override {}
236 }; 216 };
237 217
238 void NaClListener::Listen() { 218 void NaClListener::Listen() {
239 mojo::ScopedMessagePipeHandle handle(
240 mojo::edk::CreateChildMessagePipe(
241 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
242 switches::kMojoChannelToken)));
243 DCHECK(handle.is_valid());
244
245 channel_ = IPC::SyncChannel::Create(this, io_thread_.task_runner().get(), 219 channel_ = IPC::SyncChannel::Create(this, io_thread_.task_runner().get(),
246 &shutdown_event_); 220 &shutdown_event_);
247 filter_ = channel_->CreateSyncMessageFilter(); 221 filter_ = channel_->CreateSyncMessageFilter();
248 channel_->AddFilter(new FileTokenMessageFilter()); 222 channel_->AddFilter(new FileTokenMessageFilter());
249 channel_->Init(handle.release(), IPC::Channel::MODE_CLIENT, true); 223 mojo::ScopedMessagePipeHandle channel_handle;
224 std::unique_ptr<service_manager::ServiceContext> service_context =
225 CreateNaClServiceContext(io_thread_.task_runner(), &channel_handle);
226 channel_->Init(channel_handle.release(), IPC::Channel::MODE_CLIENT, true);
250 main_task_runner_ = base::ThreadTaskRunnerHandle::Get(); 227 main_task_runner_ = base::ThreadTaskRunnerHandle::Get();
251 base::RunLoop().Run(); 228 base::RunLoop().Run();
252 } 229 }
253 230
254 bool NaClListener::OnMessageReceived(const IPC::Message& msg) { 231 bool NaClListener::OnMessageReceived(const IPC::Message& msg) {
255 bool handled = true; 232 bool handled = true;
256 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg) 233 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg)
257 IPC_MESSAGE_HANDLER(NaClProcessMsg_AddPrefetchedResource, 234 IPC_MESSAGE_HANDLER(NaClProcessMsg_AddPrefetchedResource,
258 OnAddPrefetchedResource) 235 OnAddPrefetchedResource)
259 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart) 236 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart)
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 } 438 }
462 439
463 void NaClListener::OnFileTokenResolved( 440 void NaClListener::OnFileTokenResolved(
464 uint64_t token_lo, 441 uint64_t token_lo,
465 uint64_t token_hi, 442 uint64_t token_hi,
466 IPC::PlatformFileForTransit ipc_fd, 443 IPC::PlatformFileForTransit ipc_fd,
467 base::FilePath file_path) { 444 base::FilePath file_path) {
468 resolved_cb_.Run(ipc_fd, file_path); 445 resolved_cb_.Run(ipc_fd, file_path);
469 resolved_cb_.Reset(); 446 resolved_cb_.Reset();
470 } 447 }
OLDNEW
« no previous file with comments | « components/nacl/loader/nacl_listener.h ('k') | components/nacl/loader/nacl_loader_manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698