Chromium Code Reviews| Index: components/nacl/browser/nacl_file_host.cc |
| diff --git a/components/nacl/browser/nacl_file_host.cc b/components/nacl/browser/nacl_file_host.cc |
| index 0a0f10c34244338cecaf407fdd98b83c316d3fee..49907868bf332af3b795025ad08e010009311eee 100644 |
| --- a/components/nacl/browser/nacl_file_host.cc |
| +++ b/components/nacl/browser/nacl_file_host.cc |
| @@ -38,14 +38,59 @@ void NotifyRendererOfError( |
| nacl_host_message_filter->Send(reply_msg); |
| } |
| -base::File PnaclDoOpenFile(const base::FilePath& file_to_open) { |
| - return base::File(file_to_open, |
| - base::File::FLAG_OPEN | base::File::FLAG_READ); |
| +// Make a wrapper function for the NaClHostMsg_GetReadonlyPnaclFD macro, |
| +// so that there is a function pointer. |
|
teravest
2014/06/26 21:19:24
I'm confused. Why can't you make a function pointe
jvoung (off chromium)
2014/06/26 22:48:39
Hmm, Bind was failing to infer the template parame
|
| +void WriteGetReadonlyPnaclFDReply(IPC::Message* reply_msg, |
| + IPC::PlatformFileForTransit file_desc, |
| + uint64 file_token_lo, |
| + uint64 file_token_hi) { |
| + NaClHostMsg_GetReadonlyPnaclFD::WriteReplyParams(reply_msg, |
| + file_desc, |
| + file_token_lo, |
| + file_token_hi); |
| +} |
| + |
| +// Make a wrapper function for the NaClHostMsg_OpenNaClExecutable macro, |
| +// so that there is a function pointer. |
| +void WriteOpenNaClExecutableReply(IPC::Message* reply_msg, |
| + IPC::PlatformFileForTransit file_desc, |
| + uint64 file_token_lo, |
| + uint64 file_token_hi) { |
| + NaClHostMsg_OpenNaClExecutable::WriteReplyParams(reply_msg, |
| + file_desc, |
| + file_token_lo, |
| + file_token_hi); |
| +} |
| + |
| +void DoRegisterOpenedNaClExecutableFile( |
| + scoped_refptr<nacl::NaClHostMessageFilter> nacl_host_message_filter, |
| + base::File file, |
|
teravest
2014/06/26 21:19:24
something is funky in the indentation for the argu
jvoung (off chromium)
2014/06/26 22:48:39
Done.
|
| + base::FilePath file_path, |
| + IPC::Message* reply_msg, |
| + void (*WriteReplyParams)(IPC::Message* msg, |
| + IPC::PlatformFileForTransit desc, |
| + uint64 lo_token, |
| + uint64 hi_token)) { |
| + // IO thread owns the NaClBrowser singleton. |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + |
| + nacl::NaClBrowser* nacl_browser = nacl::NaClBrowser::GetInstance(); |
| + uint64 file_token_lo = 0; |
| + uint64 file_token_hi = 0; |
| + nacl_browser->PutFilePath(file_path, &file_token_lo, &file_token_hi); |
| + |
| + IPC::PlatformFileForTransit file_desc = IPC::TakeFileHandleForProcess( |
| + file.Pass(), |
| + nacl_host_message_filter->PeerHandle()); |
| + |
| + (*WriteReplyParams)(reply_msg, file_desc, file_token_lo, file_token_hi); |
| + nacl_host_message_filter->Send(reply_msg); |
| } |
| void DoOpenPnaclFile( |
| scoped_refptr<nacl::NaClHostMessageFilter> nacl_host_message_filter, |
| const std::string& filename, |
| + bool is_executable, |
| IPC::Message* reply_msg) { |
| DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| base::FilePath full_filepath; |
| @@ -64,46 +109,31 @@ void DoOpenPnaclFile( |
| return; |
| } |
| - base::File file_to_open = PnaclDoOpenFile(full_filepath); |
| + base::File file_to_open = nacl::OpenNaClReadExecImpl(full_filepath, |
| + is_executable); |
| if (!file_to_open.IsValid()) { |
| NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
| return; |
| } |
| - // Send the reply! |
| - // Do any DuplicateHandle magic that is necessary first. |
| - IPC::PlatformFileForTransit target_desc = |
| - IPC::TakeFileHandleForProcess(file_to_open.Pass(), |
| - nacl_host_message_filter->PeerHandle()); |
| - if (target_desc == IPC::InvalidPlatformFileForTransit()) { |
| - NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
| - return; |
| + // This function is running on the blocking pool, but the path needs to be |
| + // registered in a structure owned by the IO thread. |
| + // Not all PNaCl files are executable. Only register those that are |
| + // executable in the NaCl file_path cache. |
| + if (is_executable) { |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, FROM_HERE, |
| + base::Bind(&DoRegisterOpenedNaClExecutableFile, |
| + nacl_host_message_filter, |
| + Passed(file_to_open.Pass()), full_filepath, reply_msg, |
| + &WriteGetReadonlyPnaclFDReply)); |
| + } else { |
| + IPC::PlatformFileForTransit target_desc = |
| + IPC::TakeFileHandleForProcess(file_to_open.Pass(), |
| + nacl_host_message_filter->PeerHandle()); |
| + WriteGetReadonlyPnaclFDReply(reply_msg, target_desc, 0, 0); |
| + nacl_host_message_filter->Send(reply_msg); |
| } |
| - NaClHostMsg_GetReadonlyPnaclFD::WriteReplyParams( |
| - reply_msg, target_desc); |
| - nacl_host_message_filter->Send(reply_msg); |
| -} |
| - |
| -void DoRegisterOpenedNaClExecutableFile( |
| - scoped_refptr<nacl::NaClHostMessageFilter> nacl_host_message_filter, |
| - base::File file, |
| - base::FilePath file_path, |
| - IPC::Message* reply_msg) { |
| - // IO thread owns the NaClBrowser singleton. |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| - |
| - nacl::NaClBrowser* nacl_browser = nacl::NaClBrowser::GetInstance(); |
| - uint64 file_token_lo = 0; |
| - uint64 file_token_hi = 0; |
| - nacl_browser->PutFilePath(file_path, &file_token_lo, &file_token_hi); |
| - |
| - IPC::PlatformFileForTransit file_desc = IPC::TakeFileHandleForProcess( |
| - file.Pass(), |
| - nacl_host_message_filter->PeerHandle()); |
| - |
| - NaClHostMsg_OpenNaClExecutable::WriteReplyParams( |
| - reply_msg, file_desc, file_token_lo, file_token_hi); |
| - nacl_host_message_filter->Send(reply_msg); |
| } |
| // Convert the file URL into a file descriptor. |
| @@ -125,7 +155,8 @@ void DoOpenNaClExecutableOnThreadPool( |
| return; |
| } |
| - base::File file = nacl::OpenNaClExecutableImpl(file_path); |
| + base::File file = nacl::OpenNaClReadExecImpl(file_path, |
| + true /* is_executable */); |
| if (file.IsValid()) { |
| // This function is running on the blocking pool, but the path needs to be |
| // registered in a structure owned by the IO thread. |
| @@ -134,7 +165,8 @@ void DoOpenNaClExecutableOnThreadPool( |
| base::Bind( |
| &DoRegisterOpenedNaClExecutableFile, |
| nacl_host_message_filter, |
| - Passed(file.Pass()), file_path, reply_msg)); |
| + Passed(file.Pass()), file_path, reply_msg, |
| + &WriteOpenNaClExecutableReply)); |
| } else { |
| NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
| return; |
| @@ -148,12 +180,14 @@ namespace nacl_file_host { |
| void GetReadonlyPnaclFd( |
| scoped_refptr<nacl::NaClHostMessageFilter> nacl_host_message_filter, |
| const std::string& filename, |
| + bool is_executable, |
| IPC::Message* reply_msg) { |
| if (!BrowserThread::PostBlockingPoolTask( |
| FROM_HERE, |
| base::Bind(&DoOpenPnaclFile, |
| nacl_host_message_filter, |
| filename, |
| + is_executable, |
| reply_msg))) { |
| NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
| } |