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

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

Issue 1144153004: components: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. 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
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>
11 11
12 #if defined(OS_POSIX) 12 #if defined(OS_POSIX)
13 #include <unistd.h> 13 #include <unistd.h>
14 #endif 14 #endif
15 15
16 #include "base/command_line.h" 16 #include "base/command_line.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
19 #include "base/message_loop/message_loop.h"
20 #include "base/rand_util.h" 19 #include "base/rand_util.h"
20 #include "base/single_thread_task_runner.h"
21 #include "components/nacl/common/nacl_messages.h" 21 #include "components/nacl/common/nacl_messages.h"
22 #include "components/nacl/common/nacl_renderer_messages.h" 22 #include "components/nacl/common/nacl_renderer_messages.h"
23 #include "components/nacl/common/nacl_switches.h" 23 #include "components/nacl/common/nacl_switches.h"
24 #include "components/nacl/loader/nacl_ipc_adapter.h" 24 #include "components/nacl/loader/nacl_ipc_adapter.h"
25 #include "components/nacl/loader/nacl_validation_db.h" 25 #include "components/nacl/loader/nacl_validation_db.h"
26 #include "components/nacl/loader/nacl_validation_query.h" 26 #include "components/nacl/loader/nacl_validation_query.h"
27 #include "ipc/ipc_channel_handle.h" 27 #include "ipc/ipc_channel_handle.h"
28 #include "ipc/ipc_switches.h" 28 #include "ipc/ipc_switches.h"
29 #include "ipc/ipc_sync_channel.h" 29 #include "ipc/ipc_sync_channel.h"
30 #include "ipc/ipc_sync_message_filter.h" 30 #include "ipc/ipc_sync_message_filter.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 136
137 #endif 137 #endif
138 138
139 // Creates the PPAPI IPC channel between the NaCl IRT and the host 139 // Creates the PPAPI IPC channel between the NaCl IRT and the host
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::MessageLoopProxy> message_loop_proxy, 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( 151 scoped_refptr<NaClIPCAdapter> ipc_adapter(new NaClIPCAdapter(
152 new NaClIPCAdapter(*handle, 152 *handle, task_runner.get(), resolve_file_token_cb, open_resource_cb));
153 message_loop_proxy.get(),
154 resolve_file_token_cb,
155 open_resource_cb));
156 ipc_adapter->ConnectChannel(); 153 ipc_adapter->ConnectChannel();
157 #if defined(OS_POSIX) 154 #if defined(OS_POSIX)
158 handle->socket = 155 handle->socket =
159 base::FileDescriptor(ipc_adapter->TakeClientFileDescriptor()); 156 base::FileDescriptor(ipc_adapter->TakeClientFileDescriptor());
160 #endif 157 #endif
161 158
162 // Pass a NaClDesc to the untrusted side. This will hold a ref to the 159 // Pass a NaClDesc to the untrusted side. This will hold a ref to the
163 // NaClIPCAdapter. 160 // NaClIPCAdapter.
164 NaClAppSetDesc(nap, nacl_fd, ipc_adapter->MakeNaClDesc()); 161 NaClAppSetDesc(nap, nacl_fd, ipc_adapter->MakeNaClDesc());
165 } 162 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 g_listener->OnFileTokenResolved(token_lo, token_hi, ipc_fd, file_path); 253 g_listener->OnFileTokenResolved(token_lo, token_hi, ipc_fd, file_path);
257 } 254 }
258 private: 255 private:
259 ~FileTokenMessageFilter() override {} 256 ~FileTokenMessageFilter() override {}
260 }; 257 };
261 258
262 void NaClListener::Listen() { 259 void NaClListener::Listen() {
263 std::string channel_name = 260 std::string channel_name =
264 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 261 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
265 switches::kProcessChannelID); 262 switches::kProcessChannelID);
266 channel_ = IPC::SyncChannel::Create( 263 channel_ = IPC::SyncChannel::Create(this, io_thread_.task_runner().get(),
267 this, io_thread_.message_loop_proxy().get(), &shutdown_event_); 264 &shutdown_event_);
268 filter_ = new IPC::SyncMessageFilter(&shutdown_event_); 265 filter_ = new IPC::SyncMessageFilter(&shutdown_event_);
269 channel_->AddFilter(filter_.get()); 266 channel_->AddFilter(filter_.get());
270 channel_->AddFilter(new FileTokenMessageFilter()); 267 channel_->AddFilter(new FileTokenMessageFilter());
271 channel_->Init(channel_name, IPC::Channel::MODE_CLIENT, true); 268 channel_->Init(channel_name, IPC::Channel::MODE_CLIENT, true);
272 main_loop_ = base::MessageLoop::current(); 269 main_loop_ = base::MessageLoop::current();
273 main_loop_->Run(); 270 main_loop_->Run();
274 } 271 }
275 272
276 bool NaClListener::OnMessageReceived(const IPC::Message& msg) { 273 bool NaClListener::OnMessageReceived(const IPC::Message& msg) {
277 bool handled = true; 274 bool handled = true;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 IPC::ChannelHandle manifest_service_handle; 353 IPC::ChannelHandle manifest_service_handle;
357 354
358 if (params.enable_ipc_proxy) { 355 if (params.enable_ipc_proxy) {
359 browser_handle = IPC::Channel::GenerateVerifiedChannelID("nacl"); 356 browser_handle = IPC::Channel::GenerateVerifiedChannelID("nacl");
360 ppapi_renderer_handle = IPC::Channel::GenerateVerifiedChannelID("nacl"); 357 ppapi_renderer_handle = IPC::Channel::GenerateVerifiedChannelID("nacl");
361 manifest_service_handle = IPC::Channel::GenerateVerifiedChannelID("nacl"); 358 manifest_service_handle = IPC::Channel::GenerateVerifiedChannelID("nacl");
362 359
363 // Create the PPAPI IPC channels between the NaCl IRT and the host 360 // Create the PPAPI IPC channels between the NaCl IRT and the host
364 // (browser/renderer) processes. The IRT uses these channels to 361 // (browser/renderer) processes. The IRT uses these channels to
365 // communicate with the host and to initialize the IPC dispatchers. 362 // communicate with the host and to initialize the IPC dispatchers.
366 SetUpIPCAdapter(&browser_handle, io_thread_.message_loop_proxy(), 363 SetUpIPCAdapter(&browser_handle, io_thread_.task_runner(), nap,
367 nap, NACL_CHROME_DESC_BASE, 364 NACL_CHROME_DESC_BASE,
368 NaClIPCAdapter::ResolveFileTokenCallback(), 365 NaClIPCAdapter::ResolveFileTokenCallback(),
369 NaClIPCAdapter::OpenResourceCallback()); 366 NaClIPCAdapter::OpenResourceCallback());
370 SetUpIPCAdapter(&ppapi_renderer_handle, io_thread_.message_loop_proxy(), 367 SetUpIPCAdapter(&ppapi_renderer_handle, io_thread_.task_runner(), nap,
371 nap, NACL_CHROME_DESC_BASE + 1, 368 NACL_CHROME_DESC_BASE + 1,
372 NaClIPCAdapter::ResolveFileTokenCallback(), 369 NaClIPCAdapter::ResolveFileTokenCallback(),
373 NaClIPCAdapter::OpenResourceCallback()); 370 NaClIPCAdapter::OpenResourceCallback());
374 SetUpIPCAdapter(&manifest_service_handle, 371 SetUpIPCAdapter(
375 io_thread_.message_loop_proxy(), 372 &manifest_service_handle, io_thread_.task_runner(), nap,
376 nap, 373 NACL_CHROME_DESC_BASE + 2,
377 NACL_CHROME_DESC_BASE + 2, 374 base::Bind(&NaClListener::ResolveFileToken, base::Unretained(this)),
378 base::Bind(&NaClListener::ResolveFileToken, 375 base::Bind(&NaClListener::OnOpenResource, base::Unretained(this)));
379 base::Unretained(this)),
380 base::Bind(&NaClListener::OnOpenResource,
381 base::Unretained(this)));
382 } 376 }
383 377
384 trusted_listener_ = new NaClTrustedListener( 378 trusted_listener_ =
385 IPC::Channel::GenerateVerifiedChannelID("nacl"), 379 new NaClTrustedListener(IPC::Channel::GenerateVerifiedChannelID("nacl"),
386 io_thread_.message_loop_proxy().get(), 380 io_thread_.task_runner().get(), &shutdown_event_);
387 &shutdown_event_);
388 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated( 381 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated(
389 browser_handle, 382 browser_handle,
390 ppapi_renderer_handle, 383 ppapi_renderer_handle,
391 trusted_listener_->TakeClientChannelHandle(), 384 trusted_listener_->TakeClientChannelHandle(),
392 manifest_service_handle))) 385 manifest_service_handle)))
393 LOG(ERROR) << "Failed to send IPC channel handle to NaClProcessHost."; 386 LOG(ERROR) << "Failed to send IPC channel handle to NaClProcessHost.";
394 387
395 struct NaClChromeMainArgs* args = NaClChromeMainArgsCreate(); 388 struct NaClChromeMainArgs* args = NaClChromeMainArgsCreate();
396 if (args == NULL) { 389 if (args == NULL) {
397 LOG(ERROR) << "NaClChromeMainArgsCreate() failed"; 390 LOG(ERROR) << "NaClChromeMainArgsCreate() failed";
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 } 500 }
508 501
509 void NaClListener::OnFileTokenResolved( 502 void NaClListener::OnFileTokenResolved(
510 uint64_t token_lo, 503 uint64_t token_lo,
511 uint64_t token_hi, 504 uint64_t token_hi,
512 IPC::PlatformFileForTransit ipc_fd, 505 IPC::PlatformFileForTransit ipc_fd,
513 base::FilePath file_path) { 506 base::FilePath file_path) {
514 resolved_cb_.Run(ipc_fd, file_path); 507 resolved_cb_.Run(ipc_fd, file_path);
515 resolved_cb_.Reset(); 508 resolved_cb_.Reset();
516 } 509 }
OLDNEW
« no previous file with comments | « components/nacl/loader/nacl_listener.h ('k') | components/nacl/loader/nonsfi/nonsfi_listener.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698