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

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

Issue 1010183002: SFI NaCl: Batch-open resource files (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review Created 5 years, 9 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>
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 268
269 bool NaClListener::OnMessageReceived(const IPC::Message& msg) { 269 bool NaClListener::OnMessageReceived(const IPC::Message& msg) {
270 bool handled = true; 270 bool handled = true;
271 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg) 271 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg)
272 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart) 272 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart)
273 IPC_MESSAGE_UNHANDLED(handled = false) 273 IPC_MESSAGE_UNHANDLED(handled = false)
274 IPC_END_MESSAGE_MAP() 274 IPC_END_MESSAGE_MAP()
275 return handled; 275 return handled;
276 } 276 }
277 277
278 bool NaClListener::OnOpenResource(
279 const IPC::Message& msg,
280 const std::string& key,
281 NaClIPCAdapter::OpenResourceReplyCallback cb) {
282 DCHECK(!cb.is_null());
283 std::map<std::string, std::pair<
Mark Seaborn 2015/03/20 00:40:52 Nit: Define a typedef for this std::map?
Yusuke Sato 2015/04/16 02:38:45 Done.
284 IPC::PlatformFileForTransit, base::FilePath> >::iterator it;
285
286 const std::string files_prefix = "files/";
287 if (key.find(files_prefix) == 0)
Mark Seaborn 2015/03/20 00:40:52 You're stripping off the "files/" prefix which is
Yusuke Sato 2015/04/16 02:38:45 Sure, let me add a TODO for now.
Yusuke Sato 2015/04/16 03:51:14 https://codereview.chromium.org/1070233007/
288 it = prefetched_resource_files_.find(key.substr(files_prefix.length()));
Mark Seaborn 2015/03/20 00:40:52 Can you comment this as a fast path, like how it's
Yusuke Sato 2015/04/16 02:38:45 Done.
289 else
290 it = prefetched_resource_files_.find(key);
291
292 if (it != prefetched_resource_files_.end()) {
293 IPC::PlatformFileForTransit file = it->second.first;
294 base::FilePath path = it->second.second;
295 prefetched_resource_files_.erase(it);
Mark Seaborn 2015/03/20 00:40:52 Can you add a comment saying why this is thread-sa
Yusuke Sato 2015/04/16 02:38:45 Done.
296 // A pre-opened resource descriptor is available. Run the reply callback
297 // and return true.
298 cb.Run(msg, file, path);
299 return true;
300 }
301
302 // Return false to let the IPC adapter issue an IPC to the renderer.
Mark Seaborn 2015/03/20 00:40:52 ...and fall back to the slow path.
Yusuke Sato 2015/04/16 02:38:45 Done.
303 return false;
304 }
305
278 void NaClListener::OnStart(const nacl::NaClStartParams& params) { 306 void NaClListener::OnStart(const nacl::NaClStartParams& params) {
279 #if defined(OS_LINUX) || defined(OS_MACOSX) 307 #if defined(OS_LINUX) || defined(OS_MACOSX)
280 int urandom_fd = dup(base::GetUrandomFD()); 308 int urandom_fd = dup(base::GetUrandomFD());
281 if (urandom_fd < 0) { 309 if (urandom_fd < 0) {
282 LOG(ERROR) << "Failed to dup() the urandom FD"; 310 LOG(ERROR) << "Failed to dup() the urandom FD";
283 return; 311 return;
284 } 312 }
285 NaClChromeMainSetUrandomFd(urandom_fd); 313 NaClChromeMainSetUrandomFd(urandom_fd);
286 #endif 314 #endif
287 struct NaClApp* nap = NULL; 315 struct NaClApp* nap = NULL;
288 NaClChromeMainInit(); 316 NaClChromeMainInit();
289 317
290 crash_info_shmem_.reset(new base::SharedMemory(params.crash_info_shmem_handle, 318 crash_info_shmem_.reset(new base::SharedMemory(params.crash_info_shmem_handle,
291 false)); 319 false));
292 CHECK(crash_info_shmem_->Map(nacl::kNaClCrashInfoShmemSize)); 320 CHECK(crash_info_shmem_->Map(nacl::kNaClCrashInfoShmemSize));
293 NaClSetFatalErrorCallback(&FatalLogHandler); 321 NaClSetFatalErrorCallback(&FatalLogHandler);
294 322
295 nap = NaClAppCreate(); 323 nap = NaClAppCreate();
296 if (nap == NULL) { 324 if (nap == NULL) {
297 LOG(ERROR) << "NaClAppCreate() failed"; 325 LOG(ERROR) << "NaClAppCreate() failed";
298 return; 326 return;
299 } 327 }
300 328
301 IPC::ChannelHandle browser_handle; 329 IPC::ChannelHandle browser_handle;
302 IPC::ChannelHandle ppapi_renderer_handle; 330 IPC::ChannelHandle ppapi_renderer_handle;
303 IPC::ChannelHandle manifest_service_handle; 331 IPC::ChannelHandle manifest_service_handle;
304 332
333 for (size_t i = 0; i < params.prefetched_resource_files.size(); ++i) {
334 bool result = prefetched_resource_files_.insert(std::make_pair(
335 params.prefetched_resource_files[i].file_key,
336 std::make_pair(
337 params.prefetched_resource_files[i].file,
338 params.prefetched_resource_files[i].file_path_metadata))).second;
339 if (!result) {
340 DLOG(ERROR) << "Duplicated open_resource key: "
341 << params.prefetched_resource_files[i].file_key;
342 }
343 }
344
305 if (params.enable_ipc_proxy) { 345 if (params.enable_ipc_proxy) {
306 browser_handle = IPC::Channel::GenerateVerifiedChannelID("nacl"); 346 browser_handle = IPC::Channel::GenerateVerifiedChannelID("nacl");
307 ppapi_renderer_handle = IPC::Channel::GenerateVerifiedChannelID("nacl"); 347 ppapi_renderer_handle = IPC::Channel::GenerateVerifiedChannelID("nacl");
308 manifest_service_handle = IPC::Channel::GenerateVerifiedChannelID("nacl"); 348 manifest_service_handle = IPC::Channel::GenerateVerifiedChannelID("nacl");
309 349
310 // Create the PPAPI IPC channels between the NaCl IRT and the host 350 // Create the PPAPI IPC channels between the NaCl IRT and the host
311 // (browser/renderer) processes. The IRT uses these channels to 351 // (browser/renderer) processes. The IRT uses these channels to
312 // communicate with the host and to initialize the IPC dispatchers. 352 // communicate with the host and to initialize the IPC dispatchers.
313 SetUpIPCAdapter(&browser_handle, io_thread_.message_loop_proxy(), 353 SetUpIPCAdapter(&browser_handle, io_thread_.message_loop_proxy(),
314 nap, NACL_CHROME_DESC_BASE); 354 nap, NACL_CHROME_DESC_BASE);
315 SetUpIPCAdapter(&ppapi_renderer_handle, io_thread_.message_loop_proxy(), 355 SetUpIPCAdapter(&ppapi_renderer_handle, io_thread_.message_loop_proxy(),
316 nap, NACL_CHROME_DESC_BASE + 1); 356 nap, NACL_CHROME_DESC_BASE + 1);
317 357
318 scoped_refptr<NaClIPCAdapter> manifest_ipc_adapter = 358 scoped_refptr<NaClIPCAdapter> manifest_ipc_adapter =
319 SetUpIPCAdapter(&manifest_service_handle, 359 SetUpIPCAdapter(&manifest_service_handle,
320 io_thread_.message_loop_proxy(), 360 io_thread_.message_loop_proxy(),
321 nap, 361 nap,
322 NACL_CHROME_DESC_BASE + 2); 362 NACL_CHROME_DESC_BASE + 2);
323 manifest_ipc_adapter->set_resolve_file_token_callback( 363 manifest_ipc_adapter->set_resolve_file_token_callback(
324 base::Bind(&NaClListener::ResolveFileToken, base::Unretained(this))); 364 base::Bind(&NaClListener::ResolveFileToken, base::Unretained(this)));
365 manifest_ipc_adapter->set_open_resource_callback(
366 base::Bind(&NaClListener::OnOpenResource, base::Unretained(this)));
325 } 367 }
326 368
327 trusted_listener_ = new NaClTrustedListener( 369 trusted_listener_ = new NaClTrustedListener(
328 IPC::Channel::GenerateVerifiedChannelID("nacl"), 370 IPC::Channel::GenerateVerifiedChannelID("nacl"),
329 io_thread_.message_loop_proxy().get(), 371 io_thread_.message_loop_proxy().get(),
330 &shutdown_event_); 372 &shutdown_event_);
331 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated( 373 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated(
332 browser_handle, 374 browser_handle,
333 ppapi_renderer_handle, 375 ppapi_renderer_handle,
334 trusted_listener_->TakeClientChannelHandle(), 376 trusted_listener_->TakeClientChannelHandle(),
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 // //mojo/nacl for implementation details. 483 // //mojo/nacl for implementation details.
442 InjectMojo(nap); 484 InjectMojo(nap);
443 } else { 485 } else {
444 // When Mojo isn't enabled, we inject a file descriptor that intentionally 486 // When Mojo isn't enabled, we inject a file descriptor that intentionally
445 // fails on any imc_sendmsg() call to make debugging easier. 487 // fails on any imc_sendmsg() call to make debugging easier.
446 InjectDisabledMojo(nap); 488 InjectDisabledMojo(nap);
447 } 489 }
448 #else 490 #else
449 InjectDisabledMojo(nap); 491 InjectDisabledMojo(nap);
450 #endif 492 #endif
451 // TODO(yusukes): Support pre-opening resource files.
452 CHECK(params.prefetched_resource_files.empty());
453 493
454 int exit_status; 494 int exit_status;
455 if (!NaClChromeMainStart(nap, args, &exit_status)) 495 if (!NaClChromeMainStart(nap, args, &exit_status))
456 NaClExit(1); 496 NaClExit(1);
457 497
458 // Report the plugin's exit status if the application started successfully. 498 // Report the plugin's exit status if the application started successfully.
459 trusted_listener_->Send(new NaClRendererMsg_ReportExitStatus(exit_status)); 499 trusted_listener_->Send(new NaClRendererMsg_ReportExitStatus(exit_status));
460 NaClExit(exit_status); 500 NaClExit(exit_status);
461 } 501 }
462 502
463 void NaClListener::ResolveFileToken( 503 void NaClListener::ResolveFileToken(
464 uint64_t token_lo, 504 uint64_t token_lo,
465 uint64_t token_hi, 505 uint64_t token_hi,
466 base::Callback<void(IPC::PlatformFileForTransit, base::FilePath)> cb) { 506 base::Callback<void(IPC::PlatformFileForTransit, base::FilePath)> cb) {
467 if (!Send(new NaClProcessMsg_ResolveFileToken(token_lo, token_hi))) { 507 if (!Send(new NaClProcessMsg_ResolveFileToken(token_lo, token_hi))) {
468 cb.Run(IPC::PlatformFileForTransit(), base::FilePath()); 508 cb.Run(IPC::PlatformFileForTransit(), base::FilePath());
469 return; 509 return;
470 } 510 }
471 resolved_cb_ = cb; 511 resolved_cb_ = cb;
472 } 512 }
473 513
474 void NaClListener::OnFileTokenResolved( 514 void NaClListener::OnFileTokenResolved(
475 uint64_t token_lo, 515 uint64_t token_lo,
476 uint64_t token_hi, 516 uint64_t token_hi,
477 IPC::PlatformFileForTransit ipc_fd, 517 IPC::PlatformFileForTransit ipc_fd,
478 base::FilePath file_path) { 518 base::FilePath file_path) {
479 resolved_cb_.Run(ipc_fd, file_path); 519 resolved_cb_.Run(ipc_fd, file_path);
480 resolved_cb_.Reset(); 520 resolved_cb_.Reset();
481 } 521 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698