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 IPC::AttachmentBrokerUnprivileged::CreateBrokerIfNeeded(); | 35 attachment_broker_.reset( |
| 36 IPC::AttachmentBrokerUnprivileged::CreateBroker().release()); |
36 } | 37 } |
37 | 38 |
38 NaClBrokerListener::~NaClBrokerListener() { | 39 NaClBrokerListener::~NaClBrokerListener() { |
39 IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal(); | |
40 if (broker && !broker->IsPrivilegedBroker() && channel_) | |
41 broker->DeregisterBrokerCommunicationChannel(channel_.get()); | |
42 } | 40 } |
43 | 41 |
44 void NaClBrokerListener::Listen() { | 42 void NaClBrokerListener::Listen() { |
45 std::string channel_name = | 43 std::string channel_name = |
46 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 44 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
47 switches::kProcessChannelID); | 45 switches::kProcessChannelID); |
48 channel_ = IPC::Channel::CreateClient(channel_name, this); | 46 channel_ = IPC::Channel::CreateClient(channel_name, this); |
49 IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal(); | 47 if (attachment_broker_.get()) |
50 if (broker && !broker->IsPrivilegedBroker()) | 48 attachment_broker_->DesignateBrokerCommunicationChannel(channel_.get()); |
51 broker->RegisterBrokerCommunicationChannel(channel_.get()); | |
52 CHECK(channel_->Connect()); | 49 CHECK(channel_->Connect()); |
53 base::MessageLoop::current()->Run(); | 50 base::MessageLoop::current()->Run(); |
54 } | 51 } |
55 | 52 |
56 // NOTE: changes to this method need to be reviewed by the security team. | 53 // NOTE: changes to this method need to be reviewed by the security team. |
57 bool NaClBrokerListener::PreSpawnTarget(sandbox::TargetPolicy* policy) { | 54 bool NaClBrokerListener::PreSpawnTarget(sandbox::TargetPolicy* policy) { |
58 // This code is duplicated in chrome_content_browser_client.cc. | 55 // This code is duplicated in chrome_content_browser_client.cc. |
59 | 56 |
60 // Allow the server side of a pipe restricted to the "chrome.nacl." | 57 // Allow the server side of a pipe restricted to the "chrome.nacl." |
61 // namespace so that it cannot impersonate other system or other chrome | 58 // namespace so that it cannot impersonate other system or other chrome |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 const std::string& startup_info) { | 133 const std::string& startup_info) { |
137 NaClStartDebugExceptionHandlerThread( | 134 NaClStartDebugExceptionHandlerThread( |
138 base::Process(process_handle), startup_info, | 135 base::Process(process_handle), startup_info, |
139 base::ThreadTaskRunnerHandle::Get(), | 136 base::ThreadTaskRunnerHandle::Get(), |
140 base::Bind(SendReply, channel_.get(), pid)); | 137 base::Bind(SendReply, channel_.get(), pid)); |
141 } | 138 } |
142 | 139 |
143 void NaClBrokerListener::OnStopBroker() { | 140 void NaClBrokerListener::OnStopBroker() { |
144 base::MessageLoop::current()->QuitWhenIdle(); | 141 base::MessageLoop::current()->QuitWhenIdle(); |
145 } | 142 } |
OLD | NEW |