Commit 76efdcf8 authored by Anand K. Mistry's avatar Anand K. Mistry Committed by Commit Bot

Migrate file_system file manager APIs to UIThreadExtensionFunction.

BUG=934541

Change-Id: Ibd06bda730bd10c270d187d83f68315159fa6a43
Reviewed-on: https://chromium-review.googlesource.com/c/1482172Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Commit-Queue: Anand Mistry <amistry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#634562}
parent e1cf0f63
...@@ -344,44 +344,43 @@ void PostNotificationCallbackTaskToUIThread( ...@@ -344,44 +344,43 @@ void PostNotificationCallbackTaskToUIThread(
} // namespace } // namespace
void FileWatchFunctionBase::Respond(bool success) { void FileWatchFunctionBase::RespondWith(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);
} }
bool FileWatchFunctionBase::RunAsync() { ExtensionFunction::ResponseAction FileWatchFunctionBase::Run() {
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 false; return RespondNow(Error("Invalid state"));
// 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 false; return RespondNow(Error("Empty watch URL"));
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(
GetProfile(), render_frame_host()); chrome_details.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()) {
Respond(false); return RespondNow(OneArgument(std::make_unique<base::Value>(false)));
return true;
} }
file_manager::EventRouter* const event_router = file_manager::EventRouter* const event_router =
file_manager::EventRouterFactory::GetForProfile(GetProfile()); file_manager::EventRouterFactory::GetForProfile(
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 true; return RespondLater();
} }
void FileWatchFunctionBase::RunAsyncOnIOThread( void FileWatchFunctionBase::RunAsyncOnIOThread(
...@@ -416,9 +415,10 @@ void FileManagerPrivateInternalAddFileWatchFunction:: ...@@ -416,9 +415,10 @@ void FileManagerPrivateInternalAddFileWatchFunction::
watcher_manager->AddWatcher( watcher_manager->AddWatcher(
file_system_url, false /* recursive */, file_system_url, false /* recursive */,
base::Bind(&StatusCallbackToResponseCallback, base::Bind(
base::Bind(&PostResponseCallbackTaskToUIThread, &StatusCallbackToResponseCallback,
base::Bind(&FileWatchFunctionBase::Respond, this))), base::Bind(&PostResponseCallbackTaskToUIThread,
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(file_system_url.path(), event_router->AddFileWatch(
file_system_url.virtual_path(), extension_id(), file_system_url.path(), file_system_url.virtual_path(), extension_id(),
base::Bind(&FileWatchFunctionBase::Respond, this)); base::Bind(&FileWatchFunctionBase::RespondWith, 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::Respond, this)))); base::Bind(&FileWatchFunctionBase::RespondWith, this))));
} }
void FileManagerPrivateInternalRemoveFileWatchFunction:: void FileManagerPrivateInternalRemoveFileWatchFunction::
...@@ -463,35 +463,37 @@ void FileManagerPrivateInternalRemoveFileWatchFunction:: ...@@ -463,35 +463,37 @@ 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());
Respond(true); RespondWith(true);
} }
bool FileManagerPrivateGetSizeStatsFunction::RunAsync() { ExtensionFunction::ResponseAction
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;
VolumeManager* const volume_manager = VolumeManager::Get(GetProfile()); const ChromeExtensionFunctionDetails chrome_details(this);
VolumeManager* const volume_manager =
VolumeManager::Get(chrome_details.GetProfile());
if (!volume_manager) if (!volume_manager)
return false; return RespondNow(Error("Invalid state"));
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 false; return RespondNow(Error("Volume not found"));
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(GetProfile()); drive::util::GetFileSystemByProfile(chrome_details.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().
SendResponse(true); return RespondNow(NoArguments());
return true;
} }
file_system->GetAvailableSpace(base::BindOnce( file_system->GetAvailableSpace(base::BindOnce(
...@@ -525,7 +527,7 @@ bool FileManagerPrivateGetSizeStatsFunction::RunAsync() { ...@@ -525,7 +527,7 @@ bool FileManagerPrivateGetSizeStatsFunction::RunAsync() {
this, base::Owned(total_size), this, base::Owned(total_size),
base::Owned(remaining_size))); base::Owned(remaining_size)));
} }
return true; return RespondLater();
} }
void FileManagerPrivateGetSizeStatsFunction::OnGetDriveAvailableSpace( void FileManagerPrivateGetSizeStatsFunction::OnGetDriveAvailableSpace(
...@@ -540,7 +542,7 @@ void FileManagerPrivateGetSizeStatsFunction::OnGetDriveAvailableSpace( ...@@ -540,7 +542,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.
SendResponse(true); Respond(NoArguments());
} }
} }
...@@ -550,7 +552,7 @@ void FileManagerPrivateGetSizeStatsFunction::OnGetMtpAvailableSpace( ...@@ -550,7 +552,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.
SendResponse(true); Respond(NoArguments());
return; return;
} }
...@@ -567,30 +569,29 @@ void FileManagerPrivateGetSizeStatsFunction::OnGetSizeStats( ...@@ -567,30 +569,29 @@ 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));
SetResult(std::move(sizes)); Respond(OneArgument(std::move(sizes)));
SendResponse(true);
} }
bool FileManagerPrivateInternalValidatePathNameLengthFunction::RunAsync() { ExtensionFunction::ResponseAction
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(
GetProfile(), render_frame_host()); chrome_details.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 false; return RespondNow(Error("Invalid URL"));
// 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) {
SetResult(std::make_unique<base::Value>(true)); return RespondNow(OneArgument(std::make_unique<base::Value>(true)));
SendResponse(true);
return true;
} }
base::PostTaskWithTraitsAndReplyWithResult( base::PostTaskWithTraitsAndReplyWithResult(
...@@ -600,57 +601,61 @@ bool FileManagerPrivateInternalValidatePathNameLengthFunction::RunAsync() { ...@@ -600,57 +601,61 @@ bool FileManagerPrivateInternalValidatePathNameLengthFunction::RunAsync() {
base::BindOnce(&FileManagerPrivateInternalValidatePathNameLengthFunction:: base::BindOnce(&FileManagerPrivateInternalValidatePathNameLengthFunction::
OnFilePathLimitRetrieved, OnFilePathLimitRetrieved,
this, params->name.size())); this, params->name.size()));
return true; return RespondLater();
} }
void FileManagerPrivateInternalValidatePathNameLengthFunction:: void FileManagerPrivateInternalValidatePathNameLengthFunction::
OnFilePathLimitRetrieved(size_t current_length, size_t max_length) { OnFilePathLimitRetrieved(size_t current_length, size_t max_length) {
SetResult(std::make_unique<base::Value>(current_length <= max_length)); Respond(
SendResponse(true); OneArgument(std::make_unique<base::Value>(current_length <= max_length)));
} }
bool FileManagerPrivateFormatVolumeFunction::RunAsync() { ExtensionFunction::ResponseAction
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;
VolumeManager* const volume_manager = VolumeManager::Get(GetProfile()); const ChromeExtensionFunctionDetails chrome_details(this);
VolumeManager* const volume_manager =
VolumeManager::Get(chrome_details.GetProfile());
if (!volume_manager) if (!volume_manager)
return false; return RespondNow(Error("Invalid state"));
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 false; return RespondNow(Error("Volume not found"));
DiskMountManager::GetInstance()->FormatMountedDevice( DiskMountManager::GetInstance()->FormatMountedDevice(
volume->mount_path().AsUTF8Unsafe()); volume->mount_path().AsUTF8Unsafe());
SendResponse(true); return RespondNow(NoArguments());
return true;
} }
bool FileManagerPrivateRenameVolumeFunction::RunAsync() { ExtensionFunction::ResponseAction
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;
VolumeManager* const volume_manager = VolumeManager::Get(GetProfile()); const ChromeExtensionFunctionDetails chrome_details(this);
VolumeManager* const volume_manager =
VolumeManager::Get(chrome_details.GetProfile());
if (!volume_manager) if (!volume_manager)
return false; return RespondNow(Error("Invalid state"));
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 false; return RespondNow(Error("Volume not found"));
DiskMountManager::GetInstance()->RenameMountedDevice( DiskMountManager::GetInstance()->RenameMountedDevice(
volume->mount_path().AsUTF8Unsafe(), params->new_name); volume->mount_path().AsUTF8Unsafe(), params->new_name);
SendResponse(true); return RespondNow(NoArguments());
return true;
} }
namespace { namespace {
...@@ -677,7 +682,12 @@ int64_t GetLocalDiskSpace(const base::FilePath& path) { ...@@ -677,7 +682,12 @@ int64_t GetLocalDiskSpace(const base::FilePath& path) {
} // namespace } // namespace
bool FileManagerPrivateInternalStartCopyFunction::RunAsync() { FileManagerPrivateInternalStartCopyFunction::
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;
...@@ -687,13 +697,12 @@ bool FileManagerPrivateInternalStartCopyFunction::RunAsync() { ...@@ -687,13 +697,12 @@ bool FileManagerPrivateInternalStartCopyFunction::RunAsync() {
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.
SetError("EncodingError"); return RespondNow(Error("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(
GetProfile(), render_frame_host()); chrome_details_.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;
...@@ -707,12 +716,11 @@ bool FileManagerPrivateInternalStartCopyFunction::RunAsync() { ...@@ -707,12 +716,11 @@ bool FileManagerPrivateInternalStartCopyFunction::RunAsync() {
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.
SetError("EncodingError"); return RespondNow(Error("EncodingError"));
return false;
} }
// Check how much space we need for the copy operation. // Check how much space we need for the copy operation.
return base::PostTaskWithTraits( 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_,
...@@ -721,6 +729,7 @@ bool FileManagerPrivateInternalStartCopyFunction::RunAsync() { ...@@ -721,6 +729,7 @@ bool FileManagerPrivateInternalStartCopyFunction::RunAsync() {
base::BindOnce(&FileManagerPrivateInternalStartCopyFunction:: base::BindOnce(&FileManagerPrivateInternalStartCopyFunction::
RunAfterGetFileMetadata, RunAfterGetFileMetadata,
this))); this)));
return RespondLater();
} }
void FileManagerPrivateInternalStartCopyFunction::RunAfterGetFileMetadata( void FileManagerPrivateInternalStartCopyFunction::RunAfterGetFileMetadata(
...@@ -729,17 +738,18 @@ void FileManagerPrivateInternalStartCopyFunction::RunAfterGetFileMetadata( ...@@ -729,17 +738,18 @@ 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) {
SetError("NotFoundError"); Respond(Error("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(GetProfile()).BaseName().value()) { drive::util::GetDriveMountPointPath(chrome_details_.GetProfile())
.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 = destination_dir = file_manager::util::GetMyFilesFolderForProfile(
file_manager::util::GetMyFilesFolderForProfile(GetProfile()); chrome_details_.GetProfile());
} else { } else {
destination_dir = destination_url_.path().DirName(); destination_dir = destination_url_.path().DirName();
} }
...@@ -760,9 +770,11 @@ void FileManagerPrivateInternalStartCopyFunction::RunAfterCheckDiskSpace( ...@@ -760,9 +770,11 @@ 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(GetProfile()) || file_manager::util::GetDownloadsMountPointName(
chrome_details_.GetProfile()) ||
destination_url_.filesystem_id() == destination_url_.filesystem_id() ==
drive::util::GetDriveMountPointPath(GetProfile()) drive::util::GetDriveMountPointPath(
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
...@@ -772,7 +784,7 @@ void FileManagerPrivateInternalStartCopyFunction::RunAfterCheckDiskSpace( ...@@ -772,7 +784,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(GetProfile()); drive::util::GetFileSystemByProfile(chrome_details_.GetProfile());
if (!drive_file_system) { if (!drive_file_system) {
RunAfterFreeDiskSpace(false); RunAfterFreeDiskSpace(false);
} else { } else {
...@@ -793,51 +805,47 @@ void FileManagerPrivateInternalStartCopyFunction::RunAfterFreeDiskSpace( ...@@ -793,51 +805,47 @@ void FileManagerPrivateInternalStartCopyFunction::RunAfterFreeDiskSpace(
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!available) { if (!available) {
SetError("QuotaExceededError"); Respond(Error("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(
GetProfile(), render_frame_host()); chrome_details_.GetProfile(), render_frame_host());
const bool result = base::PostTaskWithTraitsAndReplyWithResult( base::PostTaskWithTraitsAndReplyWithResult(
FROM_HERE, {BrowserThread::IO}, FROM_HERE, {BrowserThread::IO},
base::BindOnce(&StartCopyOnIOThread, GetProfile(), file_system_context, base::BindOnce(&StartCopyOnIOThread, chrome_details_.GetProfile(),
source_url_, destination_url_), file_system_context, 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);
SetResult(std::make_unique<base::Value>(operation_id)); Respond(OneArgument(std::make_unique<base::Value>(operation_id)));
SendResponse(true);
} }
bool FileManagerPrivateCancelCopyFunction::RunAsync() { ExtensionFunction::ResponseAction FileManagerPrivateCancelCopyFunction::Run() {
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(
GetProfile(), render_frame_host()); chrome_details.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));
SendResponse(true); return RespondNow(NoArguments());
return true;
} }
ExtensionFunction::ResponseAction ExtensionFunction::ResponseAction
...@@ -917,26 +925,26 @@ FileManagerPrivateInternalComputeChecksumFunction:: ...@@ -917,26 +925,26 @@ FileManagerPrivateInternalComputeChecksumFunction::
FileManagerPrivateInternalComputeChecksumFunction:: FileManagerPrivateInternalComputeChecksumFunction::
~FileManagerPrivateInternalComputeChecksumFunction() = default; ~FileManagerPrivateInternalComputeChecksumFunction() = default;
bool FileManagerPrivateInternalComputeChecksumFunction::RunAsync() { ExtensionFunction::ResponseAction
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()) {
SetError("File URL must be provided."); return RespondNow(Error("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(
GetProfile(), render_frame_host()); chrome_details.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()) {
SetError("File URL was invalid"); return RespondNow(Error("File URL was invalid"));
return false;
} }
std::unique_ptr<storage::FileStreamReader> reader = std::unique_ptr<storage::FileStreamReader> reader =
...@@ -945,25 +953,30 @@ bool FileManagerPrivateInternalComputeChecksumFunction::RunAsync() { ...@@ -945,25 +953,30 @@ bool FileManagerPrivateInternalComputeChecksumFunction::RunAsync() {
FileStreamMd5Digester::ResultCallback result_callback = base::Bind( FileStreamMd5Digester::ResultCallback result_callback = base::Bind(
&ComputeChecksumRespondOnUIThread, &ComputeChecksumRespondOnUIThread,
base::Bind(&FileManagerPrivateInternalComputeChecksumFunction::Respond, base::Bind(
this)); &FileManagerPrivateInternalComputeChecksumFunction::RespondWith,
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 true; return RespondLater();
} }
void FileManagerPrivateInternalComputeChecksumFunction::Respond( void FileManagerPrivateInternalComputeChecksumFunction::RespondWith(
const std::string& hash) { const std::string& hash) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
SetResult(std::make_unique<base::Value>(hash)); Respond(OneArgument(std::make_unique<base::Value>(hash)));
SendResponse(true);
} }
bool FileManagerPrivateSearchFilesByHashesFunction::RunAsync() { FileManagerPrivateSearchFilesByHashesFunction::
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);
...@@ -972,7 +985,7 @@ bool FileManagerPrivateSearchFilesByHashesFunction::RunAsync() { ...@@ -972,7 +985,7 @@ bool FileManagerPrivateSearchFilesByHashesFunction::RunAsync() {
// than Drive. // than Drive.
drive::EventLogger* const logger = drive::EventLogger* const logger =
file_manager::util::GetLogger(GetProfile()); file_manager::util::GetLogger(chrome_details_.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(),
...@@ -982,17 +995,17 @@ bool FileManagerPrivateSearchFilesByHashesFunction::RunAsync() { ...@@ -982,17 +995,17 @@ bool FileManagerPrivateSearchFilesByHashesFunction::RunAsync() {
set_log_on_completion(true); set_log_on_completion(true);
drive::DriveIntegrationService* integration_service = drive::DriveIntegrationService* integration_service =
drive::util::GetIntegrationServiceByProfile(GetProfile()); drive::util::GetIntegrationServiceByProfile(chrome_details_.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 false; return RespondNow(Error("Drive not available"));
} }
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(GetProfile()); drive::util::GetFileSystemByProfile(chrome_details_.GetProfile());
if (file_system) { if (file_system) {
file_system->SearchByHashes( file_system->SearchByHashes(
hashes, hashes,
...@@ -1010,13 +1023,13 @@ bool FileManagerPrivateSearchFilesByHashesFunction::RunAsync() { ...@@ -1010,13 +1023,13 @@ bool FileManagerPrivateSearchFilesByHashesFunction::RunAsync() {
this, hashes, this, hashes,
integration_service->GetMountPointPath().Append( integration_service->GetMountPointPath().Append(
drive::util::kDriveMyDriveRootDirName), drive::util::kDriveMyDriveRootDirName),
drive::util::GetDriveMountPointPath(GetProfile())), drive::util::GetDriveMountPointPath(chrome_details_.GetProfile())),
base::BindOnce( base::BindOnce(
&FileManagerPrivateSearchFilesByHashesFunction::OnSearchByAttribute, &FileManagerPrivateSearchFilesByHashesFunction::OnSearchByAttribute,
this, hashes)); this, hashes));
} }
return true; return RespondLater();
} }
std::vector<drive::HashAndFilePath> std::vector<drive::HashAndFilePath>
...@@ -1062,7 +1075,7 @@ void FileManagerPrivateSearchFilesByHashesFunction::OnSearchByHashes( ...@@ -1062,7 +1075,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) {
SendResponse(false); Respond(Error(drive::FileErrorToString(error)));
return; return;
} }
...@@ -1077,10 +1090,10 @@ void FileManagerPrivateSearchFilesByHashesFunction::OnSearchByHashes( ...@@ -1077,10 +1090,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(
GetProfile(), hashAndPath.path, extension_id()).spec()); chrome_details_.GetProfile(), hashAndPath.path, extension_id())
.spec());
} }
SetResult(std::move(result)); Respond(OneArgument(std::move(result)));
SendResponse(true);
} }
ExtensionFunction::ResponseAction ExtensionFunction::ResponseAction
...@@ -1147,37 +1160,37 @@ void FileManagerPrivateInternalSetEntryTagFunction::OnSetEntryPropertyCompleted( ...@@ -1147,37 +1160,37 @@ void FileManagerPrivateInternalSetEntryTagFunction::OnSetEntryPropertyCompleted(
: Error("Failed to set a tag.")); : Error("Failed to set a tag."));
} }
bool FileManagerPrivateInternalGetDirectorySizeFunction::RunAsync() { ExtensionFunction::ResponseAction
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()) {
SetError("File URL must be provided."); return RespondNow(Error("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(
GetProfile(), render_frame_host()); chrome_details.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)) {
SetError("FileSystemBackend failed to handle the entry's url."); return RespondNow(
return false; Error("FileSystemBackend failed to handle the entry's url."));
} }
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) {
SetError("Only local directories are supported."); return RespondNow(Error("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(), GetProfile(), GURL(params->url)); render_frame_host(), chrome_details.GetProfile(), GURL(params->url));
if (root_path.empty()) { if (root_path.empty()) {
SetError("Failed to get a local path from the entry's url."); return RespondNow(
return false; Error("Failed to get a local path from the entry's url."));
} }
base::PostTaskWithTraitsAndReplyWithResult( base::PostTaskWithTraitsAndReplyWithResult(
...@@ -1186,13 +1199,13 @@ bool FileManagerPrivateInternalGetDirectorySizeFunction::RunAsync() { ...@@ -1186,13 +1199,13 @@ bool FileManagerPrivateInternalGetDirectorySizeFunction::RunAsync() {
base::BindOnce(&FileManagerPrivateInternalGetDirectorySizeFunction:: base::BindOnce(&FileManagerPrivateInternalGetDirectorySizeFunction::
OnDirectorySizeRetrieved, OnDirectorySizeRetrieved,
this)); this));
return true; return RespondLater();
} }
void FileManagerPrivateInternalGetDirectorySizeFunction:: void FileManagerPrivateInternalGetDirectorySizeFunction::
OnDirectorySizeRetrieved(int64_t size) { OnDirectorySizeRetrieved(int64_t size) {
SetResult(std::make_unique<base::Value>(static_cast<double>(size))); Respond(
SendResponse(true); OneArgument(std::make_unique<base::Value>(static_cast<double>(size))));
} }
} // namespace extensions } // namespace extensions
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#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"
...@@ -87,12 +86,12 @@ class FileManagerPrivateGrantAccessFunction : public UIThreadExtensionFunction { ...@@ -87,12 +86,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 LoggedAsyncExtensionFunction { class FileWatchFunctionBase : public LoggedUIThreadExtensionFunction {
public: public:
using ResponseCallback = base::Callback<void(bool success)>; using ResponseCallback = base::Callback<void(bool success)>;
// Calls SendResponse() with |success| converted to base::Value. // Calls Respond() with |success| converted to base::Value.
void Respond(bool success); void RespondWith(bool success);
protected: protected:
~FileWatchFunctionBase() override = default; ~FileWatchFunctionBase() override = default;
...@@ -112,8 +111,8 @@ class FileWatchFunctionBase : public LoggedAsyncExtensionFunction { ...@@ -112,8 +111,8 @@ class FileWatchFunctionBase : public LoggedAsyncExtensionFunction {
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;
// ChromeAsyncExtensionFunction overrides. // ExtensionFunction overrides.
bool RunAsync() override; ResponseAction Run() override;
private: private:
void RunAsyncOnIOThread( void RunAsyncOnIOThread(
...@@ -169,7 +168,7 @@ class FileManagerPrivateInternalRemoveFileWatchFunction ...@@ -169,7 +168,7 @@ class FileManagerPrivateInternalRemoveFileWatchFunction
// Implements the chrome.fileManagerPrivate.getSizeStats method. // Implements the chrome.fileManagerPrivate.getSizeStats method.
class FileManagerPrivateGetSizeStatsFunction class FileManagerPrivateGetSizeStatsFunction
: public LoggedAsyncExtensionFunction { : public LoggedUIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.getSizeStats", DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.getSizeStats",
FILEMANAGERPRIVATE_GETSIZESTATS) FILEMANAGERPRIVATE_GETSIZESTATS)
...@@ -177,8 +176,8 @@ class FileManagerPrivateGetSizeStatsFunction ...@@ -177,8 +176,8 @@ class FileManagerPrivateGetSizeStatsFunction
protected: protected:
~FileManagerPrivateGetSizeStatsFunction() override = default; ~FileManagerPrivateGetSizeStatsFunction() override = default;
// ChromeAsyncExtensionFunction overrides. // ExtensionFunction overrides.
bool RunAsync() override; ResponseAction Run() override;
private: private:
void OnGetDriveAvailableSpace(drive::FileError error, void OnGetDriveAvailableSpace(drive::FileError error,
...@@ -194,7 +193,7 @@ class FileManagerPrivateGetSizeStatsFunction ...@@ -194,7 +193,7 @@ class FileManagerPrivateGetSizeStatsFunction
// Implements the chrome.fileManagerPrivate.validatePathNameLength method. // Implements the chrome.fileManagerPrivate.validatePathNameLength method.
class FileManagerPrivateInternalValidatePathNameLengthFunction class FileManagerPrivateInternalValidatePathNameLengthFunction
: public LoggedAsyncExtensionFunction { : public LoggedUIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION( DECLARE_EXTENSION_FUNCTION(
"fileManagerPrivateInternal.validatePathNameLength", "fileManagerPrivateInternal.validatePathNameLength",
...@@ -206,14 +205,14 @@ class FileManagerPrivateInternalValidatePathNameLengthFunction ...@@ -206,14 +205,14 @@ class FileManagerPrivateInternalValidatePathNameLengthFunction
void OnFilePathLimitRetrieved(size_t current_length, size_t max_length); void OnFilePathLimitRetrieved(size_t current_length, size_t max_length);
// ChromeAsyncExtensionFunction overrides. // ExtensionFunction overrides.
bool RunAsync() override; ResponseAction Run() 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 LoggedAsyncExtensionFunction { : public LoggedUIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.formatVolume", DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.formatVolume",
FILEMANAGERPRIVATE_FORMATVOLUME) FILEMANAGERPRIVATE_FORMATVOLUME)
...@@ -221,14 +220,14 @@ class FileManagerPrivateFormatVolumeFunction ...@@ -221,14 +220,14 @@ class FileManagerPrivateFormatVolumeFunction
protected: protected:
~FileManagerPrivateFormatVolumeFunction() override = default; ~FileManagerPrivateFormatVolumeFunction() override = default;
// ChromeAsyncExtensionFunction overrides. // ExtensionFunction overrides.
bool RunAsync() override; ResponseAction Run() 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 LoggedAsyncExtensionFunction { : public LoggedUIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.renameVolume", DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.renameVolume",
FILEMANAGERPRIVATE_RENAMEVOLUME) FILEMANAGERPRIVATE_RENAMEVOLUME)
...@@ -236,22 +235,24 @@ class FileManagerPrivateRenameVolumeFunction ...@@ -236,22 +235,24 @@ class FileManagerPrivateRenameVolumeFunction
protected: protected:
~FileManagerPrivateRenameVolumeFunction() override = default; ~FileManagerPrivateRenameVolumeFunction() override = default;
// ChromeAsyncExtensionFunction overrides. // ExtensionFunction overrides.
bool RunAsync() override; ResponseAction Run() override;
}; };
// Implements the chrome.fileManagerPrivate.startCopy method. // Implements the chrome.fileManagerPrivate.startCopy method.
class FileManagerPrivateInternalStartCopyFunction class FileManagerPrivateInternalStartCopyFunction
: public LoggedAsyncExtensionFunction { : public LoggedUIThreadExtensionFunction {
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;
// ChromeAsyncExtensionFunction overrides. // ExtensionFunction overrides.
bool RunAsync() override; ResponseAction Run() override;
private: private:
void RunAfterGetFileMetadata(base::File::Error result, void RunAfterGetFileMetadata(base::File::Error result,
...@@ -270,11 +271,12 @@ class FileManagerPrivateInternalStartCopyFunction ...@@ -270,11 +271,12 @@ 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 LoggedAsyncExtensionFunction { : public LoggedUIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.cancelCopy", DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.cancelCopy",
FILEMANAGERPRIVATE_CANCELCOPY) FILEMANAGERPRIVATE_CANCELCOPY)
...@@ -282,8 +284,8 @@ class FileManagerPrivateCancelCopyFunction ...@@ -282,8 +284,8 @@ class FileManagerPrivateCancelCopyFunction
protected: protected:
~FileManagerPrivateCancelCopyFunction() override = default; ~FileManagerPrivateCancelCopyFunction() override = default;
// ChromeAsyncExtensionFunction overrides. // ExtensionFunction overrides.
bool RunAsync() override; ResponseAction Run() override;
}; };
// Implements the chrome.fileManagerPrivateInternal.resolveIsolatedEntries // Implements the chrome.fileManagerPrivateInternal.resolveIsolatedEntries
...@@ -309,7 +311,7 @@ class FileManagerPrivateInternalResolveIsolatedEntriesFunction ...@@ -309,7 +311,7 @@ class FileManagerPrivateInternalResolveIsolatedEntriesFunction
}; };
class FileManagerPrivateInternalComputeChecksumFunction class FileManagerPrivateInternalComputeChecksumFunction
: public LoggedAsyncExtensionFunction { : public LoggedUIThreadExtensionFunction {
public: public:
FileManagerPrivateInternalComputeChecksumFunction(); FileManagerPrivateInternalComputeChecksumFunction();
...@@ -319,20 +321,22 @@ class FileManagerPrivateInternalComputeChecksumFunction ...@@ -319,20 +321,22 @@ class FileManagerPrivateInternalComputeChecksumFunction
protected: protected:
~FileManagerPrivateInternalComputeChecksumFunction() override; ~FileManagerPrivateInternalComputeChecksumFunction() override;
// ChromeAsyncExtensionFunction overrides. // ExtensionFunction overrides.
bool RunAsync() override; ResponseAction Run() override;
private: private:
std::unique_ptr<drive::util::FileStreamMd5Digester> digester_; std::unique_ptr<drive::util::FileStreamMd5Digester> digester_;
void Respond(const std::string& hash); void RespondWith(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 LoggedAsyncExtensionFunction { : public LoggedUIThreadExtensionFunction {
public: public:
FileManagerPrivateSearchFilesByHashesFunction();
DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.searchFilesByHashes", DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.searchFilesByHashes",
FILEMANAGERPRIVATE_SEARCHFILESBYHASHES) FILEMANAGERPRIVATE_SEARCHFILESBYHASHES)
...@@ -340,8 +344,8 @@ class FileManagerPrivateSearchFilesByHashesFunction ...@@ -340,8 +344,8 @@ class FileManagerPrivateSearchFilesByHashesFunction
~FileManagerPrivateSearchFilesByHashesFunction() override = default; ~FileManagerPrivateSearchFilesByHashesFunction() override = default;
private: private:
// ChromeAsyncExtensionFunction overrides. // ExtensionFunction overrides.
bool RunAsync() override; ResponseAction Run() 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(
...@@ -355,6 +359,8 @@ class FileManagerPrivateSearchFilesByHashesFunction ...@@ -355,6 +359,8 @@ 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.
...@@ -394,7 +400,7 @@ class FileManagerPrivateInternalSetEntryTagFunction ...@@ -394,7 +400,7 @@ class FileManagerPrivateInternalSetEntryTagFunction
// Implements the chrome.fileManagerPrivate.getDirectorySize method. // Implements the chrome.fileManagerPrivate.getDirectorySize method.
class FileManagerPrivateInternalGetDirectorySizeFunction class FileManagerPrivateInternalGetDirectorySizeFunction
: public LoggedAsyncExtensionFunction { : public LoggedUIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.getDirectorySize", DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.getDirectorySize",
FILEMANAGERPRIVATEINTERNAL_GETDIRECTORYSIZE) FILEMANAGERPRIVATEINTERNAL_GETDIRECTORYSIZE)
...@@ -404,8 +410,8 @@ class FileManagerPrivateInternalGetDirectorySizeFunction ...@@ -404,8 +410,8 @@ class FileManagerPrivateInternalGetDirectorySizeFunction
void OnDirectorySizeRetrieved(int64_t size); void OnDirectorySizeRetrieved(int64_t size);
// ChromeAsyncExtensionFunction overrides // ExtensionFunction overrides
bool RunAsync() override; ResponseAction Run() 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