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

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: bbudge CR fb 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
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/plugin.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
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 NaClFileInfo tmp_info(nexe_downloader_.GetFileInfo());
755 NaClFileInfoAutoCloser info(&tmp_info);
749 PLUGIN_PRINTF(("Plugin::NexeFileDidOpen (file_desc=%" NACL_PRId32 ")\n", 756 PLUGIN_PRINTF(("Plugin::NexeFileDidOpen (file_desc=%" NACL_PRId32 ")\n",
750 info.desc)); 757 info.get_desc()));
751 HistogramHTTPStatusCode( 758 HistogramHTTPStatusCode(
752 is_installed_ ? 759 is_installed_ ?
753 "NaCl.HttpStatusCodeClass.Nexe.InstalledApp" : 760 "NaCl.HttpStatusCodeClass.Nexe.InstalledApp" :
754 "NaCl.HttpStatusCodeClass.Nexe.NotInstalledApp", 761 "NaCl.HttpStatusCodeClass.Nexe.NotInstalledApp",
755 nexe_downloader_.status_code()); 762 nexe_downloader_.status_code());
756 ErrorInfo error_info; 763 ErrorInfo error_info;
757 if (pp_error != PP_OK || info.desc == NACL_NO_FILE_DESC) { 764 if (pp_error != PP_OK || info.get_desc() == NACL_NO_FILE_DESC) {
758 if (pp_error == PP_ERROR_ABORTED) { 765 if (pp_error == PP_ERROR_ABORTED) {
759 ReportLoadAbort(); 766 ReportLoadAbort();
760 } else if (pp_error == PP_ERROR_NOACCESS) { 767 } else if (pp_error == PP_ERROR_NOACCESS) {
761 error_info.SetReport(ERROR_NEXE_NOACCESS_URL, 768 error_info.SetReport(ERROR_NEXE_NOACCESS_URL,
762 "access to nexe url was denied."); 769 "access to nexe url was denied.");
763 ReportLoadError(error_info); 770 ReportLoadError(error_info);
764 } else { 771 } else {
765 error_info.SetReport(ERROR_NEXE_LOAD_URL, "could not load nexe url."); 772 error_info.SetReport(ERROR_NEXE_LOAD_URL, "could not load nexe url.");
766 ReportLoadError(error_info); 773 ReportLoadError(error_info);
767 } 774 }
768 return; 775 return;
769 } 776 }
770 int32_t file_desc_ok_to_close = DUP(info.desc); 777 int32_t file_desc_ok_to_close = DUP(info.get_desc());
771 if (file_desc_ok_to_close == NACL_NO_FILE_DESC) { 778 if (file_desc_ok_to_close == NACL_NO_FILE_DESC) {
772 error_info.SetReport(ERROR_NEXE_FH_DUP, 779 error_info.SetReport(ERROR_NEXE_FH_DUP,
773 "could not duplicate loaded file handle."); 780 "could not duplicate loaded file handle.");
774 ReportLoadError(error_info); 781 ReportLoadError(error_info);
775 return; 782 return;
776 } 783 }
777 struct stat stat_buf; 784 struct stat stat_buf;
778 if (0 != fstat(file_desc_ok_to_close, &stat_buf)) { 785 if (0 != fstat(file_desc_ok_to_close, &stat_buf)) {
779 CLOSE(file_desc_ok_to_close); 786 CLOSE(file_desc_ok_to_close);
780 error_info.SetReport(ERROR_NEXE_STAT, "could not stat nexe file."); 787 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()); 1029 nexe_downloader_.TimeSinceOpenMilliseconds());
1023 HistogramHTTPStatusCode( 1030 HistogramHTTPStatusCode(
1024 is_installed_ ? 1031 is_installed_ ?
1025 "NaCl.HttpStatusCodeClass.Manifest.InstalledApp" : 1032 "NaCl.HttpStatusCodeClass.Manifest.InstalledApp" :
1026 "NaCl.HttpStatusCodeClass.Manifest.NotInstalledApp", 1033 "NaCl.HttpStatusCodeClass.Manifest.NotInstalledApp",
1027 nexe_downloader_.status_code()); 1034 nexe_downloader_.status_code());
1028 ErrorInfo error_info; 1035 ErrorInfo error_info;
1029 // The manifest file was successfully opened. Set the src property on the 1036 // 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. 1037 // plugin now, so that the full url is available to error handlers.
1031 set_manifest_url(nexe_downloader_.url()); 1038 set_manifest_url(nexe_downloader_.url());
1032 struct NaClFileInfo info = nexe_downloader_.GetFileInfo(); 1039 NaClFileInfo tmp_info(nexe_downloader_.GetFileInfo());
1040 NaClFileInfoAutoCloser info(&tmp_info);
1033 PLUGIN_PRINTF(("Plugin::NaClManifestFileDidOpen (file_desc=%" 1041 PLUGIN_PRINTF(("Plugin::NaClManifestFileDidOpen (file_desc=%"
1034 NACL_PRId32 ")\n", info.desc)); 1042 NACL_PRId32 ")\n", info.get_desc()));
1035 if (pp_error != PP_OK || info.desc == NACL_NO_FILE_DESC) { 1043 if (pp_error != PP_OK || info.get_desc() == NACL_NO_FILE_DESC) {
1036 if (pp_error == PP_ERROR_ABORTED) { 1044 if (pp_error == PP_ERROR_ABORTED) {
1037 ReportLoadAbort(); 1045 ReportLoadAbort();
1038 } else if (pp_error == PP_ERROR_NOACCESS) { 1046 } else if (pp_error == PP_ERROR_NOACCESS) {
1039 error_info.SetReport(ERROR_MANIFEST_NOACCESS_URL, 1047 error_info.SetReport(ERROR_MANIFEST_NOACCESS_URL,
1040 "access to manifest url was denied."); 1048 "access to manifest url was denied.");
1041 ReportLoadError(error_info); 1049 ReportLoadError(error_info);
1042 } else { 1050 } else {
1043 error_info.SetReport(ERROR_MANIFEST_LOAD_URL, 1051 error_info.SetReport(ERROR_MANIFEST_LOAD_URL,
1044 "could not load manifest url."); 1052 "could not load manifest url.");
1045 ReportLoadError(error_info); 1053 ReportLoadError(error_info);
1046 } 1054 }
1047 return; 1055 return;
1048 } 1056 }
1049 // SlurpFile closes the file descriptor after reading (or on error). 1057 // SlurpFile closes the file descriptor after reading (or on error).
1050 // Duplicate our file descriptor since it will be handled by the browser. 1058 // Duplicate our file descriptor since it will be handled by the browser.
1051 int dup_file_desc = DUP(info.desc); 1059 int dup_file_desc = DUP(info.get_desc());
1052 nacl::string json_buffer; 1060 nacl::string json_buffer;
1053 file_utils::StatusCode status = file_utils::SlurpFile( 1061 file_utils::StatusCode status = file_utils::SlurpFile(
1054 dup_file_desc, json_buffer, kNaClManifestMaxFileBytes); 1062 dup_file_desc, json_buffer, kNaClManifestMaxFileBytes);
1055 1063
1056 if (status != file_utils::PLUGIN_FILE_SUCCESS) { 1064 if (status != file_utils::PLUGIN_FILE_SUCCESS) {
1057 switch (status) { 1065 switch (status) {
1058 case file_utils::PLUGIN_FILE_SUCCESS: 1066 case file_utils::PLUGIN_FILE_SUCCESS:
1059 CHECK(0); 1067 CHECK(0);
1060 break; 1068 break;
1061 case file_utils::PLUGIN_FILE_ERROR_MEM_ALLOC: 1069 case file_utils::PLUGIN_FILE_ERROR_MEM_ALLOC:
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 } 1213 }
1206 1214
1207 void Plugin::UrlDidOpenForStreamAsFile(int32_t pp_error, 1215 void Plugin::UrlDidOpenForStreamAsFile(int32_t pp_error,
1208 FileDownloader*& url_downloader, 1216 FileDownloader*& url_downloader,
1209 PP_CompletionCallback callback) { 1217 PP_CompletionCallback callback) {
1210 PLUGIN_PRINTF(("Plugin::UrlDidOpen (pp_error=%" NACL_PRId32 1218 PLUGIN_PRINTF(("Plugin::UrlDidOpen (pp_error=%" NACL_PRId32
1211 ", url_downloader=%p)\n", pp_error, 1219 ", url_downloader=%p)\n", pp_error,
1212 static_cast<void*>(url_downloader))); 1220 static_cast<void*>(url_downloader)));
1213 url_downloaders_.erase(url_downloader); 1221 url_downloaders_.erase(url_downloader);
1214 nacl::scoped_ptr<FileDownloader> scoped_url_downloader(url_downloader); 1222 nacl::scoped_ptr<FileDownloader> scoped_url_downloader(url_downloader);
1215 struct NaClFileInfo info = scoped_url_downloader->GetFileInfo(); 1223 NaClFileInfo tmp_info(scoped_url_downloader->GetFileInfo());
1224 NaClFileInfoAutoCloser *info = new NaClFileInfoAutoCloser(&tmp_info);
1216 1225
1217 if (pp_error != PP_OK) { 1226 if (pp_error != PP_OK) {
1218 PP_RunCompletionCallback(&callback, pp_error); 1227 PP_RunCompletionCallback(&callback, pp_error);
1219 } else if (info.desc > NACL_NO_FILE_DESC) { 1228 delete info;
1229 } else if (info->get_desc() > NACL_NO_FILE_DESC) {
1230 std::map<nacl::string, NaClFileInfoAutoCloser*>::iterator it =
1231 url_file_info_map_.find(url_downloader->url_to_open());
1232 if (it != url_file_info_map_.end()) {
1233 delete it->second;
1234 }
1220 url_file_info_map_[url_downloader->url_to_open()] = info; 1235 url_file_info_map_[url_downloader->url_to_open()] = info;
1221 PP_RunCompletionCallback(&callback, PP_OK); 1236 PP_RunCompletionCallback(&callback, PP_OK);
1222 } else { 1237 } else {
1223 PP_RunCompletionCallback(&callback, PP_ERROR_FAILED); 1238 PP_RunCompletionCallback(&callback, PP_ERROR_FAILED);
1239 delete info;
1224 } 1240 }
1225 } 1241 }
1226 1242
1227 struct NaClFileInfo Plugin::GetFileInfo(const nacl::string& url) { 1243 struct NaClFileInfo Plugin::GetFileInfo(const nacl::string& url) {
1228 struct NaClFileInfo info; 1244 struct NaClFileInfo info;
1229 memset(&info, 0, sizeof(info)); 1245 memset(&info, 0, sizeof(info));
1230 std::map<nacl::string, struct NaClFileInfo>::iterator it = 1246 std::map<nacl::string, NaClFileInfoAutoCloser*>::iterator it =
1231 url_file_info_map_.find(url); 1247 url_file_info_map_.find(url);
1232 if (it != url_file_info_map_.end()) { 1248 if (it != url_file_info_map_.end()) {
1233 info = it->second; 1249 info = it->second->get();
1234 info.desc = DUP(info.desc); 1250 info.desc = DUP(info.desc);
1235 } else { 1251 } else {
1236 info.desc = -1; 1252 info.desc = -1;
1237 } 1253 }
1238 return info; 1254 return info;
1239 } 1255 }
1240 1256
1241 bool Plugin::StreamAsFile(const nacl::string& url, 1257 bool Plugin::StreamAsFile(const nacl::string& url,
1242 PP_CompletionCallback callback) { 1258 PP_CompletionCallback callback) {
1243 PLUGIN_PRINTF(("Plugin::StreamAsFile (url='%s')\n", url.c_str())); 1259 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()); 1587 DCHECK(pp::Module::Get()->core()->IsMainThread());
1572 DCHECK(nacl_interface_); 1588 DCHECK(nacl_interface_);
1573 exit_status_ = exit_status; 1589 exit_status_ = exit_status;
1574 nacl_interface_->SetReadOnlyProperty(pp_instance(), 1590 nacl_interface_->SetReadOnlyProperty(pp_instance(),
1575 pp::Var("exitStatus").pp_var(), 1591 pp::Var("exitStatus").pp_var(),
1576 pp::Var(exit_status_).pp_var()); 1592 pp::Var(exit_status_).pp_var());
1577 } 1593 }
1578 1594
1579 1595
1580 } // namespace plugin 1596 } // namespace plugin
OLDNEW
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/plugin.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698