diff options
author | oleg@chromium.org <oleg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-26 11:18:26 +0000 |
---|---|---|
committer | oleg@chromium.org <oleg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-26 11:18:26 +0000 |
commit | 49b67d2e3b61bcdc4af5a3f0b396f3d0539cf10f (patch) | |
tree | 03d1c959de6a1d7c7fd84962ec85cc6ac7eee6ef /webkit | |
parent | b06b95096627f9a4e34ff8cbe7916a3b6233caf0 (diff) | |
download | chromium_src-49b67d2e3b61bcdc4af5a3f0b396f3d0539cf10f.zip chromium_src-49b67d2e3b61bcdc4af5a3f0b396f3d0539cf10f.tar.gz chromium_src-49b67d2e3b61bcdc4af5a3f0b396f3d0539cf10f.tar.bz2 |
Refactor FileSystemOperation:
1. Get FileSystemFileUtil inside FileSystemOperation, do not receive it as a parameter.
2. Extract the common code to the separate method.
Review URL: http://codereview.chromium.org/8355003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107331 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/fileapi/file_system_dir_url_request_job.cc | 3 | ||||
-rw-r--r-- | webkit/fileapi/file_system_operation.cc | 348 | ||||
-rw-r--r-- | webkit/fileapi/file_system_operation.h | 28 | ||||
-rw-r--r-- | webkit/fileapi/file_system_test_helper.cc | 4 | ||||
-rw-r--r-- | webkit/fileapi/file_system_url_request_job.cc | 4 | ||||
-rw-r--r-- | webkit/tools/test_shell/simple_file_system.cc | 2 | ||||
-rw-r--r-- | webkit/tools/test_shell/simple_file_writer.cc | 3 |
7 files changed, 165 insertions, 227 deletions
diff --git a/webkit/fileapi/file_system_dir_url_request_job.cc b/webkit/fileapi/file_system_dir_url_request_job.cc index aefbccc..6100994 100644 --- a/webkit/fileapi/file_system_dir_url_request_job.cc +++ b/webkit/fileapi/file_system_dir_url_request_job.cc @@ -178,8 +178,7 @@ void FileSystemDirURLRequestJob::DidReadDirectory( FileSystemOperation* FileSystemDirURLRequestJob::GetNewOperation() { return new FileSystemOperation(new CallbackDispatcher(this), file_thread_proxy_, - file_system_context_, - NULL); + file_system_context_); } } // namespace fileapi diff --git a/webkit/fileapi/file_system_operation.cc b/webkit/fileapi/file_system_operation.cc index 20584ab..e6bb157 100644 --- a/webkit/fileapi/file_system_operation.cc +++ b/webkit/fileapi/file_system_operation.cc @@ -60,13 +60,11 @@ FileSystemOperation::ScopedQuotaUtilHelper::~ScopedQuotaUtilHelper() { FileSystemOperation::FileSystemOperation( FileSystemCallbackDispatcher* dispatcher, scoped_refptr<base::MessageLoopProxy> proxy, - FileSystemContext* file_system_context, - FileSystemFileUtil* file_util) + FileSystemContext* file_system_context) : proxy_(proxy), dispatcher_(dispatcher), - file_system_operation_context_(file_system_context, file_util), + operation_context_(file_system_context, NULL), ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { - DCHECK(dispatcher); #ifndef NDEBUG pending_operation_ = kOperationNone; #endif @@ -75,7 +73,7 @@ FileSystemOperation::FileSystemOperation( FileSystemOperation::~FileSystemOperation() { if (file_writer_delegate_.get()) FileSystemFileUtilProxy::Close( - file_system_operation_context_, proxy_, file_writer_delegate_->file(), + operation_context_, proxy_, file_writer_delegate_->file(), FileSystemFileUtilProxy::StatusCallback()); } @@ -88,8 +86,8 @@ void FileSystemOperation::OpenFileSystem( #endif DCHECK(file_system_context()); - file_system_operation_context_.set_src_origin_url(origin_url); - file_system_operation_context_.set_src_type(type); + operation_context_.set_src_origin_url(origin_url); + operation_context_.set_src_type(type); // TODO(ericu): We don't really need to make this call if !create. // Also, in the future we won't need it either way, as long as we do all // permission+quota checks beforehand. We only need it now because we have to @@ -108,37 +106,29 @@ void FileSystemOperation::CreateFile(const GURL& path, DCHECK(kOperationNone == pending_operation_); pending_operation_ = kOperationCreateFile; #endif - GURL origin_url; - FileSystemType type; - FileSystemFileUtil* file_util; - if (!VerifyFileSystemPathForWrite(path, true /* create */, &origin_url, - &type, &src_virtual_path_, &file_util)) { + if (!SetupSrcContextForWrite(path, true)) { delete this; return; } - file_system_operation_context_.set_src_origin_url(origin_url); - file_system_operation_context_.set_src_type(type); - if (!file_system_operation_context_.src_file_util()) - file_system_operation_context_.set_src_file_util(file_util); exclusive_ = exclusive; GetUsageAndQuotaThenCallback( - origin_url, + operation_context_.src_origin_url(), base::Bind(&FileSystemOperation::DelayedCreateFileForQuota, weak_factory_.GetWeakPtr())); } void FileSystemOperation::DelayedCreateFileForQuota( quota::QuotaStatusCode status, int64 usage, int64 quota) { - file_system_operation_context_.set_allowed_bytes_growth(quota - usage); + operation_context_.set_allowed_bytes_growth(quota - usage); quota_util_helper_.reset(new ScopedQuotaUtilHelper( file_system_context(), - file_system_operation_context_.src_origin_url(), - file_system_operation_context_.src_type())); + operation_context_.src_origin_url(), + operation_context_.src_type())); FileSystemFileUtilProxy::EnsureFileExists( - file_system_operation_context_, + operation_context_, proxy_, src_virtual_path_, base::Bind( @@ -154,39 +144,30 @@ void FileSystemOperation::CreateDirectory(const GURL& path, DCHECK(kOperationNone == pending_operation_); pending_operation_ = kOperationCreateDirectory; #endif - GURL origin_url; - FileSystemType type; - FileSystemFileUtil* file_util; - - if (!VerifyFileSystemPathForWrite(path, true /* create */, &origin_url, - &type, &src_virtual_path_, &file_util)) { + if (!SetupSrcContextForWrite(path, true)) { delete this; return; } - file_system_operation_context_.set_src_origin_url(origin_url); - file_system_operation_context_.set_src_type(type); - if (!file_system_operation_context_.src_file_util()) - file_system_operation_context_.set_src_file_util(file_util); exclusive_ = exclusive; recursive_ = recursive; GetUsageAndQuotaThenCallback( - origin_url, + operation_context_.src_origin_url(), base::Bind(&FileSystemOperation::DelayedCreateDirectoryForQuota, weak_factory_.GetWeakPtr())); } void FileSystemOperation::DelayedCreateDirectoryForQuota( quota::QuotaStatusCode status, int64 usage, int64 quota) { - file_system_operation_context_.set_allowed_bytes_growth(quota - usage); + operation_context_.set_allowed_bytes_growth(quota - usage); quota_util_helper_.reset(new ScopedQuotaUtilHelper( file_system_context(), - file_system_operation_context_.src_origin_url(), - file_system_operation_context_.src_type())); + operation_context_.src_origin_url(), + operation_context_.src_type())); FileSystemFileUtilProxy::CreateDirectory( - file_system_operation_context_, proxy_, src_virtual_path_, exclusive_, + operation_context_, proxy_, src_virtual_path_, exclusive_, recursive_, base::Bind(&FileSystemOperation::DidFinishFileOperation, weak_factory_.GetWeakPtr())); @@ -198,46 +179,29 @@ void FileSystemOperation::Copy(const GURL& src_path, DCHECK(kOperationNone == pending_operation_); pending_operation_ = kOperationCopy; #endif - GURL src_origin_url; - GURL dest_origin_url; - FileSystemType src_type; - FileSystemType dest_type; - FileSystemFileUtil* src_file_util; - FileSystemFileUtil* dest_file_util; - - if (!VerifyFileSystemPathForRead(src_path, &src_origin_url, &src_type, - &src_virtual_path_, &src_file_util) || - !VerifyFileSystemPathForWrite(dest_path, true /* create */, - &dest_origin_url, &dest_type, &dest_virtual_path_, &dest_file_util)) { + if (!SetupSrcContextForRead(src_path) || + !SetupDestContextForWrite(dest_path, true)) { delete this; return; } - file_system_operation_context_.set_src_origin_url(src_origin_url); - file_system_operation_context_.set_dest_origin_url(dest_origin_url); - file_system_operation_context_.set_src_type(src_type); - file_system_operation_context_.set_dest_type(dest_type); - if (!file_system_operation_context_.src_file_util()) - file_system_operation_context_.set_src_file_util(src_file_util); - if (!file_system_operation_context_.dest_file_util()) - file_system_operation_context_.set_dest_file_util(dest_file_util); GetUsageAndQuotaThenCallback( - dest_origin_url, + operation_context_.dest_origin_url(), base::Bind(&FileSystemOperation::DelayedCopyForQuota, weak_factory_.GetWeakPtr())); } void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status, int64 usage, int64 quota) { - file_system_operation_context_.set_allowed_bytes_growth(quota - usage); + operation_context_.set_allowed_bytes_growth(quota - usage); quota_util_helper_.reset(new ScopedQuotaUtilHelper( file_system_context(), - file_system_operation_context_.dest_origin_url(), - file_system_operation_context_.dest_type())); + operation_context_.dest_origin_url(), + operation_context_.dest_type())); FileSystemFileUtilProxy::Copy( - file_system_operation_context_, proxy_, src_virtual_path_, + operation_context_, proxy_, src_virtual_path_, dest_virtual_path_, base::Bind(&FileSystemOperation::DidFinishFileOperation, weak_factory_.GetWeakPtr())); @@ -249,46 +213,29 @@ void FileSystemOperation::Move(const GURL& src_path, DCHECK(kOperationNone == pending_operation_); pending_operation_ = kOperationMove; #endif - GURL src_origin_url; - GURL dest_origin_url; - FileSystemType src_type; - FileSystemType dest_type; - FileSystemFileUtil* src_file_util; - FileSystemFileUtil* dest_file_util; - - if (!VerifyFileSystemPathForWrite(src_path, false, &src_origin_url, &src_type, - &src_virtual_path_, &src_file_util) || - !VerifyFileSystemPathForWrite(dest_path, true /* create */, - &dest_origin_url, &dest_type, &dest_virtual_path_, &dest_file_util)) { + if (!SetupSrcContextForWrite(src_path, false) || + !SetupDestContextForWrite(dest_path, true)) { delete this; return; } - file_system_operation_context_.set_src_origin_url(src_origin_url); - file_system_operation_context_.set_dest_origin_url(dest_origin_url); - file_system_operation_context_.set_src_type(src_type); - file_system_operation_context_.set_dest_type(dest_type); - if (!file_system_operation_context_.src_file_util()) - file_system_operation_context_.set_src_file_util(src_file_util); - if (!file_system_operation_context_.dest_file_util()) - file_system_operation_context_.set_dest_file_util(dest_file_util); GetUsageAndQuotaThenCallback( - dest_origin_url, + operation_context_.dest_origin_url(), base::Bind(&FileSystemOperation::DelayedMoveForQuota, weak_factory_.GetWeakPtr())); } void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status, int64 usage, int64 quota) { - file_system_operation_context_.set_allowed_bytes_growth(quota - usage); + operation_context_.set_allowed_bytes_growth(quota - usage); quota_util_helper_.reset(new ScopedQuotaUtilHelper( file_system_context(), - file_system_operation_context_.dest_origin_url(), - file_system_operation_context_.dest_type())); + operation_context_.dest_origin_url(), + operation_context_.dest_type())); FileSystemFileUtilProxy::Move( - file_system_operation_context_, proxy_, src_virtual_path_, + operation_context_, proxy_, src_virtual_path_, dest_virtual_path_, base::Bind(&FileSystemOperation::DidFinishFileOperation, weak_factory_.GetWeakPtr())); @@ -299,22 +246,13 @@ void FileSystemOperation::DirectoryExists(const GURL& path) { DCHECK(kOperationNone == pending_operation_); pending_operation_ = kOperationDirectoryExists; #endif - - FilePath virtual_path; - GURL origin_url; - FileSystemType type; - FileSystemFileUtil* file_util; - if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path, - &file_util)) { + if (!SetupSrcContextForRead(path)) { delete this; return; } - file_system_operation_context_.set_src_origin_url(origin_url); - file_system_operation_context_.set_src_type(type); - if (!file_system_operation_context_.src_file_util()) - file_system_operation_context_.set_src_file_util(file_util); + FileSystemFileUtilProxy::GetFileInfo( - file_system_operation_context_, proxy_, virtual_path, + operation_context_, proxy_, src_virtual_path_, base::Bind(&FileSystemOperation::DidDirectoryExists, weak_factory_.GetWeakPtr())); } @@ -324,22 +262,13 @@ void FileSystemOperation::FileExists(const GURL& path) { DCHECK(kOperationNone == pending_operation_); pending_operation_ = kOperationFileExists; #endif - - FilePath virtual_path; - GURL origin_url; - FileSystemType type; - FileSystemFileUtil* file_util; - if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path, - &file_util)) { + if (!SetupSrcContextForRead(path)) { delete this; return; } - file_system_operation_context_.set_src_origin_url(origin_url); - file_system_operation_context_.set_src_type(type); - if (!file_system_operation_context_.src_file_util()) - file_system_operation_context_.set_src_file_util(file_util); + FileSystemFileUtilProxy::GetFileInfo( - file_system_operation_context_, proxy_, virtual_path, + operation_context_, proxy_, src_virtual_path_, base::Bind(&FileSystemOperation::DidFileExists, weak_factory_.GetWeakPtr())); } @@ -349,22 +278,13 @@ void FileSystemOperation::GetMetadata(const GURL& path) { DCHECK(kOperationNone == pending_operation_); pending_operation_ = kOperationGetMetadata; #endif - - FilePath virtual_path; - GURL origin_url; - FileSystemType type; - FileSystemFileUtil* file_util; - if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path, - &file_util)) { + if (!SetupSrcContextForRead(path)) { delete this; return; } - file_system_operation_context_.set_src_origin_url(origin_url); - file_system_operation_context_.set_src_type(type); - if (!file_system_operation_context_.src_file_util()) - file_system_operation_context_.set_src_file_util(file_util); + FileSystemFileUtilProxy::GetFileInfo( - file_system_operation_context_, proxy_, virtual_path, + operation_context_, proxy_, src_virtual_path_, base::Bind(&FileSystemOperation::DidGetMetadata, weak_factory_.GetWeakPtr())); } @@ -374,22 +294,13 @@ void FileSystemOperation::ReadDirectory(const GURL& path) { DCHECK(kOperationNone == pending_operation_); pending_operation_ = kOperationReadDirectory; #endif - - FilePath virtual_path; - GURL origin_url; - FileSystemType type; - FileSystemFileUtil* file_util; - if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path, - &file_util)) { + if (!SetupSrcContextForRead(path)) { delete this; return; } - file_system_operation_context_.set_src_origin_url(origin_url); - file_system_operation_context_.set_src_type(type); - if (!file_system_operation_context_.src_file_util()) - file_system_operation_context_.set_src_file_util(file_util); + FileSystemFileUtilProxy::ReadDirectory( - file_system_operation_context_, proxy_, virtual_path, + operation_context_, proxy_, src_virtual_path_, base::Bind(&FileSystemOperation::DidReadDirectory, weak_factory_.GetWeakPtr())); } @@ -399,22 +310,13 @@ void FileSystemOperation::Remove(const GURL& path, bool recursive) { DCHECK(kOperationNone == pending_operation_); pending_operation_ = kOperationRemove; #endif - - FilePath virtual_path; - GURL origin_url; - FileSystemType type; - FileSystemFileUtil* file_util; - if (!VerifyFileSystemPathForWrite(path, false /* create */, &origin_url, - &type, &virtual_path, &file_util)) { + if (!SetupSrcContextForWrite(path, false)) { delete this; return; } - file_system_operation_context_.set_src_origin_url(origin_url); - file_system_operation_context_.set_src_type(type); - if (!file_system_operation_context_.src_file_util()) - file_system_operation_context_.set_src_file_util(file_util); + FileSystemFileUtilProxy::Delete( - file_system_operation_context_, proxy_, virtual_path, recursive, + operation_context_, proxy_, src_virtual_path_, recursive, base::Bind(&FileSystemOperation::DidFinishFileOperation, weak_factory_.GetWeakPtr())); } @@ -428,18 +330,10 @@ void FileSystemOperation::Write( DCHECK(kOperationNone == pending_operation_); pending_operation_ = kOperationWrite; #endif - GURL origin_url; - FileSystemType type; - FileSystemFileUtil* file_util; - if (!VerifyFileSystemPathForWrite(path, true /* create */, &origin_url, - &type, &src_virtual_path_, &file_util)) { + if (!SetupSrcContextForWrite(path, true)) { delete this; return; } - file_system_operation_context_.set_src_origin_url(origin_url); - file_system_operation_context_.set_src_type(type); - if (!file_system_operation_context_.src_file_util()) - file_system_operation_context_.set_src_file_util(file_util); DCHECK(blob_url.is_valid()); file_writer_delegate_.reset(new FileWriterDelegate(this, offset, proxy_)); blob_request_.reset( @@ -447,22 +341,22 @@ void FileSystemOperation::Write( blob_request_->set_context(url_request_context); GetUsageAndQuotaThenCallback( - origin_url, + operation_context_.src_origin_url(), base::Bind(&FileSystemOperation::DelayedWriteForQuota, weak_factory_.GetWeakPtr())); } void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status, int64 usage, int64 quota) { - file_system_operation_context_.set_allowed_bytes_growth(quota - usage); + operation_context_.set_allowed_bytes_growth(quota - usage); quota_util_helper_.reset(new ScopedQuotaUtilHelper( file_system_context(), - file_system_operation_context_.src_origin_url(), - file_system_operation_context_.src_type())); + operation_context_.src_origin_url(), + operation_context_.src_type())); FileSystemFileUtilProxy::CreateOrOpen( - file_system_operation_context_, + operation_context_, proxy_, src_virtual_path_, base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE | @@ -476,37 +370,29 @@ void FileSystemOperation::Truncate(const GURL& path, int64 length) { DCHECK(kOperationNone == pending_operation_); pending_operation_ = kOperationTruncate; #endif - GURL origin_url; - FileSystemType type; - FileSystemFileUtil* file_util; - if (!VerifyFileSystemPathForWrite(path, false /* create */, &origin_url, - &type, &src_virtual_path_, &file_util)) { + if (!SetupSrcContextForWrite(path, false)) { delete this; return; } - file_system_operation_context_.set_src_origin_url(origin_url); - file_system_operation_context_.set_src_type(type); - if (!file_system_operation_context_.src_file_util()) - file_system_operation_context_.set_src_file_util(file_util); length_ = length; GetUsageAndQuotaThenCallback( - origin_url, + operation_context_.src_origin_url(), base::Bind(&FileSystemOperation::DelayedTruncateForQuota, weak_factory_.GetWeakPtr())); } void FileSystemOperation::DelayedTruncateForQuota(quota::QuotaStatusCode status, int64 usage, int64 quota) { - file_system_operation_context_.set_allowed_bytes_growth(quota - usage); + operation_context_.set_allowed_bytes_growth(quota - usage); quota_util_helper_.reset(new ScopedQuotaUtilHelper( file_system_context(), - file_system_operation_context_.src_origin_url(), - file_system_operation_context_.src_type())); + operation_context_.src_origin_url(), + operation_context_.src_type())); FileSystemFileUtilProxy::Truncate( - file_system_operation_context_, proxy_, src_virtual_path_, length_, + operation_context_, proxy_, src_virtual_path_, length_, base::Bind(&FileSystemOperation::DidFinishFileOperation, weak_factory_.GetWeakPtr())); } @@ -518,23 +404,14 @@ void FileSystemOperation::TouchFile(const GURL& path, DCHECK(kOperationNone == pending_operation_); pending_operation_ = kOperationTouchFile; #endif - - FilePath virtual_path; - GURL origin_url; - FileSystemType type; - FileSystemFileUtil* file_util; - if (!VerifyFileSystemPathForWrite(path, true /* create */, &origin_url, - &type, &virtual_path, &file_util)) { + if (!SetupSrcContextForWrite(path, true)) { delete this; return; } - file_system_operation_context_.set_src_origin_url(origin_url); - file_system_operation_context_.set_src_type(type); - if (!file_system_operation_context_.src_file_util()) - file_system_operation_context_.set_src_file_util(file_util); + FileSystemFileUtilProxy::Touch( - file_system_operation_context_, proxy_, virtual_path, last_access_time, - last_modified_time, + operation_context_, proxy_, src_virtual_path_, + last_access_time, last_modified_time, base::Bind(&FileSystemOperation::DidTouchFile, weak_factory_.GetWeakPtr())); } @@ -546,11 +423,8 @@ void FileSystemOperation::OpenFile(const GURL& path, DCHECK(kOperationNone == pending_operation_); pending_operation_ = kOperationOpenFile; #endif - peer_handle_ = peer_handle; - GURL origin_url; - FileSystemType type; - FileSystemFileUtil* file_util; + if (file_flags & ( (base::PLATFORM_FILE_ENUMERATE | base::PLATFORM_FILE_TEMPORARY | base::PLATFORM_FILE_HIDDEN))) { @@ -563,45 +437,56 @@ 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 (!VerifyFileSystemPathForWrite(path, true /* create */, &origin_url, - &type, &src_virtual_path_, &file_util)) { + if (!SetupSrcContextForWrite(path, true)) { delete this; return; } } else { - if (!VerifyFileSystemPathForRead(path, &origin_url, &type, - &src_virtual_path_, &file_util)) { + if (!SetupSrcContextForRead(path)) { delete this; return; } } - file_system_operation_context_.set_src_origin_url(origin_url); - file_system_operation_context_.set_src_type(type); - if (!file_system_operation_context_.src_file_util()) - file_system_operation_context_.set_src_file_util(file_util); file_flags_ = file_flags; GetUsageAndQuotaThenCallback( - origin_url, + operation_context_.src_origin_url(), base::Bind(&FileSystemOperation::DelayedOpenFileForQuota, weak_factory_.GetWeakPtr())); } void FileSystemOperation::DelayedOpenFileForQuota(quota::QuotaStatusCode status, int64 usage, int64 quota) { - file_system_operation_context_.set_allowed_bytes_growth(quota - usage); + operation_context_.set_allowed_bytes_growth(quota - usage); quota_util_helper_.reset(new ScopedQuotaUtilHelper( file_system_context(), - file_system_operation_context_.src_origin_url(), - file_system_operation_context_.src_type())); + operation_context_.src_origin_url(), + operation_context_.src_type())); FileSystemFileUtilProxy::CreateOrOpen( - file_system_operation_context_, proxy_, src_virtual_path_, file_flags_, + operation_context_, proxy_, src_virtual_path_, file_flags_, base::Bind(&FileSystemOperation::DidOpenFile, weak_factory_.GetWeakPtr())); } +void FileSystemOperation::SyncGetPlatformPath(const GURL& path, + FilePath* platform_path) { +#ifndef NDEBUG + DCHECK(kOperationNone == pending_operation_); + pending_operation_ = kOperationGetLocalPath; +#endif + if (!SetupSrcContextForRead(path)) { + delete this; + return; + } + + operation_context_.src_file_util()->GetLocalFilePath( + &operation_context_, src_virtual_path_, platform_path); + + delete this; +} + // 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(FileSystemOperation* cancel_operation_ptr) { @@ -642,7 +527,7 @@ void FileSystemOperation::GetUsageAndQuotaThenCallback( file_system_context()->quota_manager_proxy(); if (!quota_manager_proxy || !file_system_context()->GetQuotaUtil( - file_system_operation_context_.src_type())) { + operation_context_.src_type())) { // If we don't have the quota manager or the requested filesystem type // does not support quota, we should be able to let it go. callback.Run(quota::kQuotaStatusOk, 0, kint64max); @@ -651,9 +536,9 @@ void FileSystemOperation::GetUsageAndQuotaThenCallback( DCHECK(quota_manager_proxy); DCHECK(quota_manager_proxy->quota_manager()); quota_manager_proxy->quota_manager()->GetUsageAndQuota( - file_system_operation_context_.src_origin_url(), + operation_context_.src_origin_url(), FileSystemTypeToQuotaStorageType( - file_system_operation_context_.src_type()), + operation_context_.src_type()), callback); } @@ -666,8 +551,8 @@ void FileSystemOperation::DidGetRootPath( // that we could create/find the path. if (success) { result = GetFileSystemRootURI( - file_system_operation_context_.src_origin_url(), - file_system_operation_context_.src_type()); + operation_context_.src_origin_url(), + operation_context_.src_type()); } dispatcher_->DidOpenFileSystem(name, result); delete this; @@ -819,8 +704,8 @@ bool FileSystemOperation::VerifyFileSystemPathForRead( #else *virtual_path = FilePath(path.path()); #endif - *type = file_system_operation_context_.src_type(); - *origin_url = file_system_operation_context_.src_origin_url(); + *type = operation_context_.src_type(); + *origin_url = operation_context_.src_origin_url(); *file_util = NULL; return true; } @@ -874,8 +759,8 @@ bool FileSystemOperation::VerifyFileSystemPathForWrite( #else *virtual_path = FilePath(path.path()); #endif - *type = file_system_operation_context_.dest_type(); - *origin_url = file_system_operation_context_.dest_origin_url(); + *type = operation_context_.dest_type(); + *origin_url = operation_context_.dest_origin_url(); *file_util = NULL; return true; } @@ -907,4 +792,45 @@ bool FileSystemOperation::VerifyFileSystemPathForWrite( return true; } +bool FileSystemOperation::SetupSrcContextForRead(const GURL& path) { + GURL origin_url; + FileSystemType type; + FileSystemFileUtil* file_util; + bool 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); + if (!operation_context_.src_file_util()) + operation_context_.set_src_file_util(file_util); + return result; +} + +bool FileSystemOperation::SetupSrcContextForWrite(const GURL& path, + bool create) { + GURL origin_url; + FileSystemType type; + FileSystemFileUtil* file_util; + bool 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); + if (!operation_context_.src_file_util()) + operation_context_.set_src_file_util(file_util); + return result; +} + +bool FileSystemOperation::SetupDestContextForWrite(const GURL& path, + bool create) { + GURL origin_url; + FileSystemType type; + FileSystemFileUtil* file_util; + bool 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); + if (!operation_context_.dest_file_util()) + operation_context_.set_dest_file_util(file_util); + return result; +} + } // namespace fileapi diff --git a/webkit/fileapi/file_system_operation.h b/webkit/fileapi/file_system_operation.h index 3cfa69f..ccfb033 100644 --- a/webkit/fileapi/file_system_operation.h +++ b/webkit/fileapi/file_system_operation.h @@ -50,12 +50,9 @@ class FileSystemQuotaUtil; class FileSystemOperation { public: // |dispatcher| will be owned by this class. - // |file_util| is optional; if supplied, it will not be deleted by - // the class. It's expecting a pointer to a singleton. FileSystemOperation(FileSystemCallbackDispatcher* dispatcher, scoped_refptr<base::MessageLoopProxy> proxy, - FileSystemContext* file_system_context, - FileSystemFileUtil* file_util); + FileSystemContext* file_system_context); virtual ~FileSystemOperation(); void OpenFileSystem(const GURL& origin_url, @@ -87,6 +84,7 @@ class FileSystemOperation { const GURL& path, int file_flags, base::ProcessHandle peer_handle); + void SyncGetPlatformPath(const GURL& path, FilePath* platform_path); // Try to cancel the current operation [we support cancelling write or // truncate only]. Report failure for the current operation, then tell the @@ -97,11 +95,11 @@ class FileSystemOperation { class ScopedQuotaUtilHelper; FileSystemContext* file_system_context() const { - return file_system_operation_context_.file_system_context(); + return operation_context_.file_system_context(); } FileSystemOperationContext* file_system_operation_context() { - return &file_system_operation_context_; + return &operation_context_; } friend class FileSystemOperationTest; @@ -110,6 +108,14 @@ class FileSystemOperation { friend class FileSystemTestOriginHelper; friend class FileSystemQuotaTest; + // The unit tests that need to specify and control the lifetime of the + // file_util on their own should call this before performing the actual + // operation. If it is given it will not be overwritten by the class. + void set_override_file_util(FileSystemFileUtil* file_util) { + operation_context_.set_src_file_util(file_util); + operation_context_.set_dest_file_util(file_util); + } + void GetUsageAndQuotaThenCallback( const GURL& origin_url, const quota::QuotaManager::GetUsageAndQuotaCallback& callback); @@ -209,6 +215,14 @@ class FileSystemOperation { FilePath* virtual_path, FileSystemFileUtil** file_util); + // Setup*Context*() functions will call the appropriate VerifyFileSystem + // function and store the results to operation_context_ and + // *_virtual_path_. + // Return the result of VerifyFileSystem*(). + bool SetupSrcContextForRead(const GURL& path); + bool SetupSrcContextForWrite(const GURL& path, bool create); + bool SetupDestContextForWrite(const GURL& path, bool create); + #ifndef NDEBUG enum OperationType { kOperationNone, @@ -239,7 +253,7 @@ class FileSystemOperation { scoped_ptr<FileSystemCallbackDispatcher> dispatcher_; - FileSystemOperationContext file_system_operation_context_; + FileSystemOperationContext operation_context_; base::WeakPtrFactory<FileSystemOperation> weak_factory_; diff --git a/webkit/fileapi/file_system_test_helper.cc b/webkit/fileapi/file_system_test_helper.cc index 6422f66..9f68043 100644 --- a/webkit/fileapi/file_system_test_helper.cc +++ b/webkit/fileapi/file_system_test_helper.cc @@ -152,8 +152,8 @@ FileSystemOperation* FileSystemTestOriginHelper::NewOperation( FileSystemOperation* operation = new FileSystemOperation(callback_dispatcher, base::MessageLoopProxy::current(), - file_system_context_.get(), - file_util_); + file_system_context_.get()); + operation->set_override_file_util(file_util_); InitializeOperationContext(operation->file_system_operation_context()); return operation; } diff --git a/webkit/fileapi/file_system_url_request_job.cc b/webkit/fileapi/file_system_url_request_job.cc index 1876280..55379f9 100644 --- a/webkit/fileapi/file_system_url_request_job.cc +++ b/webkit/fileapi/file_system_url_request_job.cc @@ -216,8 +216,8 @@ void FileSystemURLRequestJob::StartAsync() { if (request_) { (new FileSystemOperation(new CallbackDispatcher(this), file_thread_proxy_, - file_system_context_, - NULL))->GetMetadata(request_->url()); + file_system_context_) + )->GetMetadata(request_->url()); } } diff --git a/webkit/tools/test_shell/simple_file_system.cc b/webkit/tools/test_shell/simple_file_system.cc index 08718d1..3a50d61 100644 --- a/webkit/tools/test_shell/simple_file_system.cc +++ b/webkit/tools/test_shell/simple_file_system.cc @@ -231,6 +231,6 @@ FileSystemOperation* SimpleFileSystem::GetNewOperation( new SimpleFileSystemCallbackDispatcher(AsWeakPtr(), callbacks); FileSystemOperation* operation = new FileSystemOperation( dispatcher, base::MessageLoopProxy::current(), - file_system_context_.get(), NULL); + file_system_context_.get()); return operation; } diff --git a/webkit/tools/test_shell/simple_file_writer.cc b/webkit/tools/test_shell/simple_file_writer.cc index 5956696..dfa37ba 100644 --- a/webkit/tools/test_shell/simple_file_writer.cc +++ b/webkit/tools/test_shell/simple_file_writer.cc @@ -130,8 +130,7 @@ class SimpleFileWriter::IOThreadProxy FileSystemOperation* GetNewOperation() { // The FileSystemOperation takes ownership of the CallbackDispatcher. return new FileSystemOperation(new CallbackDispatcher(this), - io_thread_, file_system_context_.get(), - NULL); + io_thread_, file_system_context_.get()); } void DidSucceed() { |