| 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/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> |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 : shutdown_event_(true, false), | 189 : shutdown_event_(true, false), |
| 190 io_thread_("NaCl_IOThread"), | 190 io_thread_("NaCl_IOThread"), |
| 191 #if defined(OS_LINUX) | 191 #if defined(OS_LINUX) |
| 192 prereserved_sandbox_size_(0), | 192 prereserved_sandbox_size_(0), |
| 193 #endif | 193 #endif |
| 194 #if defined(OS_POSIX) | 194 #if defined(OS_POSIX) |
| 195 number_of_cores_(-1), // unknown/error | 195 number_of_cores_(-1), // unknown/error |
| 196 #endif | 196 #endif |
| 197 main_loop_(NULL), | 197 main_loop_(NULL), |
| 198 is_started_(false) { | 198 is_started_(false) { |
| 199 IPC::AttachmentBrokerUnprivileged::CreateBrokerIfNeeded(); | 199 attachment_broker_.reset( |
| 200 IPC::AttachmentBrokerUnprivileged::CreateBroker().release()); |
| 200 io_thread_.StartWithOptions( | 201 io_thread_.StartWithOptions( |
| 201 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); | 202 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
| 202 DCHECK(g_listener == NULL); | 203 DCHECK(g_listener == NULL); |
| 203 g_listener = this; | 204 g_listener = this; |
| 204 } | 205 } |
| 205 | 206 |
| 206 NaClListener::~NaClListener() { | 207 NaClListener::~NaClListener() { |
| 207 NOTREACHED(); | 208 NOTREACHED(); |
| 208 shutdown_event_.Signal(); | 209 shutdown_event_.Signal(); |
| 209 g_listener = NULL; | 210 g_listener = NULL; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 | 251 |
| 251 void NaClListener::Listen() { | 252 void NaClListener::Listen() { |
| 252 std::string channel_name = | 253 std::string channel_name = |
| 253 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 254 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 254 switches::kProcessChannelID); | 255 switches::kProcessChannelID); |
| 255 channel_ = IPC::SyncChannel::Create(this, io_thread_.task_runner().get(), | 256 channel_ = IPC::SyncChannel::Create(this, io_thread_.task_runner().get(), |
| 256 &shutdown_event_); | 257 &shutdown_event_); |
| 257 filter_ = channel_->CreateSyncMessageFilter(); | 258 filter_ = channel_->CreateSyncMessageFilter(); |
| 258 channel_->AddFilter(new FileTokenMessageFilter()); | 259 channel_->AddFilter(new FileTokenMessageFilter()); |
| 259 channel_->Init(channel_name, IPC::Channel::MODE_CLIENT, true); | 260 channel_->Init(channel_name, IPC::Channel::MODE_CLIENT, true); |
| 260 IPC::AttachmentBroker* global = IPC::AttachmentBroker::GetGlobal(); | 261 if (attachment_broker_.get()) |
| 261 if (global && !global->IsPrivilegedBroker()) | 262 attachment_broker_->DesignateBrokerCommunicationChannel(channel_.get()); |
| 262 global->RegisterBrokerCommunicationChannel(channel_.get()); | |
| 263 main_loop_ = base::MessageLoop::current(); | 263 main_loop_ = base::MessageLoop::current(); |
| 264 main_loop_->Run(); | 264 main_loop_->Run(); |
| 265 } | 265 } |
| 266 | 266 |
| 267 bool NaClListener::OnMessageReceived(const IPC::Message& msg) { | 267 bool NaClListener::OnMessageReceived(const IPC::Message& msg) { |
| 268 bool handled = true; | 268 bool handled = true; |
| 269 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg) | 269 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg) |
| 270 IPC_MESSAGE_HANDLER(NaClProcessMsg_AddPrefetchedResource, | 270 IPC_MESSAGE_HANDLER(NaClProcessMsg_AddPrefetchedResource, |
| 271 OnAddPrefetchedResource) | 271 OnAddPrefetchedResource) |
| 272 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart) | 272 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart) |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 } | 479 } |
| 480 | 480 |
| 481 void NaClListener::OnFileTokenResolved( | 481 void NaClListener::OnFileTokenResolved( |
| 482 uint64_t token_lo, | 482 uint64_t token_lo, |
| 483 uint64_t token_hi, | 483 uint64_t token_hi, |
| 484 IPC::PlatformFileForTransit ipc_fd, | 484 IPC::PlatformFileForTransit ipc_fd, |
| 485 base::FilePath file_path) { | 485 base::FilePath file_path) { |
| 486 resolved_cb_.Run(ipc_fd, file_path); | 486 resolved_cb_.Run(ipc_fd, file_path); |
| 487 resolved_cb_.Reset(); | 487 resolved_cb_.Reset(); |
| 488 } | 488 } |
| OLD | NEW |