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

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

Issue 287153006: Pepper: Manifest refactoring in trusted plugin. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 7 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 namespace plugin { 43 namespace plugin {
44 44
45 namespace { 45 namespace {
46 46
47 // Up to 20 seconds 47 // Up to 20 seconds
48 const int64_t kTimeSmallMin = 1; // in ms 48 const int64_t kTimeSmallMin = 1; // in ms
49 const int64_t kTimeSmallMax = 20000; // in ms 49 const int64_t kTimeSmallMax = 20000; // in ms
50 const uint32_t kTimeSmallBuckets = 100; 50 const uint32_t kTimeSmallBuckets = 100;
51 51
52 const int64_t kSizeKBMin = 1;
53 const int64_t kSizeKBMax = 512*1024; // very large .nexe
54 const uint32_t kSizeKBBuckets = 100;
55
56 // Converts a PP_FileHandle to a POSIX file descriptor. 52 // Converts a PP_FileHandle to a POSIX file descriptor.
57 int32_t ConvertFileDescriptor(PP_FileHandle handle) { 53 int32_t ConvertFileDescriptor(PP_FileHandle handle) {
58 PLUGIN_PRINTF(("ConvertFileDescriptor, handle=%d\n", handle)); 54 PLUGIN_PRINTF(("ConvertFileDescriptor, handle=%d\n", handle));
59 #if NACL_WINDOWS 55 #if NACL_WINDOWS
60 int32_t file_desc = NACL_NO_FILE_DESC; 56 int32_t file_desc = NACL_NO_FILE_DESC;
61 // On Windows, valid handles are 32 bit unsigned integers so this is safe. 57 // On Windows, valid handles are 32 bit unsigned integers so this is safe.
62 file_desc = reinterpret_cast<intptr_t>(handle); 58 file_desc = reinterpret_cast<intptr_t>(handle);
63 // Convert the Windows HANDLE from Pepper to a POSIX file descriptor. 59 // Convert the Windows HANDLE from Pepper to a POSIX file descriptor.
64 int32_t posix_desc = _open_osfhandle(file_desc, _O_RDWR | _O_BINARY); 60 int32_t posix_desc = _open_osfhandle(file_desc, _O_RDWR | _O_BINARY);
65 if (posix_desc == -1) { 61 if (posix_desc == -1) {
(...skipping 26 matching lines...) Expand all
92 88
93 void Plugin::HistogramTimeSmall(const std::string& name, 89 void Plugin::HistogramTimeSmall(const std::string& name,
94 int64_t ms) { 90 int64_t ms) {
95 if (ms < 0) return; 91 if (ms < 0) return;
96 uma_interface_.HistogramCustomTimes(name, 92 uma_interface_.HistogramCustomTimes(name,
97 ms, 93 ms,
98 kTimeSmallMin, kTimeSmallMax, 94 kTimeSmallMin, kTimeSmallMax,
99 kTimeSmallBuckets); 95 kTimeSmallBuckets);
100 } 96 }
101 97
102 void Plugin::HistogramSizeKB(const std::string& name,
103 int32_t sample) {
104 if (sample < 0) return;
105 uma_interface_.HistogramCustomCounts(name,
106 sample,
107 kSizeKBMin, kSizeKBMax,
108 kSizeKBBuckets);
109 }
110
111 void Plugin::HistogramEnumerateSelLdrLoadStatus(NaClErrorCode error_code) { 98 void Plugin::HistogramEnumerateSelLdrLoadStatus(NaClErrorCode error_code) {
112 if (error_code < 0 || error_code > NACL_ERROR_CODE_MAX) 99 if (error_code < 0 || error_code > NACL_ERROR_CODE_MAX)
113 error_code = LOAD_STATUS_UNKNOWN; 100 error_code = LOAD_STATUS_UNKNOWN;
114 101
115 uma_interface_.HistogramEnumeration("NaCl.LoadStatus.SelLdr", 102 uma_interface_.HistogramEnumeration("NaCl.LoadStatus.SelLdr",
116 error_code, 103 error_code,
117 NACL_ERROR_CODE_MAX); 104 NACL_ERROR_CODE_MAX);
118 105
119 // Gather data to see if being installed changes load outcomes. 106 // Gather data to see if being installed changes load outcomes.
120 const char* name = nacl_interface_->GetIsInstalled(pp_instance()) ? 107 const char* name = nacl_interface_->GetIsInstalled(pp_instance()) ?
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 375
389 for (std::map<nacl::string, NaClFileInfoAutoCloser*>::iterator it = 376 for (std::map<nacl::string, NaClFileInfoAutoCloser*>::iterator it =
390 url_file_info_map_.begin(); 377 url_file_info_map_.begin();
391 it != url_file_info_map_.end(); 378 it != url_file_info_map_.end();
392 ++it) { 379 ++it) {
393 delete it->second; 380 delete it->second;
394 } 381 }
395 url_downloaders_.erase(url_downloaders_.begin(), url_downloaders_.end()); 382 url_downloaders_.erase(url_downloaders_.begin(), url_downloaders_.end());
396 383
397 // Clean up accounting for our instance inside the NaCl interface. 384 // Clean up accounting for our instance inside the NaCl interface.
385 if (manifest_id_ != -1)
386 nacl_interface_->DestroyManifest(pp_instance(), manifest_id_);
398 nacl_interface_->InstanceDestroyed(pp_instance()); 387 nacl_interface_->InstanceDestroyed(pp_instance());
399 388
400 // ShutDownSubprocesses shuts down the main subprocess, which shuts 389 // ShutDownSubprocesses shuts down the main subprocess, which shuts
401 // down the main ServiceRuntime object, which kills the subprocess. 390 // down the main ServiceRuntime object, which kills the subprocess.
402 // As a side effect of the subprocess being killed, the reverse 391 // As a side effect of the subprocess being killed, the reverse
403 // services thread(s) will get EOF on the reverse channel(s), and 392 // services thread(s) will get EOF on the reverse channel(s), and
404 // the thread(s) will exit. In ServiceRuntime::Shutdown, we invoke 393 // the thread(s) will exit. In ServiceRuntime::Shutdown, we invoke
405 // ReverseService::WaitForServiceThreadsToExit(), so that there will 394 // ReverseService::WaitForServiceThreadsToExit(), so that there will
406 // not be an extent thread(s) hanging around. This means that the 395 // not be an extent thread(s) hanging around. This means that the
407 // ~Plugin will block until this happens. This is a requirement, 396 // ~Plugin will block until this happens. This is a requirement,
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 int64_t loaded; 514 int64_t loaded;
526 int64_t total; 515 int64_t total;
527 pnacl_coordinator_->GetCurrentProgress(&loaded, &total); 516 pnacl_coordinator_->GetCurrentProgress(&loaded, &total);
528 ReportLoadSuccess(loaded, total); 517 ReportLoadSuccess(loaded, total);
529 } 518 }
530 } 519 }
531 520
532 void Plugin::NaClManifestFileDidOpen(int32_t pp_error) { 521 void Plugin::NaClManifestFileDidOpen(int32_t pp_error) {
533 PLUGIN_PRINTF(("Plugin::NaClManifestFileDidOpen (pp_error=%" 522 PLUGIN_PRINTF(("Plugin::NaClManifestFileDidOpen (pp_error=%"
534 NACL_PRId32 ")\n", pp_error)); 523 NACL_PRId32 ")\n", pp_error));
535 if (pp_error == PP_OK) { 524 if (pp_error != PP_OK || manifest_id_ == -1)
536 // Take local ownership of manifest_data_var_
537 pp::Var manifest_data = pp::Var(pp::PASS_REF, manifest_data_var_);
538 manifest_data_var_ = PP_MakeUndefined();
539
540 std::string json_buffer = manifest_data.AsString();
541 ProcessNaClManifest(json_buffer);
542 }
543 }
544
545 void Plugin::ProcessNaClManifest(const nacl::string& manifest_json) {
546 HistogramSizeKB("NaCl.Perf.Size.Manifest",
547 static_cast<int32_t>(manifest_json.length() / 1024));
548 if (!SetManifestObject(manifest_json))
549 return; 525 return;
550 526
551 PP_Var pp_program_url; 527 PP_Var pp_program_url;
552 PP_PNaClOptions pnacl_options = {PP_FALSE, PP_FALSE, 2}; 528 PP_PNaClOptions pnacl_options = {PP_FALSE, PP_FALSE, 2};
553 PP_Bool uses_nonsfi_mode; 529 PP_Bool uses_nonsfi_mode;
554 if (nacl_interface_->GetManifestProgramURL(pp_instance(), 530 if (nacl_interface_->GetManifestProgramURL(pp_instance(),
555 manifest_id_, &pp_program_url, &pnacl_options, &uses_nonsfi_mode)) { 531 manifest_id_, &pp_program_url, &pnacl_options, &uses_nonsfi_mode)) {
556 program_url_ = pp::Var(pp::PASS_REF, pp_program_url).AsString(); 532 program_url_ = pp::Var(pp::PASS_REF, pp_program_url).AsString();
557 // TODO(teravest): Make ProcessNaClManifest take responsibility for more of 533 // TODO(teravest): Make ProcessNaClManifest take responsibility for more of
558 // this function. 534 // this function.
(...skipping 20 matching lines...) Expand all
579 } 555 }
580 } 556 }
581 } 557 }
582 558
583 void Plugin::RequestNaClManifest(const nacl::string& url) { 559 void Plugin::RequestNaClManifest(const nacl::string& url) {
584 PLUGIN_PRINTF(("Plugin::RequestNaClManifest (url='%s')\n", url.c_str())); 560 PLUGIN_PRINTF(("Plugin::RequestNaClManifest (url='%s')\n", url.c_str()));
585 pp::CompletionCallback open_callback = 561 pp::CompletionCallback open_callback =
586 callback_factory_.NewCallback(&Plugin::NaClManifestFileDidOpen); 562 callback_factory_.NewCallback(&Plugin::NaClManifestFileDidOpen);
587 nacl_interface_->RequestNaClManifest(pp_instance(), 563 nacl_interface_->RequestNaClManifest(pp_instance(),
588 url.c_str(), 564 url.c_str(),
589 &manifest_data_var_, 565 &manifest_id_,
590 open_callback.pp_completion_callback()); 566 open_callback.pp_completion_callback());
591 } 567 }
592 568
593
594 bool Plugin::SetManifestObject(const nacl::string& manifest_json) {
595 PLUGIN_PRINTF(("Plugin::SetManifestObject(): manifest_json='%s'.\n",
596 manifest_json.c_str()));
597 // Determine whether lookups should use portable (i.e., pnacl versions)
598 // rather than platform-specific files.
599 pp::Var manifest_base_url =
600 pp::Var(pp::PASS_REF, nacl_interface_->GetManifestBaseURL(pp_instance()));
601 std::string manifest_base_url_str = manifest_base_url.AsString();
602
603 int32_t manifest_id = nacl_interface_->CreateJsonManifest(
604 pp_instance(),
605 manifest_base_url_str.c_str(),
606 manifest_json.c_str());
607 if (manifest_id == -1)
608 return false;
609 manifest_id_ = manifest_id;
610 return true;
611 }
612
613 void Plugin::UrlDidOpenForStreamAsFile( 569 void Plugin::UrlDidOpenForStreamAsFile(
614 int32_t pp_error, 570 int32_t pp_error,
615 FileDownloader* url_downloader, 571 FileDownloader* url_downloader,
616 pp::CompletionCallback callback) { 572 pp::CompletionCallback callback) {
617 PLUGIN_PRINTF(("Plugin::UrlDidOpen (pp_error=%" NACL_PRId32 573 PLUGIN_PRINTF(("Plugin::UrlDidOpen (pp_error=%" NACL_PRId32
618 ", url_downloader=%p)\n", pp_error, 574 ", url_downloader=%p)\n", pp_error,
619 static_cast<void*>(url_downloader))); 575 static_cast<void*>(url_downloader)));
620 url_downloaders_.erase(url_downloader); 576 url_downloaders_.erase(url_downloader);
621 nacl::scoped_ptr<FileDownloader> scoped_url_downloader(url_downloader); 577 nacl::scoped_ptr<FileDownloader> scoped_url_downloader(url_downloader);
622 NaClFileInfo tmp_info(scoped_url_downloader->GetFileInfo()); 578 NaClFileInfo tmp_info(scoped_url_downloader->GetFileInfo());
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 768
813 void Plugin::SetExitStatusOnMainThread(int32_t pp_error, 769 void Plugin::SetExitStatusOnMainThread(int32_t pp_error,
814 int exit_status) { 770 int exit_status) {
815 DCHECK(pp::Module::Get()->core()->IsMainThread()); 771 DCHECK(pp::Module::Get()->core()->IsMainThread());
816 DCHECK(nacl_interface_); 772 DCHECK(nacl_interface_);
817 nacl_interface_->SetExitStatus(pp_instance(), exit_status); 773 nacl_interface_->SetExitStatus(pp_instance(), exit_status);
818 } 774 }
819 775
820 776
821 } // namespace plugin 777 } // namespace plugin
OLDNEW
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/plugin.h ('k') | ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698