Commit f775245e authored by yusukes's avatar yusukes Committed by Commit bot

Consolidate 4 GetIntentHelper functions

and have it in arc::ArcIntentHelperBridge.

BUG=b:29079617, b:31406784
TEST=try, ARC still loads activity icons

Review-Url: https://codereview.chromium.org/2337193005
Cr-Commit-Position: refs/heads/master@{#418706}
parent f35464f3
......@@ -31,26 +31,6 @@ scoped_refptr<ActivityIconLoader> GetIconLoader() {
return arc_service_manager ? arc_service_manager->icon_loader() : nullptr;
}
mojom::IntentHelperInstance* GetIntentHelper() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
ArcBridgeService* bridge_service = ArcBridgeService::Get();
if (!bridge_service) {
VLOG(1) << "ARC bridge is not ready.";
return nullptr;
}
mojom::IntentHelperInstance* intent_helper_instance =
bridge_service->intent_helper()->instance();
if (!intent_helper_instance) {
VLOG(1) << "ARC intent helper instance is not ready.";
return nullptr;
}
if (bridge_service->intent_helper()->version() < kMinInstanceVersion) {
VLOG(1) << "ARC intent helper instance is too old.";
return nullptr;
}
return intent_helper_instance;
}
} // namespace
ArcNavigationThrottle::ArcNavigationThrottle(
......@@ -131,7 +111,8 @@ ArcNavigationThrottle::HandleRequest() {
return content::NavigationThrottle::PROCEED;
}
mojom::IntentHelperInstance* bridge_instance = GetIntentHelper();
mojom::IntentHelperInstance* bridge_instance =
arc::ArcIntentHelperBridge::GetIntentHelperInstance(kMinInstanceVersion);
if (!bridge_instance)
return content::NavigationThrottle::PROCEED;
bridge_instance->RequestUrlHandlerList(
......@@ -236,7 +217,8 @@ void ArcNavigationThrottle::OnIntentPickerClosed(
previous_user_action_ = close_reason;
mojom::IntentHelperInstance* bridge = GetIntentHelper();
mojom::IntentHelperInstance* bridge =
arc::ArcIntentHelperBridge::GetIntentHelperInstance(kMinInstanceVersion);
if (!bridge || selected_app_index >= handlers.size()) {
close_reason = CloseReason::ERROR;
}
......
......@@ -58,21 +58,7 @@ arc::mojom::IntentHelperInstance* GetArcIntentHelper(Profile* profile,
// File manager in secondary profile cannot access ARC.
if (!chromeos::ProfileHelper::IsPrimaryProfile(profile))
return nullptr;
arc::ArcBridgeService* arc_service = arc::ArcBridgeService::Get();
if (!arc_service)
return nullptr;
arc::mojom::IntentHelperInstance* intent_helper_instance =
arc_service->intent_helper()->instance();
if (!intent_helper_instance)
return nullptr;
if (arc_service->intent_helper()->version() < min_version) {
DLOG(WARNING) << "ARC intent helper instance is too old.";
return nullptr;
}
return intent_helper_instance;
return arc::ArcIntentHelperBridge::GetIntentHelperInstance(min_version);
}
// Returns the icon loader that wraps the Mojo interface for ARC Intent Helper.
......
......@@ -28,30 +28,6 @@ const size_t kMaxIconSizeInPx = 200;
const int kMinInstanceVersion = 3; // see intent_helper.mojom
mojom::IntentHelperInstance* GetIntentHelperInstance(
ActivityIconLoader::GetResult* out_error_code) {
DCHECK(out_error_code);
ArcBridgeService* bridge_service = arc::ArcBridgeService::Get();
if (!bridge_service) {
VLOG(2) << "ARC bridge is not ready.";
*out_error_code = ActivityIconLoader::GetResult::FAILED_ARC_NOT_SUPPORTED;
return nullptr;
}
mojom::IntentHelperInstance* intent_helper_instance =
bridge_service->intent_helper()->instance();
if (!intent_helper_instance) {
VLOG(2) << "ARC intent helper instance is not ready.";
*out_error_code = ActivityIconLoader::GetResult::FAILED_ARC_NOT_READY;
return nullptr;
}
if (bridge_service->intent_helper()->version() < kMinInstanceVersion) {
VLOG(1) << "ARC intent helper instance is too old.";
*out_error_code = ActivityIconLoader::GetResult::FAILED_ARC_NOT_SUPPORTED;
return nullptr;
}
return intent_helper_instance;
}
ui::ScaleFactor GetSupportedScaleFactor() {
std::vector<ui::ScaleFactor> scale_factors = ui::GetSupportedScaleFactors();
DCHECK(!scale_factors.empty());
......@@ -112,13 +88,21 @@ ActivityIconLoader::GetResult ActivityIconLoader::GetActivityIcons(
return GetResult::SUCCEEDED_SYNC;
}
GetResult error_code = GetResult::FAILED_ARC_NOT_SUPPORTED;
mojom::IntentHelperInstance* instance = GetIntentHelperInstance(&error_code);
ArcIntentHelperBridge::GetResult error_code;
mojom::IntentHelperInstance* instance =
ArcIntentHelperBridge::GetIntentHelperInstanceWithErrorCode(
kMinInstanceVersion, &error_code);
if (!instance) {
// The mojo channel is not yet ready (or not supported at all). Run the
// callback with |result| that could be empty.
cb.Run(std::move(result));
return error_code;
switch (error_code) {
case ArcIntentHelperBridge::GetResult::FAILED_ARC_NOT_READY:
return GetResult(GetResult::FAILED_ARC_NOT_READY);
case ArcIntentHelperBridge::GetResult::FAILED_ARC_NOT_SUPPORTED:
return GetResult(GetResult::FAILED_ARC_NOT_SUPPORTED);
}
NOTREACHED();
}
// Fetch icons from ARC.
......
......@@ -16,6 +16,7 @@
#include "base/threading/thread_checker.h"
#include "components/arc/arc_service.h"
#include "components/arc/common/intent_helper.mojom.h"
#include "components/arc/intent_helper/arc_intent_helper_bridge.h"
#include "ui/base/layout.h"
#include "ui/gfx/image/image.h"
......
......@@ -12,6 +12,7 @@
#include "ash/common/wallpaper/wallpaper_delegate.h"
#include "ash/common/wm_shell.h"
#include "ash/shell.h"
#include "base/command_line.h"
#include "base/memory/weak_ptr.h"
#include "components/arc/intent_helper/activity_icon_loader.h"
#include "components/arc/intent_helper/link_handler_model_impl.h"
......@@ -126,6 +127,49 @@ ArcIntentHelperBridge::FilterOutIntentHelper(
return handlers_filtered;
}
// static
mojom::IntentHelperInstance*
ArcIntentHelperBridge::GetIntentHelperInstanceWithErrorCode(
int min_instance_version,
GetResult* out_error_code) {
ArcBridgeService* bridge_service = ArcBridgeService::Get();
if (!bridge_service) {
if (!ArcBridgeService::GetEnabled(base::CommandLine::ForCurrentProcess())) {
VLOG(2) << "ARC bridge is not supported.";
if (out_error_code)
*out_error_code = GetResult::FAILED_ARC_NOT_SUPPORTED;
} else {
VLOG(2) << "ARC bridge is not ready.";
if (out_error_code)
*out_error_code = GetResult::FAILED_ARC_NOT_READY;
}
return nullptr;
}
mojom::IntentHelperInstance* intent_helper_instance =
bridge_service->intent_helper()->instance();
if (!intent_helper_instance) {
VLOG(2) << "ARC intent helper instance is not ready.";
if (out_error_code)
*out_error_code = GetResult::FAILED_ARC_NOT_READY;
return nullptr;
}
const int version = bridge_service->intent_helper()->version();
if (version < min_instance_version) {
VLOG(1) << "ARC intent helper instance is too old. required: "
<< min_instance_version << ", actual: " << version;
if (out_error_code)
*out_error_code = GetResult::FAILED_ARC_NOT_SUPPORTED;
return nullptr;
}
return intent_helper_instance;
}
// static
mojom::IntentHelperInstance* ArcIntentHelperBridge::GetIntentHelperInstance(
int min_instance_version) {
return GetIntentHelperInstanceWithErrorCode(min_instance_version, nullptr);
}
void ArcIntentHelperBridge::OnIntentFiltersUpdated(
mojo::Array<mojom::IntentFilterPtr> filters) {
DCHECK(thread_checker_.CalledOnValidThread());
......
......@@ -37,6 +37,15 @@ class ArcIntentHelperBridge
public mojom::IntentHelperHost,
public ash::LinkHandlerModelFactory {
public:
enum class GetResult {
// Failed. The intent_helper instance is not yet ready. This is a temporary
// error.
FAILED_ARC_NOT_READY,
// Failed. Either ARC is not supported at all or intent_helper instance
// version is too old.
FAILED_ARC_NOT_SUPPORTED,
};
ArcIntentHelperBridge(
ArcBridgeService* bridge_service,
const scoped_refptr<ActivityIconLoader>& icon_loader,
......@@ -67,6 +76,16 @@ class ArcIntentHelperBridge
static mojo::Array<mojom::UrlHandlerInfoPtr> FilterOutIntentHelper(
mojo::Array<mojom::UrlHandlerInfoPtr> handlers);
// Gets the mojo instance if it's available. On failure, returns nullptr and
// updates |out_error_code| if it's not nullptr.
static mojom::IntentHelperInstance* GetIntentHelperInstanceWithErrorCode(
int min_instance_version,
GetResult* out_error_code);
// Does the same as above without asking for the error code.
static mojom::IntentHelperInstance* GetIntentHelperInstance(
int min_instance_version);
private:
mojo::Binding<mojom::IntentHelperHost> binding_;
scoped_refptr<ActivityIconLoader> icon_loader_;
......
......@@ -56,7 +56,8 @@ LinkHandlerModelImpl::LinkHandlerModelImpl(
LinkHandlerModelImpl::~LinkHandlerModelImpl() {}
bool LinkHandlerModelImpl::Init(const GURL& url) {
mojom::IntentHelperInstance* intent_helper_instance = GetIntentHelper();
mojom::IntentHelperInstance* intent_helper_instance =
ArcIntentHelperBridge::GetIntentHelperInstance(kMinInstanceVersion);
if (!intent_helper_instance)
return false;
......@@ -77,7 +78,8 @@ void LinkHandlerModelImpl::AddObserver(Observer* observer) {
void LinkHandlerModelImpl::OpenLinkWithHandler(const GURL& url,
uint32_t handler_id) {
mojom::IntentHelperInstance* intent_helper_instance = GetIntentHelper();
mojom::IntentHelperInstance* intent_helper_instance =
ArcIntentHelperBridge::GetIntentHelperInstance(kMinInstanceVersion);
if (!intent_helper_instance)
return;
if (handler_id >= handlers_.size())
......@@ -87,25 +89,6 @@ void LinkHandlerModelImpl::OpenLinkWithHandler(const GURL& url,
handlers_[handler_id]->package_name);
}
mojom::IntentHelperInstance* LinkHandlerModelImpl::GetIntentHelper() {
ArcBridgeService* bridge_service = arc::ArcBridgeService::Get();
if (!bridge_service) {
DLOG(WARNING) << "ARC bridge is not ready.";
return nullptr;
}
mojom::IntentHelperInstance* intent_helper_instance =
bridge_service->intent_helper()->instance();
if (!intent_helper_instance) {
DLOG(WARNING) << "ARC intent helper instance is not ready.";
return nullptr;
}
if (bridge_service->intent_helper()->version() < kMinInstanceVersion) {
DLOG(WARNING) << "ARC intent helper instance is too old.";
return nullptr;
}
return intent_helper_instance;
}
void LinkHandlerModelImpl::OnUrlHandlerList(
mojo::Array<mojom::UrlHandlerInfoPtr> handlers) {
handlers_ = ArcIntentHelperBridge::FilterOutIntentHelper(std::move(handlers));
......
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