Commit 8cdb47be authored by kinaba's avatar kinaba Committed by Commit bot

Files app: Prepare all information necessary for Arc task execution.

Further, and hopefully the last step for refactoring needed for the feature.
 1) We need mime types on the task running time as well. Added a cycle for it.
 2) Split the task enumeration function for the placeholder for ARC stuff and
   post processing part.
 3) For the efficiency and clarity for the split of 2), changed std::vector
   value copying to movement by std::unique_ptr.

BUG=607059
TEST=unit_tests --gtest_filter='*FileManagerFileTask*'
TEST=browser_tests --gtest_filter='FileManagerJsTest.FileTasks'

Review-Url: https://codereview.chromium.org/1923953005
Cr-Commit-Position: refs/heads/master@{#390326}
parent ad8266f9
......@@ -192,11 +192,12 @@ void FileManagerPrivateInternalGetFileTasksFunction::
}
void FileManagerPrivateInternalGetFileTasksFunction::OnFileTasksListed(
const std::vector<file_manager::file_tasks::FullTaskDescriptor>& tasks) {
std::unique_ptr<std::vector<file_manager::file_tasks::FullTaskDescriptor>>
tasks) {
// Convert the tasks into JSON compatible objects.
using api::file_manager_private::FileTask;
std::vector<FileTask> results;
for (const file_manager::file_tasks::FullTaskDescriptor& task : tasks) {
for (const file_manager::file_tasks::FullTaskDescriptor& task : *tasks) {
FileTask converted;
converted.task_id =
file_manager::file_tasks::TaskDescriptorToId(task.task_descriptor());
......
......@@ -68,7 +68,8 @@ class FileManagerPrivateInternalGetFileTasksFunction
std::unique_ptr<std::set<base::FilePath>> path_directory_set);
void OnFileTasksListed(
const std::vector<file_manager::file_tasks::FullTaskDescriptor>& tasks);
std::unique_ptr<std::vector<file_manager::file_tasks::FullTaskDescriptor>>
tasks);
std::unique_ptr<app_file_handler_util::IsDirectoryCollector>
is_directory_collector_;
......
......@@ -19,6 +19,7 @@
#include "chrome/browser/chromeos/file_manager/file_browser_handlers.h"
#include "chrome/browser/chromeos/file_manager/fileapi_util.h"
#include "chrome/browser/chromeos/file_manager/open_util.h"
#include "chrome/browser/extensions/api/file_handlers/mime_util.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/profiles/profile.h"
......@@ -140,6 +141,38 @@ bool IsFallbackFileHandler(const file_tasks::TaskDescriptor& task) {
return false;
}
void FindArcTasks(Profile* profile,
const std::vector<extensions::EntryInfo>& entries,
std::unique_ptr<std::vector<FullTaskDescriptor>> result_list,
const FindTasksCallback& callback) {
// TODO(kinaba): implement.
callback.Run(std::move(result_list));
}
void ExecuteByArcAfterMimeTypesCollected(
Profile* profile,
const TaskDescriptor& task,
const std::vector<FileSystemURL>& file_urls,
const FileTaskFinishedCallback& done,
extensions::app_file_handler_util::MimeTypeCollector* mime_collector,
std::unique_ptr<std::vector<std::string>> mime_types) {
// TODO(kinaba): implement.
NOTIMPLEMENTED();
done.Run(extensions::api::file_manager_private::TASK_RESULT_FAILED);
}
void PostProcessFoundTasks(
Profile* profile,
const std::vector<extensions::EntryInfo>& entries,
const FindTasksCallback& callback,
std::unique_ptr<std::vector<FullTaskDescriptor>> result_list) {
// Google documents can only be handled by internal handlers.
if (ContainsGoogleDocument(entries))
KeepOnlyFileManagerInternalTasks(result_list.get());
ChooseAndSetDefaultTask(*profile->GetPrefs(), entries, result_list.get());
callback.Run(std::move(result_list));
}
} // namespace
FullTaskDescriptor::FullTaskDescriptor(
......@@ -275,9 +308,15 @@ bool ExecuteFileTask(Profile* profile,
const TaskDescriptor& task,
const std::vector<FileSystemURL>& file_urls,
const FileTaskFinishedCallback& done) {
// ARC apps needs mime types for launching. Retrieve them first.
if (task.task_type == TASK_TYPE_ARC_APP) {
NOTIMPLEMENTED();
return false;
extensions::app_file_handler_util::MimeTypeCollector* mime_collector =
new extensions::app_file_handler_util::MimeTypeCollector(profile);
mime_collector->CollectForURLs(
file_urls,
base::Bind(&ExecuteByArcAfterMimeTypesCollected, profile, task,
file_urls, done, base::Owned(mime_collector)));
return true;
}
// drive::FileTaskExecutor is responsible to handle drive tasks.
......@@ -525,29 +564,26 @@ void FindAllTypesOfTasks(Profile* profile,
const std::vector<GURL>& file_urls,
const FindTasksCallback& callback) {
DCHECK(profile);
std::vector<FullTaskDescriptor> result_list;
std::unique_ptr<std::vector<FullTaskDescriptor>> result_list(
new std::vector<FullTaskDescriptor>);
// Find Drive app tasks, if the drive app registry is present.
if (drive_app_registry)
FindDriveAppTasks(*drive_app_registry, entries, &result_list);
FindDriveAppTasks(*drive_app_registry, entries, result_list.get());
// Find and append file handler tasks. We know there aren't duplicates
// because Drive apps and platform apps are entirely different kinds of
// tasks.
FindFileHandlerTasks(profile, entries, &result_list);
FindFileHandlerTasks(profile, entries, result_list.get());
// Find and append file browser handler tasks. We know there aren't
// duplicates because "file_browser_handlers" and "file_handlers" shouldn't
// be used in the same manifest.json.
FindFileBrowserHandlerTasks(profile, file_urls, &result_list);
// Google documents can only be handled by internal handlers.
if (ContainsGoogleDocument(entries))
KeepOnlyFileManagerInternalTasks(&result_list);
ChooseAndSetDefaultTask(*profile->GetPrefs(), entries, &result_list);
FindFileBrowserHandlerTasks(profile, file_urls, result_list.get());
callback.Run(result_list);
// Find and append ARC handler tasks.
FindArcTasks(profile, entries, std::move(result_list),
base::Bind(&PostProcessFoundTasks, profile, entries, callback));
}
void ChooseAndSetDefaultTask(const PrefService& pref_service,
......
......@@ -111,6 +111,7 @@
#ifndef CHROME_BROWSER_CHROMEOS_FILE_MANAGER_FILE_TASKS_H_
#define CHROME_BROWSER_CHROMEOS_FILE_MANAGER_FILE_TASKS_H_
#include <memory>
#include <set>
#include <string>
#include <vector>
......@@ -289,7 +290,8 @@ void FindFileBrowserHandlerTasks(
std::vector<FullTaskDescriptor>* result_list);
// Callback function type for FindAllTypesOfTasks.
typedef base::Callback<void(const std::vector<FullTaskDescriptor>& result)>
typedef base::Callback<void(
std::unique_ptr<std::vector<FullTaskDescriptor>> result)>
FindTasksCallback;
// Finds all types (drive, file handlers, file browser handlers) of
......
......@@ -455,8 +455,8 @@ class FileManagerFileTasksComplexTest : public testing::Test {
private:
void OnReply(std::vector<FullTaskDescriptor>* out,
const std::vector<FullTaskDescriptor>& result) {
*out = result;
std::unique_ptr<std::vector<FullTaskDescriptor>> result) {
*out = *result;
run_loop_.Quit();
}
......
......@@ -77,11 +77,11 @@ void OpenFileMimeTypeAfterTasksListed(
Profile* profile,
const GURL& url,
const platform_util::OpenOperationCallback& callback,
const std::vector<file_tasks::FullTaskDescriptor>& tasks) {
std::unique_ptr<std::vector<file_tasks::FullTaskDescriptor>> tasks) {
// Select a default handler. If a default handler is not available, select
// a non-generic file handler.
const file_tasks::FullTaskDescriptor* chosen_task = nullptr;
for (const auto& task : tasks) {
for (const auto& task : *tasks) {
if (!task.is_generic_file_handler()) {
chosen_task = &task;
if (task.is_default())
......
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