OLD | NEW |
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/pnacl_file_host.h" | 5 #include "chrome/browser/nacl_host/pnacl_file_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 true /* Close source */); | 69 true /* Close source */); |
70 if (target_desc == IPC::InvalidPlatformFileForTransit()) { | 70 if (target_desc == IPC::InvalidPlatformFileForTransit()) { |
71 NotifyRendererOfError(chrome_render_message_filter, reply_msg); | 71 NotifyRendererOfError(chrome_render_message_filter, reply_msg); |
72 return; | 72 return; |
73 } | 73 } |
74 ChromeViewHostMsg_GetReadonlyPnaclFD::WriteReplyParams( | 74 ChromeViewHostMsg_GetReadonlyPnaclFD::WriteReplyParams( |
75 reply_msg, target_desc); | 75 reply_msg, target_desc); |
76 chrome_render_message_filter->Send(reply_msg); | 76 chrome_render_message_filter->Send(reply_msg); |
77 } | 77 } |
78 | 78 |
| 79 void DoCreateTemporaryFile( |
| 80 ChromeRenderMessageFilter* chrome_render_message_filter, |
| 81 IPC::Message* reply_msg) { |
| 82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 83 |
| 84 FilePath file_path; |
| 85 if (!file_util::CreateTemporaryFile(&file_path)) { |
| 86 NotifyRendererOfError(chrome_render_message_filter, reply_msg); |
| 87 return; |
| 88 } |
| 89 |
| 90 base::PlatformFileError error; |
| 91 base::PlatformFile file_handle = base::CreatePlatformFile( |
| 92 file_path, |
| 93 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_READ | |
| 94 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_TEMPORARY | |
| 95 base::PLATFORM_FILE_DELETE_ON_CLOSE, |
| 96 NULL, &error); |
| 97 |
| 98 if (error != base::PLATFORM_FILE_OK) { |
| 99 NotifyRendererOfError(chrome_render_message_filter, reply_msg); |
| 100 return; |
| 101 } |
| 102 |
| 103 // Send the reply! |
| 104 // Do any DuplicateHandle magic that is necessary first. |
| 105 IPC::PlatformFileForTransit target_desc = |
| 106 IPC::GetFileHandleForProcess(file_handle, |
| 107 chrome_render_message_filter->peer_handle(), |
| 108 true); |
| 109 if (target_desc == IPC::InvalidPlatformFileForTransit()) { |
| 110 NotifyRendererOfError(chrome_render_message_filter, reply_msg); |
| 111 return; |
| 112 } |
| 113 |
| 114 ChromeViewHostMsg_NaClCreateTemporaryFile::WriteReplyParams( |
| 115 reply_msg, target_desc); |
| 116 chrome_render_message_filter->Send(reply_msg); |
| 117 } |
| 118 |
79 } // namespace | 119 } // namespace |
80 | 120 |
81 namespace pnacl_file_host { | 121 namespace pnacl_file_host { |
82 | 122 |
83 void GetReadonlyPnaclFd( | 123 void GetReadonlyPnaclFd( |
84 ChromeRenderMessageFilter* chrome_render_message_filter, | 124 ChromeRenderMessageFilter* chrome_render_message_filter, |
85 const std::string& filename, | 125 const std::string& filename, |
86 IPC::Message* reply_msg) { | 126 IPC::Message* reply_msg) { |
87 if (!BrowserThread::PostTask( | 127 if (!BrowserThread::PostTask( |
88 BrowserThread::FILE, FROM_HERE, | 128 BrowserThread::FILE, FROM_HERE, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 } | 168 } |
129 if (pnacl_dir.empty()) { | 169 if (pnacl_dir.empty()) { |
130 return false; | 170 return false; |
131 } | 171 } |
132 | 172 |
133 FilePath full_path = pnacl_dir.Append(file_to_find); | 173 FilePath full_path = pnacl_dir.Append(file_to_find); |
134 *file_to_open = full_path; | 174 *file_to_open = full_path; |
135 return true; | 175 return true; |
136 } | 176 } |
137 | 177 |
| 178 void CreateTemporaryFile( |
| 179 ChromeRenderMessageFilter* chrome_render_message_filter, |
| 180 IPC::Message* reply_msg) { |
| 181 if (!BrowserThread::PostTask( |
| 182 BrowserThread::FILE, FROM_HERE, |
| 183 base::Bind(&DoCreateTemporaryFile, |
| 184 make_scoped_refptr(chrome_render_message_filter), |
| 185 reply_msg))) { |
| 186 NotifyRendererOfError(chrome_render_message_filter, reply_msg); |
| 187 } |
| 188 } |
| 189 |
138 } // namespace pnacl_file_host | 190 } // namespace pnacl_file_host |
OLD | NEW |