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

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

Issue 982283002: Implement DeleteFile and DeleteDirectory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 5 years, 9 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/device_media_async_file_util.h" 5 #include "chrome/browser/media_galleries/fileapi/device_media_async_file_util.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/task_runner_util.h" 10 #include "base/task_runner_util.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 callback.Run(error, AsyncFileUtil::EntryList(), false /*no more*/); 79 callback.Run(error, AsyncFileUtil::EntryList(), false /*no more*/);
80 } 80 }
81 81
82 // Called when CopyInForeignFile method call failed. 82 // Called when CopyInForeignFile method call failed.
83 void OnCopyInForeignFileError(const AsyncFileUtil::StatusCallback& callback, 83 void OnCopyInForeignFileError(const AsyncFileUtil::StatusCallback& callback,
84 base::File::Error error) { 84 base::File::Error error) {
85 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 85 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
86 callback.Run(error); 86 callback.Run(error);
87 } 87 }
88 88
89 // Called when DeleteFile method call failed.
90 void OnDeleteFileError(const AsyncFileUtil::StatusCallback& callback,
91 base::File::Error error) {
92 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
93 callback.Run(error);
94 }
95
96 // Called when DeleteDirectory method call failed.
97 void OnDeleteDirectoryError(const AsyncFileUtil::StatusCallback& callback,
98 base::File::Error error) {
99 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
100 callback.Run(error);
101 }
102
89 // Called on a blocking pool thread to create a snapshot file to hold the 103 // Called on a blocking pool thread to create a snapshot file to hold the
90 // contents of |device_file_path|. The snapshot file is created in the 104 // contents of |device_file_path|. The snapshot file is created in the
91 // "profile_path/kDeviceMediaAsyncFileUtilTempDir" directory. Return the 105 // "profile_path/kDeviceMediaAsyncFileUtilTempDir" directory. Return the
92 // snapshot file path or an empty path on failure. 106 // snapshot file path or an empty path on failure.
93 base::FilePath CreateSnapshotFileOnBlockingPool( 107 base::FilePath CreateSnapshotFileOnBlockingPool(
94 const base::FilePath& device_file_path, 108 const base::FilePath& device_file_path,
95 const base::FilePath& profile_path) { 109 const base::FilePath& profile_path) {
96 base::FilePath snapshot_file_path; 110 base::FilePath snapshot_file_path;
97 base::FilePath media_file_system_dir_path = 111 base::FilePath media_file_system_dir_path =
98 profile_path.AppendASCII(kDeviceMediaAsyncFileUtilTempDir); 112 profile_path.AppendASCII(kDeviceMediaAsyncFileUtilTempDir);
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCopyInForeignFile, 427 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCopyInForeignFile,
414 weak_ptr_factory_.GetWeakPtr(), callback), 428 weak_ptr_factory_.GetWeakPtr(), callback),
415 base::Bind(&OnCopyInForeignFileError, callback)); 429 base::Bind(&OnCopyInForeignFileError, callback));
416 } 430 }
417 431
418 void DeviceMediaAsyncFileUtil::DeleteFile( 432 void DeviceMediaAsyncFileUtil::DeleteFile(
419 scoped_ptr<FileSystemOperationContext> context, 433 scoped_ptr<FileSystemOperationContext> context,
420 const FileSystemURL& url, 434 const FileSystemURL& url,
421 const StatusCallback& callback) { 435 const StatusCallback& callback) {
422 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 436 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
423 NOTIMPLEMENTED(); 437
424 callback.Run(base::File::FILE_ERROR_SECURITY); 438 MTPDeviceAsyncDelegate* const delegate = GetMTPDeviceDelegate(url);
439 if (!delegate) {
440 OnDeleteFileError(callback, base::File::FILE_ERROR_NOT_FOUND);
441 return;
442 }
443 if (delegate->IsReadOnly()) {
444 OnDeleteFileError(callback, base::File::FILE_ERROR_SECURITY);
445 return;
446 }
447
448 delegate->DeleteFile(url.path(),
449 base::Bind(&DeviceMediaAsyncFileUtil::OnDidDeleteFile,
450 weak_ptr_factory_.GetWeakPtr(), callback),
451 base::Bind(&OnDeleteFileError, callback));
425 } 452 }
426 453
427 void DeviceMediaAsyncFileUtil::DeleteDirectory( 454 void DeviceMediaAsyncFileUtil::DeleteDirectory(
428 scoped_ptr<FileSystemOperationContext> context, 455 scoped_ptr<FileSystemOperationContext> context,
429 const FileSystemURL& url, 456 const FileSystemURL& url,
430 const StatusCallback& callback) { 457 const StatusCallback& callback) {
431 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 458 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
432 NOTIMPLEMENTED(); 459
433 callback.Run(base::File::FILE_ERROR_SECURITY); 460 MTPDeviceAsyncDelegate* const delegate = GetMTPDeviceDelegate(url);
461 if (!delegate) {
462 OnDeleteDirectoryError(callback, base::File::FILE_ERROR_NOT_FOUND);
463 return;
464 }
465 if (delegate->IsReadOnly()) {
466 OnDeleteDirectoryError(callback, base::File::FILE_ERROR_SECURITY);
467 return;
468 }
469
470 delegate->DeleteDirectory(
471 url.path(), base::Bind(&DeviceMediaAsyncFileUtil::OnDidDeleteDirectory,
472 weak_ptr_factory_.GetWeakPtr(), callback),
473 base::Bind(&OnDeleteDirectoryError, callback));
434 } 474 }
435 475
436 void DeviceMediaAsyncFileUtil::DeleteRecursively( 476 void DeviceMediaAsyncFileUtil::DeleteRecursively(
437 scoped_ptr<FileSystemOperationContext> context, 477 scoped_ptr<FileSystemOperationContext> context,
438 const FileSystemURL& url, 478 const FileSystemURL& url,
439 const StatusCallback& callback) { 479 const StatusCallback& callback) {
440 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 480 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
441 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); 481 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION);
442 } 482 }
443 483
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 base::Bind(&OnDidCheckMediaForReadDirectory, callback, has_more)); 573 base::Bind(&OnDidCheckMediaForReadDirectory, callback, has_more));
534 } 574 }
535 575
536 void DeviceMediaAsyncFileUtil::OnDidCopyInForeignFile( 576 void DeviceMediaAsyncFileUtil::OnDidCopyInForeignFile(
537 const StatusCallback& callback) { 577 const StatusCallback& callback) {
538 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 578 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
539 579
540 callback.Run(base::File::FILE_OK); 580 callback.Run(base::File::FILE_OK);
541 } 581 }
542 582
583 void DeviceMediaAsyncFileUtil::OnDidDeleteFile(const StatusCallback& callback) {
584 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
585
586 callback.Run(base::File::FILE_OK);
587 }
588
589 void DeviceMediaAsyncFileUtil::OnDidDeleteDirectory(
590 const StatusCallback& callback) {
591 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
592
593 callback.Run(base::File::FILE_OK);
594 }
595
543 bool DeviceMediaAsyncFileUtil::validate_media_files() const { 596 bool DeviceMediaAsyncFileUtil::validate_media_files() const {
544 return media_path_filter_wrapper_.get() != NULL; 597 return media_path_filter_wrapper_.get() != NULL;
545 } 598 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698