Commit 95ec6984 authored by Anand K. Mistry's avatar Anand K. Mistry Committed by Commit Bot

Convert callbacks in SnapshotManager to OnceCallback.

No changes to behaviour. Part of ongoing effort to clean up file manager
code.

BUG=875700

Change-Id: If66a7ebf25d401397492133c2977a1b9e6109dde
Reviewed-on: https://chromium-review.googlesource.com/1220347Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Commit-Queue: Anand Mistry <amistry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590565}
parent 8144b8fe
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
namespace file_manager { namespace file_manager {
namespace { namespace {
typedef base::Callback<void(int64_t)> GetNecessaryFreeSpaceCallback; typedef base::OnceCallback<void(int64_t)> GetNecessaryFreeSpaceCallback;
// Part of ComputeSpaceNeedToBeFreed. // Part of ComputeSpaceNeedToBeFreed.
int64_t ComputeSpaceNeedToBeFreedAfterGetMetadataAsync( int64_t ComputeSpaceNeedToBeFreedAfterGetMetadataAsync(
...@@ -41,31 +41,32 @@ int64_t ComputeSpaceNeedToBeFreedAfterGetMetadataAsync( ...@@ -41,31 +41,32 @@ int64_t ComputeSpaceNeedToBeFreedAfterGetMetadataAsync(
// Part of ComputeSpaceNeedToBeFreed. // Part of ComputeSpaceNeedToBeFreed.
void ComputeSpaceNeedToBeFreedAfterGetMetadata( void ComputeSpaceNeedToBeFreedAfterGetMetadata(
const base::FilePath& path, const base::FilePath& path,
const GetNecessaryFreeSpaceCallback& callback, GetNecessaryFreeSpaceCallback callback,
base::File::Error result, base::File::Error result,
const base::File::Info& file_info) { const base::File::Info& file_info) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
if (result != base::File::FILE_OK) { if (result != base::File::FILE_OK) {
callback.Run(-1); std::move(callback).Run(-1);
return; return;
} }
base::PostTaskWithTraitsAndReplyWithResult( base::PostTaskWithTraitsAndReplyWithResult(
FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_BLOCKING}, FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_BLOCKING},
base::Bind(&ComputeSpaceNeedToBeFreedAfterGetMetadataAsync, path, base::BindOnce(&ComputeSpaceNeedToBeFreedAfterGetMetadataAsync, path,
file_info.size), file_info.size),
callback); std::move(callback));
} }
// Part of ComputeSpaceNeedToBeFreed. // Part of ComputeSpaceNeedToBeFreed.
void GetMetadataOnIOThread(const base::FilePath& path, void GetMetadataOnIOThread(const base::FilePath& path,
scoped_refptr<storage::FileSystemContext> context, scoped_refptr<storage::FileSystemContext> context,
const storage::FileSystemURL& url, const storage::FileSystemURL& url,
const GetNecessaryFreeSpaceCallback& callback) { GetNecessaryFreeSpaceCallback callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
context->operation_runner()->GetMetadata( context->operation_runner()->GetMetadata(
url, storage::FileSystemOperation::GET_METADATA_FIELD_SIZE, url, storage::FileSystemOperation::GET_METADATA_FIELD_SIZE,
base::Bind(&ComputeSpaceNeedToBeFreedAfterGetMetadata, path, callback)); base::Bind(&ComputeSpaceNeedToBeFreedAfterGetMetadata, path,
base::Passed(std::move(callback))));
} }
// Computes the size of space that need to be __additionally__ made available // Computes the size of space that need to be __additionally__ made available
...@@ -75,12 +76,12 @@ void ComputeSpaceNeedToBeFreed( ...@@ -75,12 +76,12 @@ void ComputeSpaceNeedToBeFreed(
Profile* profile, Profile* profile,
scoped_refptr<storage::FileSystemContext> context, scoped_refptr<storage::FileSystemContext> context,
const storage::FileSystemURL& url, const storage::FileSystemURL& url,
const GetNecessaryFreeSpaceCallback& callback) { GetNecessaryFreeSpaceCallback callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
content::BrowserThread::PostTask( content::BrowserThread::PostTask(
content::BrowserThread::IO, FROM_HERE, content::BrowserThread::IO, FROM_HERE,
base::BindOnce(&GetMetadataOnIOThread, profile->GetPath(), context, url, base::BindOnce(&GetMetadataOnIOThread, profile->GetPath(), context, url,
google_apis::CreateRelayCallback(callback))); google_apis::CreateRelayCallback(std::move(callback))));
} }
// Part of CreateManagedSnapshot. Runs CreateSnapshotFile method of fileapi. // Part of CreateManagedSnapshot. Runs CreateSnapshotFile method of fileapi.
...@@ -129,7 +130,7 @@ SnapshotManager::~SnapshotManager() { ...@@ -129,7 +130,7 @@ SnapshotManager::~SnapshotManager() {
void SnapshotManager::CreateManagedSnapshot( void SnapshotManager::CreateManagedSnapshot(
const base::FilePath& absolute_file_path, const base::FilePath& absolute_file_path,
const LocalPathCallback& callback) { LocalPathCallback callback) {
scoped_refptr<storage::FileSystemContext> context( scoped_refptr<storage::FileSystemContext> context(
util::GetFileSystemContextForExtensionId(profile_, kFileManagerAppId)); util::GetFileSystemContextForExtensionId(profile_, kFileManagerAppId));
DCHECK(context.get()); DCHECK(context.get());
...@@ -137,28 +138,28 @@ void SnapshotManager::CreateManagedSnapshot( ...@@ -137,28 +138,28 @@ void SnapshotManager::CreateManagedSnapshot(
GURL url; GURL url;
if (!util::ConvertAbsoluteFilePathToFileSystemUrl( if (!util::ConvertAbsoluteFilePathToFileSystemUrl(
profile_, absolute_file_path, kFileManagerAppId, &url)) { profile_, absolute_file_path, kFileManagerAppId, &url)) {
callback.Run(base::FilePath()); std::move(callback).Run(base::FilePath());
return; return;
} }
storage::FileSystemURL filesystem_url = context->CrackURL(url); storage::FileSystemURL filesystem_url = context->CrackURL(url);
ComputeSpaceNeedToBeFreed(profile_, context, filesystem_url, ComputeSpaceNeedToBeFreed(
base::Bind(&SnapshotManager::CreateManagedSnapshotAfterSpaceComputed, profile_, context, filesystem_url,
weak_ptr_factory_.GetWeakPtr(), base::BindOnce(&SnapshotManager::CreateManagedSnapshotAfterSpaceComputed,
filesystem_url, weak_ptr_factory_.GetWeakPtr(), filesystem_url,
callback)); std::move(callback)));
} }
void SnapshotManager::CreateManagedSnapshotAfterSpaceComputed( void SnapshotManager::CreateManagedSnapshotAfterSpaceComputed(
const storage::FileSystemURL& filesystem_url, const storage::FileSystemURL& filesystem_url,
const LocalPathCallback& callback, LocalPathCallback callback,
int64_t needed_space) { int64_t needed_space) {
scoped_refptr<storage::FileSystemContext> context( scoped_refptr<storage::FileSystemContext> context(
util::GetFileSystemContextForExtensionId(profile_, kFileManagerAppId)); util::GetFileSystemContextForExtensionId(profile_, kFileManagerAppId));
DCHECK(context.get()); DCHECK(context.get());
if (needed_space < 0) { if (needed_space < 0) {
callback.Run(base::FilePath()); std::move(callback).Run(base::FilePath());
return; return;
} }
...@@ -178,21 +179,22 @@ void SnapshotManager::CreateManagedSnapshotAfterSpaceComputed( ...@@ -178,21 +179,22 @@ void SnapshotManager::CreateManagedSnapshotAfterSpaceComputed(
// If we still could not achieve the space requirement, abort with failure. // If we still could not achieve the space requirement, abort with failure.
if (needed_space > 0) { if (needed_space > 0) {
callback.Run(base::FilePath()); std::move(callback).Run(base::FilePath());
return; return;
} }
// Start creating the snapshot. // Start creating the snapshot.
content::BrowserThread::PostTask( content::BrowserThread::PostTask(
content::BrowserThread::IO, FROM_HERE, content::BrowserThread::IO, FROM_HERE,
base::BindOnce(&CreateSnapshotFileOnIOThread, context, filesystem_url, base::BindOnce(
google_apis::CreateRelayCallback(base::Bind( &CreateSnapshotFileOnIOThread, context, filesystem_url,
&SnapshotManager::OnCreateSnapshotFile, google_apis::CreateRelayCallback(base::BindOnce(
weak_ptr_factory_.GetWeakPtr(), callback)))); &SnapshotManager::OnCreateSnapshotFile,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)))));
} }
void SnapshotManager::OnCreateSnapshotFile( void SnapshotManager::OnCreateSnapshotFile(
const LocalPathCallback& callback, LocalPathCallback callback,
base::File::Error result, base::File::Error result,
const base::File::Info& file_info, const base::File::Info& file_info,
const base::FilePath& platform_path, const base::FilePath& platform_path,
...@@ -200,13 +202,13 @@ void SnapshotManager::OnCreateSnapshotFile( ...@@ -200,13 +202,13 @@ void SnapshotManager::OnCreateSnapshotFile(
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (result != base::File::FILE_OK) { if (result != base::File::FILE_OK) {
callback.Run(base::FilePath()); std::move(callback).Run(base::FilePath());
return; return;
} }
file_refs_.push_back( file_refs_.push_back(
FileReferenceWithSizeInfo(std::move(file_ref), file_info.size)); FileReferenceWithSizeInfo(std::move(file_ref), file_info.size));
callback.Run(platform_path); std::move(callback).Run(platform_path);
} }
} // namespace file_manager } // namespace file_manager
...@@ -37,7 +37,7 @@ namespace file_manager { ...@@ -37,7 +37,7 @@ namespace file_manager {
class SnapshotManager { class SnapshotManager {
public: public:
// The callback type for CreateManagedSnapshot. // The callback type for CreateManagedSnapshot.
typedef base::Callback<void(const base::FilePath&)> LocalPathCallback; typedef base::OnceCallback<void(const base::FilePath&)> LocalPathCallback;
explicit SnapshotManager(Profile* profile); explicit SnapshotManager(Profile* profile);
~SnapshotManager(); ~SnapshotManager();
...@@ -45,7 +45,7 @@ class SnapshotManager { ...@@ -45,7 +45,7 @@ class SnapshotManager {
// Creates a snapshot file copy of a file system file |absolute_file_path| and // Creates a snapshot file copy of a file system file |absolute_file_path| and
// returns back to |callback|. Returns empty path for failure. // returns back to |callback|. Returns empty path for failure.
void CreateManagedSnapshot(const base::FilePath& absolute_file_path, void CreateManagedSnapshot(const base::FilePath& absolute_file_path,
const LocalPathCallback& callback); LocalPathCallback callback);
// Struct for keeping the snapshot file reference with its file size used for // Struct for keeping the snapshot file reference with its file size used for
// computing the necessity of clean up. // computing the necessity of clean up.
...@@ -63,12 +63,12 @@ class SnapshotManager { ...@@ -63,12 +63,12 @@ class SnapshotManager {
// Part of CreateManagedSnapshot. // Part of CreateManagedSnapshot.
void CreateManagedSnapshotAfterSpaceComputed( void CreateManagedSnapshotAfterSpaceComputed(
const storage::FileSystemURL& filesystem_url, const storage::FileSystemURL& filesystem_url,
const LocalPathCallback& callback, LocalPathCallback callback,
int64_t needed_space); int64_t needed_space);
// Part of CreateManagedSnapshot. // Part of CreateManagedSnapshot.
void OnCreateSnapshotFile( void OnCreateSnapshotFile(
const LocalPathCallback& callback, LocalPathCallback callback,
base::File::Error result, base::File::Error result,
const base::File::Info& file_info, const base::File::Info& file_info,
const base::FilePath& platform_path, const base::FilePath& platform_path,
......
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