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

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

Issue 728113002: obsolete: SFI NaCl: Batch-open resource files (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review Created 6 years, 1 month 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 911 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 IPC::PlatformFileForTransit file = IPC::TakeFileHandleForProcess( 922 IPC::PlatformFileForTransit file = IPC::TakeFileHandleForProcess(
923 resource_files_info_[i].file().Pass(), process_->GetData().handle); 923 resource_files_info_[i].file().Pass(), process_->GetData().handle);
924 std::string file_key = resource_files_info_[i].file_key(); 924 std::string file_key = resource_files_info_[i].file_key();
925 params.resource_files.push_back( 925 params.resource_files.push_back(
926 // Pass an empty base::FilePath since Non-SFI mode does not use it. 926 // Pass an empty base::FilePath since Non-SFI mode does not use it.
927 NaClStartParams::ResourceFileInfo(file, base::FilePath(), file_key)); 927 NaClStartParams::ResourceFileInfo(file, base::FilePath(), file_key));
928 } 928 }
929 } else if (NaClBrowser::GetInstance()->GetFilePath(nexe_token_.lo, 929 } else if (NaClBrowser::GetInstance()->GetFilePath(nexe_token_.lo,
930 nexe_token_.hi, 930 nexe_token_.hi,
931 &file_path)) { 931 &file_path)) {
932 // We have to reopen the file in the browser process; we don't want a 932 std::vector<base::FilePath> file_paths(resource_files_info_len_ + 1);
933 // compromised renderer to pass an arbitrary fd that could get loaded 933 file_paths[0] = file_path;
teravest 2014/11/19 15:59:30 nit: This would be a bit easier to read now if fil
Yusuke Sato 2014/11/20 00:30:27 Done.
934 for (size_t i = 0; i < resource_files_info_len_; ++i) {
935 if (!NaClBrowser::GetInstance()->GetFilePath(
936 resource_files_info_[i].file_token().lo,
937 resource_files_info_[i].file_token().hi,
938 &file_paths[i + 1])) {
939 file_paths.resize(1); // We still need to open the main nexe file.
940 break;
941 }
942 }
943 // We have to reopen the files in the browser process; we don't want a
944 // compromised renderer to pass arbitrary fds that could get loaded
934 // into the plugin process. 945 // into the plugin process.
935 if (base::PostTaskAndReplyWithResult( 946 if (base::PostTaskAndReplyWithResult(
936 content::BrowserThread::GetBlockingPool(), 947 content::BrowserThread::GetBlockingPool(),
937 FROM_HERE, 948 FROM_HERE,
938 base::Bind(OpenNaClReadExecImpl, 949 base::Bind(OpenNaClFilesReadExecImpl,
939 file_path, 950 file_paths,
940 true /* is_executable */), 951 true /* is_executable */),
941 base::Bind(&NaClProcessHost::StartNaClFileResolved, 952 base::Bind(&NaClProcessHost::StartNaClFilesResolved,
942 weak_factory_.GetWeakPtr(), 953 weak_factory_.GetWeakPtr(),
943 params, 954 params,
944 file_path))) { 955 file_paths.size()))) {
945 return true; 956 return true;
946 } 957 }
947 } 958 }
948 params.nexe_file = IPC::TakeFileHandleForProcess(nexe_file_.Pass(), 959 params.nexe_file = IPC::TakeFileHandleForProcess(nexe_file_.Pass(),
949 process_->GetData().handle); 960 process_->GetData().handle);
950
951 params.CheckNumOfDescriptors(); 961 params.CheckNumOfDescriptors();
952 process_->Send(new NaClProcessMsg_Start(params)); 962 process_->Send(new NaClProcessMsg_Start(params));
953 return true; 963 return true;
954 } 964 }
955 965
956 void NaClProcessHost::StartNaClFileResolved( 966 void NaClProcessHost::StartNaClFilesResolved(
957 NaClStartParams params, 967 NaClStartParams params,
958 const base::FilePath& file_path, 968 size_t checked_nexe_files_len,
959 base::File checked_nexe_file) { 969 scoped_ptr<OpenNaClFileReadExecImplResult[]> checked_nexe_files) {
960 if (checked_nexe_file.IsValid()) { 970 const base::TimeDelta close_delay = base::TimeDelta::FromSeconds(5);
971
972 // The first element of the array is for the main nexe.
973 DCHECK(checked_nexe_files_len > 0);
974 if (checked_nexe_files[0].IsValid()) {
961 // Release the file received from the renderer. This has to be done on a 975 // Release the file received from the renderer. This has to be done on a
962 // thread where IO is permitted, though. 976 // thread where IO is permitted, though.
963 content::BrowserThread::GetBlockingPool()->PostTask( 977 content::BrowserThread::GetBlockingPool()->PostDelayedTask(
964 FROM_HERE, 978 FROM_HERE,
965 base::Bind(&CloseFile, base::Passed(nexe_file_.Pass()))); 979 base::Bind(&CloseFile, base::Passed(nexe_file_.Pass())),
966 params.nexe_file_path_metadata = file_path; 980 close_delay);
teravest 2014/11/19 15:59:30 Why is there a delay added here?
Yusuke Sato 2014/11/20 00:30:27 Removed. I thought posting dozens of CloseFile ta
981 params.nexe_file_path_metadata = checked_nexe_files[0].file_path();
967 params.nexe_file = IPC::TakeFileHandleForProcess( 982 params.nexe_file = IPC::TakeFileHandleForProcess(
968 checked_nexe_file.Pass(), process_->GetData().handle); 983 checked_nexe_files[0].file().Pass(), process_->GetData().handle);
969 } else { 984 } else {
970 params.nexe_file = IPC::TakeFileHandleForProcess( 985 params.nexe_file = IPC::TakeFileHandleForProcess(
971 nexe_file_.Pass(), process_->GetData().handle); 986 nexe_file_.Pass(), process_->GetData().handle);
972 } 987 }
988
989 // The rest is for resource files.
990 for (size_t i = 1; i < checked_nexe_files_len; ++i) {
991 // Release the resource files received from the renderer too.
992 content::BrowserThread::GetBlockingPool()->PostDelayedTask(
993 FROM_HERE,
994 base::Bind(&CloseFile,
995 base::Passed(resource_files_info_[i - 1].file().Pass())),
996 close_delay);
997 if (!checked_nexe_files[i].IsValid())
998 continue;
999 IPC::PlatformFileForTransit file = IPC::TakeFileHandleForProcess(
1000 checked_nexe_files[i].file().Pass(), process_->GetData().handle);
1001 std::string file_key = resource_files_info_[i - 1].file_key();
1002 params.resource_files.push_back(NaClStartParams::ResourceFileInfo(
1003 file, checked_nexe_files[i].file_path(), file_key));
1004 }
1005
1006 params.CheckNumOfDescriptors();
973 process_->Send(new NaClProcessMsg_Start(params)); 1007 process_->Send(new NaClProcessMsg_Start(params));
974 } 1008 }
975 1009
976 // This method is called when NaClProcessHostMsg_PpapiChannelCreated is 1010 // This method is called when NaClProcessHostMsg_PpapiChannelCreated is
977 // received. 1011 // received.
978 void NaClProcessHost::OnPpapiChannelsCreated( 1012 void NaClProcessHost::OnPpapiChannelsCreated(
979 const IPC::ChannelHandle& browser_channel_handle, 1013 const IPC::ChannelHandle& browser_channel_handle,
980 const IPC::ChannelHandle& ppapi_renderer_channel_handle, 1014 const IPC::ChannelHandle& ppapi_renderer_channel_handle,
981 const IPC::ChannelHandle& trusted_renderer_channel_handle, 1015 const IPC::ChannelHandle& trusted_renderer_channel_handle,
982 const IPC::ChannelHandle& manifest_service_channel_handle) { 1016 const IPC::ChannelHandle& manifest_service_channel_handle) {
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 process_handle.Take(), info, 1253 process_handle.Take(), info,
1220 base::MessageLoopProxy::current(), 1254 base::MessageLoopProxy::current(),
1221 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, 1255 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker,
1222 weak_factory_.GetWeakPtr())); 1256 weak_factory_.GetWeakPtr()));
1223 return true; 1257 return true;
1224 } 1258 }
1225 } 1259 }
1226 #endif 1260 #endif
1227 1261
1228 } // namespace nacl 1262 } // namespace nacl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698