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

Unified Diff: webkit/fileapi/file_system_operation.cc

Issue 9372044: Refactor FileSystemOperation to take callback for each method. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reflected kinuko's comments + Fixture for failing-Write -> Cancel pattern. Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/fileapi/file_system_operation.h ('k') | webkit/fileapi/file_system_operation_interface.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/fileapi/file_system_operation.cc
diff --git a/webkit/fileapi/file_system_operation.cc b/webkit/fileapi/file_system_operation.cc
index b12c5bf0589124c7a57ef0cbbdceea937d5f821c..99661055cf9b780e78749480aa93cf4e857afad1 100644
--- a/webkit/fileapi/file_system_operation.cc
+++ b/webkit/fileapi/file_system_operation.cc
@@ -9,7 +9,6 @@
#include "base/utf_string_conversions.h"
#include "net/base/escape.h"
#include "net/url_request/url_request_context.h"
-#include "webkit/fileapi/file_system_callback_dispatcher.h"
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_file_util_proxy.h"
#include "webkit/fileapi/file_system_mount_point_provider.h"
@@ -72,22 +71,26 @@ FileSystemOperation::~FileSystemOperation() {
}
void FileSystemOperation::CreateFile(const GURL& path,
- bool exclusive) {
+ bool exclusive,
+ const StatusCallback& callback) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationCreateFile;
#endif
- if (!SetupSrcContextForWrite(path, true)) {
+ base::PlatformFileError result = SetupSrcContextForWrite(path, true);
+ if (result != base::PLATFORM_FILE_OK) {
+ callback.Run(result);
delete this;
return;
}
GetUsageAndQuotaThenCallback(
operation_context_.src_origin_url(),
base::Bind(&FileSystemOperation::DelayedCreateFileForQuota,
- base::Unretained(this), exclusive));
+ base::Unretained(this), callback, exclusive));
}
void FileSystemOperation::DelayedCreateFileForQuota(
+ const StatusCallback& callback,
bool exclusive,
quota::QuotaStatusCode status, int64 usage, int64 quota) {
operation_context_.set_allowed_bytes_growth(quota - usage);
@@ -105,27 +108,31 @@ void FileSystemOperation::DelayedCreateFileForQuota(
base::Bind(
exclusive ? &FileSystemOperation::DidEnsureFileExistsExclusive
: &FileSystemOperation::DidEnsureFileExistsNonExclusive,
- base::Owned(this)));
+ base::Owned(this), callback));
}
void FileSystemOperation::CreateDirectory(const GURL& path,
bool exclusive,
- bool recursive) {
+ bool recursive,
+ const StatusCallback& callback) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationCreateDirectory;
#endif
- if (!SetupSrcContextForWrite(path, true)) {
+ base::PlatformFileError result = SetupSrcContextForWrite(path, true);
+ if (result != base::PLATFORM_FILE_OK) {
+ callback.Run(result);
delete this;
return;
}
GetUsageAndQuotaThenCallback(
operation_context_.src_origin_url(),
base::Bind(&FileSystemOperation::DelayedCreateDirectoryForQuota,
- base::Unretained(this), exclusive, recursive));
+ base::Unretained(this), callback, exclusive, recursive));
}
void FileSystemOperation::DelayedCreateDirectoryForQuota(
+ const StatusCallback& callback,
bool exclusive, bool recursive,
quota::QuotaStatusCode status, int64 usage, int64 quota) {
operation_context_.set_allowed_bytes_growth(quota - usage);
@@ -142,17 +149,21 @@ void FileSystemOperation::DelayedCreateDirectoryForQuota(
&operation_context_,
src_virtual_path_, exclusive, recursive),
base::Bind(&FileSystemOperation::DidFinishFileOperation,
- base::Owned(this)));
+ base::Owned(this), callback));
}
void FileSystemOperation::Copy(const GURL& src_path,
- const GURL& dest_path) {
+ const GURL& dest_path,
+ const StatusCallback& callback) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationCopy;
#endif
- if (!SetupSrcContextForRead(src_path) ||
- !SetupDestContextForWrite(dest_path, true)) {
+ base::PlatformFileError result = SetupSrcContextForRead(src_path);
+ if (result == base::PLATFORM_FILE_OK)
+ result = SetupDestContextForWrite(dest_path, true);
+ if (result != base::PLATFORM_FILE_OK) {
+ callback.Run(result);
delete this;
return;
}
@@ -160,10 +171,11 @@ void FileSystemOperation::Copy(const GURL& src_path,
GetUsageAndQuotaThenCallback(
operation_context_.dest_origin_url(),
base::Bind(&FileSystemOperation::DelayedCopyForQuota,
- base::Unretained(this)));
+ base::Unretained(this), callback));
}
-void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status,
+void FileSystemOperation::DelayedCopyForQuota(const StatusCallback& callback,
+ quota::QuotaStatusCode status,
int64 usage, int64 quota) {
operation_context_.set_allowed_bytes_growth(quota - usage);
@@ -179,17 +191,21 @@ void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status,
&operation_context_,
src_virtual_path_, dest_virtual_path_),
base::Bind(&FileSystemOperation::DidFinishFileOperation,
- base::Owned(this)));
+ base::Owned(this), callback));
}
void FileSystemOperation::Move(const GURL& src_path,
- const GURL& dest_path) {
+ const GURL& dest_path,
+ const StatusCallback& callback) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationMove;
#endif
- if (!SetupSrcContextForWrite(src_path, false) ||
- !SetupDestContextForWrite(dest_path, true)) {
+ base::PlatformFileError result = SetupSrcContextForWrite(src_path, false);
+ if (result == base::PLATFORM_FILE_OK)
+ result = SetupDestContextForWrite(dest_path, true);
+ if (result != base::PLATFORM_FILE_OK) {
+ callback.Run(result);
delete this;
return;
}
@@ -197,10 +213,11 @@ void FileSystemOperation::Move(const GURL& src_path,
GetUsageAndQuotaThenCallback(
operation_context_.dest_origin_url(),
base::Bind(&FileSystemOperation::DelayedMoveForQuota,
- base::Unretained(this)));
+ base::Unretained(this), callback));
}
-void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status,
+void FileSystemOperation::DelayedMoveForQuota(const StatusCallback& callback,
+ quota::QuotaStatusCode status,
int64 usage, int64 quota) {
operation_context_.set_allowed_bytes_growth(quota - usage);
@@ -216,15 +233,18 @@ void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status,
&operation_context_,
src_virtual_path_, dest_virtual_path_),
base::Bind(&FileSystemOperation::DidFinishFileOperation,
- base::Owned(this)));
+ base::Owned(this), callback));
}
-void FileSystemOperation::DirectoryExists(const GURL& path) {
+void FileSystemOperation::DirectoryExists(const GURL& path,
+ const StatusCallback& callback) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationDirectoryExists;
#endif
- if (!SetupSrcContextForRead(path)) {
+ base::PlatformFileError result = SetupSrcContextForRead(path);
+ if (result != base::PLATFORM_FILE_OK) {
+ callback.Run(result);
delete this;
return;
}
@@ -234,15 +254,19 @@ void FileSystemOperation::DirectoryExists(const GURL& path) {
base::Bind(&FileSystemFileUtil::GetFileInfo,
base::Unretained(operation_context_.src_file_util()),
&operation_context_, src_virtual_path_),
- base::Bind(&FileSystemOperation::DidDirectoryExists, base::Owned(this)));
+ base::Bind(&FileSystemOperation::DidDirectoryExists,
+ base::Owned(this), callback));
}
-void FileSystemOperation::FileExists(const GURL& path) {
+void FileSystemOperation::FileExists(const GURL& path,
+ const StatusCallback& callback) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationFileExists;
#endif
- if (!SetupSrcContextForRead(path)) {
+ base::PlatformFileError result = SetupSrcContextForRead(path);
+ if (result != base::PLATFORM_FILE_OK) {
+ callback.Run(result);
delete this;
return;
}
@@ -252,15 +276,19 @@ void FileSystemOperation::FileExists(const GURL& path) {
base::Bind(&FileSystemFileUtil::GetFileInfo,
base::Unretained(operation_context_.src_file_util()),
&operation_context_, src_virtual_path_),
- base::Bind(&FileSystemOperation::DidFileExists, base::Owned(this)));
+ base::Bind(&FileSystemOperation::DidFileExists,
+ base::Owned(this), callback));
}
-void FileSystemOperation::GetMetadata(const GURL& path) {
+void FileSystemOperation::GetMetadata(const GURL& path,
+ const GetMetadataCallback& callback) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationGetMetadata;
#endif
- if (!SetupSrcContextForRead(path)) {
+ base::PlatformFileError result = SetupSrcContextForRead(path);
+ if (result != base::PLATFORM_FILE_OK) {
+ callback.Run(result, base::PlatformFileInfo(), FilePath());
delete this;
return;
}
@@ -270,15 +298,19 @@ void FileSystemOperation::GetMetadata(const GURL& path) {
base::Bind(&FileSystemFileUtil::GetFileInfo,
base::Unretained(operation_context_.src_file_util()),
&operation_context_, src_virtual_path_),
- base::Bind(&FileSystemOperation::DidGetMetadata, base::Owned(this)));
+ base::Bind(&FileSystemOperation::DidGetMetadata,
+ base::Owned(this), callback));
}
-void FileSystemOperation::ReadDirectory(const GURL& path) {
+void FileSystemOperation::ReadDirectory(const GURL& path,
+ const ReadDirectoryCallback& callback) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationReadDirectory;
#endif
- if (!SetupSrcContextForRead(path)) {
+ base::PlatformFileError result = SetupSrcContextForRead(path);
+ if (result != base::PLATFORM_FILE_OK) {
+ callback.Run(result, std::vector<base::FileUtilProxy::Entry>(), false);
delete this;
return;
}
@@ -288,15 +320,19 @@ void FileSystemOperation::ReadDirectory(const GURL& path) {
base::Bind(&FileSystemFileUtil::ReadDirectory,
base::Unretained(operation_context_.src_file_util()),
&operation_context_, src_virtual_path_),
- base::Bind(&FileSystemOperation::DidReadDirectory, base::Owned(this)));
+ base::Bind(&FileSystemOperation::DidReadDirectory,
+ base::Owned(this), callback));
}
-void FileSystemOperation::Remove(const GURL& path, bool recursive) {
+void FileSystemOperation::Remove(const GURL& path, bool recursive,
+ const StatusCallback& callback) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationRemove;
#endif
- if (!SetupSrcContextForWrite(path, false)) {
+ base::PlatformFileError result = SetupSrcContextForWrite(path, false);
+ if (result != base::PLATFORM_FILE_OK) {
+ callback.Run(result);
delete this;
return;
}
@@ -307,24 +343,28 @@ void FileSystemOperation::Remove(const GURL& path, bool recursive) {
base::Unretained(operation_context_.src_file_util()),
&operation_context_, src_virtual_path_, recursive),
base::Bind(&FileSystemOperation::DidFinishFileOperation,
- base::Owned(this)));
+ base::Owned(this), callback));
}
void FileSystemOperation::Write(
const net::URLRequestContext* url_request_context,
const GURL& path,
const GURL& blob_url,
- int64 offset) {
+ int64 offset,
+ const WriteCallback& callback) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationWrite;
#endif
- if (!SetupSrcContextForWrite(path, true)) {
+ base::PlatformFileError result = SetupSrcContextForWrite(path, true);
+ if (result != base::PLATFORM_FILE_OK) {
+ callback.Run(result, 0, false);
delete this;
return;
}
DCHECK(blob_url.is_valid());
file_writer_delegate_.reset(new FileWriterDelegate(this, offset, proxy_));
+ set_write_callback(callback);
blob_request_.reset(
new net::URLRequest(blob_url, file_writer_delegate_.get()));
blob_request_->set_context(url_request_context);
@@ -360,24 +400,27 @@ void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status,
base::Unretained(this)));
}
-void FileSystemOperation::Truncate(const GURL& path, int64 length) {
+void FileSystemOperation::Truncate(const GURL& path, int64 length,
+ const StatusCallback& callback) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationTruncate;
#endif
- if (!SetupSrcContextForWrite(path, false)) {
+ base::PlatformFileError result = SetupSrcContextForWrite(path, false);
+ if (result != base::PLATFORM_FILE_OK) {
+ callback.Run(result);
delete this;
return;
}
GetUsageAndQuotaThenCallback(
operation_context_.src_origin_url(),
base::Bind(&FileSystemOperation::DelayedTruncateForQuota,
- base::Unretained(this), length));
+ base::Unretained(this), callback, length));
}
-void FileSystemOperation::DelayedTruncateForQuota(int64 length,
- quota::QuotaStatusCode status,
- int64 usage, int64 quota) {
+void FileSystemOperation::DelayedTruncateForQuota(
+ const StatusCallback& callback,
+ int64 length, quota::QuotaStatusCode status, int64 usage, int64 quota) {
operation_context_.set_allowed_bytes_growth(quota - usage);
quota_util_helper_.reset(new ScopedQuotaUtilHelper(
@@ -391,17 +434,20 @@ void FileSystemOperation::DelayedTruncateForQuota(int64 length,
base::Unretained(operation_context_.src_file_util()),
&operation_context_, src_virtual_path_, length),
base::Bind(&FileSystemOperation::DidFinishFileOperation,
- base::Owned(this)));
+ base::Owned(this), callback));
}
void FileSystemOperation::TouchFile(const GURL& path,
const base::Time& last_access_time,
- const base::Time& last_modified_time) {
+ const base::Time& last_modified_time,
+ const StatusCallback& callback) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationTouchFile;
#endif
- if (!SetupSrcContextForWrite(path, true)) {
+ base::PlatformFileError result = SetupSrcContextForWrite(path, true);
+ if (result != base::PLATFORM_FILE_OK) {
+ callback.Run(result);
delete this;
return;
}
@@ -412,12 +458,14 @@ void FileSystemOperation::TouchFile(const GURL& path,
base::Unretained(operation_context_.src_file_util()),
&operation_context_,
src_virtual_path_, last_access_time, last_modified_time),
- base::Bind(&FileSystemOperation::DidTouchFile, base::Owned(this)));
+ base::Bind(&FileSystemOperation::DidTouchFile,
+ base::Owned(this), callback));
}
void FileSystemOperation::OpenFile(const GURL& path,
int file_flags,
- base::ProcessHandle peer_handle) {
+ base::ProcessHandle peer_handle,
+ const OpenFileCallback& callback) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationOpenFile;
@@ -427,6 +475,8 @@ void FileSystemOperation::OpenFile(const GURL& path,
if (file_flags & (
(base::PLATFORM_FILE_ENUMERATE | base::PLATFORM_FILE_TEMPORARY |
base::PLATFORM_FILE_HIDDEN))) {
+ callback.Run(base::PLATFORM_FILE_ERROR_FAILED,
+ base::PlatformFile(), base::ProcessHandle());
delete this;
return;
}
@@ -436,12 +486,16 @@ void FileSystemOperation::OpenFile(const GURL& path,
base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE |
base::PLATFORM_FILE_DELETE_ON_CLOSE |
base::PLATFORM_FILE_WRITE_ATTRIBUTES)) {
- if (!SetupSrcContextForWrite(path, true)) {
+ base::PlatformFileError result = SetupSrcContextForWrite(path, true);
+ if (result != base::PLATFORM_FILE_OK) {
+ callback.Run(result, base::PlatformFile(), base::ProcessHandle());
delete this;
return;
}
} else {
- if (!SetupSrcContextForRead(path)) {
+ base::PlatformFileError result = SetupSrcContextForRead(path);
+ if (result != base::PLATFORM_FILE_OK) {
+ callback.Run(result, base::PlatformFile(), base::ProcessHandle());
delete this;
return;
}
@@ -449,12 +503,12 @@ void FileSystemOperation::OpenFile(const GURL& path,
GetUsageAndQuotaThenCallback(
operation_context_.src_origin_url(),
base::Bind(&FileSystemOperation::DelayedOpenFileForQuota,
- base::Unretained(this), file_flags));
+ base::Unretained(this), callback, file_flags));
}
-void FileSystemOperation::DelayedOpenFileForQuota(int file_flags,
- quota::QuotaStatusCode status,
- int64 usage, int64 quota) {
+void FileSystemOperation::DelayedOpenFileForQuota(
+ const OpenFileCallback& callback,
+ int file_flags, quota::QuotaStatusCode status, int64 usage, int64 quota) {
operation_context_.set_allowed_bytes_growth(quota - usage);
quota_util_helper_.reset(new ScopedQuotaUtilHelper(
@@ -471,13 +525,13 @@ void FileSystemOperation::DelayedOpenFileForQuota(int file_flags,
base::Bind(&FileSystemFileUtil::Close,
base::Unretained(operation_context_.src_file_util()),
&operation_context_),
- base::Bind(&FileSystemOperation::DidOpenFile, base::Owned(this)));
+ base::Bind(&FileSystemOperation::DidOpenFile,
+ base::Owned(this), callback));
}
// We can only get here on a write or truncate that's not yet completed.
// We don't support cancelling any other operation at this time.
-void FileSystemOperation::Cancel(
- scoped_ptr<FileSystemCallbackDispatcher> cancel_dispatcher) {
+void FileSystemOperation::Cancel(const StatusCallback& cancel_callback) {
if (file_writer_delegate_.get()) {
#ifndef NDEBUG
DCHECK(kOperationWrite == pending_operation_);
@@ -491,20 +545,24 @@ void FileSystemOperation::Cancel(
// This halts any calls to file_writer_delegate_ from blob_request_.
blob_request_->Cancel();
- if (dispatcher_.get())
- dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_ABORT);
- cancel_dispatcher->DidSucceed();
- dispatcher_.reset();
+ if (!write_callback_.is_null()) {
+ // Notify the failure status to the ongoing operation's callback.
+ write_callback_.Run(base::PLATFORM_FILE_ERROR_ABORT, 0, false);
+ // Do not delete this FileSystemOperation object yet. As a result of
+ // abort, this->DidWrite is called later and there we delete this object.
+ }
+ cancel_callback.Run(base::PLATFORM_FILE_OK);
+ write_callback_.Reset();
} else {
#ifndef NDEBUG
DCHECK(kOperationTruncate == pending_operation_);
#endif
// We're cancelling a truncate operation, but we can't actually stop it
// since it's been proxied to another thread. We need to save the
- // cancel_dispatcher so that when the truncate returns, it can see that it's
+ // cancel_callback so that when the truncate returns, it can see that it's
// been cancelled, report it, and report that the cancel has succeeded.
- DCHECK(!cancel_dispatcher_.get());
- cancel_dispatcher_ = cancel_dispatcher.Pass();
+ DCHECK(cancel_callback_.is_null());
+ cancel_callback_ = cancel_callback;
}
}
@@ -518,7 +576,8 @@ void FileSystemOperation::SyncGetPlatformPath(const GURL& path,
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationGetLocalPath;
#endif
- if (!SetupSrcContextForRead(path)) {
+ base::PlatformFileError result = SetupSrcContextForRead(path);
+ if (result != base::PLATFORM_FILE_OK) {
delete this;
return;
}
@@ -530,11 +589,9 @@ void FileSystemOperation::SyncGetPlatformPath(const GURL& path,
}
FileSystemOperation::FileSystemOperation(
- scoped_ptr<FileSystemCallbackDispatcher> dispatcher,
scoped_refptr<base::MessageLoopProxy> proxy,
FileSystemContext* file_system_context)
: proxy_(proxy),
- dispatcher_(dispatcher.Pass()),
operation_context_(file_system_context, NULL),
peer_handle_(base::kNullProcessHandle) {
#ifndef NDEBUG
@@ -565,151 +622,121 @@ void FileSystemOperation::GetUsageAndQuotaThenCallback(
}
void FileSystemOperation::DidEnsureFileExistsExclusive(
+ const StatusCallback& callback,
base::PlatformFileError rv, bool created) {
if (rv == base::PLATFORM_FILE_OK && !created) {
- if (dispatcher_.get())
- dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_EXISTS);
+ callback.Run(base::PLATFORM_FILE_ERROR_EXISTS);
} else {
- DidFinishFileOperation(rv);
+ DidFinishFileOperation(callback, rv);
}
}
void FileSystemOperation::DidEnsureFileExistsNonExclusive(
+ const StatusCallback& callback,
base::PlatformFileError rv, bool /* created */) {
- DidFinishFileOperation(rv);
+ DidFinishFileOperation(callback, rv);
}
void FileSystemOperation::DidFinishFileOperation(
+ const StatusCallback& callback,
base::PlatformFileError rv) {
- if (cancel_dispatcher_.get()) {
+ if (!cancel_callback_.is_null()) {
#ifndef NDEBUG
DCHECK(kOperationTruncate == pending_operation_);
#endif
-
- if (dispatcher_.get())
- dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_ABORT);
- cancel_dispatcher_->DidSucceed();
- } else if (dispatcher_.get()) {
- if (rv == base::PLATFORM_FILE_OK)
- dispatcher_->DidSucceed();
- else
- dispatcher_->DidFail(rv);
+ callback.Run(base::PLATFORM_FILE_ERROR_ABORT);
+ cancel_callback_.Run(base::PLATFORM_FILE_OK);
+ cancel_callback_.Reset();
+ } else {
+ callback.Run(rv);
}
}
void FileSystemOperation::DidDirectoryExists(
+ const StatusCallback& callback,
base::PlatformFileError rv,
const base::PlatformFileInfo& file_info,
const FilePath& unused) {
- if (!dispatcher_.get())
- return;
- if (rv == base::PLATFORM_FILE_OK) {
- if (file_info.is_directory)
- dispatcher_->DidSucceed();
- else
- dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY);
- } else {
- dispatcher_->DidFail(rv);
- }
+ if (rv == base::PLATFORM_FILE_OK && !file_info.is_directory)
+ rv = base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY;
+ callback.Run(rv);
}
void FileSystemOperation::DidFileExists(
+ const StatusCallback& callback,
base::PlatformFileError rv,
const base::PlatformFileInfo& file_info,
const FilePath& unused) {
- if (!dispatcher_.get())
- return;
- if (rv == base::PLATFORM_FILE_OK) {
- if (file_info.is_directory)
- dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_NOT_A_FILE);
- else
- dispatcher_->DidSucceed();
- } else {
- dispatcher_->DidFail(rv);
- }
+ if (rv == base::PLATFORM_FILE_OK && file_info.is_directory)
+ rv = base::PLATFORM_FILE_ERROR_NOT_A_FILE;
+ callback.Run(rv);
}
void FileSystemOperation::DidGetMetadata(
+ const GetMetadataCallback& callback,
base::PlatformFileError rv,
const base::PlatformFileInfo& file_info,
const FilePath& platform_path) {
- if (!dispatcher_.get())
- return;
- if (rv == base::PLATFORM_FILE_OK)
- dispatcher_->DidReadMetadata(file_info, platform_path);
- else
- dispatcher_->DidFail(rv);
+ callback.Run(rv, file_info, platform_path);
}
void FileSystemOperation::DidReadDirectory(
+ const ReadDirectoryCallback& callback,
base::PlatformFileError rv,
const std::vector<base::FileUtilProxy::Entry>& entries) {
- if (!dispatcher_.get())
- return;
-
- if (rv == base::PLATFORM_FILE_OK)
- dispatcher_->DidReadDirectory(entries, false /* has_more */);
- else
- dispatcher_->DidFail(rv);
+ callback.Run(rv, entries, false /* has_more */);
}
void FileSystemOperation::DidWrite(
base::PlatformFileError rv,
int64 bytes,
bool complete) {
- if (!dispatcher_.get()) {
+ if (write_callback_.is_null()) {
+ // If cancelled, callback is already invoked and set to null in Cancel().
+ // We must not call it twice. Just shut down this operation object.
delete this;
return;
}
- if (rv == base::PLATFORM_FILE_OK)
- dispatcher_->DidWrite(bytes, complete);
- else
- dispatcher_->DidFail(rv);
+ write_callback_.Run(rv, bytes, complete);
if (complete || rv != base::PLATFORM_FILE_OK)
delete this;
}
-void FileSystemOperation::DidTouchFile(base::PlatformFileError rv) {
- if (!dispatcher_.get())
- return;
- if (rv == base::PLATFORM_FILE_OK)
- dispatcher_->DidSucceed();
- else
- dispatcher_->DidFail(rv);
+void FileSystemOperation::DidTouchFile(const StatusCallback& callback,
+ base::PlatformFileError rv) {
+ callback.Run(rv);
}
void FileSystemOperation::DidOpenFile(
+ const OpenFileCallback& callback,
base::PlatformFileError rv,
base::PassPlatformFile file,
bool unused) {
- if (!dispatcher_.get())
- return;
- if (rv == base::PLATFORM_FILE_OK) {
+ if (rv == base::PLATFORM_FILE_OK)
CHECK_NE(base::kNullProcessHandle, peer_handle_);
- dispatcher_->DidOpenFile(file.ReleaseValue(), peer_handle_);
- } else {
- dispatcher_->DidFail(rv);
- }
+ callback.Run(rv, file.ReleaseValue(), peer_handle_);
}
void FileSystemOperation::OnFileOpenedForWrite(
base::PlatformFileError rv,
base::PassPlatformFile file,
bool created) {
- if (base::PLATFORM_FILE_OK != rv || !dispatcher_.get()) {
- if (dispatcher_.get())
- dispatcher_->DidFail(rv);
+ if (rv != base::PLATFORM_FILE_OK) {
+ if (!write_callback_.is_null())
+ write_callback_.Run(rv, 0, false);
delete this;
return;
}
file_writer_delegate_->Start(file.ReleaseValue(), blob_request_.get());
}
-bool FileSystemOperation::VerifyFileSystemPathForRead(
+base::PlatformFileError FileSystemOperation::VerifyFileSystemPathForRead(
const GURL& path, GURL* origin_url, FileSystemType* type,
FilePath* virtual_path, FileSystemFileUtil** file_util) {
- if (!VerifyFileSystemPath(path, origin_url, type, virtual_path, file_util))
- return false;
+ base::PlatformFileError rv =
+ VerifyFileSystemPath(path, origin_url, type, virtual_path, file_util);
+ if (rv != base::PLATFORM_FILE_OK)
+ return rv;
// We notify this read access whether the read access succeeds or not.
// This must be ok since this is used to let the QM's eviction logic know
@@ -723,57 +750,56 @@ bool FileSystemOperation::VerifyFileSystemPathForRead(
*type);
}
- return true;
+ return base::PLATFORM_FILE_OK;
}
-bool FileSystemOperation::VerifyFileSystemPathForWrite(
+base::PlatformFileError FileSystemOperation::VerifyFileSystemPathForWrite(
const GURL& path, bool create, GURL* origin_url, FileSystemType* type,
FilePath* virtual_path, FileSystemFileUtil** file_util) {
- if (!VerifyFileSystemPath(path, origin_url, type, virtual_path, file_util))
- return false;
+ base::PlatformFileError rv =
+ VerifyFileSystemPath(path, origin_url, type, virtual_path, file_util);
+ if (rv != base::PLATFORM_FILE_OK)
+ return rv;
// Any write access is disallowed on the root path.
if (virtual_path->value().length() == 0 ||
virtual_path->DirName().value() == virtual_path->value()) {
- dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY);
- return false;
+ return base::PLATFORM_FILE_ERROR_SECURITY;
}
if (create &&
file_system_context()->GetMountPointProvider(*type)->IsRestrictedFileName(
virtual_path->BaseName())) {
- dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY);
- return false;
+ return base::PLATFORM_FILE_ERROR_SECURITY;
}
- return true;
+ return base::PLATFORM_FILE_OK;
}
-bool FileSystemOperation::VerifyFileSystemPath(
+base::PlatformFileError FileSystemOperation::VerifyFileSystemPath(
const GURL& path, GURL* origin_url, FileSystemType* type,
FilePath* virtual_path, FileSystemFileUtil** file_util) {
DCHECK(file_system_context());
if (!CrackFileSystemURL(path, origin_url, type, virtual_path)) {
- dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_INVALID_URL);
- return false;
+ return base::PLATFORM_FILE_ERROR_INVALID_URL;
}
if (!file_system_context()->GetMountPointProvider(*type)->IsAccessAllowed(
*origin_url, *type, *virtual_path)) {
- dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY);
- return false;
+ return base::PLATFORM_FILE_ERROR_SECURITY;
}
DCHECK(file_util);
*file_util = file_system_context()->GetFileUtil(*type);
DCHECK(*file_util);
- return true;
+ return base::PLATFORM_FILE_OK;
}
-bool FileSystemOperation::SetupSrcContextForRead(const GURL& path) {
+base::PlatformFileError FileSystemOperation::SetupSrcContextForRead(
+ const GURL& path) {
GURL origin_url;
FileSystemType type;
FileSystemFileUtil* file_util;
- bool result = VerifyFileSystemPathForRead(
+ base::PlatformFileError result = VerifyFileSystemPathForRead(
path, &origin_url, &type, &src_virtual_path_, &file_util);
operation_context_.set_src_origin_url(origin_url);
operation_context_.set_src_type(type);
@@ -782,12 +808,13 @@ bool FileSystemOperation::SetupSrcContextForRead(const GURL& path) {
return result;
}
-bool FileSystemOperation::SetupSrcContextForWrite(const GURL& path,
- bool create) {
+base::PlatformFileError FileSystemOperation::SetupSrcContextForWrite(
+ const GURL& path,
+ bool create) {
GURL origin_url;
FileSystemType type;
FileSystemFileUtil* file_util = NULL;
- bool result = VerifyFileSystemPathForWrite(
+ base::PlatformFileError result = VerifyFileSystemPathForWrite(
path, create, &origin_url, &type, &src_virtual_path_, &file_util);
operation_context_.set_src_origin_url(origin_url);
operation_context_.set_src_type(type);
@@ -796,12 +823,13 @@ bool FileSystemOperation::SetupSrcContextForWrite(const GURL& path,
return result;
}
-bool FileSystemOperation::SetupDestContextForWrite(const GURL& path,
- bool create) {
+base::PlatformFileError FileSystemOperation::SetupDestContextForWrite(
+ const GURL& path,
+ bool create) {
GURL origin_url;
FileSystemType type;
FileSystemFileUtil* file_util = NULL;
- bool result = VerifyFileSystemPathForWrite(
+ base::PlatformFileError result = VerifyFileSystemPathForWrite(
path, create, &origin_url, &type, &dest_virtual_path_, &file_util);
operation_context_.set_dest_origin_url(origin_url);
operation_context_.set_dest_type(type);
« no previous file with comments | « webkit/fileapi/file_system_operation.h ('k') | webkit/fileapi/file_system_operation_interface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698