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

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

Issue 147083014: Introduce NaClFileInfoAutoCloser as an RAII wrapper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 10 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 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 static_cast<void*>(scriptable_plugin()))); 655 static_cast<void*>(scriptable_plugin())));
656 // Destroy the coordinator while the rest of the data is still there 656 // Destroy the coordinator while the rest of the data is still there
657 pnacl_coordinator_.reset(NULL); 657 pnacl_coordinator_.reset(NULL);
658 658
659 if (!nexe_error_reported()) { 659 if (!nexe_error_reported()) {
660 HistogramTimeLarge( 660 HistogramTimeLarge(
661 "NaCl.ModuleUptime.Normal", 661 "NaCl.ModuleUptime.Normal",
662 (shutdown_start - ready_time_) / NACL_MICROS_PER_MILLI); 662 (shutdown_start - ready_time_) / NACL_MICROS_PER_MILLI);
663 } 663 }
664 664
665 for (std::map<nacl::string, NaClFileInfoAutoCloser>::iterator it =
666 url_file_info_map_.begin();
667 it != url_file_info_map_.end();
668 ++it) {
669 delete it->second.desc;
670 }
665 url_downloaders_.erase(url_downloaders_.begin(), url_downloaders_.end()); 671 url_downloaders_.erase(url_downloaders_.begin(), url_downloaders_.end());
666 672
667 ScriptablePlugin* scriptable_plugin_ = scriptable_plugin(); 673 ScriptablePlugin* scriptable_plugin_ = scriptable_plugin();
668 ScriptablePlugin::Unref(&scriptable_plugin_); 674 ScriptablePlugin::Unref(&scriptable_plugin_);
669 675
670 // ShutDownSubprocesses shuts down the main subprocess, which shuts 676 // ShutDownSubprocesses shuts down the main subprocess, which shuts
671 // down the main ServiceRuntime object, which kills the subprocess. 677 // down the main ServiceRuntime object, which kills the subprocess.
672 // As a side effect of the subprocess being killed, the reverse 678 // As a side effect of the subprocess being killed, the reverse
673 // services thread(s) will get EOF on the reverse channel(s), and 679 // services thread(s) will get EOF on the reverse channel(s), and
674 // the thread(s) will exit. In ServiceRuntime::Shutdown, we invoke 680 // the thread(s) will exit. In ServiceRuntime::Shutdown, we invoke
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 if (nexe_size_ > 0) { 744 if (nexe_size_ > 0) {
739 float size_in_MB = static_cast<float>(nexe_size_) / (1024.f * 1024.f); 745 float size_in_MB = static_cast<float>(nexe_size_) / (1024.f * 1024.f);
740 HistogramTimeMedium(name, static_cast<int64_t>(dt)); 746 HistogramTimeMedium(name, static_cast<int64_t>(dt));
741 HistogramTimeMedium(name + "PerMB", static_cast<int64_t>(dt / size_in_MB)); 747 HistogramTimeMedium(name + "PerMB", static_cast<int64_t>(dt / size_in_MB));
742 } 748 }
743 } 749 }
744 750
745 void Plugin::NexeFileDidOpen(int32_t pp_error) { 751 void Plugin::NexeFileDidOpen(int32_t pp_error) {
746 PLUGIN_PRINTF(("Plugin::NexeFileDidOpen (pp_error=%" NACL_PRId32 ")\n", 752 PLUGIN_PRINTF(("Plugin::NexeFileDidOpen (pp_error=%" NACL_PRId32 ")\n",
747 pp_error)); 753 pp_error));
748 struct NaClFileInfo info = nexe_downloader_.GetFileInfo(); 754 NaClFileInfoAutoCloser info(nexe_downloader_.GetFileInfo());
749 PLUGIN_PRINTF(("Plugin::NexeFileDidOpen (file_desc=%" NACL_PRId32 ")\n", 755 PLUGIN_PRINTF(("Plugin::NexeFileDidOpen (file_desc=%" NACL_PRId32 ")\n",
750 info.desc)); 756 info.get_desc()));
751 HistogramHTTPStatusCode( 757 HistogramHTTPStatusCode(
752 is_installed_ ? 758 is_installed_ ?
753 "NaCl.HttpStatusCodeClass.Nexe.InstalledApp" : 759 "NaCl.HttpStatusCodeClass.Nexe.InstalledApp" :
754 "NaCl.HttpStatusCodeClass.Nexe.NotInstalledApp", 760 "NaCl.HttpStatusCodeClass.Nexe.NotInstalledApp",
755 nexe_downloader_.status_code()); 761 nexe_downloader_.status_code());
756 ErrorInfo error_info; 762 ErrorInfo error_info;
757 if (pp_error != PP_OK || info.desc == NACL_NO_FILE_DESC) { 763 if (pp_error != PP_OK || info.get_desc() == NACL_NO_FILE_DESC) {
758 if (pp_error == PP_ERROR_ABORTED) { 764 if (pp_error == PP_ERROR_ABORTED) {
759 ReportLoadAbort(); 765 ReportLoadAbort();
760 } else if (pp_error == PP_ERROR_NOACCESS) { 766 } else if (pp_error == PP_ERROR_NOACCESS) {
761 error_info.SetReport(ERROR_NEXE_NOACCESS_URL, 767 error_info.SetReport(ERROR_NEXE_NOACCESS_URL,
762 "access to nexe url was denied."); 768 "access to nexe url was denied.");
763 ReportLoadError(error_info); 769 ReportLoadError(error_info);
764 } else { 770 } else {
765 error_info.SetReport(ERROR_NEXE_LOAD_URL, "could not load nexe url."); 771 error_info.SetReport(ERROR_NEXE_LOAD_URL, "could not load nexe url.");
766 ReportLoadError(error_info); 772 ReportLoadError(error_info);
767 } 773 }
768 return; 774 return;
769 } 775 }
770 int32_t file_desc_ok_to_close = DUP(info.desc); 776 int32_t file_desc_ok_to_close = DUP(info.get_desc());
771 if (file_desc_ok_to_close == NACL_NO_FILE_DESC) { 777 if (file_desc_ok_to_close == NACL_NO_FILE_DESC) {
772 error_info.SetReport(ERROR_NEXE_FH_DUP, 778 error_info.SetReport(ERROR_NEXE_FH_DUP,
773 "could not duplicate loaded file handle."); 779 "could not duplicate loaded file handle.");
774 ReportLoadError(error_info); 780 ReportLoadError(error_info);
775 return; 781 return;
776 } 782 }
777 struct stat stat_buf; 783 struct stat stat_buf;
778 if (0 != fstat(file_desc_ok_to_close, &stat_buf)) { 784 if (0 != fstat(file_desc_ok_to_close, &stat_buf)) {
779 CLOSE(file_desc_ok_to_close); 785 CLOSE(file_desc_ok_to_close);
780 error_info.SetReport(ERROR_NEXE_STAT, "could not stat nexe file."); 786 error_info.SetReport(ERROR_NEXE_STAT, "could not stat nexe file.");
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 nexe_downloader_.TimeSinceOpenMilliseconds()); 1028 nexe_downloader_.TimeSinceOpenMilliseconds());
1023 HistogramHTTPStatusCode( 1029 HistogramHTTPStatusCode(
1024 is_installed_ ? 1030 is_installed_ ?
1025 "NaCl.HttpStatusCodeClass.Manifest.InstalledApp" : 1031 "NaCl.HttpStatusCodeClass.Manifest.InstalledApp" :
1026 "NaCl.HttpStatusCodeClass.Manifest.NotInstalledApp", 1032 "NaCl.HttpStatusCodeClass.Manifest.NotInstalledApp",
1027 nexe_downloader_.status_code()); 1033 nexe_downloader_.status_code());
1028 ErrorInfo error_info; 1034 ErrorInfo error_info;
1029 // The manifest file was successfully opened. Set the src property on the 1035 // The manifest file was successfully opened. Set the src property on the
1030 // plugin now, so that the full url is available to error handlers. 1036 // plugin now, so that the full url is available to error handlers.
1031 set_manifest_url(nexe_downloader_.url()); 1037 set_manifest_url(nexe_downloader_.url());
1032 struct NaClFileInfo info = nexe_downloader_.GetFileInfo(); 1038 NaClFileInfoAutoCloser info(nexe_downloader_.GetFileInfo());
1033 PLUGIN_PRINTF(("Plugin::NaClManifestFileDidOpen (file_desc=%" 1039 PLUGIN_PRINTF(("Plugin::NaClManifestFileDidOpen (file_desc=%"
1034 NACL_PRId32 ")\n", info.desc)); 1040 NACL_PRId32 ")\n", info.get_desc()));
1035 if (pp_error != PP_OK || info.desc == NACL_NO_FILE_DESC) { 1041 if (pp_error != PP_OK || info.get_desc() == NACL_NO_FILE_DESC) {
1036 if (pp_error == PP_ERROR_ABORTED) { 1042 if (pp_error == PP_ERROR_ABORTED) {
1037 ReportLoadAbort(); 1043 ReportLoadAbort();
1038 } else if (pp_error == PP_ERROR_NOACCESS) { 1044 } else if (pp_error == PP_ERROR_NOACCESS) {
1039 error_info.SetReport(ERROR_MANIFEST_NOACCESS_URL, 1045 error_info.SetReport(ERROR_MANIFEST_NOACCESS_URL,
1040 "access to manifest url was denied."); 1046 "access to manifest url was denied.");
1041 ReportLoadError(error_info); 1047 ReportLoadError(error_info);
1042 } else { 1048 } else {
1043 error_info.SetReport(ERROR_MANIFEST_LOAD_URL, 1049 error_info.SetReport(ERROR_MANIFEST_LOAD_URL,
1044 "could not load manifest url."); 1050 "could not load manifest url.");
1045 ReportLoadError(error_info); 1051 ReportLoadError(error_info);
1046 } 1052 }
1047 return; 1053 return;
1048 } 1054 }
1049 // SlurpFile closes the file descriptor after reading (or on error). 1055 // SlurpFile closes the file descriptor after reading (or on error).
1050 // Duplicate our file descriptor since it will be handled by the browser. 1056 // Duplicate our file descriptor since it will be handled by the browser.
1051 int dup_file_desc = DUP(info.desc); 1057 int dup_file_desc = DUP(info.get_desc());
1052 nacl::string json_buffer; 1058 nacl::string json_buffer;
1053 file_utils::StatusCode status = file_utils::SlurpFile( 1059 file_utils::StatusCode status = file_utils::SlurpFile(
1054 dup_file_desc, json_buffer, kNaClManifestMaxFileBytes); 1060 dup_file_desc, json_buffer, kNaClManifestMaxFileBytes);
1055 1061
1056 if (status != file_utils::PLUGIN_FILE_SUCCESS) { 1062 if (status != file_utils::PLUGIN_FILE_SUCCESS) {
1057 switch (status) { 1063 switch (status) {
1058 case file_utils::PLUGIN_FILE_SUCCESS: 1064 case file_utils::PLUGIN_FILE_SUCCESS:
1059 CHECK(0); 1065 CHECK(0);
1060 break; 1066 break;
1061 case file_utils::PLUGIN_FILE_ERROR_MEM_ALLOC: 1067 case file_utils::PLUGIN_FILE_ERROR_MEM_ALLOC:
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 } 1211 }
1206 1212
1207 void Plugin::UrlDidOpenForStreamAsFile(int32_t pp_error, 1213 void Plugin::UrlDidOpenForStreamAsFile(int32_t pp_error,
1208 FileDownloader*& url_downloader, 1214 FileDownloader*& url_downloader,
1209 PP_CompletionCallback callback) { 1215 PP_CompletionCallback callback) {
1210 PLUGIN_PRINTF(("Plugin::UrlDidOpen (pp_error=%" NACL_PRId32 1216 PLUGIN_PRINTF(("Plugin::UrlDidOpen (pp_error=%" NACL_PRId32
1211 ", url_downloader=%p)\n", pp_error, 1217 ", url_downloader=%p)\n", pp_error,
1212 static_cast<void*>(url_downloader))); 1218 static_cast<void*>(url_downloader)));
1213 url_downloaders_.erase(url_downloader); 1219 url_downloaders_.erase(url_downloader);
1214 nacl::scoped_ptr<FileDownloader> scoped_url_downloader(url_downloader); 1220 nacl::scoped_ptr<FileDownloader> scoped_url_downloader(url_downloader);
1215 struct NaClFileInfo info = scoped_url_downloader->GetFileInfo(); 1221 NaClFileInfoAutoCloser *info = new NaClFileInfoAutoCloser(
1222 scoped_url_downloader->GetFileInfo());
1216 1223
1217 if (pp_error != PP_OK) { 1224 if (pp_error != PP_OK) {
1218 PP_RunCompletionCallback(&callback, pp_error); 1225 PP_RunCompletionCallback(&callback, pp_error);
1219 } else if (info.desc > NACL_NO_FILE_DESC) { 1226 delete info;
1227 } else if (info.get_desc() > NACL_NO_FILE_DESC) {
1228 std::map<nacl::string, struct NaClFileInfoAutoCloser>::iterator it =
1229 url_file_info_map_.find(url_downloader->url_to_open());
1230 if (it != url_file_info_map_.end()) {
1231 delete it->second;
1232 }
1220 url_file_info_map_[url_downloader->url_to_open()] = info; 1233 url_file_info_map_[url_downloader->url_to_open()] = info;
1221 PP_RunCompletionCallback(&callback, PP_OK); 1234 PP_RunCompletionCallback(&callback, PP_OK);
1222 } else { 1235 } else {
1223 PP_RunCompletionCallback(&callback, PP_ERROR_FAILED); 1236 PP_RunCompletionCallback(&callback, PP_ERROR_FAILED);
1237 delete info;
1224 } 1238 }
1225 } 1239 }
1226 1240
1227 struct NaClFileInfo Plugin::GetFileInfo(const nacl::string& url) { 1241 struct NaClFileInfo Plugin::GetFileInfo(const nacl::string& url) {
1228 struct NaClFileInfo info; 1242 struct NaClFileInfo info;
1229 memset(&info, 0, sizeof(info)); 1243 memset(&info, 0, sizeof(info));
1230 std::map<nacl::string, struct NaClFileInfo>::iterator it = 1244 std::map<nacl::string, struct NaClFileInfoAutoCloser>::iterator it =
1231 url_file_info_map_.find(url); 1245 url_file_info_map_.find(url);
1232 if (it != url_file_info_map_.end()) { 1246 if (it != url_file_info_map_.end()) {
1233 info = it->second; 1247 info = it->second->get();
1234 info.desc = DUP(info.desc); 1248 info.desc = DUP(info.desc);
1235 } else { 1249 } else {
1236 info.desc = -1; 1250 info.desc = -1;
1237 } 1251 }
1238 return info; 1252 return info;
1239 } 1253 }
1240 1254
1241 bool Plugin::StreamAsFile(const nacl::string& url, 1255 bool Plugin::StreamAsFile(const nacl::string& url,
1242 PP_CompletionCallback callback) { 1256 PP_CompletionCallback callback) {
1243 PLUGIN_PRINTF(("Plugin::StreamAsFile (url='%s')\n", url.c_str())); 1257 PLUGIN_PRINTF(("Plugin::StreamAsFile (url='%s')\n", url.c_str()));
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
1571 DCHECK(pp::Module::Get()->core()->IsMainThread()); 1585 DCHECK(pp::Module::Get()->core()->IsMainThread());
1572 DCHECK(nacl_interface_); 1586 DCHECK(nacl_interface_);
1573 exit_status_ = exit_status; 1587 exit_status_ = exit_status;
1574 nacl_interface_->SetReadOnlyProperty(pp_instance(), 1588 nacl_interface_->SetReadOnlyProperty(pp_instance(),
1575 pp::Var("exitStatus").pp_var(), 1589 pp::Var("exitStatus").pp_var(),
1576 pp::Var(exit_status_).pp_var()); 1590 pp::Var(exit_status_).pp_var());
1577 } 1591 }
1578 1592
1579 1593
1580 } // namespace plugin 1594 } // namespace plugin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698