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

Side by Side Diff: chrome/browser/media_galleries/fileapi/native_media_file_util.cc

Issue 16413007: Make FileSystemOperation NOT self-destruct (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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/media_galleries/fileapi/native_media_file_util.h" 5 #include "chrome/browser/media_galleries/fileapi/native_media_file_util.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file_enumerator.h" 9 #include "base/files/file_enumerator.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 if (StartsWithASCII(mime_type, "image/", true) || 126 if (StartsWithASCII(mime_type, "image/", true) ||
127 StartsWithASCII(mime_type, "audio/", true) || 127 StartsWithASCII(mime_type, "audio/", true) ||
128 StartsWithASCII(mime_type, "video/", true) || 128 StartsWithASCII(mime_type, "video/", true) ||
129 mime_type == "application/x-shockwave-flash") { 129 mime_type == "application/x-shockwave-flash") {
130 return base::PLATFORM_FILE_OK; 130 return base::PLATFORM_FILE_OK;
131 } 131 }
132 return base::PLATFORM_FILE_ERROR_SECURITY; 132 return base::PLATFORM_FILE_ERROR_SECURITY;
133 } 133 }
134 134
135 bool NativeMediaFileUtil::CreateOrOpen( 135 bool NativeMediaFileUtil::CreateOrOpen(
136 fileapi::FileSystemOperationContext* context, 136 scoped_ptr<fileapi::FileSystemOperationContext> context,
137 const fileapi::FileSystemURL& url, 137 const fileapi::FileSystemURL& url,
138 int file_flags, 138 int file_flags,
139 const CreateOrOpenCallback& callback) { 139 const CreateOrOpenCallback& callback) {
140 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 140 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
141 // Only called by NaCl, which should not have access to media file systems. 141 // Only called by NaCl, which should not have access to media file systems.
142 base::PlatformFile invalid_file(base::kInvalidPlatformFileValue); 142 base::PlatformFile invalid_file(base::kInvalidPlatformFileValue);
143 if (!callback.is_null()) { 143 if (!callback.is_null()) {
144 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, 144 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY,
145 base::PassPlatformFile(&invalid_file), 145 base::PassPlatformFile(&invalid_file),
146 false); 146 false);
147 } 147 }
148 return true; 148 return true;
149 } 149 }
150 150
151 bool NativeMediaFileUtil::EnsureFileExists( 151 bool NativeMediaFileUtil::EnsureFileExists(
152 fileapi::FileSystemOperationContext* context, 152 scoped_ptr<fileapi::FileSystemOperationContext> context,
153 const fileapi::FileSystemURL& url, 153 const fileapi::FileSystemURL& url,
154 const EnsureFileExistsCallback& callback) { 154 const EnsureFileExistsCallback& callback) {
155 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 155 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
156 if (!callback.is_null()) 156 if (!callback.is_null())
157 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, false); 157 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, false);
158 return true; 158 return true;
159 } 159 }
160 160
161 bool NativeMediaFileUtil::CreateDirectory( 161 bool NativeMediaFileUtil::CreateDirectory(
162 fileapi::FileSystemOperationContext* context, 162 scoped_ptr<fileapi::FileSystemOperationContext> context,
163 const fileapi::FileSystemURL& url, 163 const fileapi::FileSystemURL& url,
164 bool exclusive, 164 bool exclusive,
165 bool recursive, 165 bool recursive,
166 const StatusCallback& callback) { 166 const StatusCallback& callback) {
167 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 167 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
168 return context->task_runner()->PostTask( 168 fileapi::FileSystemOperationContext* context_ptr = context.release();
169 return context_ptr->task_runner()->PostTask(
169 FROM_HERE, 170 FROM_HERE,
170 base::Bind(&NativeMediaFileUtil::CreateDirectoryOnTaskRunnerThread, 171 base::Bind(&NativeMediaFileUtil::CreateDirectoryOnTaskRunnerThread,
171 weak_factory_.GetWeakPtr(), context, url, exclusive, recursive, 172 weak_factory_.GetWeakPtr(), base::Owned(context_ptr),
172 callback)); 173 url, exclusive, recursive, callback));
173 } 174 }
174 175
175 bool NativeMediaFileUtil::GetFileInfo( 176 bool NativeMediaFileUtil::GetFileInfo(
176 fileapi::FileSystemOperationContext* context, 177 scoped_ptr<fileapi::FileSystemOperationContext> context,
177 const fileapi::FileSystemURL& url, 178 const fileapi::FileSystemURL& url,
178 const GetFileInfoCallback& callback) { 179 const GetFileInfoCallback& callback) {
179 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 180 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
180 return context->task_runner()->PostTask( 181 fileapi::FileSystemOperationContext* context_ptr = context.release();
182 return context_ptr->task_runner()->PostTask(
181 FROM_HERE, 183 FROM_HERE,
182 base::Bind(&NativeMediaFileUtil::GetFileInfoOnTaskRunnerThread, 184 base::Bind(&NativeMediaFileUtil::GetFileInfoOnTaskRunnerThread,
183 weak_factory_.GetWeakPtr(), context, url, callback)); 185 weak_factory_.GetWeakPtr(), base::Owned(context_ptr),
186 url, callback));
184 } 187 }
185 188
186 bool NativeMediaFileUtil::ReadDirectory( 189 bool NativeMediaFileUtil::ReadDirectory(
187 fileapi::FileSystemOperationContext* context, 190 scoped_ptr<fileapi::FileSystemOperationContext> context,
188 const fileapi::FileSystemURL& url, 191 const fileapi::FileSystemURL& url,
189 const ReadDirectoryCallback& callback) { 192 const ReadDirectoryCallback& callback) {
190 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 193 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
191 return context->task_runner()->PostTask( 194 fileapi::FileSystemOperationContext* context_ptr = context.release();
195 return context_ptr->task_runner()->PostTask(
192 FROM_HERE, 196 FROM_HERE,
193 base::Bind(&NativeMediaFileUtil::ReadDirectoryOnTaskRunnerThread, 197 base::Bind(&NativeMediaFileUtil::ReadDirectoryOnTaskRunnerThread,
194 weak_factory_.GetWeakPtr(), context, url, callback)); 198 weak_factory_.GetWeakPtr(), base::Owned(context_ptr),
199 url, callback));
195 } 200 }
196 201
197 bool NativeMediaFileUtil::Touch( 202 bool NativeMediaFileUtil::Touch(
198 fileapi::FileSystemOperationContext* context, 203 scoped_ptr<fileapi::FileSystemOperationContext> context,
199 const fileapi::FileSystemURL& url, 204 const fileapi::FileSystemURL& url,
200 const base::Time& last_access_time, 205 const base::Time& last_access_time,
201 const base::Time& last_modified_time, 206 const base::Time& last_modified_time,
202 const StatusCallback& callback) { 207 const StatusCallback& callback) {
203 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 208 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
204 if (!callback.is_null()) 209 if (!callback.is_null())
205 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); 210 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY);
206 return true; 211 return true;
207 } 212 }
208 213
209 bool NativeMediaFileUtil::Truncate( 214 bool NativeMediaFileUtil::Truncate(
210 fileapi::FileSystemOperationContext* context, 215 scoped_ptr<fileapi::FileSystemOperationContext> context,
211 const fileapi::FileSystemURL& url, 216 const fileapi::FileSystemURL& url,
212 int64 length, 217 int64 length,
213 const StatusCallback& callback) { 218 const StatusCallback& callback) {
214 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 219 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
215 if (!callback.is_null()) 220 if (!callback.is_null())
216 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); 221 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY);
217 return true; 222 return true;
218 } 223 }
219 224
220 bool NativeMediaFileUtil::CopyFileLocal( 225 bool NativeMediaFileUtil::CopyFileLocal(
221 fileapi::FileSystemOperationContext* context, 226 scoped_ptr<fileapi::FileSystemOperationContext> context,
222 const fileapi::FileSystemURL& src_url, 227 const fileapi::FileSystemURL& src_url,
223 const fileapi::FileSystemURL& dest_url, 228 const fileapi::FileSystemURL& dest_url,
224 const StatusCallback& callback) { 229 const StatusCallback& callback) {
225 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 230 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
226 return context->task_runner()->PostTask( 231 fileapi::FileSystemOperationContext* context_ptr = context.release();
232 return context_ptr->task_runner()->PostTask(
227 FROM_HERE, 233 FROM_HERE,
228 base::Bind(&NativeMediaFileUtil::CopyOrMoveFileLocalOnTaskRunnerThread, 234 base::Bind(&NativeMediaFileUtil::CopyOrMoveFileLocalOnTaskRunnerThread,
229 weak_factory_.GetWeakPtr(), context, src_url, dest_url, 235 weak_factory_.GetWeakPtr(), base::Owned(context_ptr),
230 true /* copy */, callback)); 236 src_url, dest_url, true /* copy */, callback));
231 } 237 }
232 238
233 bool NativeMediaFileUtil::MoveFileLocal( 239 bool NativeMediaFileUtil::MoveFileLocal(
234 fileapi::FileSystemOperationContext* context, 240 scoped_ptr<fileapi::FileSystemOperationContext> context,
235 const fileapi::FileSystemURL& src_url, 241 const fileapi::FileSystemURL& src_url,
236 const fileapi::FileSystemURL& dest_url, 242 const fileapi::FileSystemURL& dest_url,
237 const StatusCallback& callback) { 243 const StatusCallback& callback) {
238 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 244 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
239 return context->task_runner()->PostTask( 245 fileapi::FileSystemOperationContext* context_ptr = context.release();
246 return context_ptr->task_runner()->PostTask(
240 FROM_HERE, 247 FROM_HERE,
241 base::Bind(&NativeMediaFileUtil::CopyOrMoveFileLocalOnTaskRunnerThread, 248 base::Bind(&NativeMediaFileUtil::CopyOrMoveFileLocalOnTaskRunnerThread,
242 weak_factory_.GetWeakPtr(), context, src_url, dest_url, 249 weak_factory_.GetWeakPtr(), base::Owned(context_ptr),
243 false /* copy */, callback)); 250 src_url, dest_url, false /* copy */, callback));
244 } 251 }
245 252
246 bool NativeMediaFileUtil::CopyInForeignFile( 253 bool NativeMediaFileUtil::CopyInForeignFile(
247 fileapi::FileSystemOperationContext* context, 254 scoped_ptr<fileapi::FileSystemOperationContext> context,
248 const base::FilePath& src_file_path, 255 const base::FilePath& src_file_path,
249 const fileapi::FileSystemURL& dest_url, 256 const fileapi::FileSystemURL& dest_url,
250 const StatusCallback& callback) { 257 const StatusCallback& callback) {
251 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 258 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
252 return context->task_runner()->PostTask( 259 fileapi::FileSystemOperationContext* context_ptr = context.release();
260 return context_ptr->task_runner()->PostTask(
253 FROM_HERE, 261 FROM_HERE,
254 base::Bind(&NativeMediaFileUtil::CopyInForeignFileOnTaskRunnerThread, 262 base::Bind(&NativeMediaFileUtil::CopyInForeignFileOnTaskRunnerThread,
255 weak_factory_.GetWeakPtr(), context, src_file_path, dest_url, 263 weak_factory_.GetWeakPtr(), base::Owned(context_ptr),
256 callback)); 264 src_file_path, dest_url, callback));
257 } 265 }
258 266
259 bool NativeMediaFileUtil::DeleteFile( 267 bool NativeMediaFileUtil::DeleteFile(
260 fileapi::FileSystemOperationContext* context, 268 scoped_ptr<fileapi::FileSystemOperationContext> context,
261 const fileapi::FileSystemURL& url, 269 const fileapi::FileSystemURL& url,
262 const StatusCallback& callback) { 270 const StatusCallback& callback) {
263 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 271 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
264 if (!callback.is_null()) 272 if (!callback.is_null())
265 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); 273 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY);
266 return true; 274 return true;
267 } 275 }
268 276
269 // This is needed to support Copy and Move. 277 // This is needed to support Copy and Move.
270 bool NativeMediaFileUtil::DeleteDirectory( 278 bool NativeMediaFileUtil::DeleteDirectory(
271 fileapi::FileSystemOperationContext* context, 279 scoped_ptr<fileapi::FileSystemOperationContext> context,
272 const fileapi::FileSystemURL& url, 280 const fileapi::FileSystemURL& url,
273 const StatusCallback& callback) { 281 const StatusCallback& callback) {
274 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 282 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
275 return context->task_runner()->PostTask( 283 fileapi::FileSystemOperationContext* context_ptr = context.release();
284 return context_ptr->task_runner()->PostTask(
276 FROM_HERE, 285 FROM_HERE,
277 base::Bind(&NativeMediaFileUtil::DeleteDirectoryOnTaskRunnerThread, 286 base::Bind(&NativeMediaFileUtil::DeleteDirectoryOnTaskRunnerThread,
278 weak_factory_.GetWeakPtr(), context, url, callback)); 287 weak_factory_.GetWeakPtr(), base::Owned(context_ptr),
288 url, callback));
279 } 289 }
280 290
281 bool NativeMediaFileUtil::CreateSnapshotFile( 291 bool NativeMediaFileUtil::CreateSnapshotFile(
282 fileapi::FileSystemOperationContext* context, 292 scoped_ptr<fileapi::FileSystemOperationContext> context,
283 const fileapi::FileSystemURL& url, 293 const fileapi::FileSystemURL& url,
284 const CreateSnapshotFileCallback& callback) { 294 const CreateSnapshotFileCallback& callback) {
285 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 295 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
286 return context->task_runner()->PostTask( 296 fileapi::FileSystemOperationContext* context_ptr = context.release();
297 return context_ptr->task_runner()->PostTask(
287 FROM_HERE, 298 FROM_HERE,
288 base::Bind(&NativeMediaFileUtil::CreateSnapshotFileOnTaskRunnerThread, 299 base::Bind(&NativeMediaFileUtil::CreateSnapshotFileOnTaskRunnerThread,
289 weak_factory_.GetWeakPtr(), context, url, callback)); 300 weak_factory_.GetWeakPtr(), base::Owned(context_ptr),
301 url, callback));
290 } 302 }
291 303
292 void NativeMediaFileUtil::CreateDirectoryOnTaskRunnerThread( 304 void NativeMediaFileUtil::CreateDirectoryOnTaskRunnerThread(
293 fileapi::FileSystemOperationContext* context, 305 fileapi::FileSystemOperationContext* context,
294 const fileapi::FileSystemURL& url, 306 const fileapi::FileSystemURL& url,
295 bool exclusive, 307 bool exclusive,
296 bool recursive, 308 bool recursive,
297 const StatusCallback& callback) { 309 const StatusCallback& callback) {
298 DCHECK(IsOnTaskRunnerThread(context)); 310 DCHECK(IsOnTaskRunnerThread(context));
299 base::PlatformFileError error = 311 base::PlatformFileError error =
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 return error; 480 return error;
469 return fileapi::NativeFileUtil::CopyOrMoveFile(src_file_path, dest_file_path, 481 return fileapi::NativeFileUtil::CopyOrMoveFile(src_file_path, dest_file_path,
470 true); 482 true);
471 } 483 }
472 484
473 base::PlatformFileError NativeMediaFileUtil::GetFileInfoSync( 485 base::PlatformFileError NativeMediaFileUtil::GetFileInfoSync(
474 fileapi::FileSystemOperationContext* context, 486 fileapi::FileSystemOperationContext* context,
475 const fileapi::FileSystemURL& url, 487 const fileapi::FileSystemURL& url,
476 base::PlatformFileInfo* file_info, 488 base::PlatformFileInfo* file_info,
477 base::FilePath* platform_path) { 489 base::FilePath* platform_path) {
490 DCHECK(context);
478 DCHECK(IsOnTaskRunnerThread(context)); 491 DCHECK(IsOnTaskRunnerThread(context));
479 DCHECK(context);
480 DCHECK(file_info); 492 DCHECK(file_info);
481 DCHECK(GetMediaPathFilter(context)); 493 DCHECK(GetMediaPathFilter(context));
482 494
483 base::FilePath file_path; 495 base::FilePath file_path;
484 base::PlatformFileError error = GetLocalFilePath(context, url, &file_path); 496 base::PlatformFileError error = GetLocalFilePath(
497 context, url, &file_path);
Lei Zhang 2013/06/10 05:34:54 nit: this was fine as is before?
kinuko 2013/06/10 06:46:31 Right, reverted.
485 if (error != base::PLATFORM_FILE_OK) 498 if (error != base::PLATFORM_FILE_OK)
486 return error; 499 return error;
487 if (file_util::IsLink(file_path)) 500 if (file_util::IsLink(file_path))
488 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 501 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
489 error = fileapi::NativeFileUtil::GetFileInfo(file_path, file_info); 502 error = fileapi::NativeFileUtil::GetFileInfo(file_path, file_info);
490 if (error != base::PLATFORM_FILE_OK) 503 if (error != base::PLATFORM_FILE_OK)
491 return error; 504 return error;
492 505
493 if (platform_path) 506 if (platform_path)
494 *platform_path = file_path; 507 *platform_path = file_path;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 if (!file_info.is_directory && 646 if (!file_info.is_directory &&
634 !GetMediaPathFilter(context)->Match(file_path)) { 647 !GetMediaPathFilter(context)->Match(file_path)) {
635 return failure_error; 648 return failure_error;
636 } 649 }
637 650
638 *local_file_path = file_path; 651 *local_file_path = file_path;
639 return base::PLATFORM_FILE_OK; 652 return base::PLATFORM_FILE_OK;
640 } 653 }
641 654
642 } // namespace chrome 655 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698