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

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

Issue 1184523003: attachment broker wip (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor comments. Created 5 years, 6 months 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_main.cc » ('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>
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 // (browser/renderer) process, and starts to listen it on the thread where 140 // (browser/renderer) process, and starts to listen it on the thread where
141 // the given message_loop_proxy runs. 141 // the given message_loop_proxy runs.
142 // Also, creates and sets the corresponding NaClDesc to the given nap with 142 // Also, creates and sets the corresponding NaClDesc to the given nap with
143 // the FD #. 143 // the FD #.
144 void SetUpIPCAdapter( 144 void SetUpIPCAdapter(
145 IPC::ChannelHandle* handle, 145 IPC::ChannelHandle* handle,
146 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 146 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
147 struct NaClApp* nap, 147 struct NaClApp* nap,
148 int nacl_fd, 148 int nacl_fd,
149 NaClIPCAdapter::ResolveFileTokenCallback resolve_file_token_cb, 149 NaClIPCAdapter::ResolveFileTokenCallback resolve_file_token_cb,
150 NaClIPCAdapter::OpenResourceCallback open_resource_cb) { 150 NaClIPCAdapter::OpenResourceCallback open_resource_cb,
151 scoped_refptr<NaClIPCAdapter> ipc_adapter(new NaClIPCAdapter( 151 IPC::AttachmentBroker* broker) {
152 *handle, task_runner.get(), resolve_file_token_cb, open_resource_cb)); 152 scoped_refptr<NaClIPCAdapter> ipc_adapter(
153 new NaClIPCAdapter(*handle, task_runner.get(), resolve_file_token_cb,
154 open_resource_cb, broker));
153 ipc_adapter->ConnectChannel(); 155 ipc_adapter->ConnectChannel();
154 #if defined(OS_POSIX) 156 #if defined(OS_POSIX)
155 handle->socket = 157 handle->socket =
156 base::FileDescriptor(ipc_adapter->TakeClientFileDescriptor()); 158 base::FileDescriptor(ipc_adapter->TakeClientFileDescriptor());
157 #endif 159 #endif
158 160
159 // Pass a NaClDesc to the untrusted side. This will hold a ref to the 161 // Pass a NaClDesc to the untrusted side. This will hold a ref to the
160 // NaClIPCAdapter. 162 // NaClIPCAdapter.
161 NaClAppSetDesc(nap, nacl_fd, ipc_adapter->MakeNaClDesc()); 163 NaClAppSetDesc(nap, nacl_fd, ipc_adapter->MakeNaClDesc());
162 } 164 }
(...skipping 24 matching lines...) Expand all
187 if (!listener_->Send(new NaClProcessMsg_SetKnownToValidate(signature))) { 189 if (!listener_->Send(new NaClProcessMsg_SetKnownToValidate(signature))) {
188 LOG(ERROR) << "Failed to update NaCl validation cache."; 190 LOG(ERROR) << "Failed to update NaCl validation cache.";
189 } 191 }
190 } 192 }
191 193
192 private: 194 private:
193 // The listener never dies, otherwise this might be a dangling reference. 195 // The listener never dies, otherwise this might be a dangling reference.
194 NaClListener* listener_; 196 NaClListener* listener_;
195 }; 197 };
196 198
197 199 NaClListener::NaClListener(IPC::AttachmentBroker* broker)
198 NaClListener::NaClListener() : shutdown_event_(true, false), 200 : shutdown_event_(true, false),
199 io_thread_("NaCl_IOThread"), 201 io_thread_("NaCl_IOThread"),
202 broker_(broker),
200 #if defined(OS_LINUX) 203 #if defined(OS_LINUX)
201 prereserved_sandbox_size_(0), 204 prereserved_sandbox_size_(0),
202 #endif 205 #endif
203 #if defined(OS_POSIX) 206 #if defined(OS_POSIX)
204 number_of_cores_(-1), // unknown/error 207 number_of_cores_(-1), // unknown/error
205 #endif 208 #endif
206 main_loop_(NULL), 209 main_loop_(NULL),
207 is_started_(false) { 210 is_started_(false) {
208 io_thread_.StartWithOptions( 211 io_thread_.StartWithOptions(
209 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); 212 base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
210 DCHECK(g_listener == NULL); 213 DCHECK(g_listener == NULL);
211 g_listener = this; 214 g_listener = this;
212 } 215 }
213 216
214 NaClListener::~NaClListener() { 217 NaClListener::~NaClListener() {
215 NOTREACHED(); 218 NOTREACHED();
216 shutdown_event_.Signal(); 219 shutdown_event_.Signal();
217 g_listener = NULL; 220 g_listener = NULL;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 261
259 void NaClListener::Listen() { 262 void NaClListener::Listen() {
260 std::string channel_name = 263 std::string channel_name =
261 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 264 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
262 switches::kProcessChannelID); 265 switches::kProcessChannelID);
263 channel_ = IPC::SyncChannel::Create(this, io_thread_.task_runner().get(), 266 channel_ = IPC::SyncChannel::Create(this, io_thread_.task_runner().get(),
264 &shutdown_event_); 267 &shutdown_event_);
265 filter_ = new IPC::SyncMessageFilter(&shutdown_event_); 268 filter_ = new IPC::SyncMessageFilter(&shutdown_event_);
266 channel_->AddFilter(filter_.get()); 269 channel_->AddFilter(filter_.get());
267 channel_->AddFilter(new FileTokenMessageFilter()); 270 channel_->AddFilter(new FileTokenMessageFilter());
268 channel_->Init(channel_name, IPC::Channel::MODE_CLIENT, true); 271 channel_->Init(channel_name, IPC::Channel::MODE_CLIENT, true, broker_);
269 main_loop_ = base::MessageLoop::current(); 272 main_loop_ = base::MessageLoop::current();
270 main_loop_->Run(); 273 main_loop_->Run();
271 } 274 }
272 275
273 bool NaClListener::OnMessageReceived(const IPC::Message& msg) { 276 bool NaClListener::OnMessageReceived(const IPC::Message& msg) {
274 bool handled = true; 277 bool handled = true;
275 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg) 278 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg)
276 IPC_MESSAGE_HANDLER(NaClProcessMsg_AddPrefetchedResource, 279 IPC_MESSAGE_HANDLER(NaClProcessMsg_AddPrefetchedResource,
277 OnAddPrefetchedResource) 280 OnAddPrefetchedResource)
278 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart) 281 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart)
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 browser_handle = IPC::Channel::GenerateVerifiedChannelID("nacl"); 357 browser_handle = IPC::Channel::GenerateVerifiedChannelID("nacl");
355 ppapi_renderer_handle = IPC::Channel::GenerateVerifiedChannelID("nacl"); 358 ppapi_renderer_handle = IPC::Channel::GenerateVerifiedChannelID("nacl");
356 manifest_service_handle = IPC::Channel::GenerateVerifiedChannelID("nacl"); 359 manifest_service_handle = IPC::Channel::GenerateVerifiedChannelID("nacl");
357 360
358 // Create the PPAPI IPC channels between the NaCl IRT and the host 361 // Create the PPAPI IPC channels between the NaCl IRT and the host
359 // (browser/renderer) processes. The IRT uses these channels to 362 // (browser/renderer) processes. The IRT uses these channels to
360 // communicate with the host and to initialize the IPC dispatchers. 363 // communicate with the host and to initialize the IPC dispatchers.
361 SetUpIPCAdapter(&browser_handle, io_thread_.task_runner(), nap, 364 SetUpIPCAdapter(&browser_handle, io_thread_.task_runner(), nap,
362 NACL_CHROME_DESC_BASE, 365 NACL_CHROME_DESC_BASE,
363 NaClIPCAdapter::ResolveFileTokenCallback(), 366 NaClIPCAdapter::ResolveFileTokenCallback(),
364 NaClIPCAdapter::OpenResourceCallback()); 367 NaClIPCAdapter::OpenResourceCallback(), broker_);
365 SetUpIPCAdapter(&ppapi_renderer_handle, io_thread_.task_runner(), nap, 368 SetUpIPCAdapter(&ppapi_renderer_handle, io_thread_.task_runner(), nap,
366 NACL_CHROME_DESC_BASE + 1, 369 NACL_CHROME_DESC_BASE + 1,
367 NaClIPCAdapter::ResolveFileTokenCallback(), 370 NaClIPCAdapter::ResolveFileTokenCallback(),
368 NaClIPCAdapter::OpenResourceCallback()); 371 NaClIPCAdapter::OpenResourceCallback(), broker_);
369 SetUpIPCAdapter( 372 SetUpIPCAdapter(
370 &manifest_service_handle, io_thread_.task_runner(), nap, 373 &manifest_service_handle, io_thread_.task_runner(), nap,
371 NACL_CHROME_DESC_BASE + 2, 374 NACL_CHROME_DESC_BASE + 2,
372 base::Bind(&NaClListener::ResolveFileToken, base::Unretained(this)), 375 base::Bind(&NaClListener::ResolveFileToken, base::Unretained(this)),
373 base::Bind(&NaClListener::OnOpenResource, base::Unretained(this))); 376 base::Bind(&NaClListener::OnOpenResource, base::Unretained(this)),
377 broker_);
374 } 378 }
375 379
376 trusted_listener_ = 380 trusted_listener_ =
377 new NaClTrustedListener(IPC::Channel::GenerateVerifiedChannelID("nacl"), 381 new NaClTrustedListener(IPC::Channel::GenerateVerifiedChannelID("nacl"),
378 io_thread_.task_runner().get(), &shutdown_event_); 382 io_thread_.task_runner().get(), &shutdown_event_);
379 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated( 383 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated(
380 browser_handle, 384 browser_handle,
381 ppapi_renderer_handle, 385 ppapi_renderer_handle,
382 trusted_listener_->TakeClientChannelHandle(), 386 trusted_listener_->TakeClientChannelHandle(),
383 manifest_service_handle))) 387 manifest_service_handle)))
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 } 500 }
497 501
498 void NaClListener::OnFileTokenResolved( 502 void NaClListener::OnFileTokenResolved(
499 uint64_t token_lo, 503 uint64_t token_lo,
500 uint64_t token_hi, 504 uint64_t token_hi,
501 IPC::PlatformFileForTransit ipc_fd, 505 IPC::PlatformFileForTransit ipc_fd,
502 base::FilePath file_path) { 506 base::FilePath file_path) {
503 resolved_cb_.Run(ipc_fd, file_path); 507 resolved_cb_.Run(ipc_fd, file_path);
504 resolved_cb_.Reset(); 508 resolved_cb_.Reset();
505 } 509 }
OLDNEW
« no previous file with comments | « components/nacl/loader/nacl_listener.h ('k') | components/nacl/loader/nacl_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698