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

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

Issue 2525483002: Convert NaCl renderer-loader messages to mojo. (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
« no previous file with comments | « components/nacl/loader/nacl_listener.h ('k') | components/nacl/loader/nacl_trusted_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 "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_messages.h" 28 #include "components/nacl/common/nacl_messages.h"
28 #include "components/nacl/common/nacl_renderer_messages.h"
29 #include "components/nacl/common/nacl_switches.h" 29 #include "components/nacl/common/nacl_switches.h"
30 #include "components/nacl/loader/nacl_ipc_adapter.h" 30 #include "components/nacl/loader/nacl_ipc_adapter.h"
31 #include "components/nacl/loader/nacl_validation_db.h" 31 #include "components/nacl/loader/nacl_validation_db.h"
32 #include "components/nacl/loader/nacl_validation_query.h" 32 #include "components/nacl/loader/nacl_validation_query.h"
33 #include "content/public/common/mojo_channel_switches.h" 33 #include "content/public/common/mojo_channel_switches.h"
34 #include "ipc/ipc_channel_handle.h" 34 #include "ipc/ipc_channel_handle.h"
35 #include "ipc/ipc_sync_channel.h" 35 #include "ipc/ipc_sync_channel.h"
36 #include "ipc/ipc_sync_message_filter.h" 36 #include "ipc/ipc_sync_message_filter.h"
37 #include "mojo/edk/embedder/embedder.h" 37 #include "mojo/edk/embedder/embedder.h"
38 #include "mojo/edk/embedder/scoped_ipc_support.h" 38 #include "mojo/edk/embedder/scoped_ipc_support.h"
(...skipping 30 matching lines...) Expand all
69 // We copy the length of the crash data to the start of the shared memory 69 // We copy the length of the crash data to the start of the shared memory
70 // segment so we know how much to copy. 70 // segment so we know how much to copy.
71 memcpy(g_listener->crash_info_shmem_memory(), &copy_bytes, sizeof(uint32_t)); 71 memcpy(g_listener->crash_info_shmem_memory(), &copy_bytes, sizeof(uint32_t));
72 72
73 memcpy((char*)g_listener->crash_info_shmem_memory() + sizeof(uint32_t), 73 memcpy((char*)g_listener->crash_info_shmem_memory() + sizeof(uint32_t),
74 data, 74 data,
75 copy_bytes); 75 copy_bytes);
76 } 76 }
77 77
78 void LoadStatusCallback(int load_status) { 78 void LoadStatusCallback(int load_status) {
79 g_listener->trusted_listener()->Send( 79 g_listener->trusted_listener()->renderer_host()->ReportLoadStatus(
80 new NaClRendererMsg_ReportLoadStatus( 80 static_cast<NaClErrorCode>(load_status));
81 static_cast<NaClErrorCode>(load_status)));
82 } 81 }
83 82
84 #if defined(OS_LINUX) 83 #if defined(OS_LINUX)
85 84
86 int CreateMemoryObject(size_t size, int executable) { 85 int CreateMemoryObject(size_t size, int executable) {
87 return content::MakeSharedMemorySegmentViaIPC(size, executable); 86 return content::MakeSharedMemorySegmentViaIPC(size, executable);
88 } 87 }
89 88
90 #elif defined(OS_WIN) 89 #elif defined(OS_WIN)
91 int AttachDebugExceptionHandler(const void* info, size_t info_size) { 90 int AttachDebugExceptionHandler(const void* info, size_t info_size) {
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 SetUpIPCAdapter(&ppapi_renderer_handle, io_thread_.task_runner(), nap, 341 SetUpIPCAdapter(&ppapi_renderer_handle, io_thread_.task_runner(), nap,
343 NACL_CHROME_DESC_BASE + 1, 342 NACL_CHROME_DESC_BASE + 1,
344 NaClIPCAdapter::ResolveFileTokenCallback(), 343 NaClIPCAdapter::ResolveFileTokenCallback(),
345 NaClIPCAdapter::OpenResourceCallback()); 344 NaClIPCAdapter::OpenResourceCallback());
346 SetUpIPCAdapter( 345 SetUpIPCAdapter(
347 &manifest_service_handle, io_thread_.task_runner(), nap, 346 &manifest_service_handle, io_thread_.task_runner(), nap,
348 NACL_CHROME_DESC_BASE + 2, 347 NACL_CHROME_DESC_BASE + 2,
349 base::Bind(&NaClListener::ResolveFileToken, base::Unretained(this)), 348 base::Bind(&NaClListener::ResolveFileToken, base::Unretained(this)),
350 base::Bind(&NaClListener::OnOpenResource, base::Unretained(this))); 349 base::Bind(&NaClListener::OnOpenResource, base::Unretained(this)));
351 350
352 mojo::MessagePipe trusted_pipe; 351 nacl::mojom::NaClRendererHostPtr renderer_host;
353 trusted_listener_ =
354 new NaClTrustedListener(trusted_pipe.handle0.release(),
355 io_thread_.task_runner().get(), &shutdown_event_);
356 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated( 352 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated(
357 browser_handle, ppapi_renderer_handle, trusted_pipe.handle1.release(), 353 browser_handle, ppapi_renderer_handle,
354 GetProxy(&renderer_host).PassMessagePipe().release(),
358 manifest_service_handle))) 355 manifest_service_handle)))
359 LOG(FATAL) << "Failed to send IPC channel handle to NaClProcessHost."; 356 LOG(FATAL) << "Failed to send IPC channel handle to NaClProcessHost.";
360 357
358 trusted_listener_ = base::MakeUnique<NaClTrustedListener>(
359 std::move(renderer_host), io_thread_.task_runner().get());
361 struct NaClChromeMainArgs* args = NaClChromeMainArgsCreate(); 360 struct NaClChromeMainArgs* args = NaClChromeMainArgsCreate();
362 if (args == NULL) { 361 if (args == NULL) {
363 LOG(FATAL) << "NaClChromeMainArgsCreate() failed"; 362 LOG(FATAL) << "NaClChromeMainArgsCreate() failed";
364 } 363 }
365 364
366 #if defined(OS_POSIX) 365 #if defined(OS_POSIX)
367 args->number_of_cores = number_of_cores_; 366 args->number_of_cores = number_of_cores_;
368 #endif 367 #endif
369 368
370 #if defined(OS_LINUX) 369 #if defined(OS_LINUX)
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 params.nexe_file); 438 params.nexe_file);
440 std::string file_path_str = params.nexe_file_path_metadata.AsUTF8Unsafe(); 439 std::string file_path_str = params.nexe_file_path_metadata.AsUTF8Unsafe();
441 args->nexe_desc = NaClDescCreateWithFilePathMetadata(nexe_file, 440 args->nexe_desc = NaClDescCreateWithFilePathMetadata(nexe_file,
442 file_path_str.c_str()); 441 file_path_str.c_str());
443 442
444 int exit_status; 443 int exit_status;
445 if (!NaClChromeMainStart(nap, args, &exit_status)) 444 if (!NaClChromeMainStart(nap, args, &exit_status))
446 NaClExit(1); 445 NaClExit(1);
447 446
448 // Report the plugin's exit status if the application started successfully. 447 // Report the plugin's exit status if the application started successfully.
449 trusted_listener_->Send(new NaClRendererMsg_ReportExitStatus(exit_status)); 448 trusted_listener_->renderer_host()->ReportExitStatus(exit_status);
450 NaClExit(exit_status); 449 NaClExit(exit_status);
451 } 450 }
452 451
453 void NaClListener::ResolveFileToken( 452 void NaClListener::ResolveFileToken(
454 uint64_t token_lo, 453 uint64_t token_lo,
455 uint64_t token_hi, 454 uint64_t token_hi,
456 base::Callback<void(IPC::PlatformFileForTransit, base::FilePath)> cb) { 455 base::Callback<void(IPC::PlatformFileForTransit, base::FilePath)> cb) {
457 if (!Send(new NaClProcessMsg_ResolveFileToken(token_lo, token_hi))) { 456 if (!Send(new NaClProcessMsg_ResolveFileToken(token_lo, token_hi))) {
458 cb.Run(IPC::PlatformFileForTransit(), base::FilePath()); 457 cb.Run(IPC::PlatformFileForTransit(), base::FilePath());
459 return; 458 return;
460 } 459 }
461 resolved_cb_ = cb; 460 resolved_cb_ = cb;
462 } 461 }
463 462
464 void NaClListener::OnFileTokenResolved( 463 void NaClListener::OnFileTokenResolved(
465 uint64_t token_lo, 464 uint64_t token_lo,
466 uint64_t token_hi, 465 uint64_t token_hi,
467 IPC::PlatformFileForTransit ipc_fd, 466 IPC::PlatformFileForTransit ipc_fd,
468 base::FilePath file_path) { 467 base::FilePath file_path) {
469 resolved_cb_.Run(ipc_fd, file_path); 468 resolved_cb_.Run(ipc_fd, file_path);
470 resolved_cb_.Reset(); 469 resolved_cb_.Reset();
471 } 470 }
OLDNEW
« no previous file with comments | « components/nacl/loader/nacl_listener.h ('k') | components/nacl/loader/nacl_trusted_listener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698