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

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

Issue 315753003: Pepper: Miscellaneous trusted plugin cleanup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | 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 #ifdef _MSC_VER 5 #ifdef _MSC_VER
6 // Do not warn about use of std::copy with raw pointers. 6 // Do not warn about use of std::copy with raw pointers.
7 #pragma warning(disable : 4996) 7 #pragma warning(disable : 4996)
8 #endif 8 #endif
9 9
10 #include "ppapi/native_client/src/trusted/plugin/plugin.h" 10 #include "ppapi/native_client/src/trusted/plugin/plugin.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 68
69 void Plugin::HistogramTimeSmall(const std::string& name, 69 void Plugin::HistogramTimeSmall(const std::string& name,
70 int64_t ms) { 70 int64_t ms) {
71 if (ms < 0) return; 71 if (ms < 0) return;
72 uma_interface_.HistogramCustomTimes(name, 72 uma_interface_.HistogramCustomTimes(name,
73 ms, 73 ms,
74 kTimeSmallMin, kTimeSmallMax, 74 kTimeSmallMin, kTimeSmallMax,
75 kTimeSmallBuckets); 75 kTimeSmallBuckets);
76 } 76 }
77 77
78 void Plugin::HistogramEnumerateSelLdrLoadStatus(NaClErrorCode error_code) {
79 if (error_code < 0 || error_code > NACL_ERROR_CODE_MAX)
80 error_code = LOAD_STATUS_UNKNOWN;
81
82 uma_interface_.HistogramEnumeration("NaCl.LoadStatus.SelLdr",
83 error_code,
84 NACL_ERROR_CODE_MAX);
85
86 // Gather data to see if being installed changes load outcomes.
87 const char* name = nacl_interface_->GetIsInstalled(pp_instance()) ?
88 "NaCl.LoadStatus.SelLdr.InstalledApp" :
89 "NaCl.LoadStatus.SelLdr.NotInstalledApp";
90 uma_interface_.HistogramEnumeration(name, error_code, NACL_ERROR_CODE_MAX);
91 }
92
93 bool Plugin::LoadNaClModuleFromBackgroundThread( 78 bool Plugin::LoadNaClModuleFromBackgroundThread(
94 PP_FileHandle file_handle, 79 PP_FileHandle file_handle,
95 NaClSubprocess* subprocess, 80 NaClSubprocess* subprocess,
96 const SelLdrStartParams& params) { 81 const SelLdrStartParams& params) {
97 CHECK(!pp::Module::Get()->core()->IsMainThread()); 82 CHECK(!pp::Module::Get()->core()->IsMainThread());
98 ServiceRuntime* service_runtime = 83 ServiceRuntime* service_runtime =
99 new ServiceRuntime(this, false, uses_nonsfi_mode_, 84 new ServiceRuntime(this, false, uses_nonsfi_mode_,
100 pp::BlockUntilComplete(), pp::BlockUntilComplete()); 85 pp::BlockUntilComplete(), pp::BlockUntilComplete());
101 subprocess->set_service_runtime(service_runtime); 86 subprocess->set_service_runtime(service_runtime);
102 PLUGIN_PRINTF(("Plugin::LoadNaClModuleFromBackgroundThread " 87 PLUGIN_PRINTF(("Plugin::LoadNaClModuleFromBackgroundThread "
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 return nacl_subprocess.release(); 294 return nacl_subprocess.release();
310 } 295 }
311 296
312 // All failures of this function will show up as "Missing Plugin-in", so 297 // All failures of this function will show up as "Missing Plugin-in", so
313 // there is no need to log to JS console that there was an initialization 298 // there is no need to log to JS console that there was an initialization
314 // failure. Note that module loading functions will log their own errors. 299 // failure. Note that module loading functions will log their own errors.
315 bool Plugin::Init(uint32_t argc, const char* argn[], const char* argv[]) { 300 bool Plugin::Init(uint32_t argc, const char* argn[], const char* argv[]) {
316 PLUGIN_PRINTF(("Plugin::Init (argc=%" NACL_PRIu32 ")\n", argc)); 301 PLUGIN_PRINTF(("Plugin::Init (argc=%" NACL_PRIu32 ")\n", argc));
317 nacl_interface_->InitializePlugin(pp_instance(), argc, argn, argv); 302 nacl_interface_->InitializePlugin(pp_instance(), argc, argn, argv);
318 wrapper_factory_ = new nacl::DescWrapperFactory(); 303 wrapper_factory_ = new nacl::DescWrapperFactory();
319 pp::Var manifest_url(pp::PASS_REF, nacl_interface_->GetManifestURLArgument( 304 pp::CompletionCallback open_cb =
320 pp_instance())); 305 callback_factory_.NewCallback(&Plugin::NaClManifestFileDidOpen);
321 if (manifest_url.is_string() && !manifest_url.AsString().empty()) 306 nacl_interface_->RequestNaClManifest(pp_instance(),
322 RequestNaClManifest(manifest_url.AsString()); 307 open_cb.pp_completion_callback());
323 return true; 308 return true;
324 } 309 }
325 310
326 Plugin::Plugin(PP_Instance pp_instance) 311 Plugin::Plugin(PP_Instance pp_instance)
327 : pp::Instance(pp_instance), 312 : pp::Instance(pp_instance),
328 main_subprocess_("main subprocess", NULL, NULL), 313 main_subprocess_("main subprocess", NULL, NULL),
329 uses_nonsfi_mode_(false), 314 uses_nonsfi_mode_(false),
330 wrapper_factory_(NULL), 315 wrapper_factory_(NULL),
331 time_of_last_progress_event_(0), 316 time_of_last_progress_event_(0),
332 nacl_interface_(NULL), 317 nacl_interface_(NULL),
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 nexe_file_info_, 398 nexe_file_info_,
414 uses_nonsfi_mode_, 399 uses_nonsfi_mode_,
415 true, /* enable_dyncode_syscalls */ 400 true, /* enable_dyncode_syscalls */
416 true, /* enable_exception_handling */ 401 true, /* enable_exception_handling */
417 false, /* enable_crash_throttling */ 402 false, /* enable_crash_throttling */
418 callback_factory_.NewCallback(&Plugin::NexeFileDidOpenContinuation), 403 callback_factory_.NewCallback(&Plugin::NexeFileDidOpenContinuation),
419 callback_factory_.NewCallback(&Plugin::NexeDidCrash)); 404 callback_factory_.NewCallback(&Plugin::NexeDidCrash));
420 } 405 }
421 406
422 void Plugin::NexeFileDidOpenContinuation(int32_t pp_error) { 407 void Plugin::NexeFileDidOpenContinuation(int32_t pp_error) {
423 bool was_successful;
424
425 UNREFERENCED_PARAMETER(pp_error); 408 UNREFERENCED_PARAMETER(pp_error);
426 NaClLog(4, "Entered NexeFileDidOpenContinuation\n"); 409 NaClLog(4, "Entered NexeFileDidOpenContinuation\n");
427 NaClLog(4, "NexeFileDidOpenContinuation: invoking" 410 if (LoadNaClModuleContinuationIntern()) {
428 " LoadNaClModuleContinuationIntern\n");
429 was_successful = LoadNaClModuleContinuationIntern();
430 if (was_successful) {
431 NaClLog(4, "NexeFileDidOpenContinuation: success;" 411 NaClLog(4, "NexeFileDidOpenContinuation: success;"
432 " setting histograms\n"); 412 " setting histograms\n");
433 int64_t nexe_size = nacl_interface_->GetNexeSize(pp_instance()); 413 int64_t nexe_size = nacl_interface_->GetNexeSize(pp_instance());
434 ReportLoadSuccess(nexe_size, nexe_size); 414 nacl_interface_->ReportLoadSuccess(
415 pp_instance(), program_url_.c_str(), nexe_size, nexe_size);
435 } else { 416 } else {
436 NaClLog(4, "NexeFileDidOpenContinuation: failed."); 417 NaClLog(4, "NexeFileDidOpenContinuation: failed.");
437 } 418 }
438 NaClLog(4, "Leaving NexeFileDidOpenContinuation\n"); 419 NaClLog(4, "Leaving NexeFileDidOpenContinuation\n");
439 } 420 }
440 421
441 void Plugin::NexeDidCrash(int32_t pp_error) { 422 void Plugin::NexeDidCrash(int32_t pp_error) {
442 PLUGIN_PRINTF(("Plugin::NexeDidCrash (pp_error=%" NACL_PRId32 ")\n", 423 PLUGIN_PRINTF(("Plugin::NexeDidCrash (pp_error=%" NACL_PRId32 ")\n",
443 pp_error)); 424 pp_error));
444 if (pp_error != PP_OK) { 425 if (pp_error != PP_OK) {
(...skipping 26 matching lines...) Expand all
471 info, 452 info,
472 false, /* uses_nonsfi_mode */ 453 false, /* uses_nonsfi_mode */
473 false, /* enable_dyncode_syscalls */ 454 false, /* enable_dyncode_syscalls */
474 false, /* enable_exception_handling */ 455 false, /* enable_exception_handling */
475 true, /* enable_crash_throttling */ 456 true, /* enable_crash_throttling */
476 callback_factory_.NewCallback(&Plugin::BitcodeDidTranslateContinuation), 457 callback_factory_.NewCallback(&Plugin::BitcodeDidTranslateContinuation),
477 callback_factory_.NewCallback(&Plugin::NexeDidCrash)); 458 callback_factory_.NewCallback(&Plugin::NexeDidCrash));
478 } 459 }
479 460
480 void Plugin::BitcodeDidTranslateContinuation(int32_t pp_error) { 461 void Plugin::BitcodeDidTranslateContinuation(int32_t pp_error) {
481 bool was_successful = LoadNaClModuleContinuationIntern();
482
483 NaClLog(4, "Entered BitcodeDidTranslateContinuation\n"); 462 NaClLog(4, "Entered BitcodeDidTranslateContinuation\n");
484 UNREFERENCED_PARAMETER(pp_error); 463 UNREFERENCED_PARAMETER(pp_error);
485 if (was_successful) { 464 if (LoadNaClModuleContinuationIntern()) {
486 int64_t loaded; 465 int64_t loaded;
487 int64_t total; 466 int64_t total;
467 // TODO(teravest): Tighten this up so we can get rid of
468 // GetCurrentProgress(). loaded should always equal total.
488 pnacl_coordinator_->GetCurrentProgress(&loaded, &total); 469 pnacl_coordinator_->GetCurrentProgress(&loaded, &total);
489 ReportLoadSuccess(loaded, total); 470 nacl_interface_->ReportLoadSuccess(
471 pp_instance(), program_url_.c_str(), loaded, total);
490 } 472 }
491 } 473 }
492 474
493 void Plugin::NaClManifestFileDidOpen(int32_t pp_error) { 475 void Plugin::NaClManifestFileDidOpen(int32_t pp_error) {
494 PLUGIN_PRINTF(("Plugin::NaClManifestFileDidOpen (pp_error=%" 476 PLUGIN_PRINTF(("Plugin::NaClManifestFileDidOpen (pp_error=%"
495 NACL_PRId32 ")\n", pp_error)); 477 NACL_PRId32 ")\n", pp_error));
496 if (pp_error != PP_OK) 478 if (pp_error != PP_OK)
497 return; 479 return;
498 480
499 PP_Var pp_program_url; 481 PP_Var pp_program_url;
(...skipping 21 matching lines...) Expand all
521 // Will always call the callback on success or failure. 503 // Will always call the callback on success or failure.
522 nacl_interface_->DownloadNexe(pp_instance(), 504 nacl_interface_->DownloadNexe(pp_instance(),
523 program_url_.c_str(), 505 program_url_.c_str(),
524 &nexe_file_info_, 506 &nexe_file_info_,
525 open_callback.pp_completion_callback()); 507 open_callback.pp_completion_callback());
526 return; 508 return;
527 } 509 }
528 } 510 }
529 } 511 }
530 512
531 void Plugin::RequestNaClManifest(const nacl::string& url) {
532 PLUGIN_PRINTF(("Plugin::RequestNaClManifest (url='%s')\n", url.c_str()));
533 pp::CompletionCallback open_callback =
534 callback_factory_.NewCallback(&Plugin::NaClManifestFileDidOpen);
535 nacl_interface_->RequestNaClManifest(pp_instance(),
536 url.c_str(),
537 open_callback.pp_completion_callback());
538 }
539
540 void Plugin::ReportLoadSuccess(uint64_t loaded_bytes, uint64_t total_bytes) {
541 nacl_interface_->ReportLoadSuccess(
542 pp_instance(), program_url_.c_str(), loaded_bytes, total_bytes);
543 }
544
545
546 void Plugin::ReportLoadError(const ErrorInfo& error_info) { 513 void Plugin::ReportLoadError(const ErrorInfo& error_info) {
547 nacl_interface_->ReportLoadError(pp_instance(), 514 nacl_interface_->ReportLoadError(pp_instance(),
548 error_info.error_code(), 515 error_info.error_code(),
549 error_info.message().c_str(), 516 error_info.message().c_str(),
550 error_info.console_message().c_str()); 517 error_info.console_message().c_str());
551 } 518 }
552 519
553
554 void Plugin::ReportLoadAbort() {
555 nacl_interface_->ReportLoadAbort(pp_instance());
556 }
557
558 void Plugin::ReportSelLdrLoadStatus(int status) {
559 HistogramEnumerateSelLdrLoadStatus(static_cast<NaClErrorCode>(status));
560 }
561
562 bool Plugin::DocumentCanRequest(const std::string& url) { 520 bool Plugin::DocumentCanRequest(const std::string& url) {
563 CHECK(pp::Module::Get()->core()->IsMainThread()); 521 CHECK(pp::Module::Get()->core()->IsMainThread());
564 CHECK(pp::URLUtil_Dev::Get() != NULL); 522 CHECK(pp::URLUtil_Dev::Get() != NULL);
565 return pp::URLUtil_Dev::Get()->DocumentCanRequest(this, pp::Var(url)); 523 return pp::URLUtil_Dev::Get()->DocumentCanRequest(this, pp::Var(url));
566 } 524 }
567 525
568 void Plugin::set_exit_status(int exit_status) { 526 void Plugin::set_exit_status(int exit_status) {
569 pp::Core* core = pp::Module::Get()->core(); 527 pp::Core* core = pp::Module::Get()->core();
570 if (core->IsMainThread()) { 528 if (core->IsMainThread()) {
571 SetExitStatusOnMainThread(PP_OK, exit_status); 529 SetExitStatusOnMainThread(PP_OK, exit_status);
572 } else { 530 } else {
573 pp::CompletionCallback callback = 531 pp::CompletionCallback callback =
574 callback_factory_.NewCallback(&Plugin::SetExitStatusOnMainThread, 532 callback_factory_.NewCallback(&Plugin::SetExitStatusOnMainThread,
575 exit_status); 533 exit_status);
576 core->CallOnMainThread(0, callback, 0); 534 core->CallOnMainThread(0, callback, 0);
577 } 535 }
578 } 536 }
579 537
580 void Plugin::SetExitStatusOnMainThread(int32_t pp_error, 538 void Plugin::SetExitStatusOnMainThread(int32_t pp_error,
581 int exit_status) { 539 int exit_status) {
582 DCHECK(pp::Module::Get()->core()->IsMainThread()); 540 DCHECK(pp::Module::Get()->core()->IsMainThread());
583 DCHECK(nacl_interface_); 541 DCHECK(nacl_interface_);
584 nacl_interface_->SetExitStatus(pp_instance(), exit_status); 542 nacl_interface_->SetExitStatus(pp_instance(), exit_status);
585 } 543 }
586 544
587 545
588 } // namespace plugin 546 } // namespace plugin
OLDNEW
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/plugin.h ('k') | ppapi/native_client/src/trusted/plugin/service_runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698