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

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

Issue 145303002: Convert Media Galleries to use base::File (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 10 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 <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 return true; 67 return true;
68 #endif 68 #endif
69 return false; 69 return false;
70 } 70 }
71 71
72 // Returns true if the current thread is capable of doing IO. 72 // Returns true if the current thread is capable of doing IO.
73 bool IsOnTaskRunnerThread(fileapi::FileSystemOperationContext* context) { 73 bool IsOnTaskRunnerThread(fileapi::FileSystemOperationContext* context) {
74 return context->task_runner()->RunsTasksOnCurrentThread(); 74 return context->task_runner()->RunsTasksOnCurrentThread();
75 } 75 }
76 76
77 base::PlatformFileError IsMediaHeader(const char* buf, size_t length) { 77 base::File::Error IsMediaHeader(const char* buf, size_t length) {
78 if (length == 0) 78 if (length == 0)
79 return base::PLATFORM_FILE_ERROR_SECURITY; 79 return base::File::FILE_ERROR_SECURITY;
80 80
81 std::string mime_type; 81 std::string mime_type;
82 if (!net::SniffMimeTypeFromLocalData(buf, length, &mime_type)) 82 if (!net::SniffMimeTypeFromLocalData(buf, length, &mime_type))
83 return base::PLATFORM_FILE_ERROR_SECURITY; 83 return base::File::FILE_ERROR_SECURITY;
84 84
85 if (StartsWithASCII(mime_type, "image/", true) || 85 if (StartsWithASCII(mime_type, "image/", true) ||
86 StartsWithASCII(mime_type, "audio/", true) || 86 StartsWithASCII(mime_type, "audio/", true) ||
87 StartsWithASCII(mime_type, "video/", true) || 87 StartsWithASCII(mime_type, "video/", true) ||
88 mime_type == "application/x-shockwave-flash") { 88 mime_type == "application/x-shockwave-flash") {
89 return base::PLATFORM_FILE_OK; 89 return base::File::FILE_OK;
90 } 90 }
91 return base::PLATFORM_FILE_ERROR_SECURITY; 91 return base::File::FILE_ERROR_SECURITY;
92 } 92 }
93 93
94 } // namespace 94 } // namespace
95 95
96 NativeMediaFileUtil::NativeMediaFileUtil(MediaPathFilter* media_path_filter) 96 NativeMediaFileUtil::NativeMediaFileUtil(MediaPathFilter* media_path_filter)
97 : media_path_filter_(media_path_filter), 97 : media_path_filter_(media_path_filter),
98 weak_factory_(this) { 98 weak_factory_(this) {
99 } 99 }
100 100
101 NativeMediaFileUtil::~NativeMediaFileUtil() { 101 NativeMediaFileUtil::~NativeMediaFileUtil() {
102 } 102 }
103 103
104 // static 104 // static
105 base::PlatformFileError NativeMediaFileUtil::IsMediaFile( 105 base::File::Error NativeMediaFileUtil::IsMediaFile(
106 const base::FilePath& path) { 106 const base::FilePath& path) {
107 base::PlatformFile file_handle; 107 base::PlatformFile file_handle;
108 const int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ; 108 const int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
109 base::PlatformFileError error = 109 base::File::Error error =
110 fileapi::NativeFileUtil::CreateOrOpen(path, flags, &file_handle, NULL); 110 fileapi::NativeFileUtil::CreateOrOpen(path, flags, &file_handle, NULL);
111 if (error != base::PLATFORM_FILE_OK) 111 if (error != base::File::FILE_OK)
112 return error; 112 return error;
113 113
114 base::ScopedPlatformFileCloser scoped_platform_file(&file_handle); 114 base::ScopedPlatformFileCloser scoped_platform_file(&file_handle);
115 char buffer[net::kMaxBytesToSniff]; 115 char buffer[net::kMaxBytesToSniff];
116 116
117 // Read as much as net::SniffMimeTypeFromLocalData() will bother looking at. 117 // Read as much as net::SniffMimeTypeFromLocalData() will bother looking at.
118 int64 len = 118 int64 len =
119 base::ReadPlatformFile(file_handle, 0, buffer, net::kMaxBytesToSniff); 119 base::ReadPlatformFile(file_handle, 0, buffer, net::kMaxBytesToSniff);
120 if (len < 0) 120 if (len < 0)
121 return base::PLATFORM_FILE_ERROR_FAILED; 121 return base::File::FILE_ERROR_FAILED;
122 122
123 return IsMediaHeader(buffer, len); 123 return IsMediaHeader(buffer, len);
124 } 124 }
125 125
126 // static 126 // static
127 base::PlatformFileError NativeMediaFileUtil::BufferIsMediaHeader( 127 base::File::Error NativeMediaFileUtil::BufferIsMediaHeader(
128 net::IOBuffer* buf, size_t length) { 128 net::IOBuffer* buf, size_t length) {
129 return IsMediaHeader(buf->data(), length); 129 return IsMediaHeader(buf->data(), length);
130 } 130 }
131 131
132 void NativeMediaFileUtil::CreateOrOpen( 132 void NativeMediaFileUtil::CreateOrOpen(
133 scoped_ptr<fileapi::FileSystemOperationContext> context, 133 scoped_ptr<fileapi::FileSystemOperationContext> context,
134 const fileapi::FileSystemURL& url, 134 const fileapi::FileSystemURL& url,
135 int file_flags, 135 int file_flags,
136 const CreateOrOpenCallback& callback) { 136 const CreateOrOpenCallback& callback) {
137 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 137 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
138 // Only called by NaCl, which should not have access to media file systems. 138 // Only called by NaCl, which should not have access to media file systems.
139 base::PlatformFile invalid_file(base::kInvalidPlatformFileValue); 139 base::PlatformFile invalid_file(base::kInvalidPlatformFileValue);
140 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, 140 callback.Run(base::File::FILE_ERROR_SECURITY,
141 base::PassPlatformFile(&invalid_file), 141 base::PassPlatformFile(&invalid_file),
142 base::Closure()); 142 base::Closure());
143 } 143 }
144 144
145 void NativeMediaFileUtil::EnsureFileExists( 145 void NativeMediaFileUtil::EnsureFileExists(
146 scoped_ptr<fileapi::FileSystemOperationContext> context, 146 scoped_ptr<fileapi::FileSystemOperationContext> context,
147 const fileapi::FileSystemURL& url, 147 const fileapi::FileSystemURL& url,
148 const EnsureFileExistsCallback& callback) { 148 const EnsureFileExistsCallback& callback) {
149 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 149 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
150 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, false); 150 callback.Run(base::File::FILE_ERROR_SECURITY, false);
151 } 151 }
152 152
153 void NativeMediaFileUtil::CreateDirectory( 153 void NativeMediaFileUtil::CreateDirectory(
154 scoped_ptr<fileapi::FileSystemOperationContext> context, 154 scoped_ptr<fileapi::FileSystemOperationContext> context,
155 const fileapi::FileSystemURL& url, 155 const fileapi::FileSystemURL& url,
156 bool exclusive, 156 bool exclusive,
157 bool recursive, 157 bool recursive,
158 const StatusCallback& callback) { 158 const StatusCallback& callback) {
159 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 159 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
160 fileapi::FileSystemOperationContext* context_ptr = context.get(); 160 fileapi::FileSystemOperationContext* context_ptr = context.get();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 DCHECK(success); 194 DCHECK(success);
195 } 195 }
196 196
197 void NativeMediaFileUtil::Touch( 197 void NativeMediaFileUtil::Touch(
198 scoped_ptr<fileapi::FileSystemOperationContext> context, 198 scoped_ptr<fileapi::FileSystemOperationContext> context,
199 const fileapi::FileSystemURL& url, 199 const fileapi::FileSystemURL& url,
200 const base::Time& last_access_time, 200 const base::Time& last_access_time,
201 const base::Time& last_modified_time, 201 const base::Time& last_modified_time,
202 const StatusCallback& callback) { 202 const StatusCallback& callback) {
203 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 203 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
204 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); 204 callback.Run(base::File::FILE_ERROR_SECURITY);
205 } 205 }
206 206
207 void NativeMediaFileUtil::Truncate( 207 void NativeMediaFileUtil::Truncate(
208 scoped_ptr<fileapi::FileSystemOperationContext> context, 208 scoped_ptr<fileapi::FileSystemOperationContext> context,
209 const fileapi::FileSystemURL& url, 209 const fileapi::FileSystemURL& url,
210 int64 length, 210 int64 length,
211 const StatusCallback& callback) { 211 const StatusCallback& callback) {
212 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 212 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
213 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); 213 callback.Run(base::File::FILE_ERROR_SECURITY);
214 } 214 }
215 215
216 void NativeMediaFileUtil::CopyFileLocal( 216 void NativeMediaFileUtil::CopyFileLocal(
217 scoped_ptr<fileapi::FileSystemOperationContext> context, 217 scoped_ptr<fileapi::FileSystemOperationContext> context,
218 const fileapi::FileSystemURL& src_url, 218 const fileapi::FileSystemURL& src_url,
219 const fileapi::FileSystemURL& dest_url, 219 const fileapi::FileSystemURL& dest_url,
220 CopyOrMoveOption option, 220 CopyOrMoveOption option,
221 const CopyFileProgressCallback& progress_callback, 221 const CopyFileProgressCallback& progress_callback,
222 const StatusCallback& callback) { 222 const StatusCallback& callback) {
223 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 223 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 weak_factory_.GetWeakPtr(), base::Passed(&context), 288 weak_factory_.GetWeakPtr(), base::Passed(&context),
289 url, callback)); 289 url, callback));
290 DCHECK(success); 290 DCHECK(success);
291 } 291 }
292 292
293 void NativeMediaFileUtil::DeleteRecursively( 293 void NativeMediaFileUtil::DeleteRecursively(
294 scoped_ptr<fileapi::FileSystemOperationContext> context, 294 scoped_ptr<fileapi::FileSystemOperationContext> context,
295 const fileapi::FileSystemURL& url, 295 const fileapi::FileSystemURL& url,
296 const StatusCallback& callback) { 296 const StatusCallback& callback) {
297 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 297 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
298 callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); 298 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION);
299 } 299 }
300 300
301 void NativeMediaFileUtil::CreateSnapshotFile( 301 void NativeMediaFileUtil::CreateSnapshotFile(
302 scoped_ptr<fileapi::FileSystemOperationContext> context, 302 scoped_ptr<fileapi::FileSystemOperationContext> context,
303 const fileapi::FileSystemURL& url, 303 const fileapi::FileSystemURL& url,
304 const CreateSnapshotFileCallback& callback) { 304 const CreateSnapshotFileCallback& callback) {
305 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 305 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
306 fileapi::FileSystemOperationContext* context_ptr = context.get(); 306 fileapi::FileSystemOperationContext* context_ptr = context.get();
307 const bool success = context_ptr->task_runner()->PostTask( 307 const bool success = context_ptr->task_runner()->PostTask(
308 FROM_HERE, 308 FROM_HERE,
309 base::Bind(&NativeMediaFileUtil::CreateSnapshotFileOnTaskRunnerThread, 309 base::Bind(&NativeMediaFileUtil::CreateSnapshotFileOnTaskRunnerThread,
310 weak_factory_.GetWeakPtr(), base::Passed(&context), 310 weak_factory_.GetWeakPtr(), base::Passed(&context),
311 url, callback)); 311 url, callback));
312 DCHECK(success); 312 DCHECK(success);
313 } 313 }
314 314
315 void NativeMediaFileUtil::CreateDirectoryOnTaskRunnerThread( 315 void NativeMediaFileUtil::CreateDirectoryOnTaskRunnerThread(
316 scoped_ptr<fileapi::FileSystemOperationContext> context, 316 scoped_ptr<fileapi::FileSystemOperationContext> context,
317 const fileapi::FileSystemURL& url, 317 const fileapi::FileSystemURL& url,
318 bool exclusive, 318 bool exclusive,
319 bool recursive, 319 bool recursive,
320 const StatusCallback& callback) { 320 const StatusCallback& callback) {
321 DCHECK(IsOnTaskRunnerThread(context.get())); 321 DCHECK(IsOnTaskRunnerThread(context.get()));
322 base::PlatformFileError error = 322 base::File::Error error =
323 CreateDirectorySync(context.get(), url, exclusive, recursive); 323 CreateDirectorySync(context.get(), url, exclusive, recursive);
324 content::BrowserThread::PostTask( 324 content::BrowserThread::PostTask(
325 content::BrowserThread::IO, 325 content::BrowserThread::IO,
326 FROM_HERE, 326 FROM_HERE,
327 base::Bind(callback, error)); 327 base::Bind(callback, error));
328 } 328 }
329 329
330 void NativeMediaFileUtil::GetFileInfoOnTaskRunnerThread( 330 void NativeMediaFileUtil::GetFileInfoOnTaskRunnerThread(
331 scoped_ptr<fileapi::FileSystemOperationContext> context, 331 scoped_ptr<fileapi::FileSystemOperationContext> context,
332 const fileapi::FileSystemURL& url, 332 const fileapi::FileSystemURL& url,
333 const GetFileInfoCallback& callback) { 333 const GetFileInfoCallback& callback) {
334 DCHECK(IsOnTaskRunnerThread(context.get())); 334 DCHECK(IsOnTaskRunnerThread(context.get()));
335 base::PlatformFileInfo file_info; 335 base::File::Info file_info;
336 base::PlatformFileError error = 336 base::File::Error error =
337 GetFileInfoSync(context.get(), url, &file_info, NULL); 337 GetFileInfoSync(context.get(), url, &file_info, NULL);
338 content::BrowserThread::PostTask( 338 content::BrowserThread::PostTask(
339 content::BrowserThread::IO, 339 content::BrowserThread::IO,
340 FROM_HERE, 340 FROM_HERE,
341 base::Bind(callback, error, file_info)); 341 base::Bind(callback, error, file_info));
342 } 342 }
343 343
344 void NativeMediaFileUtil::ReadDirectoryOnTaskRunnerThread( 344 void NativeMediaFileUtil::ReadDirectoryOnTaskRunnerThread(
345 scoped_ptr<fileapi::FileSystemOperationContext> context, 345 scoped_ptr<fileapi::FileSystemOperationContext> context,
346 const fileapi::FileSystemURL& url, 346 const fileapi::FileSystemURL& url,
347 const ReadDirectoryCallback& callback) { 347 const ReadDirectoryCallback& callback) {
348 DCHECK(IsOnTaskRunnerThread(context.get())); 348 DCHECK(IsOnTaskRunnerThread(context.get()));
349 EntryList entry_list; 349 EntryList entry_list;
350 base::PlatformFileError error = 350 base::File::Error error =
351 ReadDirectorySync(context.get(), url, &entry_list); 351 ReadDirectorySync(context.get(), url, &entry_list);
352 content::BrowserThread::PostTask( 352 content::BrowserThread::PostTask(
353 content::BrowserThread::IO, 353 content::BrowserThread::IO,
354 FROM_HERE, 354 FROM_HERE,
355 base::Bind(callback, error, entry_list, false /* has_more */)); 355 base::Bind(callback, error, entry_list, false /* has_more */));
356 } 356 }
357 357
358 void NativeMediaFileUtil::CopyOrMoveFileLocalOnTaskRunnerThread( 358 void NativeMediaFileUtil::CopyOrMoveFileLocalOnTaskRunnerThread(
359 scoped_ptr<fileapi::FileSystemOperationContext> context, 359 scoped_ptr<fileapi::FileSystemOperationContext> context,
360 const fileapi::FileSystemURL& src_url, 360 const fileapi::FileSystemURL& src_url,
361 const fileapi::FileSystemURL& dest_url, 361 const fileapi::FileSystemURL& dest_url,
362 CopyOrMoveOption option, 362 CopyOrMoveOption option,
363 bool copy, 363 bool copy,
364 const StatusCallback& callback) { 364 const StatusCallback& callback) {
365 DCHECK(IsOnTaskRunnerThread(context.get())); 365 DCHECK(IsOnTaskRunnerThread(context.get()));
366 base::PlatformFileError error = 366 base::File::Error error =
367 CopyOrMoveFileSync(context.get(), src_url, dest_url, option, copy); 367 CopyOrMoveFileSync(context.get(), src_url, dest_url, option, copy);
368 content::BrowserThread::PostTask( 368 content::BrowserThread::PostTask(
369 content::BrowserThread::IO, 369 content::BrowserThread::IO,
370 FROM_HERE, 370 FROM_HERE,
371 base::Bind(callback, error)); 371 base::Bind(callback, error));
372 } 372 }
373 373
374 void NativeMediaFileUtil::CopyInForeignFileOnTaskRunnerThread( 374 void NativeMediaFileUtil::CopyInForeignFileOnTaskRunnerThread(
375 scoped_ptr<fileapi::FileSystemOperationContext> context, 375 scoped_ptr<fileapi::FileSystemOperationContext> context,
376 const base::FilePath& src_file_path, 376 const base::FilePath& src_file_path,
377 const fileapi::FileSystemURL& dest_url, 377 const fileapi::FileSystemURL& dest_url,
378 const StatusCallback& callback) { 378 const StatusCallback& callback) {
379 DCHECK(IsOnTaskRunnerThread(context.get())); 379 DCHECK(IsOnTaskRunnerThread(context.get()));
380 base::PlatformFileError error = 380 base::File::Error error =
381 CopyInForeignFileSync(context.get(), src_file_path, dest_url); 381 CopyInForeignFileSync(context.get(), src_file_path, dest_url);
382 content::BrowserThread::PostTask( 382 content::BrowserThread::PostTask(
383 content::BrowserThread::IO, 383 content::BrowserThread::IO,
384 FROM_HERE, 384 FROM_HERE,
385 base::Bind(callback, error)); 385 base::Bind(callback, error));
386 } 386 }
387 387
388 void NativeMediaFileUtil::DeleteFileOnTaskRunnerThread( 388 void NativeMediaFileUtil::DeleteFileOnTaskRunnerThread(
389 scoped_ptr<fileapi::FileSystemOperationContext> context, 389 scoped_ptr<fileapi::FileSystemOperationContext> context,
390 const fileapi::FileSystemURL& url, 390 const fileapi::FileSystemURL& url,
391 const StatusCallback& callback) { 391 const StatusCallback& callback) {
392 DCHECK(IsOnTaskRunnerThread(context.get())); 392 DCHECK(IsOnTaskRunnerThread(context.get()));
393 base::PlatformFileError error = DeleteFileSync(context.get(), url); 393 base::File::Error error = DeleteFileSync(context.get(), url);
394 content::BrowserThread::PostTask( 394 content::BrowserThread::PostTask(
395 content::BrowserThread::IO, 395 content::BrowserThread::IO,
396 FROM_HERE, 396 FROM_HERE,
397 base::Bind(callback, error)); 397 base::Bind(callback, error));
398 } 398 }
399 399
400 void NativeMediaFileUtil::DeleteDirectoryOnTaskRunnerThread( 400 void NativeMediaFileUtil::DeleteDirectoryOnTaskRunnerThread(
401 scoped_ptr<fileapi::FileSystemOperationContext> context, 401 scoped_ptr<fileapi::FileSystemOperationContext> context,
402 const fileapi::FileSystemURL& url, 402 const fileapi::FileSystemURL& url,
403 const StatusCallback& callback) { 403 const StatusCallback& callback) {
404 DCHECK(IsOnTaskRunnerThread(context.get())); 404 DCHECK(IsOnTaskRunnerThread(context.get()));
405 base::PlatformFileError error = DeleteDirectorySync(context.get(), url); 405 base::File::Error error = DeleteDirectorySync(context.get(), url);
406 content::BrowserThread::PostTask( 406 content::BrowserThread::PostTask(
407 content::BrowserThread::IO, 407 content::BrowserThread::IO,
408 FROM_HERE, 408 FROM_HERE,
409 base::Bind(callback, error)); 409 base::Bind(callback, error));
410 } 410 }
411 411
412 void NativeMediaFileUtil::CreateSnapshotFileOnTaskRunnerThread( 412 void NativeMediaFileUtil::CreateSnapshotFileOnTaskRunnerThread(
413 scoped_ptr<fileapi::FileSystemOperationContext> context, 413 scoped_ptr<fileapi::FileSystemOperationContext> context,
414 const fileapi::FileSystemURL& url, 414 const fileapi::FileSystemURL& url,
415 const CreateSnapshotFileCallback& callback) { 415 const CreateSnapshotFileCallback& callback) {
416 DCHECK(IsOnTaskRunnerThread(context.get())); 416 DCHECK(IsOnTaskRunnerThread(context.get()));
417 base::PlatformFileInfo file_info; 417 base::File::Info file_info;
418 base::FilePath platform_path; 418 base::FilePath platform_path;
419 scoped_refptr<webkit_blob::ShareableFileReference> file_ref; 419 scoped_refptr<webkit_blob::ShareableFileReference> file_ref;
420 base::PlatformFileError error = 420 base::File::Error error =
421 CreateSnapshotFileSync(context.get(), url, &file_info, &platform_path, 421 CreateSnapshotFileSync(context.get(), url, &file_info, &platform_path,
422 &file_ref); 422 &file_ref);
423 content::BrowserThread::PostTask( 423 content::BrowserThread::PostTask(
424 content::BrowserThread::IO, 424 content::BrowserThread::IO,
425 FROM_HERE, 425 FROM_HERE,
426 base::Bind(callback, error, file_info, platform_path, file_ref)); 426 base::Bind(callback, error, file_info, platform_path, file_ref));
427 } 427 }
428 428
429 base::PlatformFileError NativeMediaFileUtil::CreateDirectorySync( 429 base::File::Error NativeMediaFileUtil::CreateDirectorySync(
430 fileapi::FileSystemOperationContext* context, 430 fileapi::FileSystemOperationContext* context,
431 const fileapi::FileSystemURL& url, 431 const fileapi::FileSystemURL& url,
432 bool exclusive, 432 bool exclusive,
433 bool recursive) { 433 bool recursive) {
434 base::FilePath file_path; 434 base::FilePath file_path;
435 base::PlatformFileError error = GetLocalFilePath(context, url, &file_path); 435 base::File::Error error = GetLocalFilePath(context, url, &file_path);
436 if (error != base::PLATFORM_FILE_OK) 436 if (error != base::File::FILE_OK)
437 return error; 437 return error;
438 return fileapi::NativeFileUtil::CreateDirectory(file_path, exclusive, 438 return fileapi::NativeFileUtil::CreateDirectory(file_path, exclusive,
439 recursive); 439 recursive);
440 } 440 }
441 441
442 base::PlatformFileError NativeMediaFileUtil::CopyOrMoveFileSync( 442 base::File::Error NativeMediaFileUtil::CopyOrMoveFileSync(
443 fileapi::FileSystemOperationContext* context, 443 fileapi::FileSystemOperationContext* context,
444 const fileapi::FileSystemURL& src_url, 444 const fileapi::FileSystemURL& src_url,
445 const fileapi::FileSystemURL& dest_url, 445 const fileapi::FileSystemURL& dest_url,
446 CopyOrMoveOption option, 446 CopyOrMoveOption option,
447 bool copy) { 447 bool copy) {
448 DCHECK(IsOnTaskRunnerThread(context)); 448 DCHECK(IsOnTaskRunnerThread(context));
449 base::FilePath src_file_path; 449 base::FilePath src_file_path;
450 base::PlatformFileError error = 450 base::File::Error error =
451 GetFilteredLocalFilePathForExistingFileOrDirectory( 451 GetFilteredLocalFilePathForExistingFileOrDirectory(
452 context, src_url, 452 context, src_url,
453 base::PLATFORM_FILE_ERROR_NOT_FOUND, 453 base::File::FILE_ERROR_NOT_FOUND,
454 &src_file_path); 454 &src_file_path);
455 if (error != base::PLATFORM_FILE_OK) 455 if (error != base::File::FILE_OK)
456 return error; 456 return error;
457 if (fileapi::NativeFileUtil::DirectoryExists(src_file_path)) 457 if (fileapi::NativeFileUtil::DirectoryExists(src_file_path))
458 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; 458 return base::File::FILE_ERROR_NOT_A_FILE;
459 459
460 base::FilePath dest_file_path; 460 base::FilePath dest_file_path;
461 error = GetLocalFilePath(context, dest_url, &dest_file_path); 461 error = GetLocalFilePath(context, dest_url, &dest_file_path);
462 if (error != base::PLATFORM_FILE_OK) 462 if (error != base::File::FILE_OK)
463 return error; 463 return error;
464 base::PlatformFileInfo file_info; 464 base::File::Info file_info;
465 error = fileapi::NativeFileUtil::GetFileInfo(dest_file_path, &file_info); 465 error = fileapi::NativeFileUtil::GetFileInfo(dest_file_path, &file_info);
466 if (error != base::PLATFORM_FILE_OK && 466 if (error != base::File::FILE_OK &&
467 error != base::PLATFORM_FILE_ERROR_NOT_FOUND) 467 error != base::File::FILE_ERROR_NOT_FOUND) {
468 return error; 468 return error;
469 if (error == base::PLATFORM_FILE_OK && file_info.is_directory) 469 }
470 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 470 if (error == base::File::FILE_OK && file_info.is_directory)
471 return base::File::FILE_ERROR_INVALID_OPERATION;
471 if (!media_path_filter_->Match(dest_file_path)) 472 if (!media_path_filter_->Match(dest_file_path))
472 return base::PLATFORM_FILE_ERROR_SECURITY; 473 return base::File::FILE_ERROR_SECURITY;
473 474
474 return fileapi::NativeFileUtil::CopyOrMoveFile( 475 return fileapi::NativeFileUtil::CopyOrMoveFile(
475 src_file_path, dest_file_path, option, 476 src_file_path, dest_file_path, option,
476 fileapi::NativeFileUtil::CopyOrMoveModeForDestination(dest_url, copy)); 477 fileapi::NativeFileUtil::CopyOrMoveModeForDestination(dest_url, copy));
477 } 478 }
478 479
479 base::PlatformFileError NativeMediaFileUtil::CopyInForeignFileSync( 480 base::File::Error NativeMediaFileUtil::CopyInForeignFileSync(
480 fileapi::FileSystemOperationContext* context, 481 fileapi::FileSystemOperationContext* context,
481 const base::FilePath& src_file_path, 482 const base::FilePath& src_file_path,
482 const fileapi::FileSystemURL& dest_url) { 483 const fileapi::FileSystemURL& dest_url) {
483 DCHECK(IsOnTaskRunnerThread(context)); 484 DCHECK(IsOnTaskRunnerThread(context));
484 if (src_file_path.empty()) 485 if (src_file_path.empty())
485 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 486 return base::File::FILE_ERROR_INVALID_OPERATION;
486 487
487 base::FilePath dest_file_path; 488 base::FilePath dest_file_path;
488 base::PlatformFileError error = 489 base::File::Error error =
489 GetFilteredLocalFilePath(context, dest_url, &dest_file_path); 490 GetFilteredLocalFilePath(context, dest_url, &dest_file_path);
490 if (error != base::PLATFORM_FILE_OK) 491 if (error != base::File::FILE_OK)
491 return error; 492 return error;
492 return fileapi::NativeFileUtil::CopyOrMoveFile( 493 return fileapi::NativeFileUtil::CopyOrMoveFile(
493 src_file_path, dest_file_path, 494 src_file_path, dest_file_path,
494 fileapi::FileSystemOperation::OPTION_NONE, 495 fileapi::FileSystemOperation::OPTION_NONE,
495 fileapi::NativeFileUtil::CopyOrMoveModeForDestination(dest_url, 496 fileapi::NativeFileUtil::CopyOrMoveModeForDestination(dest_url,
496 true /* copy */)); 497 true /* copy */));
497 } 498 }
498 499
499 base::PlatformFileError NativeMediaFileUtil::GetFileInfoSync( 500 base::File::Error NativeMediaFileUtil::GetFileInfoSync(
500 fileapi::FileSystemOperationContext* context, 501 fileapi::FileSystemOperationContext* context,
501 const fileapi::FileSystemURL& url, 502 const fileapi::FileSystemURL& url,
502 base::PlatformFileInfo* file_info, 503 base::File::Info* file_info,
503 base::FilePath* platform_path) { 504 base::FilePath* platform_path) {
504 DCHECK(context); 505 DCHECK(context);
505 DCHECK(IsOnTaskRunnerThread(context)); 506 DCHECK(IsOnTaskRunnerThread(context));
506 DCHECK(file_info); 507 DCHECK(file_info);
507 508
508 base::FilePath file_path; 509 base::FilePath file_path;
509 base::PlatformFileError error = GetLocalFilePath(context, url, &file_path); 510 base::File::Error error = GetLocalFilePath(context, url, &file_path);
510 if (error != base::PLATFORM_FILE_OK) 511 if (error != base::File::FILE_OK)
511 return error; 512 return error;
512 if (base::IsLink(file_path)) 513 if (base::IsLink(file_path))
513 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 514 return base::File::FILE_ERROR_NOT_FOUND;
514 error = fileapi::NativeFileUtil::GetFileInfo(file_path, file_info); 515 error = fileapi::NativeFileUtil::GetFileInfo(file_path, file_info);
515 if (error != base::PLATFORM_FILE_OK) 516 if (error != base::File::FILE_OK)
516 return error; 517 return error;
517 518
518 if (platform_path) 519 if (platform_path)
519 *platform_path = file_path; 520 *platform_path = file_path;
520 if (file_info->is_directory || 521 if (file_info->is_directory ||
521 media_path_filter_->Match(file_path)) { 522 media_path_filter_->Match(file_path)) {
522 return base::PLATFORM_FILE_OK; 523 return base::File::FILE_OK;
523 } 524 }
524 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 525 return base::File::FILE_ERROR_NOT_FOUND;
525 } 526 }
526 527
527 base::PlatformFileError NativeMediaFileUtil::GetLocalFilePath( 528 base::File::Error NativeMediaFileUtil::GetLocalFilePath(
528 fileapi::FileSystemOperationContext* context, 529 fileapi::FileSystemOperationContext* context,
529 const fileapi::FileSystemURL& url, 530 const fileapi::FileSystemURL& url,
530 base::FilePath* local_file_path) { 531 base::FilePath* local_file_path) {
531 DCHECK(local_file_path); 532 DCHECK(local_file_path);
532 DCHECK(url.is_valid()); 533 DCHECK(url.is_valid());
533 if (url.path().empty()) { 534 if (url.path().empty()) {
534 // Root direcory case, which should not be accessed. 535 // Root direcory case, which should not be accessed.
535 return base::PLATFORM_FILE_ERROR_ACCESS_DENIED; 536 return base::File::FILE_ERROR_ACCESS_DENIED;
536 } 537 }
537 *local_file_path = url.path(); 538 *local_file_path = url.path();
538 return base::PLATFORM_FILE_OK; 539 return base::File::FILE_OK;
539 } 540 }
540 541
541 base::PlatformFileError NativeMediaFileUtil::ReadDirectorySync( 542 base::File::Error NativeMediaFileUtil::ReadDirectorySync(
542 fileapi::FileSystemOperationContext* context, 543 fileapi::FileSystemOperationContext* context,
543 const fileapi::FileSystemURL& url, 544 const fileapi::FileSystemURL& url,
544 EntryList* file_list) { 545 EntryList* file_list) {
545 DCHECK(IsOnTaskRunnerThread(context)); 546 DCHECK(IsOnTaskRunnerThread(context));
546 DCHECK(file_list); 547 DCHECK(file_list);
547 DCHECK(file_list->empty()); 548 DCHECK(file_list->empty());
548 base::PlatformFileInfo file_info; 549 base::File::Info file_info;
549 base::FilePath dir_path; 550 base::FilePath dir_path;
550 base::PlatformFileError error = 551 base::File::Error error =
551 GetFileInfoSync(context, url, &file_info, &dir_path); 552 GetFileInfoSync(context, url, &file_info, &dir_path);
552 553
553 if (error != base::PLATFORM_FILE_OK) 554 if (error != base::File::FILE_OK)
554 return error; 555 return error;
555 556
556 if (!file_info.is_directory) 557 if (!file_info.is_directory)
557 return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; 558 return base::File::FILE_ERROR_NOT_A_DIRECTORY;
558 559
559 base::FileEnumerator file_enum( 560 base::FileEnumerator file_enum(
560 dir_path, 561 dir_path,
561 false /* recursive */, 562 false /* recursive */,
562 base::FileEnumerator::FILES | base::FileEnumerator::DIRECTORIES); 563 base::FileEnumerator::FILES | base::FileEnumerator::DIRECTORIES);
563 for (base::FilePath enum_path = file_enum.Next(); 564 for (base::FilePath enum_path = file_enum.Next();
564 !enum_path.empty(); 565 !enum_path.empty();
565 enum_path = file_enum.Next()) { 566 enum_path = file_enum.Next()) {
566 // Skip symlinks. 567 // Skip symlinks.
567 if (base::IsLink(enum_path)) 568 if (base::IsLink(enum_path))
568 continue; 569 continue;
569 570
570 base::FileEnumerator::FileInfo info = file_enum.GetInfo(); 571 base::FileEnumerator::FileInfo info = file_enum.GetInfo();
571 572
572 // NativeMediaFileUtil skip criteria. 573 // NativeMediaFileUtil skip criteria.
573 if (ShouldSkip(enum_path)) 574 if (ShouldSkip(enum_path))
574 continue; 575 continue;
575 if (!info.IsDirectory() && !media_path_filter_->Match(enum_path)) 576 if (!info.IsDirectory() && !media_path_filter_->Match(enum_path))
576 continue; 577 continue;
577 578
578 fileapi::DirectoryEntry entry; 579 fileapi::DirectoryEntry entry;
579 entry.is_directory = info.IsDirectory(); 580 entry.is_directory = info.IsDirectory();
580 entry.name = enum_path.BaseName().value(); 581 entry.name = enum_path.BaseName().value();
581 entry.size = info.GetSize(); 582 entry.size = info.GetSize();
582 entry.last_modified_time = info.GetLastModifiedTime(); 583 entry.last_modified_time = info.GetLastModifiedTime();
583 584
584 file_list->push_back(entry); 585 file_list->push_back(entry);
585 } 586 }
586 587
587 return base::PLATFORM_FILE_OK; 588 return base::File::FILE_OK;
588 } 589 }
589 590
590 base::PlatformFileError NativeMediaFileUtil::DeleteFileSync( 591 base::File::Error NativeMediaFileUtil::DeleteFileSync(
591 fileapi::FileSystemOperationContext* context, 592 fileapi::FileSystemOperationContext* context,
592 const fileapi::FileSystemURL& url) { 593 const fileapi::FileSystemURL& url) {
593 DCHECK(IsOnTaskRunnerThread(context)); 594 DCHECK(IsOnTaskRunnerThread(context));
594 base::PlatformFileInfo file_info; 595 base::File::Info file_info;
595 base::FilePath file_path; 596 base::FilePath file_path;
596 base::PlatformFileError error = 597 base::File::Error error =
597 GetFileInfoSync(context, url, &file_info, &file_path); 598 GetFileInfoSync(context, url, &file_info, &file_path);
598 if (error != base::PLATFORM_FILE_OK) 599 if (error != base::File::FILE_OK)
599 return error; 600 return error;
600 if (file_info.is_directory) 601 if (file_info.is_directory)
601 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; 602 return base::File::FILE_ERROR_NOT_A_FILE;
602 return fileapi::NativeFileUtil::DeleteFile(file_path); 603 return fileapi::NativeFileUtil::DeleteFile(file_path);
603 } 604 }
604 605
605 base::PlatformFileError NativeMediaFileUtil::DeleteDirectorySync( 606 base::File::Error NativeMediaFileUtil::DeleteDirectorySync(
606 fileapi::FileSystemOperationContext* context, 607 fileapi::FileSystemOperationContext* context,
607 const fileapi::FileSystemURL& url) { 608 const fileapi::FileSystemURL& url) {
608 DCHECK(IsOnTaskRunnerThread(context)); 609 DCHECK(IsOnTaskRunnerThread(context));
609 base::FilePath file_path; 610 base::FilePath file_path;
610 base::PlatformFileError error = GetLocalFilePath(context, url, &file_path); 611 base::File::Error error = GetLocalFilePath(context, url, &file_path);
611 if (error != base::PLATFORM_FILE_OK) 612 if (error != base::File::FILE_OK)
612 return error; 613 return error;
613 return fileapi::NativeFileUtil::DeleteDirectory(file_path); 614 return fileapi::NativeFileUtil::DeleteDirectory(file_path);
614 } 615 }
615 616
616 base::PlatformFileError NativeMediaFileUtil::CreateSnapshotFileSync( 617 base::File::Error NativeMediaFileUtil::CreateSnapshotFileSync(
617 fileapi::FileSystemOperationContext* context, 618 fileapi::FileSystemOperationContext* context,
618 const fileapi::FileSystemURL& url, 619 const fileapi::FileSystemURL& url,
619 base::PlatformFileInfo* file_info, 620 base::File::Info* file_info,
620 base::FilePath* platform_path, 621 base::FilePath* platform_path,
621 scoped_refptr<webkit_blob::ShareableFileReference>* file_ref) { 622 scoped_refptr<webkit_blob::ShareableFileReference>* file_ref) {
622 DCHECK(IsOnTaskRunnerThread(context)); 623 DCHECK(IsOnTaskRunnerThread(context));
623 base::PlatformFileError error = 624 base::File::Error error =
624 GetFileInfoSync(context, url, file_info, platform_path); 625 GetFileInfoSync(context, url, file_info, platform_path);
625 if (error == base::PLATFORM_FILE_OK && file_info->is_directory) 626 if (error == base::File::FILE_OK && file_info->is_directory)
626 error = base::PLATFORM_FILE_ERROR_NOT_A_FILE; 627 error = base::File::FILE_ERROR_NOT_A_FILE;
627 if (error == base::PLATFORM_FILE_OK) 628 if (error == base::File::FILE_OK)
628 error = NativeMediaFileUtil::IsMediaFile(*platform_path); 629 error = NativeMediaFileUtil::IsMediaFile(*platform_path);
629 630
630 // We're just returning the local file information. 631 // We're just returning the local file information.
631 *file_ref = scoped_refptr<webkit_blob::ShareableFileReference>(); 632 *file_ref = scoped_refptr<webkit_blob::ShareableFileReference>();
632 633
633 return error; 634 return error;
634 } 635 }
635 636
636 base::PlatformFileError NativeMediaFileUtil::GetFilteredLocalFilePath( 637 base::File::Error NativeMediaFileUtil::GetFilteredLocalFilePath(
637 fileapi::FileSystemOperationContext* context, 638 fileapi::FileSystemOperationContext* context,
638 const fileapi::FileSystemURL& file_system_url, 639 const fileapi::FileSystemURL& file_system_url,
639 base::FilePath* local_file_path) { 640 base::FilePath* local_file_path) {
640 DCHECK(IsOnTaskRunnerThread(context)); 641 DCHECK(IsOnTaskRunnerThread(context));
641 base::FilePath file_path; 642 base::FilePath file_path;
642 base::PlatformFileError error = 643 base::File::Error error =
643 GetLocalFilePath(context, file_system_url, &file_path); 644 GetLocalFilePath(context, file_system_url, &file_path);
644 if (error != base::PLATFORM_FILE_OK) 645 if (error != base::File::FILE_OK)
645 return error; 646 return error;
646 if (!media_path_filter_->Match(file_path)) 647 if (!media_path_filter_->Match(file_path))
647 return base::PLATFORM_FILE_ERROR_SECURITY; 648 return base::File::FILE_ERROR_SECURITY;
648 649
649 *local_file_path = file_path; 650 *local_file_path = file_path;
650 return base::PLATFORM_FILE_OK; 651 return base::File::FILE_OK;
651 } 652 }
652 653
653 base::PlatformFileError 654 base::File::Error
654 NativeMediaFileUtil::GetFilteredLocalFilePathForExistingFileOrDirectory( 655 NativeMediaFileUtil::GetFilteredLocalFilePathForExistingFileOrDirectory(
655 fileapi::FileSystemOperationContext* context, 656 fileapi::FileSystemOperationContext* context,
656 const fileapi::FileSystemURL& file_system_url, 657 const fileapi::FileSystemURL& file_system_url,
657 base::PlatformFileError failure_error, 658 base::File::Error failure_error,
658 base::FilePath* local_file_path) { 659 base::FilePath* local_file_path) {
659 DCHECK(IsOnTaskRunnerThread(context)); 660 DCHECK(IsOnTaskRunnerThread(context));
660 base::FilePath file_path; 661 base::FilePath file_path;
661 base::PlatformFileError error = 662 base::File::Error error =
662 GetLocalFilePath(context, file_system_url, &file_path); 663 GetLocalFilePath(context, file_system_url, &file_path);
663 if (error != base::PLATFORM_FILE_OK) 664 if (error != base::File::FILE_OK)
664 return error; 665 return error;
665 666
666 if (!base::PathExists(file_path)) 667 if (!base::PathExists(file_path))
667 return failure_error; 668 return failure_error;
668 base::File::Info file_info; 669 base::File::Info file_info;
669 if (!base::GetFileInfo(file_path, &file_info)) 670 if (!base::GetFileInfo(file_path, &file_info))
670 return base::PLATFORM_FILE_ERROR_FAILED; 671 return base::File::FILE_ERROR_FAILED;
671 672
672 if (!file_info.is_directory && 673 if (!file_info.is_directory &&
673 !media_path_filter_->Match(file_path)) { 674 !media_path_filter_->Match(file_path)) {
674 return failure_error; 675 return failure_error;
675 } 676 }
676 677
677 *local_file_path = file_path; 678 *local_file_path = file_path;
678 return base::PLATFORM_FILE_OK; 679 return base::File::FILE_OK;
679 } 680 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698