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

Side by Side Diff: ppapi/native_client/src/trusted/plugin/pnacl_coordinator.cc

Issue 55463002: Remove PNaCl's RequestFirstInstall, use resource throttle instead (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: reorder functions Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h" 5 #include "ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "native_client/src/include/checked_cast.h" 10 #include "native_client/src/include/checked_cast.h"
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 } 419 }
420 ReportPpapiError(ERROR_PNACL_CACHE_FETCH_OTHER, 420 ReportPpapiError(ERROR_PNACL_CACHE_FETCH_OTHER,
421 pp_error, 421 pp_error,
422 "Failed to open translated nexe."); 422 "Failed to open translated nexe.");
423 return; 423 return;
424 } 424 }
425 425
426 translate_notify_callback_.Run(pp_error); 426 translate_notify_callback_.Run(pp_error);
427 } 427 }
428 428
429 void PnaclCoordinator::DidCheckPnaclInstalled(int32_t pp_error) { 429 void PnaclCoordinator::OpenBitcodeStream() {
430 if (pp_error != PP_OK) { 430 // Now open the pexe stream.
431 streaming_downloader_.reset(new FileDownloader());
432 streaming_downloader_->Initialize(plugin_);
433 // Mark the request as requesting a PNaCl bitcode file,
434 // so that component updater can detect this user action.
435 streaming_downloader_->set_request_headers(
436 "Accept: application/x-pnacl, */*");
437
438 // Even though we haven't started downloading, create the translation
439 // thread object immediately. This ensures that any pieces of the file
440 // that get downloaded before the compilation thread is accepting
441 // SRPCs won't get dropped.
442 translate_thread_.reset(new PnaclTranslateThread());
443 if (translate_thread_ == NULL) {
431 ReportNonPpapiError( 444 ReportNonPpapiError(
432 ERROR_PNACL_RESOURCE_FETCH, 445 ERROR_PNACL_THREAD_CREATE,
433 nacl::string("The Portable Native Client (pnacl) component is not " 446 "PnaclCoordinator: could not allocate translation thread.");
434 "installed. Please consult chrome://components for more "
435 "information."));
436 return; 447 return;
437 } 448 }
438 449
439 // Loading resources (e.g. llc and ld nexes) is done with PnaclResources. 450 pp::CompletionCallback cb =
440 resources_.reset(new PnaclResources(plugin_, 451 callback_factory_.NewCallback(&PnaclCoordinator::BitcodeStreamDidOpen);
441 this, 452 if (!streaming_downloader_->OpenStream(pexe_url_, cb, this)) {
442 this->manifest_.get())); 453 ReportNonPpapiError(
454 ERROR_PNACL_PEXE_FETCH_OTHER,
455 nacl::string("PnaclCoordinator: failed to open stream ") + pexe_url_);
456 return;
457 }
458 }
459
460 void PnaclCoordinator::BitcodeStreamDidOpen(int32_t pp_error) {
461 if (pp_error != PP_OK) {
462 BitcodeStreamDidFinish(pp_error);
463 // We have not spun up the translation process yet, so we need to call
464 // TranslateFinished here.
465 TranslateFinished(pp_error);
466 return;
467 }
468
469 // The component updater's resource throttles + OnDemand update/install
470 // should block the URL request until the compiler is present. Now we
471 // can load the resources (e.g. llc and ld nexes).
472 resources_.reset(new PnaclResources(plugin_, this, this->manifest_.get()));
443 CHECK(resources_ != NULL); 473 CHECK(resources_ != NULL);
444 474
445 // The first step of loading resources: read the resource info file. 475 // The first step of loading resources: read the resource info file.
446 pp::CompletionCallback resource_info_read_cb = 476 pp::CompletionCallback resource_info_read_cb =
447 callback_factory_.NewCallback( 477 callback_factory_.NewCallback(&PnaclCoordinator::ResourceInfoWasRead);
448 &PnaclCoordinator::ResourceInfoWasRead);
449 resources_->ReadResourceInfo(PnaclUrls::GetResourceInfoUrl(), 478 resources_->ReadResourceInfo(PnaclUrls::GetResourceInfoUrl(),
450 resource_info_read_cb); 479 resource_info_read_cb);
451 } 480 }
452 481
453 void PnaclCoordinator::ResourceInfoWasRead(int32_t pp_error) { 482 void PnaclCoordinator::ResourceInfoWasRead(int32_t pp_error) {
454 PLUGIN_PRINTF(("PluginCoordinator::ResourceInfoWasRead (pp_error=%" 483 PLUGIN_PRINTF(("PluginCoordinator::ResourceInfoWasRead (pp_error=%"
455 NACL_PRId32 ")\n", pp_error)); 484 NACL_PRId32 ")\n", pp_error));
456 // Second step of loading resources: call StartLoad. 485 // Second step of loading resources: call StartLoad to load pnacl-llc
486 // and pnacl-ld, based on the filenames found in the resource info file.
457 pp::CompletionCallback resources_cb = 487 pp::CompletionCallback resources_cb =
458 callback_factory_.NewCallback(&PnaclCoordinator::ResourcesDidLoad); 488 callback_factory_.NewCallback(&PnaclCoordinator::ResourcesDidLoad);
459 resources_->StartLoad(resources_cb); 489 resources_->StartLoad(resources_cb);
460 } 490 }
461 491
462 void PnaclCoordinator::ResourcesDidLoad(int32_t pp_error) { 492 void PnaclCoordinator::ResourcesDidLoad(int32_t pp_error) {
463 PLUGIN_PRINTF(("PnaclCoordinator::ResourcesDidLoad (pp_error=%" 493 PLUGIN_PRINTF(("PnaclCoordinator::ResourcesDidLoad (pp_error=%"
464 NACL_PRId32 ")\n", pp_error)); 494 NACL_PRId32 ")\n", pp_error));
465 if (pp_error != PP_OK) { 495 if (pp_error != PP_OK) {
466 // Finer-grained error code should have already been reported by 496 // Finer-grained error code should have already been reported by
(...skipping 25 matching lines...) Expand all
492 PP_FromBool(parser.CacheControlNoStore()), 522 PP_FromBool(parser.CacheControlNoStore()),
493 &is_cache_hit_, 523 &is_cache_hit_,
494 temp_nexe_file_->existing_handle(), 524 temp_nexe_file_->existing_handle(),
495 cb.pp_completion_callback()); 525 cb.pp_completion_callback());
496 if (nexe_fd_err < PP_OK_COMPLETIONPENDING) { 526 if (nexe_fd_err < PP_OK_COMPLETIONPENDING) {
497 ReportPpapiError(ERROR_PNACL_CREATE_TEMP, nexe_fd_err, 527 ReportPpapiError(ERROR_PNACL_CREATE_TEMP, nexe_fd_err,
498 nacl::string("Call to GetNexeFd failed")); 528 nacl::string("Call to GetNexeFd failed"));
499 } 529 }
500 } 530 }
501 531
502 void PnaclCoordinator::OpenBitcodeStream() {
503 // Now open the pexe stream.
504 streaming_downloader_.reset(new FileDownloader());
505 streaming_downloader_->Initialize(plugin_);
506 // Mark the request as requesting a PNaCl bitcode file,
507 // so that component updater can detect this user action.
508 streaming_downloader_->set_request_headers(
509 "Accept: application/x-pnacl, */*");
510
511 // Even though we haven't started downloading, create the translation
512 // thread object immediately. This ensures that any pieces of the file
513 // that get downloaded before the compilation thread is accepting
514 // SRPCs won't get dropped.
515 translate_thread_.reset(new PnaclTranslateThread());
516 if (translate_thread_ == NULL) {
517 ReportNonPpapiError(
518 ERROR_PNACL_THREAD_CREATE,
519 "PnaclCoordinator: could not allocate translation thread.");
520 return;
521 }
522
523 pp::CompletionCallback cb =
524 callback_factory_.NewCallback(&PnaclCoordinator::BitcodeStreamDidOpen);
525 if (!streaming_downloader_->OpenStream(pexe_url_, cb, this)) {
526 ReportNonPpapiError(
527 ERROR_PNACL_PEXE_FETCH_OTHER,
528 nacl::string("PnaclCoordinator: failed to open stream ") + pexe_url_);
529 return;
530 }
531 }
532
533 void PnaclCoordinator::BitcodeStreamDidOpen(int32_t pp_error) {
534 if (pp_error != PP_OK) {
535 BitcodeStreamDidFinish(pp_error);
536 // We have not spun up the translation process yet, so we need to call
537 // TranslateFinished here.
538 TranslateFinished(pp_error);
539 return;
540 }
541
542 // Now that we've started the url request for the response headers and
543 // for tickling the component updater's On-Demand API, check that the
544 // compiler is present, or block until it is present or an error is hit.
545 pp::CompletionCallback pnacl_installed_cb =
546 callback_factory_.NewCallback(&PnaclCoordinator::DidCheckPnaclInstalled);
547 plugin_->nacl_interface()->EnsurePnaclInstalled(
548 plugin_->pp_instance(),
549 pnacl_installed_cb.pp_completion_callback());
550 }
551
552 void PnaclCoordinator::NexeFdDidOpen(int32_t pp_error) { 532 void PnaclCoordinator::NexeFdDidOpen(int32_t pp_error) {
553 PLUGIN_PRINTF(("PnaclCoordinator::NexeFdDidOpen (pp_error=%" 533 PLUGIN_PRINTF(("PnaclCoordinator::NexeFdDidOpen (pp_error=%"
554 NACL_PRId32 ", hit=%d, handle=%d)\n", pp_error, 534 NACL_PRId32 ", hit=%d, handle=%d)\n", pp_error,
555 is_cache_hit_ == PP_TRUE, 535 is_cache_hit_ == PP_TRUE,
556 *temp_nexe_file_->existing_handle())); 536 *temp_nexe_file_->existing_handle()));
557 if (pp_error < PP_OK) { 537 if (pp_error < PP_OK) {
558 ReportPpapiError(ERROR_PNACL_CREATE_TEMP, pp_error, 538 ReportPpapiError(ERROR_PNACL_CREATE_TEMP, pp_error,
559 nacl::string("GetNexeFd failed")); 539 nacl::string("GetNexeFd failed"));
560 return; 540 return;
561 } 541 }
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 obj_file_.get(), 691 obj_file_.get(),
712 temp_nexe_file_.get(), 692 temp_nexe_file_.get(),
713 &error_info_, 693 &error_info_,
714 resources_.get(), 694 resources_.get(),
715 &pnacl_options_, 695 &pnacl_options_,
716 this, 696 this,
717 plugin_); 697 plugin_);
718 } 698 }
719 699
720 } // namespace plugin 700 } // namespace plugin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698