Commit 6f069b69 authored by Maggie Cai's avatar Maggie Cai Committed by Commit Bot

[IntentHandling] Link files app to query task from app service.

This CL creates an app service file tasks to allow the files app to
query sharing task from app service intent handling backend. This is for
testing the backend and it is behind a flag. It might need to be
modified after link up with unified sharesheet UI.

BUG=1092784

Change-Id: I4ba54f7b2ee9e9ae3fd89184b808c1040a01c288
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2279411
Commit-Queue: Maggie Cai <mxcai@chromium.org>
Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#785316}
parent 0dd97072
...@@ -1083,6 +1083,8 @@ source_set("chromeos") { ...@@ -1083,6 +1083,8 @@ source_set("chromeos") {
"external_protocol_dialog.cc", "external_protocol_dialog.cc",
"external_protocol_dialog.h", "external_protocol_dialog.h",
"file_manager/app_id.h", "file_manager/app_id.h",
"file_manager/app_service_file_tasks.cc",
"file_manager/app_service_file_tasks.h",
"file_manager/arc_file_tasks.cc", "file_manager/arc_file_tasks.cc",
"file_manager/arc_file_tasks.h", "file_manager/arc_file_tasks.h",
"file_manager/documents_provider_root_manager.cc", "file_manager/documents_provider_root_manager.cc",
......
// Copyright (c) 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/file_manager/app_service_file_tasks.h"
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_restrictions.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
#include "chrome/browser/chromeos/file_manager/fileapi_util.h"
#include "chrome/browser/chromeos/file_manager/path_util.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/api/file_manager_private.h"
#include "components/arc/intent_helper/intent_constants.h"
#include "components/arc/mojom/file_system.mojom.h"
#include "components/arc/mojom/intent_helper.mojom.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/browser/entry_info.h"
#include "storage/browser/file_system/file_system_context.h"
#include "storage/browser/file_system/file_system_url.h"
#include "url/gurl.h"
namespace file_manager {
namespace file_tasks {
namespace {
// TODO(crbug/1092784): Only going to support ARC app and web app
// for now.
TaskType GetTaskType(apps::mojom::AppType app_type) {
switch (app_type) {
case apps::mojom::AppType::kArc:
return TASK_TYPE_ARC_APP;
case apps::mojom::AppType::kWeb:
return TASK_TYPE_WEB_APP;
case apps::mojom::AppType::kUnknown:
case apps::mojom::AppType::kCrostini:
case apps::mojom::AppType::kBuiltIn:
case apps::mojom::AppType::kExtension:
case apps::mojom::AppType::kMacNative:
case apps::mojom::AppType::kPluginVm:
case apps::mojom::AppType::kLacros:
return TASK_TYPE_UNKNOWN;
}
}
} // namespace
void FindAppServiceTasks(Profile* profile,
const std::vector<extensions::EntryInfo>& entries,
const std::vector<GURL>& file_urls,
std::vector<FullTaskDescriptor>* result_list) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK_EQ(entries.size(), file_urls.size());
apps::AppServiceProxy* proxy =
apps::AppServiceProxyFactory::GetForProfile(profile);
if (!proxy)
return;
std::vector<std::string> mime_types;
for (auto& entry : entries)
mime_types.push_back(entry.mime_type);
std::vector<apps::AppIdAndActivityName> app_id_and_activities =
proxy->GetAppsForFiles(file_urls, mime_types);
std::string task_action_id = entries.size() == 1 ? "send" : "send_multiple";
using extensions::api::file_manager_private::Verb;
// TODO(crbug/1092784): Get the icons.
// TODO(crbug/1092784): Support file open with in the future.
for (auto& app_id_and_activity : app_id_and_activities) {
apps::mojom::AppType app_type =
proxy->AppRegistryCache().GetAppType(app_id_and_activity.app_id);
// TODO(crbug/1092784): Only going to support ARC app and web app.
if (!(app_type == apps::mojom::AppType::kArc ||
app_type == apps::mojom::AppType::kWeb)) {
continue;
}
result_list->push_back(FullTaskDescriptor(
TaskDescriptor(app_id_and_activity.app_id, GetTaskType(app_type),
task_action_id),
app_id_and_activity.activity_name, Verb::VERB_SHARE_WITH, GURL(),
/* is_default=*/false,
/* is_generic=*/true,
/* is_file_extension_match=*/false));
}
}
void ExecuteAppServiceTask(
Profile* profile,
const TaskDescriptor& task,
const std::vector<storage::FileSystemURL>& file_system_urls,
const std::vector<std::string>& mime_types,
FileTaskFinishedCallback done) {
NOTIMPLEMENTED();
}
} // namespace file_tasks
} // namespace file_manager
// Copyright (c) 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_FILE_MANAGER_APP_SERVICE_FILE_TASKS_H_
#define CHROME_BROWSER_CHROMEOS_FILE_MANAGER_APP_SERVICE_FILE_TASKS_H_
#include <memory>
#include <string>
#include <vector>
#include "chrome/browser/chromeos/file_manager/file_tasks.h"
class Profile;
namespace extensions {
struct EntryInfo;
}
namespace storage {
class FileSystemURL;
}
namespace file_manager {
namespace file_tasks {
// Finds the app services tasks that can handle |entries|, appends them to
// |result_list|, and calls back to |callback|.
// Only support sharing at the moment.
void FindAppServiceTasks(Profile* profile,
const std::vector<extensions::EntryInfo>& entries,
const std::vector<GURL>& file_urls,
std::vector<FullTaskDescriptor>* result_list);
// Executes the specified task by app service.
void ExecuteAppServiceTask(
Profile* profile,
const TaskDescriptor& task,
const std::vector<storage::FileSystemURL>& file_system_urls,
const std::vector<std::string>& mime_types,
FileTaskFinishedCallback done);
} // namespace file_tasks
} // namespace file_manager
#endif // CHROME_BROWSER_CHROMEOS_FILE_MANAGER_APP_SERVICE_FILE_TASKS_H_
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "chrome/browser/chromeos/file_manager/path_util.h" #include "chrome/browser/chromeos/file_manager/path_util.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/extensions/api/file_manager_private.h" #include "chrome/common/extensions/api/file_manager_private.h"
#include "components/arc/arc_service_manager.h" #include "components/arc/arc_service_manager.h"
#include "components/arc/intent_helper/arc_intent_helper_bridge.h" #include "components/arc/intent_helper/arc_intent_helper_bridge.h"
...@@ -183,6 +184,10 @@ void OnArcIconLoaded( ...@@ -183,6 +184,10 @@ void OnArcIconLoaded(
Verb handler_verb = Verb::VERB_NONE; Verb handler_verb = Verb::VERB_NONE;
if (action == arc::kIntentActionSend || if (action == arc::kIntentActionSend ||
action == arc::kIntentActionSendMultiple) { action == arc::kIntentActionSendMultiple) {
// Use app service to get send tasks when the flag is on, so skip
// the send tasks here.
if (base::FeatureList::IsEnabled(features::kIntentHandlingSharing))
continue;
handler_verb = Verb::VERB_SHARE_WITH; handler_verb = Verb::VERB_SHARE_WITH;
} }
auto it = icons->find(arc::ArcIntentHelperBridge::ActivityName( auto it = icons->find(arc::ArcIntentHelperBridge::ActivityName(
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "chrome/browser/chromeos/crostini/crostini_features.h" #include "chrome/browser/chromeos/crostini/crostini_features.h"
#include "chrome/browser/chromeos/drive/file_system_util.h" #include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/chromeos/file_manager/app_id.h" #include "chrome/browser/chromeos/file_manager/app_id.h"
#include "chrome/browser/chromeos/file_manager/app_service_file_tasks.h"
#include "chrome/browser/chromeos/file_manager/arc_file_tasks.h" #include "chrome/browser/chromeos/file_manager/arc_file_tasks.h"
#include "chrome/browser/chromeos/file_manager/file_browser_handlers.h" #include "chrome/browser/chromeos/file_manager/file_browser_handlers.h"
#include "chrome/browser/chromeos/file_manager/file_tasks_notifier.h" #include "chrome/browser/chromeos/file_manager/file_tasks_notifier.h"
...@@ -38,6 +39,7 @@ ...@@ -38,6 +39,7 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/extensions/application_launch.h" #include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/browser/ui/webui/extensions/extension_icon_source.h" #include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/extensions/api/file_browser_handlers/file_browser_handler.h" #include "chrome/common/extensions/api/file_browser_handlers/file_browser_handler.h"
#include "chrome/common/extensions/api/file_manager_private.h" #include "chrome/common/extensions/api/file_manager_private.h"
#include "chrome/common/extensions/extension_constants.h" #include "chrome/common/extensions/extension_constants.h"
...@@ -788,6 +790,14 @@ void FindExtensionAndAppTasks( ...@@ -788,6 +790,14 @@ void FindExtensionAndAppTasks(
// be used in the same manifest.json. // be used in the same manifest.json.
FindFileBrowserHandlerTasks(profile, file_urls, result_list_ptr); FindFileBrowserHandlerTasks(profile, file_urls, result_list_ptr);
// TODO(crbug/1092784): Link app service task finder here to test the intent
// handling backend. This is not fully completed and only support sharing for
// now. When the unified sharesheet UI is completed, this might be called from
// a different place.
if (base::FeatureList::IsEnabled(features::kIntentHandlingSharing)) {
FindAppServiceTasks(profile, entries, file_urls, result_list_ptr);
}
// 5. Find and append Guest OS tasks. // 5. Find and append Guest OS tasks.
FindGuestOsTasks(profile, entries, file_urls, result_list_ptr, FindGuestOsTasks(profile, entries, file_urls, result_list_ptr,
// Done. Apply post-filtering and callback. // Done. Apply post-filtering and callback.
......
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