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

Side by Side Diff: chrome/browser/nacl_host/nacl_process_host.cc

Issue 10020002: Pass the nacl start parameters as a struct. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 #include "chrome/browser/nacl_host/nacl_process_host.h" 5 #include "chrome/browser/nacl_host/nacl_process_host.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 873
874 // The asynchronous attempt to get the IRT file open has completed. 874 // The asynchronous attempt to get the IRT file open has completed.
875 void NaClProcessHost::IrtReady() { 875 void NaClProcessHost::IrtReady() {
876 NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); 876 NaClBrowser* nacl_browser = NaClBrowser::GetInstance();
877 if (!nacl_browser->IrtAvailable() || !SendStart()) { 877 if (!nacl_browser->IrtAvailable() || !SendStart()) {
878 DLOG(ERROR) << "Cannot launch NaCl process"; 878 DLOG(ERROR) << "Cannot launch NaCl process";
879 delete this; 879 delete this;
880 } 880 }
881 } 881 }
882 882
883 bool NaClProcessHost::SendStart() { 883 bool NaClProcessHost::MakeStartParams(nacl::NaClStartParams* params) {
884 NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); 884 NaClBrowser* nacl_browser = NaClBrowser::GetInstance();
885
886 params->validation_cache_key = nacl_browser->GetValidatorCacheKey();
887 params->version = chrome::VersionInfo().CreateVersionString();
888 params->enable_exception_handling = enable_exception_handling_;
889
885 base::PlatformFile irt_file = nacl_browser->IrtFile(); 890 base::PlatformFile irt_file = nacl_browser->IrtFile();
886 CHECK_NE(irt_file, base::kInvalidPlatformFileValue); 891 CHECK_NE(irt_file, base::kInvalidPlatformFileValue);
887 892
888 std::vector<nacl::FileDescriptor> handles_for_renderer; 893 std::vector<nacl::FileDescriptor> handles_for_renderer;
889 base::ProcessHandle nacl_process_handle; 894 base::ProcessHandle nacl_process_handle;
890 895
891 for (size_t i = 0; i < internal_->sockets_for_renderer.size(); i++) { 896 for (size_t i = 0; i < internal_->sockets_for_renderer.size(); i++) {
892 #if defined(OS_WIN) 897 #if defined(OS_WIN)
893 // Copy the handle into the renderer process. 898 // Copy the handle into the renderer process.
894 HANDLE handle_in_renderer; 899 HANDLE handle_in_renderer;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 // Get the pid of the NaCl process 941 // Get the pid of the NaCl process
937 base::ProcessId nacl_process_id = base::GetProcId(data.handle); 942 base::ProcessId nacl_process_id = base::GetProcId(data.handle);
938 943
939 ChromeViewHostMsg_LaunchNaCl::WriteReplyParams( 944 ChromeViewHostMsg_LaunchNaCl::WriteReplyParams(
940 reply_msg_, handles_for_renderer, nacl_process_handle, nacl_process_id); 945 reply_msg_, handles_for_renderer, nacl_process_handle, nacl_process_id);
941 chrome_render_message_filter_->Send(reply_msg_); 946 chrome_render_message_filter_->Send(reply_msg_);
942 chrome_render_message_filter_ = NULL; 947 chrome_render_message_filter_ = NULL;
943 reply_msg_ = NULL; 948 reply_msg_ = NULL;
944 internal_->sockets_for_renderer.clear(); 949 internal_->sockets_for_renderer.clear();
945 950
946 std::vector<nacl::FileDescriptor> handles_for_sel_ldr;
947 for (size_t i = 0; i < internal_->sockets_for_sel_ldr.size(); i++) { 951 for (size_t i = 0; i < internal_->sockets_for_sel_ldr.size(); i++) {
948 if (!SendHandleToSelLdr(data.handle, 952 if (!SendHandleToSelLdr(data.handle,
949 internal_->sockets_for_sel_ldr[i], true, 953 internal_->sockets_for_sel_ldr[i], true,
950 &handles_for_sel_ldr)) { 954 &params->sockets)) {
951 return false; 955 return false;
952 } 956 }
953 } 957 }
954 958
955 // Send over the IRT file handle. We don't close our own copy! 959 // Send over the IRT file handle. We don't close our own copy!
956 if (!SendHandleToSelLdr(data.handle, irt_file, false, &handles_for_sel_ldr)) 960 if (!SendHandleToSelLdr(data.handle, irt_file, false, &params->sockets))
957 return false; 961 return false;
958 962
959 #if defined(OS_MACOSX) 963 #if defined(OS_MACOSX)
960 // For dynamic loading support, NaCl requires a file descriptor that 964 // For dynamic loading support, NaCl requires a file descriptor that
961 // was created in /tmp, since those created with shm_open() are not 965 // was created in /tmp, since those created with shm_open() are not
962 // mappable with PROT_EXEC. Rather than requiring an extra IPC 966 // mappable with PROT_EXEC. Rather than requiring an extra IPC
963 // round trip out of the sandbox, we create an FD here. 967 // round trip out of the sandbox, we create an FD here.
964 base::SharedMemory memory_buffer; 968 base::SharedMemory memory_buffer;
965 base::SharedMemoryCreateOptions options; 969 base::SharedMemoryCreateOptions options;
966 options.size = 1; 970 options.size = 1;
967 options.executable = true; 971 options.executable = true;
968 if (!memory_buffer.Create(options)) { 972 if (!memory_buffer.Create(options)) {
969 DLOG(ERROR) << "Failed to allocate memory buffer"; 973 DLOG(ERROR) << "Failed to allocate memory buffer";
970 return false; 974 return false;
971 } 975 }
972 nacl::FileDescriptor memory_fd; 976 nacl::FileDescriptor memory_fd;
973 memory_fd.fd = dup(memory_buffer.handle().fd); 977 memory_fd.fd = dup(memory_buffer.handle().fd);
974 if (memory_fd.fd < 0) { 978 if (memory_fd.fd < 0) {
975 DLOG(ERROR) << "Failed to dup() a file descriptor"; 979 DLOG(ERROR) << "Failed to dup() a file descriptor";
976 return false; 980 return false;
977 } 981 }
978 memory_fd.auto_close = true; 982 memory_fd.auto_close = true;
979 handles_for_sel_ldr.push_back(memory_fd); 983 params->sockets.push_back(memory_fd);
Mark Seaborn 2012/04/06 23:13:50 The name "sockets" isn't accurate because this arr
980 #endif 984 #endif
981 985
982 // Sending the version string over IPC avoids linkage issues in cases where 986 return true;
Mark Seaborn 2012/04/06 23:13:50 Can you keep this comment and move it to the point
983 // NaCl is not compiled into the main Chromium executable or DLL. 987 }
984 chrome::VersionInfo version_info; 988
985 IPC::Message* start_message = 989 bool NaClProcessHost::SendStart() {
986 new NaClProcessMsg_Start(handles_for_sel_ldr, 990 nacl::NaClStartParams params;
987 nacl_browser->GetValidatorCacheKey(), 991 if (!MakeStartParams(&params))
988 version_info.CreateVersionString(), 992 return false;
989 enable_exception_handling_); 993
994 IPC::Message* start_message = new NaClProcessMsg_Start(params);
990 #if defined(OS_WIN) 995 #if defined(OS_WIN)
991 if (debug_context_ != NULL) { 996 if (debug_context_ != NULL) {
992 debug_context_->SetStartMessage(start_message); 997 debug_context_->SetStartMessage(start_message);
993 debug_context_->SendStartMessage(); 998 debug_context_->SendStartMessage();
994 } else { 999 } else {
995 process_->Send(start_message); 1000 process_->Send(start_message);
996 } 1001 }
997 #else 1002 #else
998 process_->Send(start_message); 1003 process_->Send(start_message);
999 #endif 1004 #endif
(...skipping 25 matching lines...) Expand all
1025 } 1030 }
1026 1031
1027 void NaClProcessHost::OnQueryKnownToValidate(const std::string& signature, 1032 void NaClProcessHost::OnQueryKnownToValidate(const std::string& signature,
1028 bool* result) { 1033 bool* result) {
1029 *result = NaClBrowser::GetInstance()->QueryKnownToValidate(signature); 1034 *result = NaClBrowser::GetInstance()->QueryKnownToValidate(signature);
1030 } 1035 }
1031 1036
1032 void NaClProcessHost::OnSetKnownToValidate(const std::string& signature) { 1037 void NaClProcessHost::OnSetKnownToValidate(const std::string& signature) {
1033 NaClBrowser::GetInstance()->SetKnownToValidate(signature); 1038 NaClBrowser::GetInstance()->SetKnownToValidate(signature);
1034 } 1039 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698