Commit 94893f7c authored by Marijn Kruisselbrink's avatar Marijn Kruisselbrink Committed by Commit Bot

[FileSystem] Change callback types in FileSystemOperation to be Once or Repeating.

Bug: 714018
Change-Id: I02bc49853ff630a0422ba0ddc8f08b7412046327
Reviewed-on: https://chromium-review.googlesource.com/1255148Reviewed-by: default avatarStuart Langley <slangley@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Commit-Queue: Marijn Kruisselbrink <mek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595636}
parent 59aed376
...@@ -260,12 +260,13 @@ void ComputeChecksumRespondOnUIThread( ...@@ -260,12 +260,13 @@ void ComputeChecksumRespondOnUIThread(
// Calls a response callback on the UI thread. // Calls a response callback on the UI thread.
void GetFileMetadataRespondOnUIThread( void GetFileMetadataRespondOnUIThread(
const storage::FileSystemOperation::GetMetadataCallback& callback, storage::FileSystemOperation::GetMetadataCallback callback,
base::File::Error result, base::File::Error result,
const base::File::Info& file_info) { const base::File::Info& file_info) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI}, base::PostTaskWithTraits(
base::BindOnce(callback, result, file_info)); FROM_HERE, {BrowserThread::UI},
base::BindOnce(std::move(callback), result, file_info));
} }
} // namespace } // namespace
...@@ -656,10 +657,11 @@ void GetFileMetadataOnIOThread( ...@@ -656,10 +657,11 @@ void GetFileMetadataOnIOThread(
scoped_refptr<storage::FileSystemContext> file_system_context, scoped_refptr<storage::FileSystemContext> file_system_context,
const FileSystemURL& url, const FileSystemURL& url,
int fields, int fields,
const storage::FileSystemOperation::GetMetadataCallback& callback) { storage::FileSystemOperation::GetMetadataCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
file_system_context->operation_runner()->GetMetadata( file_system_context->operation_runner()->GetMetadata(
url, fields, base::Bind(&GetFileMetadataRespondOnUIThread, callback)); url, fields,
base::BindOnce(&GetFileMetadataRespondOnUIThread, std::move(callback)));
} }
// Checks if the available space of the |path| is enough for required |bytes|. // Checks if the available space of the |path| is enough for required |bytes|.
...@@ -708,12 +710,12 @@ bool FileManagerPrivateInternalStartCopyFunction::RunAsync() { ...@@ -708,12 +710,12 @@ bool FileManagerPrivateInternalStartCopyFunction::RunAsync() {
file_manager::util::GetDownloadsMountPointName(GetProfile())) { file_manager::util::GetDownloadsMountPointName(GetProfile())) {
return base::PostTaskWithTraits( return base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::IO}, FROM_HERE, {BrowserThread::IO},
base::BindOnce(&GetFileMetadataOnIOThread, file_system_context, base::BindOnce(
source_url_, &GetFileMetadataOnIOThread, file_system_context, source_url_,
storage::FileSystemOperation::GET_METADATA_FIELD_SIZE, storage::FileSystemOperation::GET_METADATA_FIELD_SIZE,
base::Bind(&FileManagerPrivateInternalStartCopyFunction:: base::BindOnce(&FileManagerPrivateInternalStartCopyFunction::
RunAfterGetFileMetadata, RunAfterGetFileMetadata,
this))); this)));
} }
return base::PostTaskWithTraits( return base::PostTaskWithTraits(
......
...@@ -357,9 +357,10 @@ class ConvertSelectedFileInfoListToFileChooserFileInfoListImpl { ...@@ -357,9 +357,10 @@ class ConvertSelectedFileInfoListToFileChooserFileInfoListImpl {
storage::FileSystemOperation::GET_METADATA_FIELD_IS_DIRECTORY | storage::FileSystemOperation::GET_METADATA_FIELD_IS_DIRECTORY |
storage::FileSystemOperation::GET_METADATA_FIELD_SIZE | storage::FileSystemOperation::GET_METADATA_FIELD_SIZE |
storage::FileSystemOperation::GET_METADATA_FIELD_LAST_MODIFIED, storage::FileSystemOperation::GET_METADATA_FIELD_LAST_MODIFIED,
base::Bind(&ConvertSelectedFileInfoListToFileChooserFileInfoListImpl:: base::BindOnce(
OnGotMetadataOnIOThread, &ConvertSelectedFileInfoListToFileChooserFileInfoListImpl::
base::Unretained(this), base::Passed(&lifetime), it)); OnGotMetadataOnIOThread,
base::Unretained(this), std::move(lifetime), it));
} }
// Callback invoked after GetMetadata. // Callback invoked after GetMetadata.
...@@ -423,7 +424,7 @@ void GetMetadataForPathOnIoThread( ...@@ -423,7 +424,7 @@ void GetMetadataForPathOnIoThread(
storage::FileSystemOperationRunner::GetMetadataCallback callback) { storage::FileSystemOperationRunner::GetMetadataCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
file_system_context->operation_runner()->GetMetadata(internal_url, fields, file_system_context->operation_runner()->GetMetadata(internal_url, fields,
callback); std::move(callback));
} }
} // namespace } // namespace
...@@ -577,7 +578,7 @@ std::unique_ptr<base::ListValue> ConvertEntryDefinitionListToListValue( ...@@ -577,7 +578,7 @@ std::unique_ptr<base::ListValue> ConvertEntryDefinitionListToListValue(
void CheckIfDirectoryExists( void CheckIfDirectoryExists(
scoped_refptr<storage::FileSystemContext> file_system_context, scoped_refptr<storage::FileSystemContext> file_system_context,
const base::FilePath& directory_path, const base::FilePath& directory_path,
const storage::FileSystemOperationRunner::StatusCallback& callback) { storage::FileSystemOperationRunner::StatusCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
storage::ExternalFileSystemBackend* const backend = storage::ExternalFileSystemBackend* const backend =
...@@ -589,14 +590,15 @@ void CheckIfDirectoryExists( ...@@ -589,14 +590,15 @@ void CheckIfDirectoryExists(
base::PostTaskWithTraits( base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::IO}, FROM_HERE, {BrowserThread::IO},
base::BindOnce(&CheckIfDirectoryExistsOnIoThread, file_system_context, base::BindOnce(&CheckIfDirectoryExistsOnIoThread, file_system_context,
internal_url, google_apis::CreateRelayCallback(callback))); internal_url,
google_apis::CreateRelayCallback(std::move(callback))));
} }
void GetMetadataForPath( void GetMetadataForPath(
scoped_refptr<storage::FileSystemContext> file_system_context, scoped_refptr<storage::FileSystemContext> file_system_context,
const base::FilePath& entry_path, const base::FilePath& entry_path,
int fields, int fields,
const storage::FileSystemOperationRunner::GetMetadataCallback& callback) { storage::FileSystemOperationRunner::GetMetadataCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
storage::ExternalFileSystemBackend* const backend = storage::ExternalFileSystemBackend* const backend =
...@@ -609,7 +611,7 @@ void GetMetadataForPath( ...@@ -609,7 +611,7 @@ void GetMetadataForPath(
FROM_HERE, {BrowserThread::IO}, FROM_HERE, {BrowserThread::IO},
base::BindOnce(&GetMetadataForPathOnIoThread, file_system_context, base::BindOnce(&GetMetadataForPathOnIoThread, file_system_context,
internal_url, fields, internal_url, fields,
google_apis::CreateRelayCallback(callback))); google_apis::CreateRelayCallback(std::move(callback))));
} }
storage::FileSystemURL CreateIsolatedURLFromVirtualPath( storage::FileSystemURL CreateIsolatedURLFromVirtualPath(
......
...@@ -161,14 +161,14 @@ std::unique_ptr<base::ListValue> ConvertEntryDefinitionListToListValue( ...@@ -161,14 +161,14 @@ std::unique_ptr<base::ListValue> ConvertEntryDefinitionListToListValue(
void CheckIfDirectoryExists( void CheckIfDirectoryExists(
scoped_refptr<storage::FileSystemContext> file_system_context, scoped_refptr<storage::FileSystemContext> file_system_context,
const base::FilePath& directory_path, const base::FilePath& directory_path,
const storage::FileSystemOperationRunner::StatusCallback& callback); storage::FileSystemOperationRunner::StatusCallback callback);
// Get metadata for an entry at |entry_path| absolute path. // Get metadata for an entry at |entry_path| absolute path.
void GetMetadataForPath( void GetMetadataForPath(
scoped_refptr<storage::FileSystemContext> file_system_context, scoped_refptr<storage::FileSystemContext> file_system_context,
const base::FilePath& entry_path, const base::FilePath& entry_path,
int fields, int fields,
const storage::FileSystemOperationRunner::GetMetadataCallback& callback); storage::FileSystemOperationRunner::GetMetadataCallback callback);
// Obtains isolated file system URL from |virtual_path| pointing a file in the // Obtains isolated file system URL from |virtual_path| pointing a file in the
// external file system. // external file system.
......
...@@ -91,12 +91,12 @@ void BoolCallbackAsFileErrorCallback(base::OnceCallback<void(bool)> callback, ...@@ -91,12 +91,12 @@ void BoolCallbackAsFileErrorCallback(base::OnceCallback<void(bool)> callback,
void PrepareFileAfterCheckExistOnIOThread( void PrepareFileAfterCheckExistOnIOThread(
scoped_refptr<storage::FileSystemContext> file_system_context, scoped_refptr<storage::FileSystemContext> file_system_context,
const storage::FileSystemURL& url, const storage::FileSystemURL& url,
const storage::FileSystemOperation::StatusCallback& callback, storage::FileSystemOperation::StatusCallback callback,
base::File::Error error) { base::File::Error error) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
if (error != base::File::FILE_ERROR_NOT_FOUND) { if (error != base::File::FILE_ERROR_NOT_FOUND) {
callback.Run(error); std::move(callback).Run(error);
return; return;
} }
...@@ -106,7 +106,8 @@ void PrepareFileAfterCheckExistOnIOThread( ...@@ -106,7 +106,8 @@ void PrepareFileAfterCheckExistOnIOThread(
// //
// Note that the preceding call to FileExists is necessary for handling // Note that the preceding call to FileExists is necessary for handling
// read only filesystems that blindly rejects handling CreateFile(). // read only filesystems that blindly rejects handling CreateFile().
file_system_context->operation_runner()->CreateFile(url, false, callback); file_system_context->operation_runner()->CreateFile(url, false,
std::move(callback));
} }
// Checks whether a file exists at the given |url|, and try creating it if it // Checks whether a file exists at the given |url|, and try creating it if it
...@@ -118,10 +119,10 @@ void PrepareFileOnIOThread( ...@@ -118,10 +119,10 @@ void PrepareFileOnIOThread(
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
file_system_context->operation_runner()->FileExists( file_system_context->operation_runner()->FileExists(
url, base::Bind(&PrepareFileAfterCheckExistOnIOThread, url, base::BindOnce(&PrepareFileAfterCheckExistOnIOThread,
file_system_context, url, std::move(file_system_context), url,
base::Bind(&BoolCallbackAsFileErrorCallback, base::BindOnce(&BoolCallbackAsFileErrorCallback,
base::Passed(std::move(callback))))); std::move(callback))));
} }
} // namespace } // namespace
......
...@@ -48,24 +48,25 @@ void ReadDirectoryOnIOThread( ...@@ -48,24 +48,25 @@ void ReadDirectoryOnIOThread(
} }
void OnGetMetadataOnIOThread( void OnGetMetadataOnIOThread(
const storage::FileSystemOperation::GetMetadataCallback& callback, storage::FileSystemOperation::GetMetadataCallback callback,
base::File::Error result, base::File::Error result,
const base::File::Info& info) { const base::File::Info& info) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI}, base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI},
base::BindOnce(callback, result, info)); base::BindOnce(std::move(callback), result, info));
} }
void GetMetadataOnIOThread( void GetMetadataOnIOThread(
scoped_refptr<storage::FileSystemContext> file_system_context, scoped_refptr<storage::FileSystemContext> file_system_context,
const storage::FileSystemURL& url, const storage::FileSystemURL& url,
int fields, int fields,
const storage::FileSystemOperation::GetMetadataCallback& callback) { storage::FileSystemOperation::GetMetadataCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
file_system_context->operation_runner()->GetMetadata( file_system_context->operation_runner()->GetMetadata(
url, fields, base::Bind(&OnGetMetadataOnIOThread, callback)); url, fields,
base::BindOnce(&OnGetMetadataOnIOThread, std::move(callback)));
} }
} // namespace } // namespace
...@@ -138,8 +139,8 @@ void RecentDownloadSource::OnReadDirectory( ...@@ -138,8 +139,8 @@ void RecentDownloadSource::OnReadDirectory(
&GetMetadataOnIOThread, &GetMetadataOnIOThread,
base::WrapRefCounted(params_.value().file_system_context()), url, base::WrapRefCounted(params_.value().file_system_context()), url,
storage::FileSystemOperation::GET_METADATA_FIELD_LAST_MODIFIED, storage::FileSystemOperation::GET_METADATA_FIELD_LAST_MODIFIED,
base::Bind(&RecentDownloadSource::OnGetMetadata, base::BindOnce(&RecentDownloadSource::OnGetMetadata,
weak_ptr_factory_.GetWeakPtr(), url))); weak_ptr_factory_.GetWeakPtr(), url)));
} }
} }
......
...@@ -28,24 +28,25 @@ namespace chromeos { ...@@ -28,24 +28,25 @@ namespace chromeos {
namespace { namespace {
void OnGetMetadataOnIOThread( void OnGetMetadataOnIOThread(
const storage::FileSystemOperation::GetMetadataCallback& callback, storage::FileSystemOperation::GetMetadataCallback callback,
base::File::Error result, base::File::Error result,
const base::File::Info& info) { const base::File::Info& info) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI}, base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI},
base::BindOnce(callback, result, info)); base::BindOnce(std::move(callback), result, info));
} }
void GetMetadataOnIOThread( void GetMetadataOnIOThread(
scoped_refptr<storage::FileSystemContext> file_system_context, scoped_refptr<storage::FileSystemContext> file_system_context,
const storage::FileSystemURL& url, const storage::FileSystemURL& url,
int fields, int fields,
const storage::FileSystemOperation::GetMetadataCallback& callback) { storage::FileSystemOperation::GetMetadataCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
file_system_context->operation_runner()->GetMetadata( file_system_context->operation_runner()->GetMetadata(
url, fields, base::Bind(&OnGetMetadataOnIOThread, callback)); url, fields,
base::BindOnce(&OnGetMetadataOnIOThread, std::move(callback)));
} }
} // namespace } // namespace
...@@ -139,8 +140,8 @@ void RecentDriveSource::OnSearchMetadata( ...@@ -139,8 +140,8 @@ void RecentDriveSource::OnSearchMetadata(
&GetMetadataOnIOThread, &GetMetadataOnIOThread,
base::WrapRefCounted(params_.value().file_system_context()), url, base::WrapRefCounted(params_.value().file_system_context()), url,
storage::FileSystemOperation::GET_METADATA_FIELD_LAST_MODIFIED, storage::FileSystemOperation::GET_METADATA_FIELD_LAST_MODIFIED,
base::Bind(&RecentDriveSource::OnGetMetadata, base::BindOnce(&RecentDriveSource::OnGetMetadata,
weak_ptr_factory_.GetWeakPtr(), url))); weak_ptr_factory_.GetWeakPtr(), url)));
} }
if (num_inflight_stats_ == 0) if (num_inflight_stats_ == 0)
......
...@@ -363,7 +363,7 @@ void LocalFileSyncContext::DidRemoveExistingEntryForRemoteAddOrUpdate( ...@@ -363,7 +363,7 @@ void LocalFileSyncContext::DidRemoveExistingEntryForRemoteAddOrUpdate(
FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync( FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync(
file_system_context, url); file_system_context, url);
FileSystemOperation::StatusCallback operation_callback = base::Bind( FileSystemOperation::StatusCallback operation_callback = base::BindOnce(
&LocalFileSyncContext::DidApplyRemoteChange, this, url, callback); &LocalFileSyncContext::DidApplyRemoteChange, this, url, callback);
DCHECK_EQ(FileChange::FILE_CHANGE_ADD_OR_UPDATE, change.change()); DCHECK_EQ(FileChange::FILE_CHANGE_ADD_OR_UPDATE, change.change());
...@@ -375,7 +375,7 @@ void LocalFileSyncContext::DidRemoveExistingEntryForRemoteAddOrUpdate( ...@@ -375,7 +375,7 @@ void LocalFileSyncContext::DidRemoveExistingEntryForRemoteAddOrUpdate(
storage::VirtualPath::DirName(dir_path) == dir_path) { storage::VirtualPath::DirName(dir_path) == dir_path) {
// Copying into the root directory. // Copying into the root directory.
file_system_context->operation_runner()->CopyInForeignFile( file_system_context->operation_runner()->CopyInForeignFile(
local_path, url_for_sync, operation_callback); local_path, url_for_sync, std::move(operation_callback));
} else { } else {
FileSystemURL dir_url = file_system_context->CreateCrackedFileSystemURL( FileSystemURL dir_url = file_system_context->CreateCrackedFileSystemURL(
url_for_sync.origin(), url_for_sync.origin(),
...@@ -383,16 +383,16 @@ void LocalFileSyncContext::DidRemoveExistingEntryForRemoteAddOrUpdate( ...@@ -383,16 +383,16 @@ void LocalFileSyncContext::DidRemoveExistingEntryForRemoteAddOrUpdate(
storage::VirtualPath::DirName(url_for_sync.virtual_path())); storage::VirtualPath::DirName(url_for_sync.virtual_path()));
file_system_context->operation_runner()->CreateDirectory( file_system_context->operation_runner()->CreateDirectory(
dir_url, false /* exclusive */, true /* recursive */, dir_url, false /* exclusive */, true /* recursive */,
base::Bind(&LocalFileSyncContext::DidCreateDirectoryForCopyIn, this, base::BindOnce(&LocalFileSyncContext::DidCreateDirectoryForCopyIn,
base::RetainedRef(file_system_context), local_path, url, this, base::RetainedRef(file_system_context),
operation_callback)); local_path, url, std::move(operation_callback)));
} }
break; break;
} }
case SYNC_FILE_TYPE_DIRECTORY: case SYNC_FILE_TYPE_DIRECTORY:
file_system_context->operation_runner()->CreateDirectory( file_system_context->operation_runner()->CreateDirectory(
url_for_sync, false /* exclusive */, true /* recursive */, url_for_sync, false /* exclusive */, true /* recursive */,
operation_callback); std::move(operation_callback));
break; break;
case SYNC_FILE_TYPE_UNKNOWN: case SYNC_FILE_TYPE_UNKNOWN:
NOTREACHED() << "File type unknown for ADD_OR_UPDATE change"; NOTREACHED() << "File type unknown for ADD_OR_UPDATE change";
...@@ -1037,17 +1037,17 @@ void LocalFileSyncContext::DidCreateDirectoryForCopyIn( ...@@ -1037,17 +1037,17 @@ void LocalFileSyncContext::DidCreateDirectoryForCopyIn(
FileSystemContext* file_system_context, FileSystemContext* file_system_context,
const base::FilePath& local_path, const base::FilePath& local_path,
const FileSystemURL& dest_url, const FileSystemURL& dest_url,
const StatusCallback& callback, StatusCallback callback,
base::File::Error error) { base::File::Error error) {
if (error != base::File::FILE_OK) { if (error != base::File::FILE_OK) {
callback.Run(error); std::move(callback).Run(error);
return; return;
} }
FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync( FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync(
file_system_context, dest_url); file_system_context, dest_url);
file_system_context->operation_runner()->CopyInForeignFile( file_system_context->operation_runner()->CopyInForeignFile(
local_path, url_for_sync, callback); local_path, url_for_sync, std::move(callback));
} }
} // namespace sync_file_system } // namespace sync_file_system
...@@ -210,7 +210,7 @@ class LocalFileSyncContext ...@@ -210,7 +210,7 @@ class LocalFileSyncContext
void OnWriteEnabled(const storage::FileSystemURL& url) override; void OnWriteEnabled(const storage::FileSystemURL& url) override;
private: private:
using StatusCallback = base::Callback<void(base::File::Error result)>; using StatusCallback = base::OnceCallback<void(base::File::Error result)>;
using StatusCallbackQueue = base::circular_deque<SyncStatusCallback>; using StatusCallbackQueue = base::circular_deque<SyncStatusCallback>;
using FileSystemURLQueue = base::circular_deque<storage::FileSystemURL>; using FileSystemURLQueue = base::circular_deque<storage::FileSystemURL>;
friend class base::RefCountedThreadSafe<LocalFileSyncContext>; friend class base::RefCountedThreadSafe<LocalFileSyncContext>;
...@@ -324,7 +324,7 @@ class LocalFileSyncContext ...@@ -324,7 +324,7 @@ class LocalFileSyncContext
storage::FileSystemContext* file_system_context, storage::FileSystemContext* file_system_context,
const base::FilePath& local_file_path, const base::FilePath& local_file_path,
const storage::FileSystemURL& dest_url, const storage::FileSystemURL& dest_url,
const StatusCallback& callback, StatusCallback callback,
base::File::Error error); base::File::Error error);
const base::FilePath local_base_path_; const base::FilePath local_base_path_;
......
...@@ -384,10 +384,12 @@ TEST_F(SyncableFileOperationRunnerTest, CopyInForeignFile) { ...@@ -384,10 +384,12 @@ TEST_F(SyncableFileOperationRunnerTest, CopyInForeignFile) {
EXPECT_EQ(1, callback_count_); EXPECT_EQ(1, callback_count_);
// Now the file must have been created and have the same content as temp_path. // Now the file must have been created and have the same content as temp_path.
// TODO(mek): AdaptCallbackForRepeating is needed here because
// CannedSyncableFileSystem hasn't switched to OnceCallback yet.
ResetCallbackStatus(); ResetCallbackStatus();
file_system_.DoVerifyFile( file_system_.DoVerifyFile(
URL(kFile), kTestData, URL(kFile), kTestData,
ExpectStatus(FROM_HERE, File::FILE_OK)); base::AdaptCallbackForRepeating(ExpectStatus(FROM_HERE, File::FILE_OK)));
content::RunAllTasksUntilIdle(); content::RunAllTasksUntilIdle();
EXPECT_EQ(1, callback_count_); EXPECT_EQ(1, callback_count_);
} }
......
...@@ -34,66 +34,66 @@ class SyncableFileSystemOperation : public storage::FileSystemOperation { ...@@ -34,66 +34,66 @@ class SyncableFileSystemOperation : public storage::FileSystemOperation {
// storage::FileSystemOperation overrides. // storage::FileSystemOperation overrides.
void CreateFile(const storage::FileSystemURL& url, void CreateFile(const storage::FileSystemURL& url,
bool exclusive, bool exclusive,
const StatusCallback& callback) override; StatusCallback callback) override;
void CreateDirectory(const storage::FileSystemURL& url, void CreateDirectory(const storage::FileSystemURL& url,
bool exclusive, bool exclusive,
bool recursive, bool recursive,
const StatusCallback& callback) override; StatusCallback callback) override;
void Copy(const storage::FileSystemURL& src_url, void Copy(const storage::FileSystemURL& src_url,
const storage::FileSystemURL& dest_url, const storage::FileSystemURL& dest_url,
CopyOrMoveOption option, CopyOrMoveOption option,
ErrorBehavior error_behavior, ErrorBehavior error_behavior,
const CopyProgressCallback& progress_callback, const CopyProgressCallback& progress_callback,
const StatusCallback& callback) override; StatusCallback callback) override;
void Move(const storage::FileSystemURL& src_url, void Move(const storage::FileSystemURL& src_url,
const storage::FileSystemURL& dest_url, const storage::FileSystemURL& dest_url,
CopyOrMoveOption option, CopyOrMoveOption option,
const StatusCallback& callback) override; StatusCallback callback) override;
void DirectoryExists(const storage::FileSystemURL& url, void DirectoryExists(const storage::FileSystemURL& url,
const StatusCallback& callback) override; StatusCallback callback) override;
void FileExists(const storage::FileSystemURL& url, void FileExists(const storage::FileSystemURL& url,
const StatusCallback& callback) override; StatusCallback callback) override;
void GetMetadata(const storage::FileSystemURL& url, void GetMetadata(const storage::FileSystemURL& url,
int fields, int fields,
const GetMetadataCallback& callback) override; GetMetadataCallback callback) override;
void ReadDirectory(const storage::FileSystemURL& url, void ReadDirectory(const storage::FileSystemURL& url,
const ReadDirectoryCallback& callback) override; const ReadDirectoryCallback& callback) override;
void Remove(const storage::FileSystemURL& url, void Remove(const storage::FileSystemURL& url,
bool recursive, bool recursive,
const StatusCallback& callback) override; StatusCallback callback) override;
void Write(const storage::FileSystemURL& url, void Write(const storage::FileSystemURL& url,
std::unique_ptr<storage::FileWriterDelegate> writer_delegate, std::unique_ptr<storage::FileWriterDelegate> writer_delegate,
std::unique_ptr<storage::BlobReader> blob_reader, std::unique_ptr<storage::BlobReader> blob_reader,
const WriteCallback& callback) override; const WriteCallback& callback) override;
void Truncate(const storage::FileSystemURL& url, void Truncate(const storage::FileSystemURL& url,
int64_t length, int64_t length,
const StatusCallback& callback) override; StatusCallback callback) override;
void TouchFile(const storage::FileSystemURL& url, void TouchFile(const storage::FileSystemURL& url,
const base::Time& last_access_time, const base::Time& last_access_time,
const base::Time& last_modified_time, const base::Time& last_modified_time,
const StatusCallback& callback) override; StatusCallback callback) override;
void OpenFile(const storage::FileSystemURL& url, void OpenFile(const storage::FileSystemURL& url,
int file_flags, int file_flags,
const OpenFileCallback& callback) override; OpenFileCallback callback) override;
void Cancel(const StatusCallback& cancel_callback) override; void Cancel(StatusCallback cancel_callback) override;
void CreateSnapshotFile(const storage::FileSystemURL& path, void CreateSnapshotFile(const storage::FileSystemURL& path,
SnapshotFileCallback callback) override; SnapshotFileCallback callback) override;
void CopyInForeignFile(const base::FilePath& src_local_disk_path, void CopyInForeignFile(const base::FilePath& src_local_disk_path,
const storage::FileSystemURL& dest_url, const storage::FileSystemURL& dest_url,
const StatusCallback& callback) override; StatusCallback callback) override;
void RemoveFile(const storage::FileSystemURL& url, void RemoveFile(const storage::FileSystemURL& url,
const StatusCallback& callback) override; StatusCallback callback) override;
void RemoveDirectory(const storage::FileSystemURL& url, void RemoveDirectory(const storage::FileSystemURL& url,
const StatusCallback& callback) override; StatusCallback callback) override;
void CopyFileLocal(const storage::FileSystemURL& src_url, void CopyFileLocal(const storage::FileSystemURL& src_url,
const storage::FileSystemURL& dest_url, const storage::FileSystemURL& dest_url,
CopyOrMoveOption option, CopyOrMoveOption option,
const CopyFileProgressCallback& progress_callback, const CopyFileProgressCallback& progress_callback,
const StatusCallback& callback) override; StatusCallback callback) override;
void MoveFileLocal(const storage::FileSystemURL& src_url, void MoveFileLocal(const storage::FileSystemURL& src_url,
const storage::FileSystemURL& dest_url, const storage::FileSystemURL& dest_url,
CopyOrMoveOption option, CopyOrMoveOption option,
const StatusCallback& callback) override; StatusCallback callback) override;
base::File::Error SyncGetPlatformPath(const storage::FileSystemURL& url, base::File::Error SyncGetPlatformPath(const storage::FileSystemURL& url,
base::FilePath* platform_path) override; base::FilePath* platform_path) override;
......
...@@ -57,7 +57,7 @@ class CopyOrMoveOperationDelegate ...@@ -57,7 +57,7 @@ class CopyOrMoveOperationDelegate
const base::TimeDelta& min_progress_callback_invocation_span); const base::TimeDelta& min_progress_callback_invocation_span);
~StreamCopyHelper(); ~StreamCopyHelper();
void Run(const StatusCallback& callback); void Run(StatusCallback callback);
// Requests cancelling. After the cancelling is done, |callback| passed to // Requests cancelling. After the cancelling is done, |callback| passed to
// Run will be called. // Run will be called.
...@@ -65,18 +65,19 @@ class CopyOrMoveOperationDelegate ...@@ -65,18 +65,19 @@ class CopyOrMoveOperationDelegate
private: private:
// Reads the content from the |reader_|. // Reads the content from the |reader_|.
void Read(const StatusCallback& callback); void Read(StatusCallback callback);
void DidRead(const StatusCallback& callback, int result); void DidRead(StatusCallback callback, int result);
// Writes the content in |buffer| to |writer_|. // Writes the content in |buffer| to |writer_|.
void Write(const StatusCallback& callback, void Write(StatusCallback callback,
scoped_refptr<net::DrainableIOBuffer> buffer); scoped_refptr<net::DrainableIOBuffer> buffer);
void DidWrite(const StatusCallback& callback, void DidWrite(StatusCallback callback,
scoped_refptr<net::DrainableIOBuffer> buffer, int result); scoped_refptr<net::DrainableIOBuffer> buffer,
int result);
// Flushes the written content in |writer_|. // Flushes the written content in |writer_|.
void Flush(const StatusCallback& callback, bool is_eof); void Flush(StatusCallback callback, bool is_eof);
void DidFlush(const StatusCallback& callback, bool is_eof, int result); void DidFlush(StatusCallback callback, bool is_eof, int result);
std::unique_ptr<storage::FileStreamReader> reader_; std::unique_ptr<storage::FileStreamReader> reader_;
std::unique_ptr<FileStreamWriter> writer_; std::unique_ptr<FileStreamWriter> writer_;
...@@ -99,18 +100,17 @@ class CopyOrMoveOperationDelegate ...@@ -99,18 +100,17 @@ class CopyOrMoveOperationDelegate
CopyOrMoveOption option, CopyOrMoveOption option,
ErrorBehavior error_behavior, ErrorBehavior error_behavior,
const CopyProgressCallback& progress_callback, const CopyProgressCallback& progress_callback,
const StatusCallback& callback); StatusCallback callback);
~CopyOrMoveOperationDelegate() override; ~CopyOrMoveOperationDelegate() override;
// RecursiveOperationDelegate overrides: // RecursiveOperationDelegate overrides:
void Run() override; void Run() override;
void RunRecursively() override; void RunRecursively() override;
void ProcessFile(const FileSystemURL& url, void ProcessFile(const FileSystemURL& url, StatusCallback callback) override;
const StatusCallback& callback) override;
void ProcessDirectory(const FileSystemURL& url, void ProcessDirectory(const FileSystemURL& url,
const StatusCallback& callback) override; StatusCallback callback) override;
void PostProcessDirectory(const FileSystemURL& url, void PostProcessDirectory(const FileSystemURL& url,
const StatusCallback& callback) override; StatusCallback callback) override;
protected: protected:
void OnCancel() override; void OnCancel() override;
...@@ -118,32 +118,33 @@ class CopyOrMoveOperationDelegate ...@@ -118,32 +118,33 @@ class CopyOrMoveOperationDelegate
private: private:
void DidCopyOrMoveFile(const FileSystemURL& src_url, void DidCopyOrMoveFile(const FileSystemURL& src_url,
const FileSystemURL& dest_url, const FileSystemURL& dest_url,
const StatusCallback& callback, StatusCallback callback,
CopyOrMoveImpl* impl, CopyOrMoveImpl* impl,
base::File::Error error); base::File::Error error);
void DidTryRemoveDestRoot(const StatusCallback& callback, void DidTryRemoveDestRoot(StatusCallback callback, base::File::Error error);
base::File::Error error);
void ProcessDirectoryInternal(const FileSystemURL& src_url, void ProcessDirectoryInternal(const FileSystemURL& src_url,
const FileSystemURL& dest_url, const FileSystemURL& dest_url,
const StatusCallback& callback); StatusCallback callback);
void DidCreateDirectory(const FileSystemURL& src_url, void DidCreateDirectory(const FileSystemURL& src_url,
const FileSystemURL& dest_url, const FileSystemURL& dest_url,
const StatusCallback& callback, StatusCallback callback,
base::File::Error error); base::File::Error error);
void PostProcessDirectoryAfterGetMetadata( void PostProcessDirectoryAfterGetMetadata(const FileSystemURL& src_url,
const FileSystemURL& src_url, StatusCallback callback,
const StatusCallback& callback, base::File::Error error,
base::File::Error error, const base::File::Info& file_info);
const base::File::Info& file_info);
void PostProcessDirectoryAfterTouchFile(const FileSystemURL& src_url, void PostProcessDirectoryAfterTouchFile(const FileSystemURL& src_url,
const StatusCallback& callback, StatusCallback callback,
base::File::Error error); base::File::Error error);
void DidRemoveSourceForMove(const StatusCallback& callback, void DidRemoveSourceForMove(StatusCallback callback, base::File::Error error);
base::File::Error error);
void OnCopyFileProgress(const FileSystemURL& src_url, int64_t size); void OnCopyFileProgress(const FileSystemURL& src_url, int64_t size);
FileSystemURL CreateDestURL(const FileSystemURL& src_url) const; FileSystemURL CreateDestURL(const FileSystemURL& src_url) const;
#if DCHECK_IS_ON()
bool did_run_ = false;
#endif
FileSystemURL src_root_; FileSystemURL src_root_;
FileSystemURL dest_root_; FileSystemURL dest_root_;
bool same_file_system_; bool same_file_system_;
......
...@@ -35,66 +35,64 @@ class STORAGE_EXPORT FileSystemOperationImpl : public FileSystemOperation { ...@@ -35,66 +35,64 @@ class STORAGE_EXPORT FileSystemOperationImpl : public FileSystemOperation {
// FileSystemOperation overrides. // FileSystemOperation overrides.
void CreateFile(const FileSystemURL& url, void CreateFile(const FileSystemURL& url,
bool exclusive, bool exclusive,
const StatusCallback& callback) override; StatusCallback callback) override;
void CreateDirectory(const FileSystemURL& url, void CreateDirectory(const FileSystemURL& url,
bool exclusive, bool exclusive,
bool recursive, bool recursive,
const StatusCallback& callback) override; StatusCallback callback) override;
void Copy(const FileSystemURL& src_url, void Copy(const FileSystemURL& src_url,
const FileSystemURL& dest_url, const FileSystemURL& dest_url,
CopyOrMoveOption option, CopyOrMoveOption option,
ErrorBehavior error_behavior, ErrorBehavior error_behavior,
const CopyProgressCallback& progress_callback, const CopyProgressCallback& progress_callback,
const StatusCallback& callback) override; StatusCallback callback) override;
void Move(const FileSystemURL& src_url, void Move(const FileSystemURL& src_url,
const FileSystemURL& dest_url, const FileSystemURL& dest_url,
CopyOrMoveOption option, CopyOrMoveOption option,
const StatusCallback& callback) override; StatusCallback callback) override;
void DirectoryExists(const FileSystemURL& url, void DirectoryExists(const FileSystemURL& url,
const StatusCallback& callback) override; StatusCallback callback) override;
void FileExists(const FileSystemURL& url, void FileExists(const FileSystemURL& url, StatusCallback callback) override;
const StatusCallback& callback) override;
void GetMetadata(const FileSystemURL& url, void GetMetadata(const FileSystemURL& url,
int fields, int fields,
const GetMetadataCallback& callback) override; GetMetadataCallback callback) override;
void ReadDirectory(const FileSystemURL& url, void ReadDirectory(const FileSystemURL& url,
const ReadDirectoryCallback& callback) override; const ReadDirectoryCallback& callback) override;
void Remove(const FileSystemURL& url, void Remove(const FileSystemURL& url,
bool recursive, bool recursive,
const StatusCallback& callback) override; StatusCallback callback) override;
void Write(const FileSystemURL& url, void Write(const FileSystemURL& url,
std::unique_ptr<FileWriterDelegate> writer_delegate, std::unique_ptr<FileWriterDelegate> writer_delegate,
std::unique_ptr<BlobReader> blob_reader, std::unique_ptr<BlobReader> blob_reader,
const WriteCallback& callback) override; const WriteCallback& callback) override;
void Truncate(const FileSystemURL& url, void Truncate(const FileSystemURL& url,
int64_t length, int64_t length,
const StatusCallback& callback) override; StatusCallback callback) override;
void TouchFile(const FileSystemURL& url, void TouchFile(const FileSystemURL& url,
const base::Time& last_access_time, const base::Time& last_access_time,
const base::Time& last_modified_time, const base::Time& last_modified_time,
const StatusCallback& callback) override; StatusCallback callback) override;
void OpenFile(const FileSystemURL& url, void OpenFile(const FileSystemURL& url,
int file_flags, int file_flags,
const OpenFileCallback& callback) override; OpenFileCallback callback) override;
void Cancel(const StatusCallback& cancel_callback) override; void Cancel(StatusCallback cancel_callback) override;
void CreateSnapshotFile(const FileSystemURL& path, void CreateSnapshotFile(const FileSystemURL& path,
SnapshotFileCallback callback) override; SnapshotFileCallback callback) override;
void CopyInForeignFile(const base::FilePath& src_local_disk_path, void CopyInForeignFile(const base::FilePath& src_local_disk_path,
const FileSystemURL& dest_url, const FileSystemURL& dest_url,
const StatusCallback& callback) override; StatusCallback callback) override;
void RemoveFile(const FileSystemURL& url, void RemoveFile(const FileSystemURL& url, StatusCallback callback) override;
const StatusCallback& callback) override;
void RemoveDirectory(const FileSystemURL& url, void RemoveDirectory(const FileSystemURL& url,
const StatusCallback& callback) override; StatusCallback callback) override;
void CopyFileLocal(const FileSystemURL& src_url, void CopyFileLocal(const FileSystemURL& src_url,
const FileSystemURL& dest_url, const FileSystemURL& dest_url,
CopyOrMoveOption option, CopyOrMoveOption option,
const CopyFileProgressCallback& progress_callback, const CopyFileProgressCallback& progress_callback,
const StatusCallback& callback) override; StatusCallback callback) override;
void MoveFileLocal(const FileSystemURL& src_url, void MoveFileLocal(const FileSystemURL& src_url,
const FileSystemURL& dest_url, const FileSystemURL& dest_url,
CopyOrMoveOption option, CopyOrMoveOption option,
const StatusCallback& callback) override; StatusCallback callback) override;
base::File::Error SyncGetPlatformPath(const FileSystemURL& url, base::File::Error SyncGetPlatformPath(const FileSystemURL& url,
base::FilePath* platform_path) override; base::FilePath* platform_path) override;
...@@ -112,18 +110,17 @@ class STORAGE_EXPORT FileSystemOperationImpl : public FileSystemOperation { ...@@ -112,18 +110,17 @@ class STORAGE_EXPORT FileSystemOperationImpl : public FileSystemOperation {
// Queries the quota and usage and then runs the given |task|. // Queries the quota and usage and then runs the given |task|.
// If an error occurs during the quota query it runs |error_callback| instead. // If an error occurs during the quota query it runs |error_callback| instead.
void GetUsageAndQuotaThenRunTask( void GetUsageAndQuotaThenRunTask(const FileSystemURL& url,
const FileSystemURL& url, base::OnceClosure task,
const base::Closure& task, base::OnceClosure error_callback);
const base::Closure& error_callback);
// Called after the quota info is obtained from the quota manager // Called after the quota info is obtained from the quota manager
// (which is triggered by GetUsageAndQuotaThenRunTask). // (which is triggered by GetUsageAndQuotaThenRunTask).
// Sets the quota info in the operation_context_ and then runs the given // Sets the quota info in the operation_context_ and then runs the given
// |task| if the returned quota status is successful, otherwise runs // |task| if the returned quota status is successful, otherwise runs
// |error_callback|. // |error_callback|.
void DidGetUsageAndQuotaAndRunTask(const base::Closure& task, void DidGetUsageAndQuotaAndRunTask(base::OnceClosure task,
const base::Closure& error_callback, base::OnceClosure error_callback,
blink::mojom::QuotaStatusCode status, blink::mojom::QuotaStatusCode status,
int64_t usage, int64_t usage,
int64_t quota); int64_t quota);
...@@ -131,49 +128,50 @@ class STORAGE_EXPORT FileSystemOperationImpl : public FileSystemOperation { ...@@ -131,49 +128,50 @@ class STORAGE_EXPORT FileSystemOperationImpl : public FileSystemOperation {
// The 'body' methods that perform the actual work (i.e. posting the // The 'body' methods that perform the actual work (i.e. posting the
// file task on proxy_) after the quota check. // file task on proxy_) after the quota check.
void DoCreateFile(const FileSystemURL& url, void DoCreateFile(const FileSystemURL& url,
const StatusCallback& callback, bool exclusive); StatusCallback callback,
bool exclusive);
void DoCreateDirectory(const FileSystemURL& url, void DoCreateDirectory(const FileSystemURL& url,
const StatusCallback& callback, StatusCallback callback,
bool exclusive, bool exclusive,
bool recursive); bool recursive);
void DoCopyFileLocal(const FileSystemURL& src, void DoCopyFileLocal(const FileSystemURL& src,
const FileSystemURL& dest, const FileSystemURL& dest,
CopyOrMoveOption option, CopyOrMoveOption option,
const CopyFileProgressCallback& progress_callback, const CopyFileProgressCallback& progress_callback,
const StatusCallback& callback); StatusCallback callback);
void DoMoveFileLocal(const FileSystemURL& src, void DoMoveFileLocal(const FileSystemURL& src,
const FileSystemURL& dest, const FileSystemURL& dest,
CopyOrMoveOption option, CopyOrMoveOption option,
const StatusCallback& callback); StatusCallback callback);
void DoCopyInForeignFile(const base::FilePath& src_local_disk_file_path, void DoCopyInForeignFile(const base::FilePath& src_local_disk_file_path,
const FileSystemURL& dest, const FileSystemURL& dest,
const StatusCallback& callback); StatusCallback callback);
void DoTruncate(const FileSystemURL& url, void DoTruncate(const FileSystemURL& url,
const StatusCallback& callback, StatusCallback callback,
int64_t length); int64_t length);
void DoOpenFile(const FileSystemURL& url, void DoOpenFile(const FileSystemURL& url,
const OpenFileCallback& callback, int file_flags); OpenFileCallback callback,
int file_flags);
// Callback for CreateFile for |exclusive|=true cases. // Callback for CreateFile for |exclusive|=true cases.
void DidEnsureFileExistsExclusive(const StatusCallback& callback, void DidEnsureFileExistsExclusive(StatusCallback callback,
base::File::Error rv, base::File::Error rv,
bool created); bool created);
// Callback for CreateFile for |exclusive|=false cases. // Callback for CreateFile for |exclusive|=false cases.
void DidEnsureFileExistsNonExclusive(const StatusCallback& callback, void DidEnsureFileExistsNonExclusive(StatusCallback callback,
base::File::Error rv, base::File::Error rv,
bool created); bool created);
void DidFinishOperation(const StatusCallback& callback, void DidFinishOperation(StatusCallback callback, base::File::Error rv);
base::File::Error rv); void DidDirectoryExists(StatusCallback callback,
void DidDirectoryExists(const StatusCallback& callback,
base::File::Error rv, base::File::Error rv,
const base::File::Info& file_info); const base::File::Info& file_info);
void DidFileExists(const StatusCallback& callback, void DidFileExists(StatusCallback callback,
base::File::Error rv, base::File::Error rv,
const base::File::Info& file_info); const base::File::Info& file_info);
void DidDeleteRecursively(const FileSystemURL& url, void DidDeleteRecursively(const FileSystemURL& url,
const StatusCallback& callback, StatusCallback callback,
base::File::Error rv); base::File::Error rv);
void DidWrite(const FileSystemURL& url, void DidWrite(const FileSystemURL& url,
const WriteCallback& callback, const WriteCallback& callback,
......
...@@ -59,12 +59,12 @@ class STORAGE_EXPORT FileSystemOperationRunner { ...@@ -59,12 +59,12 @@ class STORAGE_EXPORT FileSystemOperationRunner {
// in case a file is already present at the URL. // in case a file is already present at the URL.
OperationID CreateFile(const FileSystemURL& url, OperationID CreateFile(const FileSystemURL& url,
bool exclusive, bool exclusive,
const StatusCallback& callback); StatusCallback callback);
OperationID CreateDirectory(const FileSystemURL& url, OperationID CreateDirectory(const FileSystemURL& url,
bool exclusive, bool exclusive,
bool recursive, bool recursive,
const StatusCallback& callback); StatusCallback callback);
// Copies a file or directory from |src_url| to |dest_url|. If // Copies a file or directory from |src_url| to |dest_url|. If
// |src_url| is a directory, the contents of |src_url| are copied to // |src_url| is a directory, the contents of |src_url| are copied to
...@@ -77,7 +77,7 @@ class STORAGE_EXPORT FileSystemOperationRunner { ...@@ -77,7 +77,7 @@ class STORAGE_EXPORT FileSystemOperationRunner {
CopyOrMoveOption option, CopyOrMoveOption option,
ErrorBehavior error_behavior, ErrorBehavior error_behavior,
const CopyProgressCallback& progress_callback, const CopyProgressCallback& progress_callback,
const StatusCallback& callback); StatusCallback callback);
// Moves a file or directory from |src_url| to |dest_url|. A new file // Moves a file or directory from |src_url| to |dest_url|. A new file
// or directory is created at |dest_url| as needed. // or directory is created at |dest_url| as needed.
...@@ -85,20 +85,19 @@ class STORAGE_EXPORT FileSystemOperationRunner { ...@@ -85,20 +85,19 @@ class STORAGE_EXPORT FileSystemOperationRunner {
OperationID Move(const FileSystemURL& src_url, OperationID Move(const FileSystemURL& src_url,
const FileSystemURL& dest_url, const FileSystemURL& dest_url,
CopyOrMoveOption option, CopyOrMoveOption option,
const StatusCallback& callback); StatusCallback callback);
// Checks if a directory is present at |url|. // Checks if a directory is present at |url|.
OperationID DirectoryExists(const FileSystemURL& url, OperationID DirectoryExists(const FileSystemURL& url,
const StatusCallback& callback); StatusCallback callback);
// Checks if a file is present at |url|. // Checks if a file is present at |url|.
OperationID FileExists(const FileSystemURL& url, OperationID FileExists(const FileSystemURL& url, StatusCallback callback);
const StatusCallback& callback);
// Gets the metadata of a file or directory at |url|. // Gets the metadata of a file or directory at |url|.
OperationID GetMetadata(const FileSystemURL& url, OperationID GetMetadata(const FileSystemURL& url,
int fields, int fields,
const GetMetadataCallback& callback); GetMetadataCallback callback);
// Reads contents of a directory at |url|. // Reads contents of a directory at |url|.
OperationID ReadDirectory(const FileSystemURL& url, OperationID ReadDirectory(const FileSystemURL& url,
...@@ -106,8 +105,9 @@ class STORAGE_EXPORT FileSystemOperationRunner { ...@@ -106,8 +105,9 @@ class STORAGE_EXPORT FileSystemOperationRunner {
// Removes a file or directory at |url|. If |recursive| is true, remove // Removes a file or directory at |url|. If |recursive| is true, remove
// all files and directories under the directory at |url| recursively. // all files and directories under the directory at |url| recursively.
OperationID Remove(const FileSystemURL& url, bool recursive, OperationID Remove(const FileSystemURL& url,
const StatusCallback& callback); bool recursive,
StatusCallback callback);
// Writes contents of |blob_url| to |url| at |offset|. // Writes contents of |blob_url| to |url| at |offset|.
OperationID Write(const FileSystemURL& url, OperationID Write(const FileSystemURL& url,
...@@ -120,12 +120,12 @@ class STORAGE_EXPORT FileSystemOperationRunner { ...@@ -120,12 +120,12 @@ class STORAGE_EXPORT FileSystemOperationRunner {
// part is filled with null bytes. // part is filled with null bytes.
OperationID Truncate(const FileSystemURL& url, OperationID Truncate(const FileSystemURL& url,
int64_t length, int64_t length,
const StatusCallback& callback); StatusCallback callback);
// Tries to cancel the operation |id| [we support cancelling write or // Tries to cancel the operation |id| [we support cancelling write or
// truncate only]. Reports failure for the current operation, then reports // truncate only]. Reports failure for the current operation, then reports
// success for the cancel operation itself via the |callback|. // success for the cancel operation itself via the |callback|.
void Cancel(OperationID id, const StatusCallback& callback); void Cancel(OperationID id, StatusCallback callback);
// Modifies timestamps of a file or directory at |url| with // Modifies timestamps of a file or directory at |url| with
// |last_access_time| and |last_modified_time|. The function DOES NOT // |last_access_time| and |last_modified_time|. The function DOES NOT
...@@ -135,7 +135,7 @@ class STORAGE_EXPORT FileSystemOperationRunner { ...@@ -135,7 +135,7 @@ class STORAGE_EXPORT FileSystemOperationRunner {
OperationID TouchFile(const FileSystemURL& url, OperationID TouchFile(const FileSystemURL& url,
const base::Time& last_access_time, const base::Time& last_access_time,
const base::Time& last_modified_time, const base::Time& last_modified_time,
const StatusCallback& callback); StatusCallback callback);
// Opens a file at |url| with |file_flags|, where flags are OR'ed // Opens a file at |url| with |file_flags|, where flags are OR'ed
// values of base::PlatformFileFlags. // values of base::PlatformFileFlags.
...@@ -146,7 +146,7 @@ class STORAGE_EXPORT FileSystemOperationRunner { ...@@ -146,7 +146,7 @@ class STORAGE_EXPORT FileSystemOperationRunner {
// This function is used only by Pepper as of writing. // This function is used only by Pepper as of writing.
OperationID OpenFile(const FileSystemURL& url, OperationID OpenFile(const FileSystemURL& url,
int file_flags, int file_flags,
const OpenFileCallback& callback); OpenFileCallback callback);
// Creates a local snapshot file for a given |url| and returns the // Creates a local snapshot file for a given |url| and returns the
// metadata and platform url of the snapshot file via |callback|. // metadata and platform url of the snapshot file via |callback|.
...@@ -171,7 +171,7 @@ class STORAGE_EXPORT FileSystemOperationRunner { ...@@ -171,7 +171,7 @@ class STORAGE_EXPORT FileSystemOperationRunner {
// //
OperationID CopyInForeignFile(const base::FilePath& src_local_disk_path, OperationID CopyInForeignFile(const base::FilePath& src_local_disk_path,
const FileSystemURL& dest_url, const FileSystemURL& dest_url,
const StatusCallback& callback); StatusCallback callback);
// Removes a single file. // Removes a single file.
// //
...@@ -179,8 +179,7 @@ class STORAGE_EXPORT FileSystemOperationRunner { ...@@ -179,8 +179,7 @@ class STORAGE_EXPORT FileSystemOperationRunner {
// - File::FILE_ERROR_NOT_FOUND if |url| does not exist. // - File::FILE_ERROR_NOT_FOUND if |url| does not exist.
// - File::FILE_ERROR_NOT_A_FILE if |url| is not a file. // - File::FILE_ERROR_NOT_A_FILE if |url| is not a file.
// //
OperationID RemoveFile(const FileSystemURL& url, OperationID RemoveFile(const FileSystemURL& url, StatusCallback callback);
const StatusCallback& callback);
// Removes a single empty directory. // Removes a single empty directory.
// //
...@@ -190,7 +189,7 @@ class STORAGE_EXPORT FileSystemOperationRunner { ...@@ -190,7 +189,7 @@ class STORAGE_EXPORT FileSystemOperationRunner {
// - File::FILE_ERROR_NOT_EMPTY if |url| is not empty. // - File::FILE_ERROR_NOT_EMPTY if |url| is not empty.
// //
OperationID RemoveDirectory(const FileSystemURL& url, OperationID RemoveDirectory(const FileSystemURL& url,
const StatusCallback& callback); StatusCallback callback);
// Copies a file from |src_url| to |dest_url|. // Copies a file from |src_url| to |dest_url|.
// This must be called for files that belong to the same filesystem // This must be called for files that belong to the same filesystem
...@@ -211,7 +210,7 @@ class STORAGE_EXPORT FileSystemOperationRunner { ...@@ -211,7 +210,7 @@ class STORAGE_EXPORT FileSystemOperationRunner {
const FileSystemURL& dest_url, const FileSystemURL& dest_url,
CopyOrMoveOption option, CopyOrMoveOption option,
const CopyFileProgressCallback& progress_callback, const CopyFileProgressCallback& progress_callback,
const StatusCallback& callback); StatusCallback callback);
// Moves a local file from |src_url| to |dest_url|. // Moves a local file from |src_url| to |dest_url|.
// This must be called for files that belong to the same filesystem // This must be called for files that belong to the same filesystem
...@@ -230,7 +229,7 @@ class STORAGE_EXPORT FileSystemOperationRunner { ...@@ -230,7 +229,7 @@ class STORAGE_EXPORT FileSystemOperationRunner {
OperationID MoveFileLocal(const FileSystemURL& src_url, OperationID MoveFileLocal(const FileSystemURL& src_url,
const FileSystemURL& dest_url, const FileSystemURL& dest_url,
CopyOrMoveOption option, CopyOrMoveOption option,
const StatusCallback& callback); StatusCallback callback);
// This is called only by pepper plugin as of writing to synchronously get // This is called only by pepper plugin as of writing to synchronously get
// the underlying platform path to upload a file in the sandboxed filesystem // the underlying platform path to upload a file in the sandboxed filesystem
...@@ -243,10 +242,10 @@ class STORAGE_EXPORT FileSystemOperationRunner { ...@@ -243,10 +242,10 @@ class STORAGE_EXPORT FileSystemOperationRunner {
explicit FileSystemOperationRunner(FileSystemContext* file_system_context); explicit FileSystemOperationRunner(FileSystemContext* file_system_context);
void DidFinish(const OperationID id, void DidFinish(const OperationID id,
const StatusCallback& callback, StatusCallback callback,
base::File::Error rv); base::File::Error rv);
void DidGetMetadata(const OperationID id, void DidGetMetadata(const OperationID id,
const GetMetadataCallback& callback, GetMetadataCallback callback,
base::File::Error rv, base::File::Error rv,
const base::File::Info& file_info); const base::File::Info& file_info);
void DidReadDirectory(const OperationID id, void DidReadDirectory(const OperationID id,
...@@ -260,7 +259,7 @@ class STORAGE_EXPORT FileSystemOperationRunner { ...@@ -260,7 +259,7 @@ class STORAGE_EXPORT FileSystemOperationRunner {
int64_t bytes, int64_t bytes,
bool complete); bool complete);
void DidOpenFile(const OperationID id, void DidOpenFile(const OperationID id,
const OpenFileCallback& callback, OpenFileCallback callback,
base::File file, base::File file,
base::OnceClosure on_close_callback); base::OnceClosure on_close_callback);
void DidCreateSnapshot( void DidCreateSnapshot(
......
...@@ -33,12 +33,12 @@ void RecursiveOperationDelegate::Cancel() { ...@@ -33,12 +33,12 @@ void RecursiveOperationDelegate::Cancel() {
void RecursiveOperationDelegate::StartRecursiveOperation( void RecursiveOperationDelegate::StartRecursiveOperation(
const FileSystemURL& root, const FileSystemURL& root,
ErrorBehavior error_behavior, ErrorBehavior error_behavior,
const StatusCallback& callback) { StatusCallback callback) {
DCHECK(pending_directory_stack_.empty()); DCHECK(pending_directory_stack_.empty());
DCHECK(pending_files_.empty()); DCHECK(pending_files_.empty());
error_behavior_ = error_behavior; error_behavior_ = error_behavior;
callback_ = callback; callback_ = std::move(callback);
TryProcessFile(root); TryProcessFile(root);
} }
...@@ -221,13 +221,13 @@ void RecursiveOperationDelegate::DidPostProcessDirectory( ...@@ -221,13 +221,13 @@ void RecursiveOperationDelegate::DidPostProcessDirectory(
void RecursiveOperationDelegate::Done(base::File::Error error) { void RecursiveOperationDelegate::Done(base::File::Error error) {
if (canceled_ && error == base::File::FILE_OK) { if (canceled_ && error == base::File::FILE_OK) {
callback_.Run(base::File::FILE_ERROR_ABORT); std::move(callback_).Run(base::File::FILE_ERROR_ABORT);
} else { } else {
if (error_behavior_ == FileSystemOperation::ERROR_BEHAVIOR_SKIP && if (error_behavior_ == FileSystemOperation::ERROR_BEHAVIOR_SKIP &&
failed_some_operations_) failed_some_operations_)
callback_.Run(base::File::FILE_ERROR_FAILED); std::move(callback_).Run(base::File::FILE_ERROR_FAILED);
else else
callback_.Run(error); std::move(callback_).Run(error);
} }
} }
......
...@@ -43,18 +43,17 @@ class STORAGE_EXPORT RecursiveOperationDelegate ...@@ -43,18 +43,17 @@ class STORAGE_EXPORT RecursiveOperationDelegate
// This is called each time a file is found while recursively // This is called each time a file is found while recursively
// performing an operation. // performing an operation.
virtual void ProcessFile(const FileSystemURL& url, virtual void ProcessFile(const FileSystemURL& url,
const StatusCallback& callback) = 0; StatusCallback callback) = 0;
// This is called each time a directory is found while recursively // This is called each time a directory is found while recursively
// performing an operation. // performing an operation.
virtual void ProcessDirectory(const FileSystemURL& url, virtual void ProcessDirectory(const FileSystemURL& url,
const StatusCallback& callback) = 0; StatusCallback callback) = 0;
// This is called each time after files and subdirectories for a // This is called each time after files and subdirectories for a
// directory is processed while recursively performing an operation. // directory is processed while recursively performing an operation.
virtual void PostProcessDirectory(const FileSystemURL& url, virtual void PostProcessDirectory(const FileSystemURL& url,
const StatusCallback& callback) = 0; StatusCallback callback) = 0;
// Cancels the currently running operation. // Cancels the currently running operation.
void Cancel(); void Cancel();
...@@ -111,7 +110,7 @@ class STORAGE_EXPORT RecursiveOperationDelegate ...@@ -111,7 +110,7 @@ class STORAGE_EXPORT RecursiveOperationDelegate
// under |root| is processed, or fired earlier when any suboperation fails. // under |root| is processed, or fired earlier when any suboperation fails.
void StartRecursiveOperation(const FileSystemURL& root, void StartRecursiveOperation(const FileSystemURL& root,
ErrorBehavior error_behavior, ErrorBehavior error_behavior,
const StatusCallback& callback); StatusCallback callback);
FileSystemContext* file_system_context() { return file_system_context_; } FileSystemContext* file_system_context() { return file_system_context_; }
const FileSystemContext* file_system_context() const { const FileSystemContext* file_system_context() const {
......
...@@ -44,10 +44,10 @@ class LoggingRecursiveOperation : public storage::RecursiveOperationDelegate { ...@@ -44,10 +44,10 @@ class LoggingRecursiveOperation : public storage::RecursiveOperationDelegate {
LoggingRecursiveOperation(FileSystemContext* file_system_context, LoggingRecursiveOperation(FileSystemContext* file_system_context,
const FileSystemURL& root, const FileSystemURL& root,
const StatusCallback& callback) StatusCallback callback)
: storage::RecursiveOperationDelegate(file_system_context), : storage::RecursiveOperationDelegate(file_system_context),
root_(root), root_(root),
callback_(callback), callback_(std::move(callback)),
weak_factory_(this) {} weak_factory_(this) {}
~LoggingRecursiveOperation() override = default; ~LoggingRecursiveOperation() override = default;
...@@ -57,40 +57,41 @@ class LoggingRecursiveOperation : public storage::RecursiveOperationDelegate { ...@@ -57,40 +57,41 @@ class LoggingRecursiveOperation : public storage::RecursiveOperationDelegate {
void Run() override { NOTREACHED(); } void Run() override { NOTREACHED(); }
void RunRecursively() override { void RunRecursively() override {
StartRecursiveOperation( StartRecursiveOperation(root_,
root_, storage::FileSystemOperation::ERROR_BEHAVIOR_ABORT, callback_); storage::FileSystemOperation::ERROR_BEHAVIOR_ABORT,
std::move(callback_));
} }
void RunRecursivelyWithIgnoringError() { void RunRecursivelyWithIgnoringError() {
StartRecursiveOperation( StartRecursiveOperation(root_,
root_, storage::FileSystemOperation::ERROR_BEHAVIOR_SKIP, callback_); storage::FileSystemOperation::ERROR_BEHAVIOR_SKIP,
std::move(callback_));
} }
void ProcessFile(const FileSystemURL& url, void ProcessFile(const FileSystemURL& url, StatusCallback callback) override {
const StatusCallback& callback) override {
RecordLogEntry(LogEntry::PROCESS_FILE, url); RecordLogEntry(LogEntry::PROCESS_FILE, url);
if (error_url_.is_valid() && error_url_ == url) { if (error_url_.is_valid() && error_url_ == url) {
callback.Run(base::File::FILE_ERROR_FAILED); std::move(callback).Run(base::File::FILE_ERROR_FAILED);
return; return;
} }
operation_runner()->GetMetadata( operation_runner()->GetMetadata(
url, storage::FileSystemOperation::GET_METADATA_FIELD_IS_DIRECTORY, url, storage::FileSystemOperation::GET_METADATA_FIELD_IS_DIRECTORY,
base::Bind(&LoggingRecursiveOperation::DidGetMetadata, base::BindOnce(&LoggingRecursiveOperation::DidGetMetadata,
weak_factory_.GetWeakPtr(), callback)); weak_factory_.GetWeakPtr(), std::move(callback)));
} }
void ProcessDirectory(const FileSystemURL& url, void ProcessDirectory(const FileSystemURL& url,
const StatusCallback& callback) override { StatusCallback callback) override {
RecordLogEntry(LogEntry::PROCESS_DIRECTORY, url); RecordLogEntry(LogEntry::PROCESS_DIRECTORY, url);
callback.Run(base::File::FILE_OK); std::move(callback).Run(base::File::FILE_OK);
} }
void PostProcessDirectory(const FileSystemURL& url, void PostProcessDirectory(const FileSystemURL& url,
const StatusCallback& callback) override { StatusCallback callback) override {
RecordLogEntry(LogEntry::POST_PROCESS_DIRECTORY, url); RecordLogEntry(LogEntry::POST_PROCESS_DIRECTORY, url);
callback.Run(base::File::FILE_OK); std::move(callback).Run(base::File::FILE_OK);
} }
void SetEntryToFail(const FileSystemURL& url) { error_url_ = url; } void SetEntryToFail(const FileSystemURL& url) { error_url_ = url; }
...@@ -103,17 +104,17 @@ class LoggingRecursiveOperation : public storage::RecursiveOperationDelegate { ...@@ -103,17 +104,17 @@ class LoggingRecursiveOperation : public storage::RecursiveOperationDelegate {
log_entries_.push_back(entry); log_entries_.push_back(entry);
} }
void DidGetMetadata(const StatusCallback& callback, void DidGetMetadata(StatusCallback callback,
base::File::Error result, base::File::Error result,
const base::File::Info& file_info) { const base::File::Info& file_info) {
if (result != base::File::FILE_OK) { if (result != base::File::FILE_OK) {
callback.Run(result); std::move(callback).Run(result);
return; return;
} }
callback.Run(file_info.is_directory ? std::move(callback).Run(file_info.is_directory
base::File::FILE_ERROR_NOT_A_FILE : ? base::File::FILE_ERROR_NOT_A_FILE
base::File::FILE_OK); : base::File::FILE_OK);
} }
FileSystemURL root_; FileSystemURL root_;
......
...@@ -13,71 +13,77 @@ namespace storage { ...@@ -13,71 +13,77 @@ namespace storage {
RemoveOperationDelegate::RemoveOperationDelegate( RemoveOperationDelegate::RemoveOperationDelegate(
FileSystemContext* file_system_context, FileSystemContext* file_system_context,
const FileSystemURL& url, const FileSystemURL& url,
const StatusCallback& callback) StatusCallback callback)
: RecursiveOperationDelegate(file_system_context), : RecursiveOperationDelegate(file_system_context),
url_(url), url_(url),
callback_(callback), callback_(std::move(callback)),
weak_factory_(this) { weak_factory_(this) {}
}
RemoveOperationDelegate::~RemoveOperationDelegate() = default; RemoveOperationDelegate::~RemoveOperationDelegate() = default;
void RemoveOperationDelegate::Run() { void RemoveOperationDelegate::Run() {
operation_runner()->RemoveFile(url_, base::Bind( #if DCHECK_IS_ON()
&RemoveOperationDelegate::DidTryRemoveFile, weak_factory_.GetWeakPtr())); DCHECK(!did_run_);
did_run_ = true;
#endif
operation_runner()->RemoveFile(
url_, base::BindOnce(&RemoveOperationDelegate::DidTryRemoveFile,
weak_factory_.GetWeakPtr()));
} }
void RemoveOperationDelegate::RunRecursively() { void RemoveOperationDelegate::RunRecursively() {
#if DCHECK_IS_ON()
DCHECK(!did_run_);
did_run_ = true;
#endif
StartRecursiveOperation(url_, FileSystemOperation::ERROR_BEHAVIOR_ABORT, StartRecursiveOperation(url_, FileSystemOperation::ERROR_BEHAVIOR_ABORT,
callback_); std::move(callback_));
} }
void RemoveOperationDelegate::ProcessFile(const FileSystemURL& url, void RemoveOperationDelegate::ProcessFile(const FileSystemURL& url,
const StatusCallback& callback) { StatusCallback callback) {
operation_runner()->RemoveFile( operation_runner()->RemoveFile(
url, url, base::BindOnce(&RemoveOperationDelegate::DidRemoveFile,
base::Bind(&RemoveOperationDelegate::DidRemoveFile, weak_factory_.GetWeakPtr(), std::move(callback)));
weak_factory_.GetWeakPtr(), callback));
} }
void RemoveOperationDelegate::ProcessDirectory(const FileSystemURL& url, void RemoveOperationDelegate::ProcessDirectory(const FileSystemURL& url,
const StatusCallback& callback) { StatusCallback callback) {
callback.Run(base::File::FILE_OK); std::move(callback).Run(base::File::FILE_OK);
} }
void RemoveOperationDelegate::PostProcessDirectory( void RemoveOperationDelegate::PostProcessDirectory(const FileSystemURL& url,
const FileSystemURL& url, const StatusCallback& callback) { StatusCallback callback) {
operation_runner()->RemoveDirectory(url, callback); operation_runner()->RemoveDirectory(url, std::move(callback));
} }
void RemoveOperationDelegate::DidTryRemoveFile(base::File::Error error) { void RemoveOperationDelegate::DidTryRemoveFile(base::File::Error error) {
if (error != base::File::FILE_ERROR_NOT_A_FILE && if (error != base::File::FILE_ERROR_NOT_A_FILE &&
error != base::File::FILE_ERROR_SECURITY) { error != base::File::FILE_ERROR_SECURITY) {
callback_.Run(error); std::move(callback_).Run(error);
return; return;
} }
operation_runner()->RemoveDirectory( operation_runner()->RemoveDirectory(
url_, url_, base::BindOnce(&RemoveOperationDelegate::DidTryRemoveDirectory,
base::Bind(&RemoveOperationDelegate::DidTryRemoveDirectory, weak_factory_.GetWeakPtr(), error));
weak_factory_.GetWeakPtr(), error));
} }
void RemoveOperationDelegate::DidTryRemoveDirectory( void RemoveOperationDelegate::DidTryRemoveDirectory(
base::File::Error remove_file_error, base::File::Error remove_file_error,
base::File::Error remove_directory_error) { base::File::Error remove_directory_error) {
callback_.Run( std::move(callback_).Run(remove_directory_error ==
remove_directory_error == base::File::FILE_ERROR_NOT_A_DIRECTORY ? base::File::FILE_ERROR_NOT_A_DIRECTORY
remove_file_error : ? remove_file_error
remove_directory_error); : remove_directory_error);
} }
void RemoveOperationDelegate::DidRemoveFile(const StatusCallback& callback, void RemoveOperationDelegate::DidRemoveFile(StatusCallback callback,
base::File::Error error) { base::File::Error error) {
if (error == base::File::FILE_ERROR_NOT_FOUND) { if (error == base::File::FILE_ERROR_NOT_FOUND) {
callback.Run(base::File::FILE_OK); std::move(callback).Run(base::File::FILE_OK);
return; return;
} }
callback.Run(error); std::move(callback).Run(error);
} }
} // namespace storage } // namespace storage
...@@ -14,26 +14,27 @@ class RemoveOperationDelegate : public RecursiveOperationDelegate { ...@@ -14,26 +14,27 @@ class RemoveOperationDelegate : public RecursiveOperationDelegate {
public: public:
RemoveOperationDelegate(FileSystemContext* file_system_context, RemoveOperationDelegate(FileSystemContext* file_system_context,
const FileSystemURL& url, const FileSystemURL& url,
const StatusCallback& callback); StatusCallback callback);
~RemoveOperationDelegate() override; ~RemoveOperationDelegate() override;
// RecursiveOperationDelegate overrides: // RecursiveOperationDelegate overrides:
void Run() override; void Run() override;
void RunRecursively() override; void RunRecursively() override;
void ProcessFile(const FileSystemURL& url, void ProcessFile(const FileSystemURL& url, StatusCallback callback) override;
const StatusCallback& callback) override;
void ProcessDirectory(const FileSystemURL& url, void ProcessDirectory(const FileSystemURL& url,
const StatusCallback& callback) override; StatusCallback callback) override;
void PostProcessDirectory(const FileSystemURL& url, void PostProcessDirectory(const FileSystemURL& url,
const StatusCallback& callback) override; StatusCallback callback) override;
private: private:
void DidTryRemoveFile(base::File::Error error); void DidTryRemoveFile(base::File::Error error);
void DidTryRemoveDirectory(base::File::Error remove_file_error, void DidTryRemoveDirectory(base::File::Error remove_file_error,
base::File::Error remove_directory_error); base::File::Error remove_directory_error);
void DidRemoveFile(const StatusCallback& callback, void DidRemoveFile(StatusCallback callback, base::File::Error error);
base::File::Error error);
#if DCHECK_IS_ON()
bool did_run_ = false;
#endif
FileSystemURL url_; FileSystemURL url_;
StatusCallback callback_; StatusCallback callback_;
base::WeakPtrFactory<RemoveOperationDelegate> weak_factory_; base::WeakPtrFactory<RemoveOperationDelegate> weak_factory_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment