| OLD | NEW |
| 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/broker/nacl_broker_listener.h" | 5 #include "components/nacl/broker/nacl_broker_listener.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/message_loop/message_loop.h" | |
| 11 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 12 #include "base/process/launch.h" | 11 #include "base/process/launch.h" |
| 13 #include "base/process/process.h" | 12 #include "base/process/process.h" |
| 14 #include "base/process/process_handle.h" | 13 #include "base/process/process_handle.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "components/nacl/common/nacl_cmd_line.h" | 15 #include "components/nacl/common/nacl_cmd_line.h" |
| 17 #include "components/nacl/common/nacl_debug_exception_handler_win.h" | 16 #include "components/nacl/common/nacl_debug_exception_handler_win.h" |
| 18 #include "components/nacl/common/nacl_messages.h" | 17 #include "components/nacl/common/nacl_messages.h" |
| 19 #include "components/nacl/common/nacl_switches.h" | 18 #include "components/nacl/common/nacl_switches.h" |
| 20 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 44 | 43 |
| 45 void NaClBrokerListener::Listen() { | 44 void NaClBrokerListener::Listen() { |
| 46 std::string channel_name = | 45 std::string channel_name = |
| 47 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 46 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 48 switches::kProcessChannelID); | 47 switches::kProcessChannelID); |
| 49 channel_ = IPC::Channel::CreateClient(channel_name, this); | 48 channel_ = IPC::Channel::CreateClient(channel_name, this); |
| 50 IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal(); | 49 IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal(); |
| 51 if (broker && !broker->IsPrivilegedBroker()) | 50 if (broker && !broker->IsPrivilegedBroker()) |
| 52 broker->RegisterBrokerCommunicationChannel(channel_.get()); | 51 broker->RegisterBrokerCommunicationChannel(channel_.get()); |
| 53 CHECK(channel_->Connect()); | 52 CHECK(channel_->Connect()); |
| 54 base::MessageLoop::current()->Run(); | 53 run_loop_.Run(); |
| 55 } | 54 } |
| 56 | 55 |
| 57 // NOTE: changes to this method need to be reviewed by the security team. | 56 // NOTE: changes to this method need to be reviewed by the security team. |
| 58 bool NaClBrokerListener::PreSpawnTarget(sandbox::TargetPolicy* policy) { | 57 bool NaClBrokerListener::PreSpawnTarget(sandbox::TargetPolicy* policy) { |
| 59 // This code is duplicated in chrome_content_browser_client.cc. | 58 // This code is duplicated in chrome_content_browser_client.cc. |
| 60 | 59 |
| 61 // Allow the server side of a pipe restricted to the "chrome.nacl." | 60 // Allow the server side of a pipe restricted to the "chrome.nacl." |
| 62 // namespace so that it cannot impersonate other system or other chrome | 61 // namespace so that it cannot impersonate other system or other chrome |
| 63 // service pipes. | 62 // service pipes. |
| 64 sandbox::ResultCode result = policy->AddRule( | 63 sandbox::ResultCode result = policy->AddRule( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 81 IPC_MESSAGE_HANDLER(NaClProcessMsg_LaunchDebugExceptionHandler, | 80 IPC_MESSAGE_HANDLER(NaClProcessMsg_LaunchDebugExceptionHandler, |
| 82 OnLaunchDebugExceptionHandler) | 81 OnLaunchDebugExceptionHandler) |
| 83 IPC_MESSAGE_HANDLER(NaClProcessMsg_StopBroker, OnStopBroker) | 82 IPC_MESSAGE_HANDLER(NaClProcessMsg_StopBroker, OnStopBroker) |
| 84 IPC_MESSAGE_UNHANDLED(handled = false) | 83 IPC_MESSAGE_UNHANDLED(handled = false) |
| 85 IPC_END_MESSAGE_MAP() | 84 IPC_END_MESSAGE_MAP() |
| 86 return handled; | 85 return handled; |
| 87 } | 86 } |
| 88 | 87 |
| 89 void NaClBrokerListener::OnChannelError() { | 88 void NaClBrokerListener::OnChannelError() { |
| 90 // The browser died unexpectedly, quit to avoid a zombie process. | 89 // The browser died unexpectedly, quit to avoid a zombie process. |
| 91 base::MessageLoop::current()->QuitWhenIdle(); | 90 run_loop_.QuitWhenIdle(); |
| 92 } | 91 } |
| 93 | 92 |
| 94 void NaClBrokerListener::OnLaunchLoaderThroughBroker( | 93 void NaClBrokerListener::OnLaunchLoaderThroughBroker( |
| 95 const std::string& loader_channel_id) { | 94 const std::string& loader_channel_id) { |
| 96 base::ProcessHandle loader_handle_in_browser = 0; | 95 base::ProcessHandle loader_handle_in_browser = 0; |
| 97 | 96 |
| 98 // Create the path to the nacl broker/loader executable - it's the executable | 97 // Create the path to the nacl broker/loader executable - it's the executable |
| 99 // this code is running in. | 98 // this code is running in. |
| 100 base::FilePath exe_path; | 99 base::FilePath exe_path; |
| 101 PathService::Get(base::FILE_EXE, &exe_path); | 100 PathService::Get(base::FILE_EXE, &exe_path); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 int32_t pid, | 136 int32_t pid, |
| 138 base::ProcessHandle process_handle, | 137 base::ProcessHandle process_handle, |
| 139 const std::string& startup_info) { | 138 const std::string& startup_info) { |
| 140 NaClStartDebugExceptionHandlerThread( | 139 NaClStartDebugExceptionHandlerThread( |
| 141 base::Process(process_handle), startup_info, | 140 base::Process(process_handle), startup_info, |
| 142 base::ThreadTaskRunnerHandle::Get(), | 141 base::ThreadTaskRunnerHandle::Get(), |
| 143 base::Bind(SendReply, channel_.get(), pid)); | 142 base::Bind(SendReply, channel_.get(), pid)); |
| 144 } | 143 } |
| 145 | 144 |
| 146 void NaClBrokerListener::OnStopBroker() { | 145 void NaClBrokerListener::OnStopBroker() { |
| 147 base::MessageLoop::current()->QuitWhenIdle(); | 146 run_loop_.QuitWhenIdle(); |
| 148 } | 147 } |
| OLD | NEW |