diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-10 04:57:15 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-10 04:57:15 +0000 |
commit | 5dfa47c9d9d5a2350b9ea8f362c4987ceed7bdda (patch) | |
tree | a6d33f1cd82419d68d810cccb3eb10e346a03109 /webkit | |
parent | 70afd12a7d12ce853c3da07e3d24be2313e43e84 (diff) | |
download | chromium_src-5dfa47c9d9d5a2350b9ea8f362c4987ceed7bdda.zip chromium_src-5dfa47c9d9d5a2350b9ea8f362c4987ceed7bdda.tar.gz chromium_src-5dfa47c9d9d5a2350b9ea8f362c4987ceed7bdda.tar.bz2 |
Deprecate LocalFileSystemOperation::SetUp
Move update and access observers setup to FileSystemOperationRunner.
BUG=176444
NOTRY=true
Review URL: https://chromiumcodereview.appspot.com/16447003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@205146 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
10 files changed, 98 insertions, 268 deletions
diff --git a/webkit/browser/chromeos/fileapi/cros_mount_point_provider.cc b/webkit/browser/chromeos/fileapi/cros_mount_point_provider.cc index 92fa828..d8c817c 100644 --- a/webkit/browser/chromeos/fileapi/cros_mount_point_provider.cc +++ b/webkit/browser/chromeos/fileapi/cros_mount_point_provider.cc @@ -285,7 +285,7 @@ fileapi::FileSystemOperation* CrosMountPointProvider::CreateFileSystemOperation( scoped_ptr<fileapi::FileSystemOperationContext> operation_context( new fileapi::FileSystemOperationContext(context)); operation_context->set_root_path(GetFileSystemRootPath(url)); - return new fileapi::LocalFileSystemOperation(context, + return new fileapi::LocalFileSystemOperation(url, context, operation_context.Pass()); } diff --git a/webkit/browser/fileapi/file_system_operation_runner.cc b/webkit/browser/fileapi/file_system_operation_runner.cc index 123eb79..e5d141b 100644 --- a/webkit/browser/fileapi/file_system_operation_runner.cc +++ b/webkit/browser/fileapi/file_system_operation_runner.cc @@ -5,6 +5,7 @@ #include "webkit/browser/fileapi/file_system_operation_runner.h" #include "base/bind.h" +#include "webkit/browser/fileapi/file_observers.h" #include "webkit/browser/fileapi/file_system_context.h" #include "webkit/browser/fileapi/local_file_system_operation.h" #include "webkit/common/blob/shareable_file_reference.h" @@ -30,6 +31,7 @@ OperationID FileSystemOperationRunner::CreateFile( return kErrorOperationID; } OperationID id = operations_.Add(operation); + PrepareForWrite(id, url); operation->CreateFile( url, exclusive, base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), @@ -50,6 +52,7 @@ OperationID FileSystemOperationRunner::CreateDirectory( return kErrorOperationID; } OperationID id = operations_.Add(operation); + PrepareForWrite(id, url); operation->CreateDirectory( url, exclusive, recursive, base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), @@ -69,6 +72,8 @@ OperationID FileSystemOperationRunner::Copy( return kErrorOperationID; } OperationID id = operations_.Add(operation); + PrepareForWrite(id, dest_url); + PrepareForRead(id, src_url); operation->Copy( src_url, dest_url, base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), @@ -88,6 +93,8 @@ OperationID FileSystemOperationRunner::Move( return kErrorOperationID; } OperationID id = operations_.Add(operation); + PrepareForWrite(id, dest_url); + PrepareForWrite(id, src_url); operation->Move( src_url, dest_url, base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), @@ -106,6 +113,7 @@ OperationID FileSystemOperationRunner::DirectoryExists( return kErrorOperationID; } OperationID id = operations_.Add(operation); + PrepareForRead(id, url); operation->DirectoryExists( url, base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), @@ -124,6 +132,7 @@ OperationID FileSystemOperationRunner::FileExists( return kErrorOperationID; } OperationID id = operations_.Add(operation); + PrepareForRead(id, url); operation->FileExists( url, base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), @@ -142,6 +151,7 @@ OperationID FileSystemOperationRunner::GetMetadata( return kErrorOperationID; } OperationID id = operations_.Add(operation); + PrepareForRead(id, url); operation->GetMetadata( url, base::Bind(&FileSystemOperationRunner::DidGetMetadata, AsWeakPtr(), @@ -160,6 +170,7 @@ OperationID FileSystemOperationRunner::ReadDirectory( return kErrorOperationID; } OperationID id = operations_.Add(operation); + PrepareForRead(id, url); operation->ReadDirectory( url, base::Bind(&FileSystemOperationRunner::DidReadDirectory, AsWeakPtr(), @@ -178,6 +189,7 @@ OperationID FileSystemOperationRunner::Remove( return kErrorOperationID; } OperationID id = operations_.Add(operation); + PrepareForWrite(id, url); operation->Remove( url, recursive, base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), @@ -199,6 +211,7 @@ OperationID FileSystemOperationRunner::Write( return kErrorOperationID; } OperationID id = operations_.Add(operation); + PrepareForWrite(id, url); operation->Write( url_request_context, url, blob_url, offset, base::Bind(&FileSystemOperationRunner::DidWrite, AsWeakPtr(), @@ -217,6 +230,7 @@ OperationID FileSystemOperationRunner::Truncate( return kErrorOperationID; } OperationID id = operations_.Add(operation); + PrepareForWrite(id, url); operation->Truncate( url, length, base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), @@ -249,6 +263,7 @@ OperationID FileSystemOperationRunner::TouchFile( return kErrorOperationID; } OperationID id = operations_.Add(operation); + PrepareForWrite(id, url); operation->TouchFile( url, last_access_time, last_modified_time, base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), @@ -270,6 +285,16 @@ OperationID FileSystemOperationRunner::OpenFile( return kErrorOperationID; } OperationID id = operations_.Add(operation); + if (file_flags & + (base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_OPEN_ALWAYS | + base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_TRUNCATED | + base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | + base::PLATFORM_FILE_DELETE_ON_CLOSE | + base::PLATFORM_FILE_WRITE_ATTRIBUTES)) { + PrepareForWrite(id, url); + } else { + PrepareForRead(id, url); + } operation->OpenFile( url, file_flags, peer_handle, base::Bind(&FileSystemOperationRunner::DidOpenFile, AsWeakPtr(), @@ -288,6 +313,7 @@ OperationID FileSystemOperationRunner::CreateSnapshotFile( return kErrorOperationID; } OperationID id = operations_.Add(operation); + PrepareForRead(id, url); operation->CreateSnapshotFile( url, base::Bind(&FileSystemOperationRunner::DidCreateSnapshot, AsWeakPtr(), @@ -408,8 +434,7 @@ void FileSystemOperationRunner::DidFinish( const StatusCallback& callback, base::PlatformFileError rv) { callback.Run(rv); - DCHECK(operations_.Lookup(id)); - operations_.Remove(id); + FinishOperation(id); } void FileSystemOperationRunner::DidGetMetadata( @@ -419,8 +444,7 @@ void FileSystemOperationRunner::DidGetMetadata( const base::PlatformFileInfo& file_info, const base::FilePath& platform_path) { callback.Run(rv, file_info, platform_path); - DCHECK(operations_.Lookup(id)); - operations_.Remove(id); + FinishOperation(id); } void FileSystemOperationRunner::DidReadDirectory( @@ -430,10 +454,8 @@ void FileSystemOperationRunner::DidReadDirectory( const std::vector<DirectoryEntry>& entries, bool has_more) { callback.Run(rv, entries, has_more); - if (rv != base::PLATFORM_FILE_OK || !has_more) { - DCHECK(operations_.Lookup(id)); - operations_.Remove(id); - } + if (rv != base::PLATFORM_FILE_OK || !has_more) + FinishOperation(id); } void FileSystemOperationRunner::DidWrite( @@ -443,10 +465,8 @@ void FileSystemOperationRunner::DidWrite( int64 bytes, bool complete) { callback.Run(rv, bytes, complete); - if (rv != base::PLATFORM_FILE_OK || complete) { - DCHECK(operations_.Lookup(id)); - operations_.Remove(id); - } + if (rv != base::PLATFORM_FILE_OK || complete) + FinishOperation(id); } void FileSystemOperationRunner::DidOpenFile( @@ -457,8 +477,7 @@ void FileSystemOperationRunner::DidOpenFile( const base::Closure& on_close_callback, base::ProcessHandle peer_handle) { callback.Run(rv, file, on_close_callback, peer_handle); - DCHECK(operations_.Lookup(id)); - operations_.Remove(id); + FinishOperation(id); } void FileSystemOperationRunner::DidCreateSnapshot( @@ -469,8 +488,7 @@ void FileSystemOperationRunner::DidCreateSnapshot( const base::FilePath& platform_path, const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { callback.Run(rv, file_info, platform_path, file_ref); - DCHECK(operations_.Lookup(id)); - operations_.Remove(id); + FinishOperation(id); } FileSystemOperation* @@ -488,4 +506,38 @@ FileSystemOperationRunner::CreateLocalFileSystemOperation( return operation; } +void FileSystemOperationRunner::PrepareForWrite(OperationID id, + const FileSystemURL& url) { + if (file_system_context_->GetUpdateObservers(url.type())) { + file_system_context_->GetUpdateObservers(url.type())->Notify( + &FileUpdateObserver::OnStartUpdate, MakeTuple(url)); + } + write_target_urls_[id].insert(url); +} + +void FileSystemOperationRunner::PrepareForRead(OperationID id, + const FileSystemURL& url) { + if (file_system_context_->GetAccessObservers(url.type())) { + file_system_context_->GetAccessObservers(url.type())->Notify( + &FileAccessObserver::OnAccess, MakeTuple(url)); + } +} + +void FileSystemOperationRunner::FinishOperation(OperationID id) { + OperationToURLSet::iterator found = write_target_urls_.find(id); + if (found != write_target_urls_.end()) { + const FileSystemURLSet& urls = found->second; + for (FileSystemURLSet::const_iterator iter = urls.begin(); + iter != urls.end(); ++iter) { + if (file_system_context_->GetUpdateObservers(iter->type())) { + file_system_context_->GetUpdateObservers(iter->type())->Notify( + &FileUpdateObserver::OnEndUpdate, MakeTuple(*iter)); + } + } + write_target_urls_.erase(found); + } + DCHECK(operations_.Lookup(id)); + operations_.Remove(id); +} + } // namespace fileapi diff --git a/webkit/browser/fileapi/file_system_operation_runner.h b/webkit/browser/fileapi/file_system_operation_runner.h index a917eb3..9c2dd85 100644 --- a/webkit/browser/fileapi/file_system_operation_runner.h +++ b/webkit/browser/fileapi/file_system_operation_runner.h @@ -5,11 +5,14 @@ #ifndef WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_RUNNER_H_ #define WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_RUNNER_H_ +#include <map> + #include "base/basictypes.h" #include "base/id_map.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "webkit/browser/fileapi/file_system_operation.h" +#include "webkit/browser/fileapi/file_system_url.h" #include "webkit/storage/webkit_storage_export.h" namespace fileapi { @@ -263,12 +266,23 @@ class WEBKIT_STORAGE_EXPORT FileSystemOperationRunner const FileSystemURL& url, base::PlatformFileError* error); + void PrepareForWrite(OperationID id, const FileSystemURL& url); + void PrepareForRead(OperationID id, const FileSystemURL& url); + + // This must be called at the end of any async operations. + void FinishOperation(OperationID id); + // Not owned; file_system_context owns this. FileSystemContext* file_system_context_; // IDMap<FileSystemOperation, IDMapOwnPointer> operations_; IDMap<FileSystemOperation> operations_; + // We keep track of the file to be modified by each operation so that + // we can notify observers when we're done. + typedef std::map<OperationID, FileSystemURLSet> OperationToURLSet; + OperationToURLSet write_target_urls_; + DISALLOW_COPY_AND_ASSIGN(FileSystemOperationRunner); }; diff --git a/webkit/browser/fileapi/isolated_mount_point_provider.cc b/webkit/browser/fileapi/isolated_mount_point_provider.cc index 8c78df0..b4e501f 100644 --- a/webkit/browser/fileapi/isolated_mount_point_provider.cc +++ b/webkit/browser/fileapi/isolated_mount_point_provider.cc @@ -122,7 +122,7 @@ FileSystemOperation* IsolatedMountPointProvider::CreateFileSystemOperation( FileSystemContext* context, base::PlatformFileError* error_code) const { return new LocalFileSystemOperation( - context, make_scoped_ptr(new FileSystemOperationContext(context))); + url, context, make_scoped_ptr(new FileSystemOperationContext(context))); } scoped_ptr<webkit_blob::FileStreamReader> diff --git a/webkit/browser/fileapi/local_file_system_operation.cc b/webkit/browser/fileapi/local_file_system_operation.cc index cd49b2a..c14a3e4d 100644 --- a/webkit/browser/fileapi/local_file_system_operation.cc +++ b/webkit/browser/fileapi/local_file_system_operation.cc @@ -38,6 +38,7 @@ void NopCloseFileCallback() {} } LocalFileSystemOperation::LocalFileSystemOperation( + const FileSystemURL& url, FileSystemContext* file_system_context, scoped_ptr<FileSystemOperationContext> operation_context) : file_system_context_(file_system_context), @@ -48,30 +49,17 @@ LocalFileSystemOperation::LocalFileSystemOperation( weak_factory_(this) { DCHECK(operation_context_.get()); operation_context_->DetachUserDataThread(); + async_file_util_ = file_system_context_->GetAsyncFileUtil(url.type()); + DCHECK(async_file_util_); } LocalFileSystemOperation::~LocalFileSystemOperation() { - for (FileSystemURLSet::iterator iter = write_target_url_.begin(); - iter != write_target_url_.end(); ++iter) { - if (file_system_context_->GetUpdateObservers(iter->type())) { - file_system_context_->GetUpdateObservers(iter->type())->Notify( - &FileUpdateObserver::OnEndUpdate, MakeTuple(*iter)); - } - } } void LocalFileSystemOperation::CreateFile(const FileSystemURL& url, bool exclusive, const StatusCallback& callback) { DCHECK(SetPendingOperationType(kOperationCreateFile)); - - base::PlatformFileError result = SetUp(url, OPERATION_MODE_WRITE); - if (result != base::PLATFORM_FILE_OK) { - callback.Run(result); - delete this; - return; - } - GetUsageAndQuotaThenRunTask( url, base::Bind(&LocalFileSystemOperation::DoCreateFile, @@ -84,13 +72,6 @@ void LocalFileSystemOperation::CreateDirectory(const FileSystemURL& url, bool recursive, const StatusCallback& callback) { DCHECK(SetPendingOperationType(kOperationCreateDirectory)); - - base::PlatformFileError result = SetUp(url, OPERATION_MODE_WRITE); - if (result != base::PLATFORM_FILE_OK) { - callback.Run(result); - delete this; - return; - } GetUsageAndQuotaThenRunTask( url, base::Bind(&LocalFileSystemOperation::DoCreateDirectory, @@ -102,21 +83,6 @@ void LocalFileSystemOperation::Copy(const FileSystemURL& src_url, const FileSystemURL& dest_url, const StatusCallback& callback) { DCHECK(SetPendingOperationType(kOperationCopy)); - - // Setting up this (dest) operation. - base::PlatformFileError result = SetUp(dest_url, OPERATION_MODE_WRITE); - if (result != base::PLATFORM_FILE_OK) { - callback.Run(result); - delete this; - return; - } - - // Notify access_observer of access on src_url. - if (file_system_context_->GetAccessObservers(src_url.type())) { - file_system_context_->GetAccessObservers(src_url.type())->Notify( - &FileAccessObserver::OnAccess, MakeTuple(src_url)); - } - DCHECK(!recursive_operation_delegate_); recursive_operation_delegate_.reset( new CopyOrMoveOperationDelegate( @@ -132,22 +98,6 @@ void LocalFileSystemOperation::Move(const FileSystemURL& src_url, const FileSystemURL& dest_url, const StatusCallback& callback) { DCHECK(SetPendingOperationType(kOperationMove)); - - // Setting up this (dest) operation. - base::PlatformFileError result = SetUp(dest_url, OPERATION_MODE_WRITE); - if (result != base::PLATFORM_FILE_OK) { - callback.Run(result); - delete this; - return; - } - - // Notify update_observer of write access on src_url. - if (file_system_context_->GetUpdateObservers(src_url.type())) { - file_system_context_->GetUpdateObservers(src_url.type())->Notify( - &FileUpdateObserver::OnStartUpdate, MakeTuple(src_url)); - } - write_target_url_.insert(src_url); - DCHECK(!recursive_operation_delegate_); recursive_operation_delegate_.reset( new CopyOrMoveOperationDelegate( @@ -162,14 +112,6 @@ void LocalFileSystemOperation::Move(const FileSystemURL& src_url, void LocalFileSystemOperation::DirectoryExists(const FileSystemURL& url, const StatusCallback& callback) { DCHECK(SetPendingOperationType(kOperationDirectoryExists)); - - base::PlatformFileError result = SetUp(url, OPERATION_MODE_READ); - if (result != base::PLATFORM_FILE_OK) { - callback.Run(result); - delete this; - return; - } - async_file_util_->GetFileInfo( operation_context(), url, base::Bind(&LocalFileSystemOperation::DidDirectoryExists, @@ -179,14 +121,6 @@ void LocalFileSystemOperation::DirectoryExists(const FileSystemURL& url, void LocalFileSystemOperation::FileExists(const FileSystemURL& url, const StatusCallback& callback) { DCHECK(SetPendingOperationType(kOperationFileExists)); - - base::PlatformFileError result = SetUp(url, OPERATION_MODE_READ); - if (result != base::PLATFORM_FILE_OK) { - callback.Run(result); - delete this; - return; - } - async_file_util_->GetFileInfo( operation_context(), url, base::Bind(&LocalFileSystemOperation::DidFileExists, @@ -196,14 +130,6 @@ void LocalFileSystemOperation::FileExists(const FileSystemURL& url, void LocalFileSystemOperation::GetMetadata( const FileSystemURL& url, const GetMetadataCallback& callback) { DCHECK(SetPendingOperationType(kOperationGetMetadata)); - - base::PlatformFileError result = SetUp(url, OPERATION_MODE_READ); - if (result != base::PLATFORM_FILE_OK) { - callback.Run(result, base::PlatformFileInfo(), base::FilePath()); - delete this; - return; - } - async_file_util_->GetFileInfo( operation_context(), url, base::Bind(&LocalFileSystemOperation::DidGetMetadata, @@ -213,14 +139,6 @@ void LocalFileSystemOperation::GetMetadata( void LocalFileSystemOperation::ReadDirectory( const FileSystemURL& url, const ReadDirectoryCallback& callback) { DCHECK(SetPendingOperationType(kOperationReadDirectory)); - - base::PlatformFileError result = SetUp(url, OPERATION_MODE_READ); - if (result != base::PLATFORM_FILE_OK) { - callback.Run(result, std::vector<DirectoryEntry>(), false); - delete this; - return; - } - async_file_util_->ReadDirectory( operation_context(), url, base::Bind(&LocalFileSystemOperation::DidReadDirectory, @@ -231,14 +149,6 @@ void LocalFileSystemOperation::Remove(const FileSystemURL& url, bool recursive, const StatusCallback& callback) { DCHECK(SetPendingOperationType(kOperationRemove)); - - base::PlatformFileError result = SetUp(url, OPERATION_MODE_WRITE); - if (result != base::PLATFORM_FILE_OK) { - callback.Run(result); - delete this; - return; - } - DCHECK(!recursive_operation_delegate_); recursive_operation_delegate_.reset( new RemoveOperationDelegate( @@ -263,13 +173,6 @@ void LocalFileSystemOperation::Write( void LocalFileSystemOperation::Truncate(const FileSystemURL& url, int64 length, const StatusCallback& callback) { DCHECK(SetPendingOperationType(kOperationTruncate)); - - base::PlatformFileError result = SetUp(url, OPERATION_MODE_WRITE); - if (result != base::PLATFORM_FILE_OK) { - callback.Run(result); - delete this; - return; - } GetUsageAndQuotaThenRunTask( url, base::Bind(&LocalFileSystemOperation::DoTruncate, @@ -282,14 +185,6 @@ void LocalFileSystemOperation::TouchFile(const FileSystemURL& url, const base::Time& last_modified_time, const StatusCallback& callback) { DCHECK(SetPendingOperationType(kOperationTouchFile)); - - base::PlatformFileError result = SetUp(url, OPERATION_MODE_WRITE); - if (result != base::PLATFORM_FILE_OK) { - callback.Run(result); - delete this; - return; - } - async_file_util_->Touch( operation_context(), url, last_access_time, last_modified_time, @@ -315,30 +210,6 @@ void LocalFileSystemOperation::OpenFile(const FileSystemURL& url, base::kNullProcessHandle); return; } - if (file_flags & - (base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_OPEN_ALWAYS | - base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_TRUNCATED | - base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | - base::PLATFORM_FILE_DELETE_ON_CLOSE | - base::PLATFORM_FILE_WRITE_ATTRIBUTES)) { - base::PlatformFileError result = SetUp(url, OPERATION_MODE_WRITE); - if (result != base::PLATFORM_FILE_OK) { - callback.Run(result, - base::kInvalidPlatformFileValue, - base::Closure(), - base::kNullProcessHandle); - return; - } - } else { - base::PlatformFileError result = SetUp(url, OPERATION_MODE_READ); - if (result != base::PLATFORM_FILE_OK) { - callback.Run(result, - base::kInvalidPlatformFileValue, - base::Closure(), - base::kNullProcessHandle); - return; - } - } GetUsageAndQuotaThenRunTask( url, base::Bind(&LocalFileSystemOperation::DoOpenFile, @@ -391,13 +262,6 @@ LocalFileSystemOperation::AsLocalFileSystemOperation() { void LocalFileSystemOperation::SyncGetPlatformPath(const FileSystemURL& url, base::FilePath* platform_path) { DCHECK(SetPendingOperationType(kOperationGetLocalPath)); - - base::PlatformFileError result = SetUp(url, OPERATION_MODE_READ); - if (result != base::PLATFORM_FILE_OK) { - delete this; - return; - } - FileSystemFileUtil* file_util = file_system_context()->GetFileUtil( url.type()); DCHECK(file_util); @@ -410,14 +274,6 @@ void LocalFileSystemOperation::CreateSnapshotFile( const FileSystemURL& url, const SnapshotFileCallback& callback) { DCHECK(SetPendingOperationType(kOperationCreateSnapshotFile)); - - base::PlatformFileError result = SetUp(url, OPERATION_MODE_READ); - if (result != base::PLATFORM_FILE_OK) { - callback.Run(result, base::PlatformFileInfo(), base::FilePath(), NULL); - delete this; - return; - } - async_file_util_->CreateSnapshotFile( operation_context(), url, base::Bind(&LocalFileSystemOperation::DidCreateSnapshotFile, @@ -429,14 +285,6 @@ void LocalFileSystemOperation::CopyInForeignFile( const FileSystemURL& dest_url, const StatusCallback& callback) { DCHECK(SetPendingOperationType(kOperationCopyInForeignFile)); - - base::PlatformFileError result = SetUp(dest_url, OPERATION_MODE_WRITE); - if (result != base::PLATFORM_FILE_OK) { - callback.Run(result); - delete this; - return; - } - GetUsageAndQuotaThenRunTask( dest_url, base::Bind(&LocalFileSystemOperation::DoCopyInForeignFile, @@ -449,13 +297,6 @@ void LocalFileSystemOperation::RemoveFile( const FileSystemURL& url, const StatusCallback& callback) { DCHECK(SetPendingOperationType(kOperationRemove)); - base::PlatformFileError result = SetUp(url, OPERATION_MODE_NESTED); - if (result != base::PLATFORM_FILE_OK) { - callback.Run(result); - delete this; - return; - } - async_file_util_->DeleteFile( operation_context(), url, base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, @@ -466,13 +307,6 @@ void LocalFileSystemOperation::RemoveDirectory( const FileSystemURL& url, const StatusCallback& callback) { DCHECK(SetPendingOperationType(kOperationRemove)); - base::PlatformFileError result = SetUp(url, OPERATION_MODE_NESTED); - if (result != base::PLATFORM_FILE_OK) { - callback.Run(result); - delete this; - return; - } - async_file_util_->DeleteDirectory( operation_context(), url, base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, @@ -485,16 +319,6 @@ void LocalFileSystemOperation::CopyFileLocal( const StatusCallback& callback) { DCHECK(SetPendingOperationType(kOperationCopy)); DCHECK(src_url.IsInSameFileSystem(dest_url)); - - base::PlatformFileError result = SetUp(src_url, OPERATION_MODE_NESTED); - if (result == base::PLATFORM_FILE_OK) - result = SetUp(dest_url, OPERATION_MODE_NESTED); - if (result != base::PLATFORM_FILE_OK) { - callback.Run(result); - delete this; - return; - } - GetUsageAndQuotaThenRunTask( dest_url, base::Bind(&LocalFileSystemOperation::DoCopyFileLocal, @@ -508,16 +332,6 @@ void LocalFileSystemOperation::MoveFileLocal( const StatusCallback& callback) { DCHECK(SetPendingOperationType(kOperationMove)); DCHECK(src_url.IsInSameFileSystem(dest_url)); - - base::PlatformFileError result = SetUp(src_url, OPERATION_MODE_NESTED); - if (result == base::PLATFORM_FILE_OK) - result = SetUp(dest_url, OPERATION_MODE_NESTED); - if (result != base::PLATFORM_FILE_OK) { - callback.Run(result); - delete this; - return; - } - GetUsageAndQuotaThenRunTask( dest_url, base::Bind(&LocalFileSystemOperation::DoMoveFileLocal, @@ -571,13 +385,6 @@ base::Closure LocalFileSystemOperation::GetWriteClosure( int64 offset, const WriteCallback& callback) { DCHECK(SetPendingOperationType(kOperationWrite)); - - base::PlatformFileError result = SetUp(url, OPERATION_MODE_WRITE); - if (result != base::PLATFORM_FILE_OK) { - return base::Bind(&LocalFileSystemOperation::DidFailWrite, - base::Owned(this), callback, result); - } - scoped_ptr<FileStreamWriter> writer( file_system_context()->CreateFileStreamWriter(url, offset)); @@ -807,36 +614,6 @@ void LocalFileSystemOperation::DidCreateSnapshotFile( callback.Run(result, file_info, platform_path, file_ref); } -base::PlatformFileError LocalFileSystemOperation::SetUp( - const FileSystemURL& url, - OperationMode mode) { - DCHECK(url.is_valid()); - - async_file_util_ = file_system_context()->GetAsyncFileUtil(url.type()); - if (!async_file_util_) - return base::PLATFORM_FILE_ERROR_SECURITY; - - switch (mode) { - case OPERATION_MODE_READ: - if (file_system_context_->GetAccessObservers(url.type())) { - file_system_context_->GetAccessObservers(url.type())->Notify( - &FileAccessObserver::OnAccess, MakeTuple(url)); - } - break; - case OPERATION_MODE_WRITE: - if (file_system_context_->GetUpdateObservers(url.type())) { - file_system_context_->GetUpdateObservers(url.type())->Notify( - &FileUpdateObserver::OnStartUpdate, MakeTuple(url)); - } - write_target_url_.insert(url); - break; - case OPERATION_MODE_NESTED: - break; - } - - return base::PLATFORM_FILE_OK; -} - bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) { if (pending_operation_ != kOperationNone) return false; diff --git a/webkit/browser/fileapi/local_file_system_operation.h b/webkit/browser/fileapi/local_file_system_operation.h index 8daddc5..35ab32b 100644 --- a/webkit/browser/fileapi/local_file_system_operation.h +++ b/webkit/browser/fileapi/local_file_system_operation.h @@ -39,6 +39,7 @@ class WEBKIT_STORAGE_EXPORT LocalFileSystemOperation // file_system_context->CreateFileSystemOperation() to instantiate // an appropriate FileSystemOperation. LocalFileSystemOperation( + const FileSystemURL& url, FileSystemContext* file_system_context, scoped_ptr<FileSystemOperationContext> operation_context); @@ -169,15 +170,6 @@ class WEBKIT_STORAGE_EXPORT LocalFileSystemOperation } private: - enum OperationMode { - OPERATION_MODE_READ, - OPERATION_MODE_WRITE, - - // Indicates the operation is only for a nested operation of a - // larger recursive operation. - OPERATION_MODE_NESTED, - }; - friend class sync_file_system::SyncableFileSystemOperation; // Queries the quota and usage and then runs the given |task|. @@ -282,11 +274,6 @@ class WEBKIT_STORAGE_EXPORT LocalFileSystemOperation const base::FilePath& platform_path, const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref); - // Checks the validity of a given |url| and populates |file_util| for |mode|. - base::PlatformFileError SetUp( - const FileSystemURL& url, - OperationMode mode); - // Used only for internal assertions. // Returns false if there's another inflight pending operation. bool SetPendingOperationType(OperationType type); @@ -316,10 +303,6 @@ class WEBKIT_STORAGE_EXPORT LocalFileSystemOperation // A flag to make sure we call operation only once per instance. OperationType pending_operation_; - // We keep track of the file to be modified by this operation so that - // we can notify observers when we're done. - FileSystemURLSet write_target_url_; - // LocalFileSystemOperation instance is usually deleted upon completion but // could be deleted while it has inflight callbacks when Cancel is called. base::WeakPtrFactory<LocalFileSystemOperation> weak_factory_; diff --git a/webkit/browser/fileapi/sandbox_mount_point_provider.cc b/webkit/browser/fileapi/sandbox_mount_point_provider.cc index 6289697..022eb59 100644 --- a/webkit/browser/fileapi/sandbox_mount_point_provider.cc +++ b/webkit/browser/fileapi/sandbox_mount_point_provider.cc @@ -321,7 +321,7 @@ FileSystemOperation* SandboxMountPointProvider::CreateFileSystemOperation( operation_context->set_update_observers(syncable_update_observers_); operation_context->set_change_observers(syncable_change_observers_); return new sync_file_system::SyncableFileSystemOperation( - context, operation_context.Pass()); + url, context, operation_context.Pass()); } // For regular sandboxed types. @@ -335,7 +335,7 @@ FileSystemOperation* SandboxMountPointProvider::CreateFileSystemOperation( operation_context->set_quota_limit_type(quota::kQuotaLimitTypeLimited); } - return new LocalFileSystemOperation(context, operation_context.Pass()); + return new LocalFileSystemOperation(url, context, operation_context.Pass()); } scoped_ptr<webkit_blob::FileStreamReader> diff --git a/webkit/browser/fileapi/syncable/syncable_file_system_operation.cc b/webkit/browser/fileapi/syncable/syncable_file_system_operation.cc index 25d4a2d..0a91777 100644 --- a/webkit/browser/fileapi/syncable/syncable_file_system_operation.cc +++ b/webkit/browser/fileapi/syncable/syncable_file_system_operation.cc @@ -345,10 +345,12 @@ void SyncableFileSystemOperation::CopyInForeignFile( } SyncableFileSystemOperation::SyncableFileSystemOperation( + const FileSystemURL& url, fileapi::FileSystemContext* file_system_context, scoped_ptr<FileSystemOperationContext> operation_context) - : LocalFileSystemOperation(file_system_context, + : LocalFileSystemOperation(url, file_system_context, operation_context.Pass()), + url_(url), inflight_operation_(NULL) { DCHECK(file_system_context); if (!file_system_context->sync_context()) { @@ -364,8 +366,7 @@ SyncableFileSystemOperation::SyncableFileSystemOperation( LocalFileSystemOperation* SyncableFileSystemOperation::NewOperation() { DCHECK(operation_context_); inflight_operation_ = new LocalFileSystemOperation( - file_system_context(), - operation_context_.Pass()); + url_, file_system_context(), operation_context_.Pass()); DCHECK(inflight_operation_); return inflight_operation_; } diff --git a/webkit/browser/fileapi/syncable/syncable_file_system_operation.h b/webkit/browser/fileapi/syncable/syncable_file_system_operation.h index 4dbc4ae..f808347 100644 --- a/webkit/browser/fileapi/syncable/syncable_file_system_operation.h +++ b/webkit/browser/fileapi/syncable/syncable_file_system_operation.h @@ -89,6 +89,7 @@ class WEBKIT_STORAGE_EXPORT SyncableFileSystemOperation friend class fileapi::SandboxMountPointProvider; friend class SandboxMountPointProvider; SyncableFileSystemOperation( + const fileapi::FileSystemURL& url, fileapi::FileSystemContext* file_system_context, scoped_ptr<fileapi::FileSystemOperationContext> operation_context); fileapi::LocalFileSystemOperation* NewOperation(); @@ -103,6 +104,8 @@ class WEBKIT_STORAGE_EXPORT SyncableFileSystemOperation void AbortOperation(const StatusCallback& callback, base::PlatformFileError error); + const fileapi::FileSystemURL url_; + base::WeakPtr<SyncableFileOperationRunner> operation_runner_; fileapi::LocalFileSystemOperation* inflight_operation_; std::vector<fileapi::FileSystemURL> target_paths_; diff --git a/webkit/browser/fileapi/test_mount_point_provider.cc b/webkit/browser/fileapi/test_mount_point_provider.cc index e608b67..14211f2 100644 --- a/webkit/browser/fileapi/test_mount_point_provider.cc +++ b/webkit/browser/fileapi/test_mount_point_provider.cc @@ -145,7 +145,7 @@ FileSystemOperation* TestMountPointProvider::CreateFileSystemOperation( operation_context->set_update_observers(update_observers_); operation_context->set_change_observers(change_observers_); operation_context->set_root_path(base_path_); - return new LocalFileSystemOperation(context, operation_context.Pass()); + return new LocalFileSystemOperation(url, context, operation_context.Pass()); } scoped_ptr<webkit_blob::FileStreamReader> |