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

Side by Side Diff: chrome/browser/nacl_host/pnacl_file_host.cc

Issue 10815080: Add an interface for nacl to create delete-on-close temp files, (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 8 years, 5 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 | Annotate | Revision Log
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 "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
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 // Also unlink the temp file immediately on posix systems.
104 #if defined(OS_POSIX)
105 if (!file_util::Delete(file_path, false)) {
brettw 2012/07/27 22:38:17 Unless I'm mistaken, it looks like this is already
jvoung - send to chromium... 2012/07/28 01:30:05 Oops make sense -- removed.
106 NotifyRendererOfError(chrome_render_message_filter, reply_msg);
107 return;
108 }
109 #endif
110
111 // Send the reply!
112 // Do any DuplicateHandle magic that is necessary first.
113 IPC::PlatformFileForTransit target_desc =
114 IPC::GetFileHandleForProcess(file_handle,
115 chrome_render_message_filter->peer_handle(),
116 true);
117 if (target_desc == IPC::InvalidPlatformFileForTransit()) {
118 NotifyRendererOfError(chrome_render_message_filter, reply_msg);
119 return;
120 }
121
122 ChromeViewHostMsg_NaClCreateTemporaryFile::WriteReplyParams(
123 reply_msg, target_desc);
124 chrome_render_message_filter->Send(reply_msg);
125 }
126
79 } // namespace 127 } // namespace
80 128
81 namespace pnacl_file_host { 129 namespace pnacl_file_host {
82 130
83 void GetReadonlyPnaclFd( 131 void GetReadonlyPnaclFd(
84 ChromeRenderMessageFilter* chrome_render_message_filter, 132 ChromeRenderMessageFilter* chrome_render_message_filter,
85 const std::string& filename, 133 const std::string& filename,
86 IPC::Message* reply_msg) { 134 IPC::Message* reply_msg) {
87 if (!BrowserThread::PostTask( 135 if (!BrowserThread::PostTask(
88 BrowserThread::FILE, FROM_HERE, 136 BrowserThread::FILE, FROM_HERE,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 } 176 }
129 if (pnacl_dir.empty()) { 177 if (pnacl_dir.empty()) {
130 return false; 178 return false;
131 } 179 }
132 180
133 FilePath full_path = pnacl_dir.Append(file_to_find); 181 FilePath full_path = pnacl_dir.Append(file_to_find);
134 *file_to_open = full_path; 182 *file_to_open = full_path;
135 return true; 183 return true;
136 } 184 }
137 185
186 void CreateTemporaryFile(
187 ChromeRenderMessageFilter* chrome_render_message_filter,
188 IPC::Message* reply_msg) {
189 if (!BrowserThread::PostTask(
190 BrowserThread::FILE, FROM_HERE,
191 base::Bind(&DoCreateTemporaryFile,
192 make_scoped_refptr(chrome_render_message_filter),
193 reply_msg))) {
194 NotifyRendererOfError(chrome_render_message_filter, reply_msg);
195 }
196 }
197
138 } // namespace pnacl_file_host 198 } // namespace pnacl_file_host
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698