summaryrefslogtreecommitdiffstats
path: root/storage
diff options
context:
space:
mode:
authoryawano <yawano@chromium.org>2015-06-24 00:22:19 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-24 07:23:13 +0000
commit77af6f93cbd761e70e254d6b353403266aeaa8bd (patch)
treee64f5b2beda81705c02c35a78a817c48ae3f5770 /storage
parent72d02e96a5bab47c3d9f3e8738dd2c1647abf872 (diff)
downloadchromium_src-77af6f93cbd761e70e254d6b353403266aeaa8bd.zip
chromium_src-77af6f93cbd761e70e254d6b353403266aeaa8bd.tar.gz
chromium_src-77af6f93cbd761e70e254d6b353403266aeaa8bd.tar.bz2
Add fileManagerPrivate.onCopyError event.
onCopyError event is dispatched when an error had happened during the operation. The error is reported for each individual copy operation. e.g. If you have /a/b/c and try to copy /a to /d, an error of copy file operation from /a/b/c to /d/b/c can be reported. BUG=499642,491046,498087 TEST=none Review URL: https://codereview.chromium.org/1194783002 Cr-Commit-Position: refs/heads/master@{#335883}
Diffstat (limited to 'storage')
-rw-r--r--storage/browser/fileapi/copy_or_move_operation_delegate.cc13
-rw-r--r--storage/browser/fileapi/copy_or_move_operation_delegate.h18
-rw-r--r--storage/browser/fileapi/file_system_operation.h17
-rw-r--r--storage/browser/fileapi/file_system_operation_impl.cc32
-rw-r--r--storage/browser/fileapi/file_system_operation_impl.h1
-rw-r--r--storage/browser/fileapi/file_system_operation_runner.cc16
-rw-r--r--storage/browser/fileapi/file_system_operation_runner.h2
-rw-r--r--storage/browser/fileapi/recursive_operation_delegate.cc31
-rw-r--r--storage/browser/fileapi/recursive_operation_delegate.h22
-rw-r--r--storage/browser/fileapi/remove_operation_delegate.cc3
10 files changed, 72 insertions, 83 deletions
diff --git a/storage/browser/fileapi/copy_or_move_operation_delegate.cc b/storage/browser/fileapi/copy_or_move_operation_delegate.cc
index 1cb92f5..cf4692b 100644
--- a/storage/browser/fileapi/copy_or_move_operation_delegate.cc
+++ b/storage/browser/fileapi/copy_or_move_operation_delegate.cc
@@ -730,6 +730,7 @@ CopyOrMoveOperationDelegate::CopyOrMoveOperationDelegate(
const FileSystemURL& dest_root,
OperationType operation_type,
CopyOrMoveOption option,
+ ErrorBehavior error_behavior,
const CopyProgressCallback& progress_callback,
const StatusCallback& callback)
: RecursiveOperationDelegate(file_system_context),
@@ -737,6 +738,7 @@ CopyOrMoveOperationDelegate::CopyOrMoveOperationDelegate(
dest_root_(dest_root),
operation_type_(operation_type),
option_(option),
+ error_behavior_(error_behavior),
progress_callback_(progress_callback),
callback_(callback),
weak_factory_(this) {
@@ -773,7 +775,7 @@ void CopyOrMoveOperationDelegate::RunRecursively() {
// TODO(kinuko): This could be too expensive for same_file_system_==true
// and operation==MOVE case, probably we can just rename the root directory.
// http://crbug.com/172187
- StartRecursiveOperation(src_root_, callback_);
+ StartRecursiveOperation(src_root_, error_behavior_, callback_);
}
void CopyOrMoveOperationDelegate::ProcessFile(
@@ -802,6 +804,10 @@ void CopyOrMoveOperationDelegate::ProcessFile(
file_system_context()->GetCopyOrMoveFileValidatorFactory(
dest_root_.type(), &error);
if (error != base::File::FILE_OK) {
+ if (!progress_callback_.is_null())
+ progress_callback_.Run(FileSystemOperation::ERROR_COPY_ENTRY, src_url,
+ dest_url, 0);
+
callback.Run(error);
return;
}
@@ -900,6 +906,11 @@ void CopyOrMoveOperationDelegate::DidCopyOrMoveFile(
running_copy_set_.erase(impl);
delete impl;
+ if (!progress_callback_.is_null() && error != base::File::FILE_OK &&
+ error != base::File::FILE_ERROR_NOT_A_FILE)
+ progress_callback_.Run(FileSystemOperation::ERROR_COPY_ENTRY, src_url,
+ dest_url, 0);
+
if (!progress_callback_.is_null() && error == base::File::FILE_OK) {
progress_callback_.Run(
FileSystemOperation::END_COPY_ENTRY, src_url, dest_url, 0);
diff --git a/storage/browser/fileapi/copy_or_move_operation_delegate.h b/storage/browser/fileapi/copy_or_move_operation_delegate.h
index e6785e9..e86c0ab 100644
--- a/storage/browser/fileapi/copy_or_move_operation_delegate.h
+++ b/storage/browser/fileapi/copy_or_move_operation_delegate.h
@@ -36,6 +36,7 @@ class CopyOrMoveOperationDelegate
class CopyOrMoveImpl;
typedef FileSystemOperation::CopyProgressCallback CopyProgressCallback;
typedef FileSystemOperation::CopyOrMoveOption CopyOrMoveOption;
+ typedef FileSystemOperation::ErrorBehavior ErrorBehavior;
enum OperationType {
OPERATION_COPY,
@@ -91,14 +92,14 @@ class CopyOrMoveOperationDelegate
DISALLOW_COPY_AND_ASSIGN(StreamCopyHelper);
};
- CopyOrMoveOperationDelegate(
- FileSystemContext* file_system_context,
- const FileSystemURL& src_root,
- const FileSystemURL& dest_root,
- OperationType operation_type,
- CopyOrMoveOption option,
- const CopyProgressCallback& progress_callback,
- const StatusCallback& callback);
+ CopyOrMoveOperationDelegate(FileSystemContext* file_system_context,
+ const FileSystemURL& src_root,
+ const FileSystemURL& dest_root,
+ OperationType operation_type,
+ CopyOrMoveOption option,
+ ErrorBehavior error_behavior,
+ const CopyProgressCallback& progress_callback,
+ const StatusCallback& callback);
~CopyOrMoveOperationDelegate() override;
// RecursiveOperationDelegate overrides:
@@ -148,6 +149,7 @@ class CopyOrMoveOperationDelegate
bool same_file_system_;
OperationType operation_type_;
CopyOrMoveOption option_;
+ ErrorBehavior error_behavior_;
CopyProgressCallback progress_callback_;
StatusCallback callback_;
diff --git a/storage/browser/fileapi/file_system_operation.h b/storage/browser/fileapi/file_system_operation.h
index bc5bc87..b9e6f95 100644
--- a/storage/browser/fileapi/file_system_operation.h
+++ b/storage/browser/fileapi/file_system_operation.h
@@ -68,12 +68,6 @@ class FileSystemOperation {
// Used for CreateFile(), etc. |result| is the return code of the operation.
typedef base::Callback<void(base::File::Error result)> StatusCallback;
- // Called when an error had happened during operation.
- // |url| is the url of processed entry.
- // |error| is the error code of the failed operation.
- typedef base::Callback<void(const FileSystemURL& url,
- base::File::Error error)> ErrorCallback;
-
// Used for GetMetadata(). |result| is the return code of the operation,
// |file_info| is the obtained file info.
typedef base::Callback<
@@ -126,6 +120,13 @@ class FileSystemOperation {
const scoped_refptr<storage::ShareableFileReference>& file_ref)>
SnapshotFileCallback;
+ // Used to specify how recursive operation delegate behaves for errors.
+ // With ERROR_BEHAVIOR_ABORT, it stops following operation when it fails an
+ // operation.
+ // With ERROR_BEHAVIOR_SKIP, it continues following operation even when it
+ // fails some of the operations.
+ enum ErrorBehavior { ERROR_BEHAVIOR_ABORT, ERROR_BEHAVIOR_SKIP };
+
// Used for progress update callback for Copy().
//
// BEGIN_COPY_ENTRY is fired for each copy creation beginning (for both
@@ -199,6 +200,7 @@ class FileSystemOperation {
BEGIN_COPY_ENTRY,
END_COPY_ENTRY,
PROGRESS,
+ ERROR_COPY_ENTRY
};
typedef base::Callback<void(CopyProgressType type,
const FileSystemURL& source_url,
@@ -251,6 +253,8 @@ class FileSystemOperation {
// |dest_path| as needed.
// |option| specifies the minor behavior of Copy(). See CopyOrMoveOption's
// comment for details.
+ // |error_behavior| specifies whether this continues operation after it
+ // failed an operation or not.
// |progress_callback| is periodically called to report the progress
// update. See also the comment of CopyProgressCallback. This callback is
// optional.
@@ -266,6 +270,7 @@ class FileSystemOperation {
virtual void Copy(const FileSystemURL& src_path,
const FileSystemURL& dest_path,
CopyOrMoveOption option,
+ ErrorBehavior error_behavior,
const CopyProgressCallback& progress_callback,
const StatusCallback& callback) = 0;
diff --git a/storage/browser/fileapi/file_system_operation_impl.cc b/storage/browser/fileapi/file_system_operation_impl.cc
index bf25967..30d8561 100644
--- a/storage/browser/fileapi/file_system_operation_impl.cc
+++ b/storage/browser/fileapi/file_system_operation_impl.cc
@@ -88,21 +88,18 @@ void FileSystemOperationImpl::Copy(
const FileSystemURL& src_url,
const FileSystemURL& dest_url,
CopyOrMoveOption option,
+ ErrorBehavior error_behavior,
const CopyProgressCallback& progress_callback,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationCopy));
DCHECK(!recursive_operation_delegate_);
- // TODO(hidehiko): Support |progress_callback|. (crbug.com/278038).
- recursive_operation_delegate_.reset(
- new CopyOrMoveOperationDelegate(
- file_system_context(),
- src_url, dest_url,
- CopyOrMoveOperationDelegate::OPERATION_COPY,
- option,
- progress_callback,
- base::Bind(&FileSystemOperationImpl::DidFinishOperation,
- weak_factory_.GetWeakPtr(), callback)));
+ recursive_operation_delegate_.reset(new CopyOrMoveOperationDelegate(
+ file_system_context(), src_url, dest_url,
+ CopyOrMoveOperationDelegate::OPERATION_COPY, option, error_behavior,
+ progress_callback,
+ base::Bind(&FileSystemOperationImpl::DidFinishOperation,
+ weak_factory_.GetWeakPtr(), callback)));
recursive_operation_delegate_->RunRecursively();
}
@@ -112,15 +109,12 @@ void FileSystemOperationImpl::Move(const FileSystemURL& src_url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationMove));
DCHECK(!recursive_operation_delegate_);
- recursive_operation_delegate_.reset(
- new CopyOrMoveOperationDelegate(
- file_system_context(),
- src_url, dest_url,
- CopyOrMoveOperationDelegate::OPERATION_MOVE,
- option,
- FileSystemOperation::CopyProgressCallback(),
- base::Bind(&FileSystemOperationImpl::DidFinishOperation,
- weak_factory_.GetWeakPtr(), callback)));
+ recursive_operation_delegate_.reset(new CopyOrMoveOperationDelegate(
+ file_system_context(), src_url, dest_url,
+ CopyOrMoveOperationDelegate::OPERATION_MOVE, option, ERROR_BEHAVIOR_ABORT,
+ FileSystemOperation::CopyProgressCallback(),
+ base::Bind(&FileSystemOperationImpl::DidFinishOperation,
+ weak_factory_.GetWeakPtr(), callback)));
recursive_operation_delegate_->RunRecursively();
}
diff --git a/storage/browser/fileapi/file_system_operation_impl.h b/storage/browser/fileapi/file_system_operation_impl.h
index dbf6e3a..6f4b662 100644
--- a/storage/browser/fileapi/file_system_operation_impl.h
+++ b/storage/browser/fileapi/file_system_operation_impl.h
@@ -41,6 +41,7 @@ class STORAGE_EXPORT FileSystemOperationImpl
void Copy(const FileSystemURL& src_url,
const FileSystemURL& dest_url,
CopyOrMoveOption option,
+ ErrorBehavior error_behavior,
const CopyProgressCallback& progress_callback,
const StatusCallback& callback) override;
void Move(const FileSystemURL& src_url,
diff --git a/storage/browser/fileapi/file_system_operation_runner.cc b/storage/browser/fileapi/file_system_operation_runner.cc
index 8dc39e6..1648055 100644
--- a/storage/browser/fileapi/file_system_operation_runner.cc
+++ b/storage/browser/fileapi/file_system_operation_runner.cc
@@ -86,6 +86,7 @@ OperationID FileSystemOperationRunner::Copy(
const FileSystemURL& src_url,
const FileSystemURL& dest_url,
CopyOrMoveOption option,
+ ErrorBehavior error_behavior,
const CopyProgressCallback& progress_callback,
const StatusCallback& callback) {
base::File::Error error = base::File::FILE_OK;
@@ -99,14 +100,13 @@ OperationID FileSystemOperationRunner::Copy(
}
PrepareForWrite(handle.id, dest_url);
PrepareForRead(handle.id, src_url);
- operation->Copy(
- src_url, dest_url, option,
- progress_callback.is_null() ?
- CopyProgressCallback() :
- base::Bind(&FileSystemOperationRunner::OnCopyProgress, AsWeakPtr(),
- handle, progress_callback),
- base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
- handle, callback));
+ operation->Copy(src_url, dest_url, option, error_behavior,
+ progress_callback.is_null()
+ ? CopyProgressCallback()
+ : base::Bind(&FileSystemOperationRunner::OnCopyProgress,
+ AsWeakPtr(), handle, progress_callback),
+ base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
+ handle, callback));
return handle.id;
}
diff --git a/storage/browser/fileapi/file_system_operation_runner.h b/storage/browser/fileapi/file_system_operation_runner.h
index deca413..0493e4c 100644
--- a/storage/browser/fileapi/file_system_operation_runner.h
+++ b/storage/browser/fileapi/file_system_operation_runner.h
@@ -43,6 +43,7 @@ class STORAGE_EXPORT FileSystemOperationRunner
typedef FileSystemOperation::StatusCallback StatusCallback;
typedef FileSystemOperation::WriteCallback WriteCallback;
typedef FileSystemOperation::OpenFileCallback OpenFileCallback;
+ typedef FileSystemOperation::ErrorBehavior ErrorBehavior;
typedef FileSystemOperation::CopyProgressCallback CopyProgressCallback;
typedef FileSystemOperation::CopyFileProgressCallback
CopyFileProgressCallback;
@@ -75,6 +76,7 @@ class STORAGE_EXPORT FileSystemOperationRunner
OperationID Copy(const FileSystemURL& src_url,
const FileSystemURL& dest_url,
CopyOrMoveOption option,
+ ErrorBehavior error_behavior,
const CopyProgressCallback& progress_callback,
const StatusCallback& callback);
diff --git a/storage/browser/fileapi/recursive_operation_delegate.cc b/storage/browser/fileapi/recursive_operation_delegate.cc
index a3cb1a86..10a4970 100644
--- a/storage/browser/fileapi/recursive_operation_delegate.cc
+++ b/storage/browser/fileapi/recursive_operation_delegate.cc
@@ -22,7 +22,7 @@ RecursiveOperationDelegate::RecursiveOperationDelegate(
: file_system_context_(file_system_context),
inflight_operations_(0),
canceled_(false),
- ignore_error_(false),
+ error_behavior_(FileSystemOperation::ERROR_BEHAVIOR_ABORT),
failed_some_operations_(false) {
}
@@ -36,31 +36,18 @@ void RecursiveOperationDelegate::Cancel() {
void RecursiveOperationDelegate::StartRecursiveOperation(
const FileSystemURL& root,
+ ErrorBehavior error_behavior,
const StatusCallback& callback) {
DCHECK(pending_directory_stack_.empty());
DCHECK(pending_files_.empty());
DCHECK_EQ(0, inflight_operations_);
+ error_behavior_ = error_behavior;
callback_ = callback;
TryProcessFile(root);
}
-void RecursiveOperationDelegate::StartRecursiveOperationWithIgnoringError(
- const FileSystemURL& root,
- const ErrorCallback& error_callback,
- const StatusCallback& status_callback) {
- DCHECK(pending_directory_stack_.empty());
- DCHECK(pending_files_.empty());
- DCHECK_EQ(0, inflight_operations_);
-
- error_callback_ = error_callback;
- callback_ = status_callback;
- ignore_error_ = true;
-
- TryProcessFile(root);
-}
-
void RecursiveOperationDelegate::TryProcessFile(const FileSystemURL& root) {
++inflight_operations_;
ProcessFile(root, base::Bind(&RecursiveOperationDelegate::DidTryProcessFile,
@@ -192,18 +179,15 @@ void RecursiveOperationDelegate::DidProcessFile(const FileSystemURL& url,
--inflight_operations_;
if (error != base::File::FILE_OK) {
- if (!ignore_error_) {
+ if (error_behavior_ == FileSystemOperation::ERROR_BEHAVIOR_ABORT) {
// If an error occurs, invoke Done immediately (even if there remain
// running operations). It is because in the callback, this instance is
// deleted.
Done(error);
return;
- } else {
- failed_some_operations_ = true;
-
- if (!error_callback_.is_null())
- error_callback_.Run(url, error);
}
+
+ failed_some_operations_ = true;
}
ProcessPendingFiles();
@@ -262,7 +246,8 @@ void RecursiveOperationDelegate::Done(base::File::Error error) {
if (canceled_ && error == base::File::FILE_OK) {
callback_.Run(base::File::FILE_ERROR_ABORT);
} else {
- if (ignore_error_ && failed_some_operations_)
+ if (error_behavior_ == FileSystemOperation::ERROR_BEHAVIOR_SKIP &&
+ failed_some_operations_)
callback_.Run(base::File::FILE_ERROR_FAILED);
else
callback_.Run(error);
diff --git a/storage/browser/fileapi/recursive_operation_delegate.h b/storage/browser/fileapi/recursive_operation_delegate.h
index d120c33..2ea09c3 100644
--- a/storage/browser/fileapi/recursive_operation_delegate.h
+++ b/storage/browser/fileapi/recursive_operation_delegate.h
@@ -28,8 +28,8 @@ class STORAGE_EXPORT RecursiveOperationDelegate
: public base::SupportsWeakPtr<RecursiveOperationDelegate> {
public:
typedef FileSystemOperation::StatusCallback StatusCallback;
- typedef FileSystemOperation::ErrorCallback ErrorCallback;
typedef FileSystemOperation::FileEntryList FileEntryList;
+ typedef FileSystemOperation::ErrorBehavior ErrorBehavior;
virtual ~RecursiveOperationDelegate();
@@ -104,25 +104,14 @@ class STORAGE_EXPORT RecursiveOperationDelegate
// PostProcessDirectory(b2_dir)
// PostProcessDirectory(a_dir)
//
+ // |error_behavior| is to specify how this behaves when an operation have
+ // failed.
// |callback| is fired with base::File::FILE_OK when every file/directory
// under |root| is processed, or fired earlier when any suboperation fails.
void StartRecursiveOperation(const FileSystemURL& root,
+ ErrorBehavior error_behavior,
const StatusCallback& callback);
- // Starts to process files/directories recursively from the given |root|.
- // Compared with StartRecursiveOperation, this continues operation with
- // ignoring erros of ProcessFile.
- //
- // |error_callback| is fired when a ProcessFile has failed in the middle of
- // operations. If some errors had happened, |status_callback| is fired with
- // base::File::FILE_ERROR_FAILED at the end.
- //
- // TODO(yawano): Handle errors of ProcessDirectory as well.
- void StartRecursiveOperationWithIgnoringError(
- const FileSystemURL& root,
- const ErrorCallback& error_callback,
- const StatusCallback& status_callback);
-
FileSystemContext* file_system_context() { return file_system_context_; }
const FileSystemContext* file_system_context() const {
return file_system_context_;
@@ -154,13 +143,12 @@ class STORAGE_EXPORT RecursiveOperationDelegate
FileSystemContext* file_system_context_;
StatusCallback callback_;
- ErrorCallback error_callback_;
std::stack<FileSystemURL> pending_directories_;
std::stack<std::queue<FileSystemURL> > pending_directory_stack_;
std::queue<FileSystemURL> pending_files_;
int inflight_operations_;
bool canceled_;
- bool ignore_error_;
+ ErrorBehavior error_behavior_;
bool failed_some_operations_;
DISALLOW_COPY_AND_ASSIGN(RecursiveOperationDelegate);
diff --git a/storage/browser/fileapi/remove_operation_delegate.cc b/storage/browser/fileapi/remove_operation_delegate.cc
index eb28587..c0de28a 100644
--- a/storage/browser/fileapi/remove_operation_delegate.cc
+++ b/storage/browser/fileapi/remove_operation_delegate.cc
@@ -28,7 +28,8 @@ void RemoveOperationDelegate::Run() {
}
void RemoveOperationDelegate::RunRecursively() {
- StartRecursiveOperation(url_, callback_);
+ StartRecursiveOperation(url_, FileSystemOperation::ERROR_BEHAVIOR_ABORT,
+ callback_);
}
void RemoveOperationDelegate::ProcessFile(const FileSystemURL& url,