Index: chrome/browser/nacl_host/pnacl_file_host.cc |
diff --git a/chrome/browser/nacl_host/pnacl_file_host.cc b/chrome/browser/nacl_host/pnacl_file_host.cc |
index a5186680453b4ab8a55a8fc249cfe0547f82ea48..fa0e5f0fe4ed086224bc4cfcf48cf69fb8b931f3 100644 |
--- a/chrome/browser/nacl_host/pnacl_file_host.cc |
+++ b/chrome/browser/nacl_host/pnacl_file_host.cc |
@@ -76,6 +76,46 @@ void DoOpenPnaclFile( |
chrome_render_message_filter->Send(reply_msg); |
} |
+void DoCreateTemporaryFile( |
+ ChromeRenderMessageFilter* chrome_render_message_filter, |
+ IPC::Message* reply_msg) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
+ |
+ FilePath file_path; |
+ if (!file_util::CreateTemporaryFile(&file_path)) { |
+ NotifyRendererOfError(chrome_render_message_filter, reply_msg); |
+ return; |
+ } |
+ |
+ base::PlatformFileError error; |
+ base::PlatformFile file_handle = base::CreatePlatformFile( |
+ file_path, |
+ base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_READ | |
+ base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_TEMPORARY | |
+ base::PLATFORM_FILE_DELETE_ON_CLOSE, |
+ NULL, &error); |
+ |
+ if (error != base::PLATFORM_FILE_OK) { |
+ NotifyRendererOfError(chrome_render_message_filter, reply_msg); |
+ return; |
+ } |
+ |
+ // Send the reply! |
+ // Do any DuplicateHandle magic that is necessary first. |
+ IPC::PlatformFileForTransit target_desc = |
+ IPC::GetFileHandleForProcess(file_handle, |
+ chrome_render_message_filter->peer_handle(), |
+ true); |
+ if (target_desc == IPC::InvalidPlatformFileForTransit()) { |
+ NotifyRendererOfError(chrome_render_message_filter, reply_msg); |
+ return; |
+ } |
+ |
+ ChromeViewHostMsg_NaClCreateTemporaryFile::WriteReplyParams( |
+ reply_msg, target_desc); |
+ chrome_render_message_filter->Send(reply_msg); |
+} |
+ |
} // namespace |
namespace pnacl_file_host { |
@@ -135,4 +175,16 @@ bool PnaclCanOpenFile(const std::string& filename, |
return true; |
} |
+void CreateTemporaryFile( |
+ ChromeRenderMessageFilter* chrome_render_message_filter, |
+ IPC::Message* reply_msg) { |
+ if (!BrowserThread::PostTask( |
+ BrowserThread::FILE, FROM_HERE, |
+ base::Bind(&DoCreateTemporaryFile, |
+ make_scoped_refptr(chrome_render_message_filter), |
+ reply_msg))) { |
+ NotifyRendererOfError(chrome_render_message_filter, reply_msg); |
+ } |
+} |
+ |
} // namespace pnacl_file_host |