| 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" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 void SendReply(IPC::Channel* channel, int32_t pid, bool result) { | 28 void SendReply(IPC::Channel* channel, int32_t pid, bool result) { |
| 29 channel->Send(new NaClProcessMsg_DebugExceptionHandlerLaunched(pid, result)); | 29 channel->Send(new NaClProcessMsg_DebugExceptionHandlerLaunched(pid, result)); |
| 30 } | 30 } |
| 31 | 31 |
| 32 } // namespace | 32 } // namespace |
| 33 | 33 |
| 34 NaClBrokerListener::NaClBrokerListener() { | 34 NaClBrokerListener::NaClBrokerListener() { |
| 35 attachment_broker_.reset( | 35 IPC::AttachmentBrokerUnprivileged::CreateBrokerIfNeeded(); |
| 36 IPC::AttachmentBrokerUnprivileged::CreateBroker().release()); | |
| 37 } | 36 } |
| 38 | 37 |
| 39 NaClBrokerListener::~NaClBrokerListener() { | 38 NaClBrokerListener::~NaClBrokerListener() { |
| 39 IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal(); |
| 40 if (broker && !broker->IsPrivilegedBroker() && channel_) |
| 41 broker->DeregisterBrokerCommunicationChannel(channel_.get()); |
| 40 } | 42 } |
| 41 | 43 |
| 42 void NaClBrokerListener::Listen() { | 44 void NaClBrokerListener::Listen() { |
| 43 std::string channel_name = | 45 std::string channel_name = |
| 44 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 46 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 45 switches::kProcessChannelID); | 47 switches::kProcessChannelID); |
| 46 channel_ = IPC::Channel::CreateClient(channel_name, this); | 48 channel_ = IPC::Channel::CreateClient(channel_name, this); |
| 47 if (attachment_broker_.get()) | 49 IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal(); |
| 48 attachment_broker_->DesignateBrokerCommunicationChannel(channel_.get()); | 50 if (broker && !broker->IsPrivilegedBroker()) |
| 51 broker->RegisterBrokerCommunicationChannel(channel_.get()); |
| 49 CHECK(channel_->Connect()); | 52 CHECK(channel_->Connect()); |
| 50 base::MessageLoop::current()->Run(); | 53 base::MessageLoop::current()->Run(); |
| 51 } | 54 } |
| 52 | 55 |
| 53 // 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. |
| 54 bool NaClBrokerListener::PreSpawnTarget(sandbox::TargetPolicy* policy) { | 57 bool NaClBrokerListener::PreSpawnTarget(sandbox::TargetPolicy* policy) { |
| 55 // This code is duplicated in chrome_content_browser_client.cc. | 58 // This code is duplicated in chrome_content_browser_client.cc. |
| 56 | 59 |
| 57 // 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." |
| 58 // namespace so that it cannot impersonate other system or other chrome | 61 // namespace so that it cannot impersonate other system or other chrome |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 const std::string& startup_info) { | 136 const std::string& startup_info) { |
| 134 NaClStartDebugExceptionHandlerThread( | 137 NaClStartDebugExceptionHandlerThread( |
| 135 base::Process(process_handle), startup_info, | 138 base::Process(process_handle), startup_info, |
| 136 base::ThreadTaskRunnerHandle::Get(), | 139 base::ThreadTaskRunnerHandle::Get(), |
| 137 base::Bind(SendReply, channel_.get(), pid)); | 140 base::Bind(SendReply, channel_.get(), pid)); |
| 138 } | 141 } |
| 139 | 142 |
| 140 void NaClBrokerListener::OnStopBroker() { | 143 void NaClBrokerListener::OnStopBroker() { |
| 141 base::MessageLoop::current()->QuitWhenIdle(); | 144 base::MessageLoop::current()->QuitWhenIdle(); |
| 142 } | 145 } |
| OLD | NEW |