Chromium Code Reviews| Index: chrome/browser/chromeos/extensions/file_manager/private_api_misc.cc |
| diff --git a/chrome/browser/chromeos/extensions/file_manager/private_api_misc.cc b/chrome/browser/chromeos/extensions/file_manager/private_api_misc.cc |
| index 0d56a55ab6e2daa11af869528695352446991c86..b17eeacdf98ceb9703ddf7f21d40ad86fb7e325f 100644 |
| --- a/chrome/browser/chromeos/extensions/file_manager/private_api_misc.cc |
| +++ b/chrome/browser/chromeos/extensions/file_manager/private_api_misc.cc |
| @@ -9,6 +9,7 @@ |
| #include "ash/frame/frame_util.h" |
| #include "base/files/file_path.h" |
| +#include "base/memory/ref_counted.h" |
| #include "base/prefs/pref_service.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/strings/utf_string_conversions.h" |
| @@ -52,8 +53,8 @@ |
| #include "url/gurl.h" |
| namespace extensions { |
| - |
| namespace { |
| + |
| const char kCWSScope[] = "https://www.googleapis.com/auth/chromewebstore"; |
| // Obtains the current app window. |
| @@ -97,6 +98,52 @@ GetLoggedInProfileInfoList() { |
| return result_profiles; |
| } |
| + |
| +// Converts a list of file system urls (as strings) to a pair of a provided file |
| +// system object and a set of paths on the file system. In case of an error, |
| +// false is returned and the error message set. |
| +bool ConvertURLsToProvidedInfo( |
| + const scoped_refptr<storage::FileSystemContext>& file_system_context, |
| + const std::vector<std::string>& urls, |
| + chromeos::file_system_provider::ProvidedFileSystemInterface** file_system, |
| + std::set<base::FilePath>* paths, |
|
fukino
2015/07/23 04:52:18
optional nit: Can we use vector for paths?
I'm a b
mtomasz
2015/09/17 05:03:46
Done.
|
| + std::string* error) { |
| + DCHECK(file_system); |
| + DCHECK(error); |
| + |
| + if (!urls.size()) { |
| + *error = "At least one file must be specified."; |
| + return false; |
| + } |
| + |
| + *file_system = nullptr; |
| + for (const auto url : urls) { |
| + const storage::FileSystemURL file_system_url( |
| + file_system_context->CrackURL(GURL(url))); |
| + |
| + LOG(ERROR) << "URL: " << url; |
|
fukino
2015/07/23 04:52:18
Remaining debug log?
mtomasz
2015/09/17 05:03:46
Done.
|
| + |
| + chromeos::file_system_provider::util::FileSystemURLParser parser( |
| + file_system_url); |
| + if (!parser.Parse()) { |
| + *error = "Related provided file system not found."; |
| + return false; |
| + } |
| + |
| + if (*file_system != nullptr) { |
| + if (*file_system != parser.file_system()) { |
| + *error = "All entries must be on the same file system."; |
| + return false; |
| + } |
| + } else { |
| + *file_system = parser.file_system(); |
| + } |
| + paths->insert(parser.file_path()); |
| + } |
| + |
| + return true; |
| +} |
| + |
| } // namespace |
| bool FileManagerPrivateLogoutUserForReauthenticationFunction::RunSync() { |
| @@ -537,14 +584,14 @@ void FileManagerPrivateConfigureVolumeFunction::OnCompleted( |
| Respond(NoArguments()); |
| } |
| -FileManagerPrivateInternalGetEntryActionsFunction:: |
| - FileManagerPrivateInternalGetEntryActionsFunction() |
| - : chrome_details_(this) { |
| -} |
| +FileManagerPrivateInternalGetCustomActionsFunction:: |
| + FileManagerPrivateInternalGetCustomActionsFunction() |
| + : chrome_details_(this) {} |
| ExtensionFunction::ResponseAction |
| -FileManagerPrivateInternalGetEntryActionsFunction::Run() { |
| - using extensions::api::file_manager_private_internal::GetEntryActions::Params; |
| +FileManagerPrivateInternalGetCustomActionsFunction::Run() { |
| + using extensions::api::file_manager_private_internal::GetCustomActions:: |
| + Params; |
| const scoped_ptr<Params> params(Params::Create(*args_)); |
| EXTENSION_FUNCTION_VALIDATE(params); |
| @@ -552,23 +599,26 @@ FileManagerPrivateInternalGetEntryActionsFunction::Run() { |
| file_manager::util::GetFileSystemContextForRenderFrameHost( |
| chrome_details_.GetProfile(), render_frame_host()); |
| - const storage::FileSystemURL file_system_url( |
| - file_system_context->CrackURL(GURL(params->url))); |
| + std::set<base::FilePath> paths; |
| + chromeos::file_system_provider::ProvidedFileSystemInterface* file_system = |
| + nullptr; |
| + std::string error; |
| - chromeos::file_system_provider::util::FileSystemURLParser parser( |
| - file_system_url); |
| - if (!parser.Parse()) |
| - return RespondNow(Error("Related provided file system not found.")); |
| + if (!ConvertURLsToProvidedInfo(file_system_context, params->urls, |
| + &file_system, &paths, &error)) { |
| + return RespondNow(Error(error)); |
| + } |
| - parser.file_system()->GetActions( |
| - parser.file_path(), |
| + DCHECK(file_system); |
| + file_system->GetActions( |
| + paths, |
| base::Bind( |
| - &FileManagerPrivateInternalGetEntryActionsFunction::OnCompleted, |
| + &FileManagerPrivateInternalGetCustomActionsFunction::OnCompleted, |
| this)); |
| return RespondLater(); |
| } |
| -void FileManagerPrivateInternalGetEntryActionsFunction::OnCompleted( |
| +void FileManagerPrivateInternalGetCustomActionsFunction::OnCompleted( |
| const chromeos::file_system_provider::Actions& actions, |
| base::File::Error result) { |
| if (result != base::File::FILE_OK) { |
| @@ -586,18 +636,17 @@ void FileManagerPrivateInternalGetEntryActionsFunction::OnCompleted( |
| } |
| Respond(ArgumentList( |
| - api::file_manager_private_internal::GetEntryActions::Results::Create( |
| + api::file_manager_private_internal::GetCustomActions::Results::Create( |
| items))); |
| } |
| -FileManagerPrivateInternalExecuteEntryActionFunction:: |
| - FileManagerPrivateInternalExecuteEntryActionFunction() |
| - : chrome_details_(this) { |
| -} |
| +FileManagerPrivateInternalExecuteCustomActionFunction:: |
| + FileManagerPrivateInternalExecuteCustomActionFunction() |
| + : chrome_details_(this) {} |
| ExtensionFunction::ResponseAction |
| -FileManagerPrivateInternalExecuteEntryActionFunction::Run() { |
| - using extensions::api::file_manager_private_internal::ExecuteEntryAction:: |
| +FileManagerPrivateInternalExecuteCustomActionFunction::Run() { |
| + using extensions::api::file_manager_private_internal::ExecuteCustomAction:: |
| Params; |
| const scoped_ptr<Params> params(Params::Create(*args_)); |
| EXTENSION_FUNCTION_VALIDATE(params); |
| @@ -606,23 +655,26 @@ FileManagerPrivateInternalExecuteEntryActionFunction::Run() { |
| file_manager::util::GetFileSystemContextForRenderFrameHost( |
| chrome_details_.GetProfile(), render_frame_host()); |
| - const storage::FileSystemURL file_system_url( |
| - file_system_context->CrackURL(GURL(params->url))); |
| + std::set<base::FilePath> paths; |
| + chromeos::file_system_provider::ProvidedFileSystemInterface* file_system = |
| + nullptr; |
| + std::string error; |
| - chromeos::file_system_provider::util::FileSystemURLParser parser( |
| - file_system_url); |
| - if (!parser.Parse()) |
| - return RespondNow(Error("Related provided file system not found.")); |
| + if (!ConvertURLsToProvidedInfo(file_system_context, params->urls, |
| + &file_system, &paths, &error)) { |
| + return RespondNow(Error(error)); |
| + } |
| - parser.file_system()->ExecuteAction( |
| - parser.file_path(), params->action_id, |
| + DCHECK(file_system); |
| + file_system->ExecuteAction( |
| + paths, params->action_id, |
| base::Bind( |
| - &FileManagerPrivateInternalExecuteEntryActionFunction::OnCompleted, |
| + &FileManagerPrivateInternalExecuteCustomActionFunction::OnCompleted, |
| this)); |
| return RespondLater(); |
| } |
| -void FileManagerPrivateInternalExecuteEntryActionFunction::OnCompleted( |
| +void FileManagerPrivateInternalExecuteCustomActionFunction::OnCompleted( |
| base::File::Error result) { |
| if (result != base::File::FILE_OK) { |
| Respond(Error("Failed to execute the action.")); |