Commit 8487fa49 authored by Christos Froussios's avatar Christos Froussios Committed by Commit Bot

Revert "Migrate file_system file manager APIs to UIThreadExtensionFunction."

This reverts commit 76efdcf8.

Reason for revert: Suspected of breaking
FileSystemProviderApiTest.RemoveWatcher
FileSystemProviderApiTest.AddWatcher
in browser_tests on linux-chromeos-rel

Example failure
https://ci.chromium.org/p/chromium/builders/luci.chromium.ci/linux-chromeos-rel/20439

Original change's description:
> Migrate file_system file manager APIs to UIThreadExtensionFunction.
> 
> BUG=934541
> 
> Change-Id: Ibd06bda730bd10c270d187d83f68315159fa6a43
> Reviewed-on: https://chromium-review.googlesource.com/c/1482172
> Reviewed-by: Sam McNally <sammc@chromium.org>
> Commit-Queue: Anand Mistry <amistry@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#634562}

TBR=sammc@chromium.org,amistry@chromium.org

Change-Id: I56ca79cb7a1d358539d31d3c1156859232e08ce3
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 934541
Reviewed-on: https://chromium-review.googlesource.com/c/1482970Reviewed-by: default avatarChristos Froussios <cfroussios@chromium.org>
Commit-Queue: Christos Froussios <cfroussios@chromium.org>
Cr-Commit-Position: refs/heads/master@{#634593}
parent 8306f020
...@@ -344,43 +344,44 @@ void PostNotificationCallbackTaskToUIThread( ...@@ -344,43 +344,44 @@ void PostNotificationCallbackTaskToUIThread(
} // namespace } // namespace
void FileWatchFunctionBase::RespondWith(bool success) { void FileWatchFunctionBase::Respond(bool success) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
Respond(OneArgument(std::make_unique<base::Value>(success)));
SetResult(std::make_unique<base::Value>(success));
SendResponse(success);
} }
ExtensionFunction::ResponseAction FileWatchFunctionBase::Run() { bool FileWatchFunctionBase::RunAsync() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!render_frame_host() || !render_frame_host()->GetProcess()) if (!render_frame_host() || !render_frame_host()->GetProcess())
return RespondNow(Error("Invalid state")); return false;
// First param is url of a file to watch. // First param is url of a file to watch.
std::string url; std::string url;
if (!args_->GetString(0, &url) || url.empty()) if (!args_->GetString(0, &url) || url.empty())
return RespondNow(Error("Empty watch URL")); return false;
const ChromeExtensionFunctionDetails chrome_details(this);
scoped_refptr<storage::FileSystemContext> file_system_context = scoped_refptr<storage::FileSystemContext> file_system_context =
file_manager::util::GetFileSystemContextForRenderFrameHost( file_manager::util::GetFileSystemContextForRenderFrameHost(
chrome_details.GetProfile(), render_frame_host()); GetProfile(), render_frame_host());
const FileSystemURL file_system_url = const FileSystemURL file_system_url =
file_system_context->CrackURL(GURL(url)); file_system_context->CrackURL(GURL(url));
if (file_system_url.path().empty()) { if (file_system_url.path().empty()) {
return RespondNow(OneArgument(std::make_unique<base::Value>(false))); Respond(false);
return true;
} }
file_manager::EventRouter* const event_router = file_manager::EventRouter* const event_router =
file_manager::EventRouterFactory::GetForProfile( file_manager::EventRouterFactory::GetForProfile(GetProfile());
chrome_details.GetProfile());
base::PostTaskWithTraits( base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::IO}, FROM_HERE, {BrowserThread::IO},
base::BindOnce(&FileWatchFunctionBase::RunAsyncOnIOThread, this, base::BindOnce(&FileWatchFunctionBase::RunAsyncOnIOThread, this,
file_system_context, file_system_url, file_system_context, file_system_url,
event_router->GetWeakPtr())); event_router->GetWeakPtr()));
return RespondLater(); return true;
} }
void FileWatchFunctionBase::RunAsyncOnIOThread( void FileWatchFunctionBase::RunAsyncOnIOThread(
...@@ -415,10 +416,9 @@ void FileManagerPrivateInternalAddFileWatchFunction:: ...@@ -415,10 +416,9 @@ void FileManagerPrivateInternalAddFileWatchFunction::
watcher_manager->AddWatcher( watcher_manager->AddWatcher(
file_system_url, false /* recursive */, file_system_url, false /* recursive */,
base::Bind( base::Bind(&StatusCallbackToResponseCallback,
&StatusCallbackToResponseCallback, base::Bind(&PostResponseCallbackTaskToUIThread,
base::Bind(&PostResponseCallbackTaskToUIThread, base::Bind(&FileWatchFunctionBase::Respond, this))),
base::Bind(&FileWatchFunctionBase::RespondWith, this))),
base::Bind( base::Bind(
&PostNotificationCallbackTaskToUIThread, &PostNotificationCallbackTaskToUIThread,
base::Bind(&file_manager::EventRouter::OnWatcherManagerNotification, base::Bind(&file_manager::EventRouter::OnWatcherManagerNotification,
...@@ -433,9 +433,9 @@ void FileManagerPrivateInternalAddFileWatchFunction:: ...@@ -433,9 +433,9 @@ void FileManagerPrivateInternalAddFileWatchFunction::
DCHECK(event_router); DCHECK(event_router);
// Obsolete. Fallback code if storage::WatcherManager is not implemented. // Obsolete. Fallback code if storage::WatcherManager is not implemented.
event_router->AddFileWatch( event_router->AddFileWatch(file_system_url.path(),
file_system_url.path(), file_system_url.virtual_path(), extension_id(), file_system_url.virtual_path(), extension_id(),
base::Bind(&FileWatchFunctionBase::RespondWith, this)); base::Bind(&FileWatchFunctionBase::Respond, this));
} }
void FileManagerPrivateInternalRemoveFileWatchFunction:: void FileManagerPrivateInternalRemoveFileWatchFunction::
...@@ -451,7 +451,7 @@ void FileManagerPrivateInternalRemoveFileWatchFunction:: ...@@ -451,7 +451,7 @@ void FileManagerPrivateInternalRemoveFileWatchFunction::
base::Bind( base::Bind(
&StatusCallbackToResponseCallback, &StatusCallbackToResponseCallback,
base::Bind(&PostResponseCallbackTaskToUIThread, base::Bind(&PostResponseCallbackTaskToUIThread,
base::Bind(&FileWatchFunctionBase::RespondWith, this)))); base::Bind(&FileWatchFunctionBase::Respond, this))));
} }
void FileManagerPrivateInternalRemoveFileWatchFunction:: void FileManagerPrivateInternalRemoveFileWatchFunction::
...@@ -463,37 +463,35 @@ void FileManagerPrivateInternalRemoveFileWatchFunction:: ...@@ -463,37 +463,35 @@ void FileManagerPrivateInternalRemoveFileWatchFunction::
// Obsolete. Fallback code if storage::WatcherManager is not implemented. // Obsolete. Fallback code if storage::WatcherManager is not implemented.
event_router->RemoveFileWatch(file_system_url.path(), extension_id()); event_router->RemoveFileWatch(file_system_url.path(), extension_id());
RespondWith(true); Respond(true);
} }
ExtensionFunction::ResponseAction bool FileManagerPrivateGetSizeStatsFunction::RunAsync() {
FileManagerPrivateGetSizeStatsFunction::Run() {
using extensions::api::file_manager_private::GetSizeStats::Params; using extensions::api::file_manager_private::GetSizeStats::Params;
const std::unique_ptr<Params> params(Params::Create(*args_)); const std::unique_ptr<Params> params(Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params); EXTENSION_FUNCTION_VALIDATE(params);
using file_manager::VolumeManager; using file_manager::VolumeManager;
using file_manager::Volume; using file_manager::Volume;
const ChromeExtensionFunctionDetails chrome_details(this); VolumeManager* const volume_manager = VolumeManager::Get(GetProfile());
VolumeManager* const volume_manager =
VolumeManager::Get(chrome_details.GetProfile());
if (!volume_manager) if (!volume_manager)
return RespondNow(Error("Invalid state")); return false;
base::WeakPtr<Volume> volume = base::WeakPtr<Volume> volume =
volume_manager->FindVolumeById(params->volume_id); volume_manager->FindVolumeById(params->volume_id);
if (!volume.get()) if (!volume.get())
return RespondNow(Error("Volume not found")); return false;
if (volume->type() == file_manager::VOLUME_TYPE_GOOGLE_DRIVE && if (volume->type() == file_manager::VOLUME_TYPE_GOOGLE_DRIVE &&
!base::FeatureList::IsEnabled(chromeos::features::kDriveFs)) { !base::FeatureList::IsEnabled(chromeos::features::kDriveFs)) {
drive::FileSystemInterface* file_system = drive::FileSystemInterface* file_system =
drive::util::GetFileSystemByProfile(chrome_details.GetProfile()); drive::util::GetFileSystemByProfile(GetProfile());
if (!file_system) { if (!file_system) {
// |file_system| is NULL if Drive is disabled. // |file_system| is NULL if Drive is disabled.
// If stats couldn't be gotten for drive, result should be left // If stats couldn't be gotten for drive, result should be left
// undefined. See comments in GetDriveAvailableSpaceCallback(). // undefined. See comments in GetDriveAvailableSpaceCallback().
return RespondNow(NoArguments()); SendResponse(true);
return true;
} }
file_system->GetAvailableSpace(base::BindOnce( file_system->GetAvailableSpace(base::BindOnce(
...@@ -527,7 +525,7 @@ FileManagerPrivateGetSizeStatsFunction::Run() { ...@@ -527,7 +525,7 @@ FileManagerPrivateGetSizeStatsFunction::Run() {
this, base::Owned(total_size), this, base::Owned(total_size),
base::Owned(remaining_size))); base::Owned(remaining_size)));
} }
return RespondLater(); return true;
} }
void FileManagerPrivateGetSizeStatsFunction::OnGetDriveAvailableSpace( void FileManagerPrivateGetSizeStatsFunction::OnGetDriveAvailableSpace(
...@@ -542,7 +540,7 @@ void FileManagerPrivateGetSizeStatsFunction::OnGetDriveAvailableSpace( ...@@ -542,7 +540,7 @@ void FileManagerPrivateGetSizeStatsFunction::OnGetDriveAvailableSpace(
OnGetSizeStats(&bytes_total_unsigned, &bytes_remaining_unsigned); OnGetSizeStats(&bytes_total_unsigned, &bytes_remaining_unsigned);
} else { } else {
// If stats couldn't be gotten for drive, result should be left undefined. // If stats couldn't be gotten for drive, result should be left undefined.
Respond(NoArguments()); SendResponse(true);
} }
} }
...@@ -552,7 +550,7 @@ void FileManagerPrivateGetSizeStatsFunction::OnGetMtpAvailableSpace( ...@@ -552,7 +550,7 @@ void FileManagerPrivateGetSizeStatsFunction::OnGetMtpAvailableSpace(
if (error) { if (error) {
// If stats couldn't be gotten from MTP volume, result should be left // If stats couldn't be gotten from MTP volume, result should be left
// undefined same as we do for Drive. // undefined same as we do for Drive.
Respond(NoArguments()); SendResponse(true);
return; return;
} }
...@@ -569,29 +567,30 @@ void FileManagerPrivateGetSizeStatsFunction::OnGetSizeStats( ...@@ -569,29 +567,30 @@ void FileManagerPrivateGetSizeStatsFunction::OnGetSizeStats(
sizes->SetDouble("totalSize", static_cast<double>(*total_size)); sizes->SetDouble("totalSize", static_cast<double>(*total_size));
sizes->SetDouble("remainingSize", static_cast<double>(*remaining_size)); sizes->SetDouble("remainingSize", static_cast<double>(*remaining_size));
Respond(OneArgument(std::move(sizes))); SetResult(std::move(sizes));
SendResponse(true);
} }
ExtensionFunction::ResponseAction bool FileManagerPrivateInternalValidatePathNameLengthFunction::RunAsync() {
FileManagerPrivateInternalValidatePathNameLengthFunction::Run() {
using extensions::api::file_manager_private_internal::ValidatePathNameLength:: using extensions::api::file_manager_private_internal::ValidatePathNameLength::
Params; Params;
const std::unique_ptr<Params> params(Params::Create(*args_)); const std::unique_ptr<Params> params(Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params); EXTENSION_FUNCTION_VALIDATE(params);
const ChromeExtensionFunctionDetails chrome_details(this);
scoped_refptr<storage::FileSystemContext> file_system_context = scoped_refptr<storage::FileSystemContext> file_system_context =
file_manager::util::GetFileSystemContextForRenderFrameHost( file_manager::util::GetFileSystemContextForRenderFrameHost(
chrome_details.GetProfile(), render_frame_host()); GetProfile(), render_frame_host());
const storage::FileSystemURL file_system_url( const storage::FileSystemURL file_system_url(
file_system_context->CrackURL(GURL(params->parent_url))); file_system_context->CrackURL(GURL(params->parent_url)));
if (!chromeos::FileSystemBackend::CanHandleURL(file_system_url)) if (!chromeos::FileSystemBackend::CanHandleURL(file_system_url))
return RespondNow(Error("Invalid URL")); return false;
// No explicit limit on the length of Drive file names. // No explicit limit on the length of Drive file names.
if (file_system_url.type() == storage::kFileSystemTypeDrive) { if (file_system_url.type() == storage::kFileSystemTypeDrive) {
return RespondNow(OneArgument(std::make_unique<base::Value>(true))); SetResult(std::make_unique<base::Value>(true));
SendResponse(true);
return true;
} }
base::PostTaskWithTraitsAndReplyWithResult( base::PostTaskWithTraitsAndReplyWithResult(
...@@ -601,61 +600,57 @@ FileManagerPrivateInternalValidatePathNameLengthFunction::Run() { ...@@ -601,61 +600,57 @@ FileManagerPrivateInternalValidatePathNameLengthFunction::Run() {
base::BindOnce(&FileManagerPrivateInternalValidatePathNameLengthFunction:: base::BindOnce(&FileManagerPrivateInternalValidatePathNameLengthFunction::
OnFilePathLimitRetrieved, OnFilePathLimitRetrieved,
this, params->name.size())); this, params->name.size()));
return RespondLater(); return true;
} }
void FileManagerPrivateInternalValidatePathNameLengthFunction:: void FileManagerPrivateInternalValidatePathNameLengthFunction::
OnFilePathLimitRetrieved(size_t current_length, size_t max_length) { OnFilePathLimitRetrieved(size_t current_length, size_t max_length) {
Respond( SetResult(std::make_unique<base::Value>(current_length <= max_length));
OneArgument(std::make_unique<base::Value>(current_length <= max_length))); SendResponse(true);
} }
ExtensionFunction::ResponseAction bool FileManagerPrivateFormatVolumeFunction::RunAsync() {
FileManagerPrivateFormatVolumeFunction::Run() {
using extensions::api::file_manager_private::FormatVolume::Params; using extensions::api::file_manager_private::FormatVolume::Params;
const std::unique_ptr<Params> params(Params::Create(*args_)); const std::unique_ptr<Params> params(Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params); EXTENSION_FUNCTION_VALIDATE(params);
using file_manager::VolumeManager; using file_manager::VolumeManager;
using file_manager::Volume; using file_manager::Volume;
const ChromeExtensionFunctionDetails chrome_details(this); VolumeManager* const volume_manager = VolumeManager::Get(GetProfile());
VolumeManager* const volume_manager =
VolumeManager::Get(chrome_details.GetProfile());
if (!volume_manager) if (!volume_manager)
return RespondNow(Error("Invalid state")); return false;
base::WeakPtr<Volume> volume = base::WeakPtr<Volume> volume =
volume_manager->FindVolumeById(params->volume_id); volume_manager->FindVolumeById(params->volume_id);
if (!volume) if (!volume)
return RespondNow(Error("Volume not found")); return false;
DiskMountManager::GetInstance()->FormatMountedDevice( DiskMountManager::GetInstance()->FormatMountedDevice(
volume->mount_path().AsUTF8Unsafe()); volume->mount_path().AsUTF8Unsafe());
return RespondNow(NoArguments()); SendResponse(true);
return true;
} }
ExtensionFunction::ResponseAction bool FileManagerPrivateRenameVolumeFunction::RunAsync() {
FileManagerPrivateRenameVolumeFunction::Run() {
using extensions::api::file_manager_private::RenameVolume::Params; using extensions::api::file_manager_private::RenameVolume::Params;
const std::unique_ptr<Params> params(Params::Create(*args_)); const std::unique_ptr<Params> params(Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params); EXTENSION_FUNCTION_VALIDATE(params);
using file_manager::VolumeManager; using file_manager::VolumeManager;
using file_manager::Volume; using file_manager::Volume;
const ChromeExtensionFunctionDetails chrome_details(this); VolumeManager* const volume_manager = VolumeManager::Get(GetProfile());
VolumeManager* const volume_manager =
VolumeManager::Get(chrome_details.GetProfile());
if (!volume_manager) if (!volume_manager)
return RespondNow(Error("Invalid state")); return false;
base::WeakPtr<Volume> volume = base::WeakPtr<Volume> volume =
volume_manager->FindVolumeById(params->volume_id); volume_manager->FindVolumeById(params->volume_id);
if (!volume) if (!volume)
return RespondNow(Error("Volume not found")); return false;
DiskMountManager::GetInstance()->RenameMountedDevice( DiskMountManager::GetInstance()->RenameMountedDevice(
volume->mount_path().AsUTF8Unsafe(), params->new_name); volume->mount_path().AsUTF8Unsafe(), params->new_name);
return RespondNow(NoArguments()); SendResponse(true);
return true;
} }
namespace { namespace {
...@@ -682,12 +677,7 @@ int64_t GetLocalDiskSpace(const base::FilePath& path) { ...@@ -682,12 +677,7 @@ int64_t GetLocalDiskSpace(const base::FilePath& path) {
} // namespace } // namespace
FileManagerPrivateInternalStartCopyFunction:: bool FileManagerPrivateInternalStartCopyFunction::RunAsync() {
FileManagerPrivateInternalStartCopyFunction()
: chrome_details_(this) {}
ExtensionFunction::ResponseAction
FileManagerPrivateInternalStartCopyFunction::Run() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
using extensions::api::file_manager_private_internal::StartCopy::Params; using extensions::api::file_manager_private_internal::StartCopy::Params;
...@@ -697,12 +687,13 @@ FileManagerPrivateInternalStartCopyFunction::Run() { ...@@ -697,12 +687,13 @@ FileManagerPrivateInternalStartCopyFunction::Run() {
if (params->url.empty() || params->parent_url.empty() || if (params->url.empty() || params->parent_url.empty() ||
params->new_name.empty()) { params->new_name.empty()) {
// Error code in format of DOMError.name. // Error code in format of DOMError.name.
return RespondNow(Error("EncodingError")); SetError("EncodingError");
return false;
} }
scoped_refptr<storage::FileSystemContext> file_system_context = scoped_refptr<storage::FileSystemContext> file_system_context =
file_manager::util::GetFileSystemContextForRenderFrameHost( file_manager::util::GetFileSystemContextForRenderFrameHost(
chrome_details_.GetProfile(), render_frame_host()); GetProfile(), render_frame_host());
// |parent| may have a trailing slash if it is a root directory. // |parent| may have a trailing slash if it is a root directory.
std::string destination_url_string = params->parent_url; std::string destination_url_string = params->parent_url;
...@@ -716,11 +707,12 @@ FileManagerPrivateInternalStartCopyFunction::Run() { ...@@ -716,11 +707,12 @@ FileManagerPrivateInternalStartCopyFunction::Run() {
if (!source_url_.is_valid() || !destination_url_.is_valid()) { if (!source_url_.is_valid() || !destination_url_.is_valid()) {
// Error code in format of DOMError.name. // Error code in format of DOMError.name.
return RespondNow(Error("EncodingError")); SetError("EncodingError");
return false;
} }
// Check how much space we need for the copy operation. // Check how much space we need for the copy operation.
base::PostTaskWithTraits( return base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::IO}, FROM_HERE, {BrowserThread::IO},
base::BindOnce( base::BindOnce(
&GetFileMetadataOnIOThread, file_system_context, source_url_, &GetFileMetadataOnIOThread, file_system_context, source_url_,
...@@ -729,7 +721,6 @@ FileManagerPrivateInternalStartCopyFunction::Run() { ...@@ -729,7 +721,6 @@ FileManagerPrivateInternalStartCopyFunction::Run() {
base::BindOnce(&FileManagerPrivateInternalStartCopyFunction:: base::BindOnce(&FileManagerPrivateInternalStartCopyFunction::
RunAfterGetFileMetadata, RunAfterGetFileMetadata,
this))); this)));
return RespondLater();
} }
void FileManagerPrivateInternalStartCopyFunction::RunAfterGetFileMetadata( void FileManagerPrivateInternalStartCopyFunction::RunAfterGetFileMetadata(
...@@ -738,18 +729,17 @@ void FileManagerPrivateInternalStartCopyFunction::RunAfterGetFileMetadata( ...@@ -738,18 +729,17 @@ void FileManagerPrivateInternalStartCopyFunction::RunAfterGetFileMetadata(
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (result != base::File::FILE_OK) { if (result != base::File::FILE_OK) {
Respond(Error("NotFoundError")); SetError("NotFoundError");
SendResponse(false);
return; return;
} }
base::FilePath destination_dir; base::FilePath destination_dir;
if (destination_url_.filesystem_id() == if (destination_url_.filesystem_id() ==
drive::util::GetDriveMountPointPath(chrome_details_.GetProfile()) drive::util::GetDriveMountPointPath(GetProfile()).BaseName().value()) {
.BaseName()
.value()) {
// Google Drive's cache is limited by the available space on the local disk. // Google Drive's cache is limited by the available space on the local disk.
destination_dir = file_manager::util::GetMyFilesFolderForProfile( destination_dir =
chrome_details_.GetProfile()); file_manager::util::GetMyFilesFolderForProfile(GetProfile());
} else { } else {
destination_dir = destination_url_.path().DirName(); destination_dir = destination_url_.path().DirName();
} }
...@@ -770,11 +760,9 @@ void FileManagerPrivateInternalStartCopyFunction::RunAfterCheckDiskSpace( ...@@ -770,11 +760,9 @@ void FileManagerPrivateInternalStartCopyFunction::RunAfterCheckDiskSpace(
// enough space. // enough space.
RunAfterFreeDiskSpace(true); RunAfterFreeDiskSpace(true);
} else if (destination_url_.filesystem_id() == } else if (destination_url_.filesystem_id() ==
file_manager::util::GetDownloadsMountPointName( file_manager::util::GetDownloadsMountPointName(GetProfile()) ||
chrome_details_.GetProfile()) ||
destination_url_.filesystem_id() == destination_url_.filesystem_id() ==
drive::util::GetDriveMountPointPath( drive::util::GetDriveMountPointPath(GetProfile())
chrome_details_.GetProfile())
.BaseName() .BaseName()
.value()) { .value()) {
// If the destination directory is local hard drive or Google Drive we // If the destination directory is local hard drive or Google Drive we
...@@ -784,7 +772,7 @@ void FileManagerPrivateInternalStartCopyFunction::RunAfterCheckDiskSpace( ...@@ -784,7 +772,7 @@ void FileManagerPrivateInternalStartCopyFunction::RunAfterCheckDiskSpace(
} else { } else {
// Also we can try to secure needed space by freeing Drive caches. // Also we can try to secure needed space by freeing Drive caches.
drive::FileSystemInterface* const drive_file_system = drive::FileSystemInterface* const drive_file_system =
drive::util::GetFileSystemByProfile(chrome_details_.GetProfile()); drive::util::GetFileSystemByProfile(GetProfile());
if (!drive_file_system) { if (!drive_file_system) {
RunAfterFreeDiskSpace(false); RunAfterFreeDiskSpace(false);
} else { } else {
...@@ -805,47 +793,51 @@ void FileManagerPrivateInternalStartCopyFunction::RunAfterFreeDiskSpace( ...@@ -805,47 +793,51 @@ void FileManagerPrivateInternalStartCopyFunction::RunAfterFreeDiskSpace(
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!available) { if (!available) {
Respond(Error("QuotaExceededError")); SetError("QuotaExceededError");
SendResponse(false);
return; return;
} }
scoped_refptr<storage::FileSystemContext> file_system_context = scoped_refptr<storage::FileSystemContext> file_system_context =
file_manager::util::GetFileSystemContextForRenderFrameHost( file_manager::util::GetFileSystemContextForRenderFrameHost(
chrome_details_.GetProfile(), render_frame_host()); GetProfile(), render_frame_host());
base::PostTaskWithTraitsAndReplyWithResult( const bool result = base::PostTaskWithTraitsAndReplyWithResult(
FROM_HERE, {BrowserThread::IO}, FROM_HERE, {BrowserThread::IO},
base::BindOnce(&StartCopyOnIOThread, chrome_details_.GetProfile(), base::BindOnce(&StartCopyOnIOThread, GetProfile(), file_system_context,
file_system_context, source_url_, destination_url_), source_url_, destination_url_),
base::BindOnce( base::BindOnce(
&FileManagerPrivateInternalStartCopyFunction::RunAfterStartCopy, &FileManagerPrivateInternalStartCopyFunction::RunAfterStartCopy,
this)); this));
if (!result)
SendResponse(false);
} }
void FileManagerPrivateInternalStartCopyFunction::RunAfterStartCopy( void FileManagerPrivateInternalStartCopyFunction::RunAfterStartCopy(
int operation_id) { int operation_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
Respond(OneArgument(std::make_unique<base::Value>(operation_id))); SetResult(std::make_unique<base::Value>(operation_id));
SendResponse(true);
} }
ExtensionFunction::ResponseAction FileManagerPrivateCancelCopyFunction::Run() { bool FileManagerPrivateCancelCopyFunction::RunAsync() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
using extensions::api::file_manager_private::CancelCopy::Params; using extensions::api::file_manager_private::CancelCopy::Params;
const std::unique_ptr<Params> params(Params::Create(*args_)); const std::unique_ptr<Params> params(Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params); EXTENSION_FUNCTION_VALIDATE(params);
const ChromeExtensionFunctionDetails chrome_details(this);
scoped_refptr<storage::FileSystemContext> file_system_context = scoped_refptr<storage::FileSystemContext> file_system_context =
file_manager::util::GetFileSystemContextForRenderFrameHost( file_manager::util::GetFileSystemContextForRenderFrameHost(
chrome_details.GetProfile(), render_frame_host()); GetProfile(), render_frame_host());
// We don't much take care about the result of cancellation. // We don't much take care about the result of cancellation.
base::PostTaskWithTraits( base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::IO}, FROM_HERE, {BrowserThread::IO},
base::BindOnce(&CancelCopyOnIOThread, file_system_context, base::BindOnce(&CancelCopyOnIOThread, file_system_context,
params->copy_id)); params->copy_id));
return RespondNow(NoArguments()); SendResponse(true);
return true;
} }
ExtensionFunction::ResponseAction ExtensionFunction::ResponseAction
...@@ -925,26 +917,26 @@ FileManagerPrivateInternalComputeChecksumFunction:: ...@@ -925,26 +917,26 @@ FileManagerPrivateInternalComputeChecksumFunction::
FileManagerPrivateInternalComputeChecksumFunction:: FileManagerPrivateInternalComputeChecksumFunction::
~FileManagerPrivateInternalComputeChecksumFunction() = default; ~FileManagerPrivateInternalComputeChecksumFunction() = default;
ExtensionFunction::ResponseAction bool FileManagerPrivateInternalComputeChecksumFunction::RunAsync() {
FileManagerPrivateInternalComputeChecksumFunction::Run() {
using extensions::api::file_manager_private_internal::ComputeChecksum::Params; using extensions::api::file_manager_private_internal::ComputeChecksum::Params;
using drive::util::FileStreamMd5Digester; using drive::util::FileStreamMd5Digester;
const std::unique_ptr<Params> params(Params::Create(*args_)); const std::unique_ptr<Params> params(Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params); EXTENSION_FUNCTION_VALIDATE(params);
if (params->url.empty()) { if (params->url.empty()) {
return RespondNow(Error("File URL must be provided.")); SetError("File URL must be provided.");
return false;
} }
const ChromeExtensionFunctionDetails chrome_details(this);
scoped_refptr<storage::FileSystemContext> file_system_context = scoped_refptr<storage::FileSystemContext> file_system_context =
file_manager::util::GetFileSystemContextForRenderFrameHost( file_manager::util::GetFileSystemContextForRenderFrameHost(
chrome_details.GetProfile(), render_frame_host()); GetProfile(), render_frame_host());
FileSystemURL file_system_url( FileSystemURL file_system_url(
file_system_context->CrackURL(GURL(params->url))); file_system_context->CrackURL(GURL(params->url)));
if (!file_system_url.is_valid()) { if (!file_system_url.is_valid()) {
return RespondNow(Error("File URL was invalid")); SetError("File URL was invalid");
return false;
} }
std::unique_ptr<storage::FileStreamReader> reader = std::unique_ptr<storage::FileStreamReader> reader =
...@@ -953,30 +945,25 @@ FileManagerPrivateInternalComputeChecksumFunction::Run() { ...@@ -953,30 +945,25 @@ FileManagerPrivateInternalComputeChecksumFunction::Run() {
FileStreamMd5Digester::ResultCallback result_callback = base::Bind( FileStreamMd5Digester::ResultCallback result_callback = base::Bind(
&ComputeChecksumRespondOnUIThread, &ComputeChecksumRespondOnUIThread,
base::Bind( base::Bind(&FileManagerPrivateInternalComputeChecksumFunction::Respond,
&FileManagerPrivateInternalComputeChecksumFunction::RespondWith, this));
this));
base::PostTaskWithTraits( base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::IO}, FROM_HERE, {BrowserThread::IO},
base::BindOnce(&FileStreamMd5Digester::GetMd5Digest, base::BindOnce(&FileStreamMd5Digester::GetMd5Digest,
base::Unretained(digester_.get()), base::Passed(&reader), base::Unretained(digester_.get()), base::Passed(&reader),
result_callback)); result_callback));
return RespondLater(); return true;
} }
void FileManagerPrivateInternalComputeChecksumFunction::RespondWith( void FileManagerPrivateInternalComputeChecksumFunction::Respond(
const std::string& hash) { const std::string& hash) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
Respond(OneArgument(std::make_unique<base::Value>(hash))); SetResult(std::make_unique<base::Value>(hash));
SendResponse(true);
} }
FileManagerPrivateSearchFilesByHashesFunction:: bool FileManagerPrivateSearchFilesByHashesFunction::RunAsync() {
FileManagerPrivateSearchFilesByHashesFunction()
: chrome_details_(this) {}
ExtensionFunction::ResponseAction
FileManagerPrivateSearchFilesByHashesFunction::Run() {
using api::file_manager_private::SearchFilesByHashes::Params; using api::file_manager_private::SearchFilesByHashes::Params;
const std::unique_ptr<Params> params(Params::Create(*args_)); const std::unique_ptr<Params> params(Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params); EXTENSION_FUNCTION_VALIDATE(params);
...@@ -985,7 +972,7 @@ FileManagerPrivateSearchFilesByHashesFunction::Run() { ...@@ -985,7 +972,7 @@ FileManagerPrivateSearchFilesByHashesFunction::Run() {
// than Drive. // than Drive.
drive::EventLogger* const logger = drive::EventLogger* const logger =
file_manager::util::GetLogger(chrome_details_.GetProfile()); file_manager::util::GetLogger(GetProfile());
if (logger) { if (logger) {
logger->Log(logging::LOG_INFO, logger->Log(logging::LOG_INFO,
"%s[%d] called. (volume id: %s, number of hashes: %zd)", name(), "%s[%d] called. (volume id: %s, number of hashes: %zd)", name(),
...@@ -995,17 +982,17 @@ FileManagerPrivateSearchFilesByHashesFunction::Run() { ...@@ -995,17 +982,17 @@ FileManagerPrivateSearchFilesByHashesFunction::Run() {
set_log_on_completion(true); set_log_on_completion(true);
drive::DriveIntegrationService* integration_service = drive::DriveIntegrationService* integration_service =
drive::util::GetIntegrationServiceByProfile(chrome_details_.GetProfile()); drive::util::GetIntegrationServiceByProfile(GetProfile());
if (!integration_service) { if (!integration_service) {
// |integration_service| is NULL if Drive is disabled or not mounted. // |integration_service| is NULL if Drive is disabled or not mounted.
return RespondNow(Error("Drive not available")); return false;
} }
std::set<std::string> hashes(params->hash_list.begin(), std::set<std::string> hashes(params->hash_list.begin(),
params->hash_list.end()); params->hash_list.end());
drive::FileSystemInterface* const file_system = drive::FileSystemInterface* const file_system =
drive::util::GetFileSystemByProfile(chrome_details_.GetProfile()); drive::util::GetFileSystemByProfile(GetProfile());
if (file_system) { if (file_system) {
file_system->SearchByHashes( file_system->SearchByHashes(
hashes, hashes,
...@@ -1023,13 +1010,13 @@ FileManagerPrivateSearchFilesByHashesFunction::Run() { ...@@ -1023,13 +1010,13 @@ FileManagerPrivateSearchFilesByHashesFunction::Run() {
this, hashes, this, hashes,
integration_service->GetMountPointPath().Append( integration_service->GetMountPointPath().Append(
drive::util::kDriveMyDriveRootDirName), drive::util::kDriveMyDriveRootDirName),
drive::util::GetDriveMountPointPath(chrome_details_.GetProfile())), drive::util::GetDriveMountPointPath(GetProfile())),
base::BindOnce( base::BindOnce(
&FileManagerPrivateSearchFilesByHashesFunction::OnSearchByAttribute, &FileManagerPrivateSearchFilesByHashesFunction::OnSearchByAttribute,
this, hashes)); this, hashes));
} }
return RespondLater(); return true;
} }
std::vector<drive::HashAndFilePath> std::vector<drive::HashAndFilePath>
...@@ -1075,7 +1062,7 @@ void FileManagerPrivateSearchFilesByHashesFunction::OnSearchByHashes( ...@@ -1075,7 +1062,7 @@ void FileManagerPrivateSearchFilesByHashesFunction::OnSearchByHashes(
drive::FileError error, drive::FileError error,
const std::vector<drive::HashAndFilePath>& search_results) { const std::vector<drive::HashAndFilePath>& search_results) {
if (error != drive::FileError::FILE_ERROR_OK) { if (error != drive::FileError::FILE_ERROR_OK) {
Respond(Error(drive::FileErrorToString(error))); SendResponse(false);
return; return;
} }
...@@ -1090,10 +1077,10 @@ void FileManagerPrivateSearchFilesByHashesFunction::OnSearchByHashes( ...@@ -1090,10 +1077,10 @@ void FileManagerPrivateSearchFilesByHashesFunction::OnSearchByHashes(
result->GetListWithoutPathExpansion(hashAndPath.hash, &list); result->GetListWithoutPathExpansion(hashAndPath.hash, &list);
list->AppendString( list->AppendString(
file_manager::util::ConvertDrivePathToFileSystemUrl( file_manager::util::ConvertDrivePathToFileSystemUrl(
chrome_details_.GetProfile(), hashAndPath.path, extension_id()) GetProfile(), hashAndPath.path, extension_id()).spec());
.spec());
} }
Respond(OneArgument(std::move(result))); SetResult(std::move(result));
SendResponse(true);
} }
ExtensionFunction::ResponseAction ExtensionFunction::ResponseAction
...@@ -1160,37 +1147,37 @@ void FileManagerPrivateInternalSetEntryTagFunction::OnSetEntryPropertyCompleted( ...@@ -1160,37 +1147,37 @@ void FileManagerPrivateInternalSetEntryTagFunction::OnSetEntryPropertyCompleted(
: Error("Failed to set a tag.")); : Error("Failed to set a tag."));
} }
ExtensionFunction::ResponseAction bool FileManagerPrivateInternalGetDirectorySizeFunction::RunAsync() {
FileManagerPrivateInternalGetDirectorySizeFunction::Run() {
using extensions::api::file_manager_private_internal::GetDirectorySize:: using extensions::api::file_manager_private_internal::GetDirectorySize::
Params; Params;
const std::unique_ptr<Params> params(Params::Create(*args_)); const std::unique_ptr<Params> params(Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params); EXTENSION_FUNCTION_VALIDATE(params);
if (params->url.empty()) { if (params->url.empty()) {
return RespondNow(Error("File URL must be provided.")); SetError("File URL must be provided.");
return false;
} }
const ChromeExtensionFunctionDetails chrome_details(this);
scoped_refptr<storage::FileSystemContext> file_system_context = scoped_refptr<storage::FileSystemContext> file_system_context =
file_manager::util::GetFileSystemContextForRenderFrameHost( file_manager::util::GetFileSystemContextForRenderFrameHost(
chrome_details.GetProfile(), render_frame_host()); GetProfile(), render_frame_host());
const storage::FileSystemURL file_system_url( const storage::FileSystemURL file_system_url(
file_system_context->CrackURL(GURL(params->url))); file_system_context->CrackURL(GURL(params->url)));
if (!chromeos::FileSystemBackend::CanHandleURL(file_system_url)) { if (!chromeos::FileSystemBackend::CanHandleURL(file_system_url)) {
return RespondNow( SetError("FileSystemBackend failed to handle the entry's url.");
Error("FileSystemBackend failed to handle the entry's url.")); return false;
} }
if (file_system_url.type() != storage::kFileSystemTypeNativeLocal && if (file_system_url.type() != storage::kFileSystemTypeNativeLocal &&
file_system_url.type() != storage::kFileSystemTypeDriveFs) { file_system_url.type() != storage::kFileSystemTypeDriveFs) {
return RespondNow(Error("Only local directories are supported.")); SetError("Only local directories are supported.");
return false;
} }
const base::FilePath root_path = file_manager::util::GetLocalPathFromURL( const base::FilePath root_path = file_manager::util::GetLocalPathFromURL(
render_frame_host(), chrome_details.GetProfile(), GURL(params->url)); render_frame_host(), GetProfile(), GURL(params->url));
if (root_path.empty()) { if (root_path.empty()) {
return RespondNow( SetError("Failed to get a local path from the entry's url.");
Error("Failed to get a local path from the entry's url.")); return false;
} }
base::PostTaskWithTraitsAndReplyWithResult( base::PostTaskWithTraitsAndReplyWithResult(
...@@ -1199,13 +1186,13 @@ FileManagerPrivateInternalGetDirectorySizeFunction::Run() { ...@@ -1199,13 +1186,13 @@ FileManagerPrivateInternalGetDirectorySizeFunction::Run() {
base::BindOnce(&FileManagerPrivateInternalGetDirectorySizeFunction:: base::BindOnce(&FileManagerPrivateInternalGetDirectorySizeFunction::
OnDirectorySizeRetrieved, OnDirectorySizeRetrieved,
this)); this));
return RespondLater(); return true;
} }
void FileManagerPrivateInternalGetDirectorySizeFunction:: void FileManagerPrivateInternalGetDirectorySizeFunction::
OnDirectorySizeRetrieved(int64_t size) { OnDirectorySizeRetrieved(int64_t size) {
Respond( SetResult(std::make_unique<base::Value>(static_cast<double>(size)));
OneArgument(std::make_unique<base::Value>(static_cast<double>(size)))); SendResponse(true);
} }
} // namespace extensions } // namespace extensions
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "chrome/browser/chromeos/extensions/file_manager/private_api_base.h" #include "chrome/browser/chromeos/extensions/file_manager/private_api_base.h"
#include "chrome/browser/extensions/chrome_extension_function.h"
#include "chrome/browser/extensions/chrome_extension_function_details.h" #include "chrome/browser/extensions/chrome_extension_function_details.h"
#include "components/drive/file_errors.h" #include "components/drive/file_errors.h"
#include "extensions/browser/extension_function.h" #include "extensions/browser/extension_function.h"
...@@ -86,12 +87,12 @@ class FileManagerPrivateGrantAccessFunction : public UIThreadExtensionFunction { ...@@ -86,12 +87,12 @@ class FileManagerPrivateGrantAccessFunction : public UIThreadExtensionFunction {
// "FileWatch", // "FileWatch",
// the class and its sub classes are used only for watching changes in // the class and its sub classes are used only for watching changes in
// directories. // directories.
class FileWatchFunctionBase : public LoggedUIThreadExtensionFunction { class FileWatchFunctionBase : public LoggedAsyncExtensionFunction {
public: public:
using ResponseCallback = base::Callback<void(bool success)>; using ResponseCallback = base::Callback<void(bool success)>;
// Calls Respond() with |success| converted to base::Value. // Calls SendResponse() with |success| converted to base::Value.
void RespondWith(bool success); void Respond(bool success);
protected: protected:
~FileWatchFunctionBase() override = default; ~FileWatchFunctionBase() override = default;
...@@ -111,8 +112,8 @@ class FileWatchFunctionBase : public LoggedUIThreadExtensionFunction { ...@@ -111,8 +112,8 @@ class FileWatchFunctionBase : public LoggedUIThreadExtensionFunction {
const storage::FileSystemURL& file_system_url, const storage::FileSystemURL& file_system_url,
base::WeakPtr<file_manager::EventRouter> event_router) = 0; base::WeakPtr<file_manager::EventRouter> event_router) = 0;
// ExtensionFunction overrides. // ChromeAsyncExtensionFunction overrides.
ResponseAction Run() override; bool RunAsync() override;
private: private:
void RunAsyncOnIOThread( void RunAsyncOnIOThread(
...@@ -168,7 +169,7 @@ class FileManagerPrivateInternalRemoveFileWatchFunction ...@@ -168,7 +169,7 @@ class FileManagerPrivateInternalRemoveFileWatchFunction
// Implements the chrome.fileManagerPrivate.getSizeStats method. // Implements the chrome.fileManagerPrivate.getSizeStats method.
class FileManagerPrivateGetSizeStatsFunction class FileManagerPrivateGetSizeStatsFunction
: public LoggedUIThreadExtensionFunction { : public LoggedAsyncExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.getSizeStats", DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.getSizeStats",
FILEMANAGERPRIVATE_GETSIZESTATS) FILEMANAGERPRIVATE_GETSIZESTATS)
...@@ -176,8 +177,8 @@ class FileManagerPrivateGetSizeStatsFunction ...@@ -176,8 +177,8 @@ class FileManagerPrivateGetSizeStatsFunction
protected: protected:
~FileManagerPrivateGetSizeStatsFunction() override = default; ~FileManagerPrivateGetSizeStatsFunction() override = default;
// ExtensionFunction overrides. // ChromeAsyncExtensionFunction overrides.
ResponseAction Run() override; bool RunAsync() override;
private: private:
void OnGetDriveAvailableSpace(drive::FileError error, void OnGetDriveAvailableSpace(drive::FileError error,
...@@ -193,7 +194,7 @@ class FileManagerPrivateGetSizeStatsFunction ...@@ -193,7 +194,7 @@ class FileManagerPrivateGetSizeStatsFunction
// Implements the chrome.fileManagerPrivate.validatePathNameLength method. // Implements the chrome.fileManagerPrivate.validatePathNameLength method.
class FileManagerPrivateInternalValidatePathNameLengthFunction class FileManagerPrivateInternalValidatePathNameLengthFunction
: public LoggedUIThreadExtensionFunction { : public LoggedAsyncExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION( DECLARE_EXTENSION_FUNCTION(
"fileManagerPrivateInternal.validatePathNameLength", "fileManagerPrivateInternal.validatePathNameLength",
...@@ -205,14 +206,14 @@ class FileManagerPrivateInternalValidatePathNameLengthFunction ...@@ -205,14 +206,14 @@ class FileManagerPrivateInternalValidatePathNameLengthFunction
void OnFilePathLimitRetrieved(size_t current_length, size_t max_length); void OnFilePathLimitRetrieved(size_t current_length, size_t max_length);
// ExtensionFunction overrides. // ChromeAsyncExtensionFunction overrides.
ResponseAction Run() override; bool RunAsync() override;
}; };
// Implements the chrome.fileManagerPrivate.formatVolume method. // Implements the chrome.fileManagerPrivate.formatVolume method.
// Formats Volume given its mount path. // Formats Volume given its mount path.
class FileManagerPrivateFormatVolumeFunction class FileManagerPrivateFormatVolumeFunction
: public LoggedUIThreadExtensionFunction { : public LoggedAsyncExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.formatVolume", DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.formatVolume",
FILEMANAGERPRIVATE_FORMATVOLUME) FILEMANAGERPRIVATE_FORMATVOLUME)
...@@ -220,14 +221,14 @@ class FileManagerPrivateFormatVolumeFunction ...@@ -220,14 +221,14 @@ class FileManagerPrivateFormatVolumeFunction
protected: protected:
~FileManagerPrivateFormatVolumeFunction() override = default; ~FileManagerPrivateFormatVolumeFunction() override = default;
// ExtensionFunction overrides. // ChromeAsyncExtensionFunction overrides.
ResponseAction Run() override; bool RunAsync() override;
}; };
// Implements the chrome.fileManagerPrivate.renameVolume method. // Implements the chrome.fileManagerPrivate.renameVolume method.
// Renames Volume given its mount path and new Volume name. // Renames Volume given its mount path and new Volume name.
class FileManagerPrivateRenameVolumeFunction class FileManagerPrivateRenameVolumeFunction
: public LoggedUIThreadExtensionFunction { : public LoggedAsyncExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.renameVolume", DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.renameVolume",
FILEMANAGERPRIVATE_RENAMEVOLUME) FILEMANAGERPRIVATE_RENAMEVOLUME)
...@@ -235,24 +236,22 @@ class FileManagerPrivateRenameVolumeFunction ...@@ -235,24 +236,22 @@ class FileManagerPrivateRenameVolumeFunction
protected: protected:
~FileManagerPrivateRenameVolumeFunction() override = default; ~FileManagerPrivateRenameVolumeFunction() override = default;
// ExtensionFunction overrides. // ChromeAsyncExtensionFunction overrides.
ResponseAction Run() override; bool RunAsync() override;
}; };
// Implements the chrome.fileManagerPrivate.startCopy method. // Implements the chrome.fileManagerPrivate.startCopy method.
class FileManagerPrivateInternalStartCopyFunction class FileManagerPrivateInternalStartCopyFunction
: public LoggedUIThreadExtensionFunction { : public LoggedAsyncExtensionFunction {
public: public:
FileManagerPrivateInternalStartCopyFunction();
DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.startCopy", DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.startCopy",
FILEMANAGERPRIVATEINTERNAL_STARTCOPY) FILEMANAGERPRIVATEINTERNAL_STARTCOPY)
protected: protected:
~FileManagerPrivateInternalStartCopyFunction() override = default; ~FileManagerPrivateInternalStartCopyFunction() override = default;
// ExtensionFunction overrides. // ChromeAsyncExtensionFunction overrides.
ResponseAction Run() override; bool RunAsync() override;
private: private:
void RunAfterGetFileMetadata(base::File::Error result, void RunAfterGetFileMetadata(base::File::Error result,
...@@ -271,12 +270,11 @@ class FileManagerPrivateInternalStartCopyFunction ...@@ -271,12 +270,11 @@ class FileManagerPrivateInternalStartCopyFunction
storage::FileSystemURL source_url_; storage::FileSystemURL source_url_;
storage::FileSystemURL destination_url_; storage::FileSystemURL destination_url_;
const ChromeExtensionFunctionDetails chrome_details_;
}; };
// Implements the chrome.fileManagerPrivate.cancelCopy method. // Implements the chrome.fileManagerPrivate.cancelCopy method.
class FileManagerPrivateCancelCopyFunction class FileManagerPrivateCancelCopyFunction
: public LoggedUIThreadExtensionFunction { : public LoggedAsyncExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.cancelCopy", DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.cancelCopy",
FILEMANAGERPRIVATE_CANCELCOPY) FILEMANAGERPRIVATE_CANCELCOPY)
...@@ -284,8 +282,8 @@ class FileManagerPrivateCancelCopyFunction ...@@ -284,8 +282,8 @@ class FileManagerPrivateCancelCopyFunction
protected: protected:
~FileManagerPrivateCancelCopyFunction() override = default; ~FileManagerPrivateCancelCopyFunction() override = default;
// ExtensionFunction overrides. // ChromeAsyncExtensionFunction overrides.
ResponseAction Run() override; bool RunAsync() override;
}; };
// Implements the chrome.fileManagerPrivateInternal.resolveIsolatedEntries // Implements the chrome.fileManagerPrivateInternal.resolveIsolatedEntries
...@@ -311,7 +309,7 @@ class FileManagerPrivateInternalResolveIsolatedEntriesFunction ...@@ -311,7 +309,7 @@ class FileManagerPrivateInternalResolveIsolatedEntriesFunction
}; };
class FileManagerPrivateInternalComputeChecksumFunction class FileManagerPrivateInternalComputeChecksumFunction
: public LoggedUIThreadExtensionFunction { : public LoggedAsyncExtensionFunction {
public: public:
FileManagerPrivateInternalComputeChecksumFunction(); FileManagerPrivateInternalComputeChecksumFunction();
...@@ -321,22 +319,20 @@ class FileManagerPrivateInternalComputeChecksumFunction ...@@ -321,22 +319,20 @@ class FileManagerPrivateInternalComputeChecksumFunction
protected: protected:
~FileManagerPrivateInternalComputeChecksumFunction() override; ~FileManagerPrivateInternalComputeChecksumFunction() override;
// ExtensionFunction overrides. // ChromeAsyncExtensionFunction overrides.
ResponseAction Run() override; bool RunAsync() override;
private: private:
std::unique_ptr<drive::util::FileStreamMd5Digester> digester_; std::unique_ptr<drive::util::FileStreamMd5Digester> digester_;
void RespondWith(const std::string& hash); void Respond(const std::string& hash);
}; };
// Implements the chrome.fileManagerPrivate.searchFilesByHashes method. // Implements the chrome.fileManagerPrivate.searchFilesByHashes method.
// TODO(b/883628): Write some tests maybe? // TODO(b/883628): Write some tests maybe?
class FileManagerPrivateSearchFilesByHashesFunction class FileManagerPrivateSearchFilesByHashesFunction
: public LoggedUIThreadExtensionFunction { : public LoggedAsyncExtensionFunction {
public: public:
FileManagerPrivateSearchFilesByHashesFunction();
DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.searchFilesByHashes", DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.searchFilesByHashes",
FILEMANAGERPRIVATE_SEARCHFILESBYHASHES) FILEMANAGERPRIVATE_SEARCHFILESBYHASHES)
...@@ -344,8 +340,8 @@ class FileManagerPrivateSearchFilesByHashesFunction ...@@ -344,8 +340,8 @@ class FileManagerPrivateSearchFilesByHashesFunction
~FileManagerPrivateSearchFilesByHashesFunction() override = default; ~FileManagerPrivateSearchFilesByHashesFunction() override = default;
private: private:
// ExtensionFunction overrides. // ChromeAsyncExtensionFunction overrides.
ResponseAction Run() override; bool RunAsync() override;
// Fallback to walking the filesystem and checking file attributes. // Fallback to walking the filesystem and checking file attributes.
std::vector<drive::HashAndFilePath> SearchByAttribute( std::vector<drive::HashAndFilePath> SearchByAttribute(
...@@ -359,8 +355,6 @@ class FileManagerPrivateSearchFilesByHashesFunction ...@@ -359,8 +355,6 @@ class FileManagerPrivateSearchFilesByHashesFunction
void OnSearchByHashes(const std::set<std::string>& hashes, void OnSearchByHashes(const std::set<std::string>& hashes,
drive::FileError error, drive::FileError error,
const std::vector<drive::HashAndFilePath>& results); const std::vector<drive::HashAndFilePath>& results);
const ChromeExtensionFunctionDetails chrome_details_;
}; };
// Implements the chrome.fileManagerPrivate.isUMAEnabled method. // Implements the chrome.fileManagerPrivate.isUMAEnabled method.
...@@ -400,7 +394,7 @@ class FileManagerPrivateInternalSetEntryTagFunction ...@@ -400,7 +394,7 @@ class FileManagerPrivateInternalSetEntryTagFunction
// Implements the chrome.fileManagerPrivate.getDirectorySize method. // Implements the chrome.fileManagerPrivate.getDirectorySize method.
class FileManagerPrivateInternalGetDirectorySizeFunction class FileManagerPrivateInternalGetDirectorySizeFunction
: public LoggedUIThreadExtensionFunction { : public LoggedAsyncExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.getDirectorySize", DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.getDirectorySize",
FILEMANAGERPRIVATEINTERNAL_GETDIRECTORYSIZE) FILEMANAGERPRIVATEINTERNAL_GETDIRECTORYSIZE)
...@@ -410,8 +404,8 @@ class FileManagerPrivateInternalGetDirectorySizeFunction ...@@ -410,8 +404,8 @@ class FileManagerPrivateInternalGetDirectorySizeFunction
void OnDirectorySizeRetrieved(int64_t size); void OnDirectorySizeRetrieved(int64_t size);
// ExtensionFunction overrides // ChromeAsyncExtensionFunction overrides
ResponseAction Run() override; bool RunAsync() override;
}; };
} // namespace extensions } // namespace extensions
......
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