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

Side by Side Diff: components/nacl/browser/nacl_process_host.cc

Issue 649603004: Non-SFI NaCl: Batch-open resource files (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: code review Created 5 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
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 "components/nacl/browser/nacl_process_host.h" 5 #include "components/nacl/browser/nacl_process_host.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 228
229 void CloseFile(base::File file) { 229 void CloseFile(base::File file) {
230 // The base::File destructor will close the file for us. 230 // The base::File destructor will close the file for us.
231 } 231 }
232 232
233 } // namespace 233 } // namespace
234 234
235 unsigned NaClProcessHost::keepalive_throttle_interval_milliseconds_ = 235 unsigned NaClProcessHost::keepalive_throttle_interval_milliseconds_ =
236 ppapi::kKeepaliveThrottleIntervalDefaultMilliseconds; 236 ppapi::kKeepaliveThrottleIntervalDefaultMilliseconds;
237 237
238 NaClProcessHost::NaClProcessHost(const GURL& manifest_url, 238 ResourceFileInfo::ResourceFileInfo()
239 base::File nexe_file, 239 : file_token_() {
240 const NaClFileToken& nexe_token, 240 }
241 ppapi::PpapiPermissions permissions, 241
242 int render_view_id, 242 ResourceFileInfo::ResourceFileInfo(
243 uint32 permission_bits, 243 base::File file,
244 bool uses_nonsfi_mode, 244 const NaClFileToken& file_token,
245 bool off_the_record, 245 const std::string& file_key)
246 NaClAppProcessType process_type, 246 : file_(file.Pass()),
247 const base::FilePath& profile_directory) 247 file_token_(file_token),
248 file_key_(file_key) {
249 }
250
251 ResourceFileInfo::~ResourceFileInfo() {
252 }
253
254 ResourceFileInfo::ResourceFileInfo(RValue other)
255 : file_(other.object->file_.Pass()),
256 file_token_(other.object->file_token_),
257 file_key_(other.object->file_key_) {
258 }
259
260 ResourceFileInfo& ResourceFileInfo::operator=(RValue other) {
261 if (this != other.object) {
262 file_ = other.object->file_.Pass();
263 file_token_ = other.object->file_token_;
264 file_key_ = other.object->file_key_;
265 }
266 return *this;
267 }
268
269 NaClProcessHost::NaClProcessHost(
270 const GURL& manifest_url,
271 base::File nexe_file,
272 const NaClFileToken& nexe_token,
273 scoped_ptr<ResourceFileInfo[]> resource_files_info,
274 size_t resource_files_info_len,
275 ppapi::PpapiPermissions permissions,
276 int render_view_id,
277 uint32 permission_bits,
278 bool uses_nonsfi_mode,
279 bool off_the_record,
280 NaClAppProcessType process_type,
281 const base::FilePath& profile_directory)
248 : manifest_url_(manifest_url), 282 : manifest_url_(manifest_url),
249 nexe_file_(nexe_file.Pass()), 283 nexe_file_(nexe_file.Pass()),
250 nexe_token_(nexe_token), 284 nexe_token_(nexe_token),
285 resource_files_info_(resource_files_info.Pass()),
286 resource_files_info_len_(resource_files_info_len),
251 permissions_(permissions), 287 permissions_(permissions),
252 #if defined(OS_WIN) 288 #if defined(OS_WIN)
253 process_launched_by_broker_(false), 289 process_launched_by_broker_(false),
254 #endif 290 #endif
255 reply_msg_(NULL), 291 reply_msg_(NULL),
256 #if defined(OS_WIN) 292 #if defined(OS_WIN)
257 debug_exception_handler_requested_(false), 293 debug_exception_handler_requested_(false),
258 #endif 294 #endif
259 uses_nonsfi_mode_(uses_nonsfi_mode), 295 uses_nonsfi_mode_(uses_nonsfi_mode),
260 enable_debug_stub_(false), 296 enable_debug_stub_(false),
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 #endif 915 #endif
880 } 916 }
881 917
882 if (!crash_info_shmem_.ShareToProcess(process_->GetData().handle, 918 if (!crash_info_shmem_.ShareToProcess(process_->GetData().handle,
883 &params.crash_info_shmem_handle)) { 919 &params.crash_info_shmem_handle)) {
884 DLOG(ERROR) << "Failed to ShareToProcess() a shared memory buffer"; 920 DLOG(ERROR) << "Failed to ShareToProcess() a shared memory buffer";
885 return false; 921 return false;
886 } 922 }
887 923
888 base::FilePath file_path; 924 base::FilePath file_path;
889 // Don't retrieve the file path when using nonsfi mode; there's no validation 925 if (uses_nonsfi_mode_) {
890 // caching in that case, so it's unnecessary work, and would expose the file 926 // Don't retrieve the file path when using nonsfi mode; there's no
891 // path to the plugin. 927 // validation caching in that case, so it's unnecessary work, and would
892 if (!uses_nonsfi_mode_ && 928 // expose the file path to the plugin.
893 NaClBrowser::GetInstance()->GetFilePath(nexe_token_.lo, 929 for (size_t i = 0; i < resource_files_info_len_; ++i) {
894 nexe_token_.hi, 930 IPC::PlatformFileForTransit file = IPC::TakeFileHandleForProcess(
895 &file_path)) { 931 resource_files_info_[i].file_.Pass(), process_->GetData().handle);
896 // We have to reopen the file in the browser process; we don't want a 932 std::string file_key = resource_files_info_[i].file_key_;
897 // compromised renderer to pass an arbitrary fd that could get loaded 933 params.resource_files.push_back(
898 // into the plugin process. 934 // Pass an empty base::FilePath since Non-SFI mode does not use it.
899 if (base::PostTaskAndReplyWithResult( 935 NaClStartParams::ResourceFileInfo(file, base::FilePath(), file_key));
900 content::BrowserThread::GetBlockingPool(),
901 FROM_HERE,
902 base::Bind(OpenNaClReadExecImpl,
903 file_path,
904 true /* is_executable */),
905 base::Bind(&NaClProcessHost::StartNaClFileResolved,
906 weak_factory_.GetWeakPtr(),
907 params,
908 file_path))) {
909 return true;
910 } 936 }
937 } else {
938 if (NaClBrowser::GetInstance()->GetFilePath(nexe_token_.lo,
939 nexe_token_.hi,
940 &file_path)) {
941 // We have to reopen the file in the browser process; we don't want a
942 // compromised renderer to pass an arbitrary fd that could get loaded
943 // into the plugin process.
944 if (base::PostTaskAndReplyWithResult(
945 content::BrowserThread::GetBlockingPool(),
946 FROM_HERE,
947 base::Bind(OpenNaClReadExecImpl,
948 file_path,
949 true /* is_executable */),
950 base::Bind(&NaClProcessHost::StartNaClFileResolved,
951 weak_factory_.GetWeakPtr(),
952 params,
953 file_path))) {
954 return true;
955 }
956 }
957 // TODO(yusukes): Handle |resource_files_info_| for SFI-NaCl.
911 } 958 }
912 959
913 params.nexe_file = IPC::TakeFileHandleForProcess(nexe_file_.Pass(), 960 params.nexe_file = IPC::TakeFileHandleForProcess(nexe_file_.Pass(),
914 process_->GetData().handle); 961 process_->GetData().handle);
962
963 params.CheckNumOfDescriptors();
915 process_->Send(new NaClProcessMsg_Start(params)); 964 process_->Send(new NaClProcessMsg_Start(params));
916 return true; 965 return true;
917 } 966 }
918 967
919 void NaClProcessHost::StartNaClFileResolved( 968 void NaClProcessHost::StartNaClFileResolved(
920 NaClStartParams params, 969 NaClStartParams params,
921 const base::FilePath& file_path, 970 const base::FilePath& file_path,
922 base::File checked_nexe_file) { 971 base::File checked_nexe_file) {
923 if (checked_nexe_file.IsValid()) { 972 if (checked_nexe_file.IsValid()) {
924 // Release the file received from the renderer. This has to be done on a 973 // Release the file received from the renderer. This has to be done on a
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 process.Pass(), info, 1229 process.Pass(), info,
1181 base::MessageLoopProxy::current(), 1230 base::MessageLoopProxy::current(),
1182 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, 1231 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker,
1183 weak_factory_.GetWeakPtr())); 1232 weak_factory_.GetWeakPtr()));
1184 return true; 1233 return true;
1185 } 1234 }
1186 } 1235 }
1187 #endif 1236 #endif
1188 1237
1189 } // namespace nacl 1238 } // namespace nacl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698