Skip to content

Commit

Permalink
Modify AppRegistryCache::GetAppType to return the non mojom AppType.
Browse files Browse the repository at this point in the history
DD:go/remove_mojom_in_app_service

AppService mojo is being removed. So modify AppRegistryCache::GetAppType
to get value from the non mojom App struct when it is available, and
return the non mojom AppType struct to remove the dependency on
mojom.

Modify clients to use the non mojom AppType struct as the return value.

This CL is pure refactor, and no function change.

BUG=1253250

Change-Id: I1fd35931d0f0b98bb1d96e34107ec234321e3a04
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3534759
Reviewed-by: Dominick Ng <dominickn@chromium.org>
Reviewed-by: Sammie Quon <sammiequon@chromium.org>
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#983566}
  • Loading branch information
Nancy Wang authored and Chromium LUCI CQ committed Mar 22, 2022
1 parent ba44873 commit f2fcc07
Show file tree
Hide file tree
Showing 49 changed files with 264 additions and 241 deletions.
6 changes: 3 additions & 3 deletions ash/shelf/shelf_view.cc
Expand Up @@ -56,7 +56,7 @@
#include "base/timer/timer.h"
#include "components/account_id/account_id.h"
#include "components/services/app_service/public/cpp/app_registry_cache_wrapper.h"
#include "components/services/app_service/public/mojom/types.mojom.h"
#include "components/services/app_service/public/cpp/app_types.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/simple_menu_model.h"
Expand Down Expand Up @@ -242,7 +242,7 @@ bool IsRemoteApp(const std::string& app_id) {
Shell::Get()->session_controller()->GetActiveAccountId();
apps::AppRegistryCache* cache =
apps::AppRegistryCacheWrapper::Get().GetAppRegistryCache(account_id);
return cache && cache->GetAppType(app_id) == apps::mojom::AppType::kRemote;
return cache && cache->GetAppType(app_id) == apps::AppType::kRemote;
}

bool IsStandaloneBrowser(const std::string& app_id) {
Expand All @@ -251,7 +251,7 @@ bool IsStandaloneBrowser(const std::string& app_id) {
apps::AppRegistryCache* cache =
apps::AppRegistryCacheWrapper::Get().GetAppRegistryCache(account_id);
return cache &&
cache->GetAppType(app_id) == apps::mojom::AppType::kStandaloneBrowser;
cache->GetAppType(app_id) == apps::AppType::kStandaloneBrowser;
}

// Records the user metric action for whenever a shelf item is pinned or
Expand Down
10 changes: 5 additions & 5 deletions chrome/browser/apps/app_service/app_icon/app_icon_source.cc
Expand Up @@ -96,18 +96,18 @@ void AppIconSource::StartDataRequest(
auto* app_service_proxy =
apps::AppServiceProxyFactory::GetForProfile(profile_);
const std::string app_id = path_parts[0];
const apps::mojom::AppType app_type =
const auto app_type =
app_service_proxy->AppRegistryCache().GetAppType(app_id);
constexpr bool allow_placeholder_icon = false;
if (base::FeatureList::IsEnabled(features::kAppServiceLoadIconWithoutMojom)) {
app_service_proxy->LoadIcon(
ConvertMojomAppTypToAppType(app_type), app_id, IconType::kCompressed,
size_in_dip, allow_placeholder_icon,
app_type, app_id, IconType::kCompressed, size_in_dip,
allow_placeholder_icon,
base::BindOnce(&RunCallback, std::move(callback)));
} else {
app_service_proxy->LoadIcon(
app_type, app_id, apps::mojom::IconType::kCompressed, size_in_dip,
allow_placeholder_icon,
ConvertAppTypeToMojomAppType(app_type), app_id,
apps::mojom::IconType::kCompressed, size_in_dip, allow_placeholder_icon,
MojomIconValueToIconValueCallback(
base::BindOnce(&RunCallback, std::move(callback))));
}
Expand Down
18 changes: 10 additions & 8 deletions chrome/browser/apps/app_service/app_service_proxy_ash.cc
Expand Up @@ -158,8 +158,8 @@ void AppServiceProxyAsh::PauseApps(
}

for (auto& data : pause_data) {
apps::mojom::AppType app_type = app_registry_cache_.GetAppType(data.first);
if (app_type == apps::mojom::AppType::kUnknown) {
auto app_type = app_registry_cache_.GetAppType(data.first);
if (app_type == AppType::kUnknown) {
continue;
}

Expand All @@ -172,7 +172,8 @@ void AppServiceProxyAsh::PauseApps(

// The app pause dialog can't be loaded for unit tests.
if (!data.second.should_show_pause_dialog || is_using_testing_profile_) {
app_service_->PauseApp(app_type, data.first);
app_service_->PauseApp(ConvertAppTypeToMojomAppType(app_type),
data.first);
continue;
}

Expand All @@ -193,21 +194,22 @@ void AppServiceProxyAsh::UnpauseApps(const std::set<std::string>& app_ids) {
}

for (auto& app_id : app_ids) {
apps::mojom::AppType app_type = app_registry_cache_.GetAppType(app_id);
if (app_type == apps::mojom::AppType::kUnknown) {
auto app_type = app_registry_cache_.GetAppType(app_id);
if (app_type == AppType::kUnknown) {
continue;
}

pending_pause_requests_.MaybeRemoveApp(app_id);
app_service_->UnpauseApp(app_type, app_id);
app_service_->UnpauseApp(ConvertAppTypeToMojomAppType(app_type), app_id);
}
}

void AppServiceProxyAsh::SetResizeLocked(const std::string& app_id,
apps::mojom::OptionalBool locked) {
if (app_service_.is_connected()) {
apps::mojom::AppType app_type = app_registry_cache_.GetAppType(app_id);
app_service_->SetResizeLocked(app_type, app_id, locked);
auto app_type = app_registry_cache_.GetAppType(app_id);
app_service_->SetResizeLocked(ConvertAppTypeToMojomAppType(app_type),
app_id, locked);
}
}

Expand Down
45 changes: 24 additions & 21 deletions chrome/browser/apps/app_service/app_service_proxy_base.cc
Expand Up @@ -369,8 +369,7 @@ void AppServiceProxyBase::LaunchAppWithUrl(

void AppServiceProxyBase::LaunchAppWithParams(AppLaunchParams&& params,
LaunchCallback callback) {
auto app_type = ConvertMojomAppTypToAppType(
app_registry_cache_.GetAppType(params.app_id));
auto app_type = app_registry_cache_.GetAppType(params.app_id);
auto* publisher = GetPublisher(app_type);
if (!publisher) {
std::move(callback).Run(LaunchResult());
Expand Down Expand Up @@ -421,20 +420,20 @@ void AppServiceProxyBase::UninstallSilently(
const std::string& app_id,
apps::mojom::UninstallSource uninstall_source) {
if (app_service_.is_connected()) {
apps::mojom::AppType app_type = app_registry_cache_.GetAppType(app_id);
app_service_->Uninstall(app_type, app_id, uninstall_source,
auto app_type = app_registry_cache_.GetAppType(app_id);
app_service_->Uninstall(ConvertAppTypeToMojomAppType(app_type), app_id,
uninstall_source,
/*clear_site_data=*/false, /*report_abuse=*/false);
PerformPostUninstallTasks(ConvertMojomAppTypToAppType(app_type), app_id,
uninstall_source);
PerformPostUninstallTasks(app_type, app_id, uninstall_source);
}
}

void AppServiceProxyBase::StopApp(const std::string& app_id) {
if (!app_service_.is_connected()) {
return;
}
apps::mojom::AppType app_type = app_registry_cache_.GetAppType(app_id);
app_service_->StopApp(app_type, app_id);
auto app_type = app_registry_cache_.GetAppType(app_id);
app_service_->StopApp(ConvertAppTypeToMojomAppType(app_type), app_id);
}

void AppServiceProxyBase::GetMenuModel(
Expand All @@ -446,9 +445,9 @@ void AppServiceProxyBase::GetMenuModel(
return;
}

apps::mojom::AppType app_type = app_registry_cache_.GetAppType(app_id);
app_service_->GetMenuModel(app_type, app_id, menu_type, display_id,
std::move(callback));
auto app_type = app_registry_cache_.GetAppType(app_id);
app_service_->GetMenuModel(ConvertAppTypeToMojomAppType(app_type), app_id,
menu_type, display_id, std::move(callback));
}

void AppServiceProxyBase::ExecuteContextMenuCommand(
Expand All @@ -460,9 +459,10 @@ void AppServiceProxyBase::ExecuteContextMenuCommand(
return;
}

apps::mojom::AppType app_type = app_registry_cache_.GetAppType(app_id);
app_service_->ExecuteContextMenuCommand(app_type, app_id, command_id,
shortcut_id, display_id);
auto app_type = app_registry_cache_.GetAppType(app_id);
app_service_->ExecuteContextMenuCommand(
ConvertAppTypeToMojomAppType(app_type), app_id, command_id, shortcut_id,
display_id);
}

void AppServiceProxyBase::OpenNativeSettings(const std::string& app_id) {
Expand Down Expand Up @@ -617,9 +617,9 @@ void AppServiceProxyBase::AddPreferredApp(

preferred_apps_.AddPreferredApp(app_id, intent_filter);
constexpr bool kFromPublisher = false;
app_service_->AddPreferredApp(app_registry_cache_.GetAppType(app_id), app_id,
std::move(intent_filter), intent->Clone(),
kFromPublisher);
app_service_->AddPreferredApp(
ConvertAppTypeToMojomAppType(app_registry_cache_.GetAppType(app_id)),
app_id, std::move(intent_filter), intent->Clone(), kFromPublisher);
}

void AppServiceProxyBase::SetSupportedLinksPreference(
Expand All @@ -640,23 +640,26 @@ void AppServiceProxyBase::SetSupportedLinksPreference(
});

app_service_->SetSupportedLinksPreference(
app_registry_cache_.GetAppType(app_id), app_id, std::move(filters));
ConvertAppTypeToMojomAppType(app_registry_cache_.GetAppType(app_id)),
app_id, std::move(filters));
}

void AppServiceProxyBase::RemoveSupportedLinksPreference(
const std::string& app_id) {
DCHECK(!app_id.empty());
if (app_service_.is_connected()) {
app_service_->RemoveSupportedLinksPreference(
app_registry_cache_.GetAppType(app_id), app_id);
ConvertAppTypeToMojomAppType(app_registry_cache_.GetAppType(app_id)),
app_id);
}
}

void AppServiceProxyBase::SetWindowMode(const std::string& app_id,
apps::mojom::WindowMode window_mode) {
if (app_service_.is_connected()) {
app_service_->SetWindowMode(app_registry_cache_.GetAppType(app_id), app_id,
window_mode);
app_service_->SetWindowMode(
ConvertAppTypeToMojomAppType(app_registry_cache_.GetAppType(app_id)),
app_id, window_mode);
}
}

Expand Down
10 changes: 6 additions & 4 deletions chrome/browser/apps/app_service/app_service_proxy_desktop.cc
Expand Up @@ -7,6 +7,7 @@
#include "chrome/browser/web_applications/app_service/web_app_publisher_helper.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "components/services/app_service/app_service_mojom_impl.h"
#include "components/services/app_service/public/cpp/app_types.h"

namespace apps {

Expand All @@ -33,8 +34,8 @@ void AppServiceProxy::Uninstall(const std::string& app_id,
apps::mojom::UninstallSource uninstall_source,
gfx::NativeWindow parent_window) {
// On non-ChromeOS, publishers run the remove dialog.
apps::mojom::AppType app_type = app_registry_cache_.GetAppType(app_id);
if (app_type == apps::mojom::AppType::kWeb) {
auto app_type = app_registry_cache_.GetAppType(app_id);
if (app_type == apps::AppType::kWeb) {
web_app::UninstallImpl(web_app::WebAppProvider::GetForWebApps(profile_),
app_id, uninstall_source, parent_window);
}
Expand All @@ -49,8 +50,9 @@ void AppServiceProxy::SetRunOnOsLoginMode(
const std::string& app_id,
apps::mojom::RunOnOsLoginMode run_on_os_login_mode) {
if (app_service_.is_connected()) {
app_service_->SetRunOnOsLoginMode(app_registry_cache_.GetAppType(app_id),
app_id, run_on_os_login_mode);
app_service_->SetRunOnOsLoginMode(
ConvertAppTypeToMojomAppType(app_registry_cache_.GetAppType(app_id)),
app_id, run_on_os_login_mode);
}
}

Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/apps/app_service/app_service_proxy_lacros.cc
Expand Up @@ -402,8 +402,8 @@ void AppServiceProxyLacros::Uninstall(
apps::mojom::UninstallSource uninstall_source,
gfx::NativeWindow parent_window) {
// On non-ChromeOS, publishers run the remove dialog.
apps::mojom::AppType app_type = app_registry_cache_.GetAppType(app_id);
if (app_type == apps::mojom::AppType::kWeb) {
auto app_type = app_registry_cache_.GetAppType(app_id);
if (app_type == AppType::kWeb) {
web_app::UninstallImpl(web_app::WebAppProvider::GetForWebApps(profile_),
app_id, uninstall_source, parent_window);
}
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/apps/app_service/app_service_proxy_lacros.h
Expand Up @@ -19,6 +19,7 @@
#include "components/keyed_service/core/keyed_service.h"
#include "components/services/app_service/public/cpp/app_capability_access_cache.h"
#include "components/services/app_service/public/cpp/app_registry_cache.h"
#include "components/services/app_service/public/cpp/app_types.h"
#include "components/services/app_service/public/cpp/icon_cache.h"
#include "components/services/app_service/public/cpp/icon_coalescer.h"
#include "components/services/app_service/public/cpp/preferred_apps_list.h"
Expand Down
Expand Up @@ -380,10 +380,9 @@ AppTypeName GetAppTypeName(Profile* profile,

AppType GetAppType(Profile* profile, const std::string& app_id) {
DCHECK(AppServiceProxyFactory::IsAppServiceAvailableForProfile(profile));
auto type = ConvertMojomAppTypToAppType(
apps::AppServiceProxyFactory::GetForProfile(profile)
->AppRegistryCache()
.GetAppType(app_id));
auto type = apps::AppServiceProxyFactory::GetForProfile(profile)
->AppRegistryCache()
.GetAppType(app_id);
if (type != AppType::kUnknown) {
return type;
}
Expand Down
12 changes: 6 additions & 6 deletions chrome/browser/apps/app_service/subscriber_crosapi.cc
Expand Up @@ -142,15 +142,15 @@ void SubscriberCrosapi::LoadIcon(const std::string& app_id,
}

auto* proxy = apps::AppServiceProxyFactory::GetForProfile(profile_);
apps::mojom::AppType app_type = proxy->AppRegistryCache().GetAppType(app_id);
auto app_type = proxy->AppRegistryCache().GetAppType(app_id);
if (base::FeatureList::IsEnabled(features::kAppServiceLoadIconWithoutMojom)) {
proxy->LoadIconFromIconKey(ConvertMojomAppTypToAppType(app_type), app_id,
*icon_key, icon_type, size_hint_in_dip,
/*allow_placeholder_icon=*/false,
std::move(callback));
proxy->LoadIconFromIconKey(
app_type, app_id, *icon_key, icon_type, size_hint_in_dip,
/*allow_placeholder_icon=*/false, std::move(callback));
} else {
proxy->LoadIconFromIconKey(
app_type, app_id, ConvertIconKeyToMojomIconKey(*icon_key),
ConvertAppTypeToMojomAppType(app_type), app_id,
ConvertIconKeyToMojomIconKey(*icon_key),
ConvertIconTypeToMojomIconType(icon_type), size_hint_in_dip,
/*allow_placeholder_icon=*/false,
MojomIconValueToIconValueCallback(std::move(callback)));
Expand Down
Expand Up @@ -32,6 +32,7 @@
#include "chrome/grit/browser_resources.h"
#include "components/policy/core/common/policy_pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/services/app_service/public/cpp/app_types.h"
#include "components/services/app_service/public/mojom/types.mojom.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/browser/navigation_handle.h"
Expand Down Expand Up @@ -136,11 +137,11 @@ GURL RedirectUrlIfSwa(Profile* profile,
return url;
}

IntentHandlingMetrics::Platform GetMetricsPlatform(mojom::AppType app_type) {
IntentHandlingMetrics::Platform GetMetricsPlatform(AppType app_type) {
switch (app_type) {
case mojom::AppType::kArc:
case AppType::kArc:
return IntentHandlingMetrics::Platform::ARC;
case mojom::AppType::kWeb:
case AppType::kWeb:
return IntentHandlingMetrics::Platform::PWA;
default:
NOTREACHED();
Expand Down Expand Up @@ -221,16 +222,15 @@ bool CommonAppsNavigationThrottle::ShouldCancelNavigation(
}

// Only automatically launch supported app types.
apps::mojom::AppType app_type =
auto app_type =
proxy->AppRegistryCache().GetAppType(preferred_app_id.value());
if (app_type != apps::mojom::AppType::kArc &&
app_type != apps::mojom::AppType::kWeb &&
if (app_type != AppType::kArc && app_type != AppType::kWeb &&
!IsSystemWebApp(profile, preferred_app_id.value())) {
return false;
}

// Don't capture if already inside the target app scope.
if (app_type == apps::mojom::AppType::kWeb) {
if (app_type == AppType::kWeb) {
auto* tab_helper = web_app::WebAppTabHelper::FromWebContents(web_contents);
if (tab_helper && tab_helper->GetAppId() == preferred_app_id.value())
return false;
Expand Down
3 changes: 1 addition & 2 deletions chrome/browser/ash/app_restore/app_launch_handler.cc
Expand Up @@ -138,8 +138,7 @@ void AppLaunchHandler::LaunchApps() {
if (app_id == app_constants::kChromeAppId)
continue;

auto app_type =
apps::ConvertMojomAppTypToAppType(cache->GetAppType(app_id));
auto app_type = cache->GetAppType(app_id);
#if !defined(OFFICIAL_BUILD)
// Make shift-click on the launch button launch apps with a delay. This
// allows developers to simulate delayed launch behaviors with ARC apps.
Expand Down
Expand Up @@ -218,7 +218,7 @@ std::string AppServiceWrapper::GetAppServiceId(const AppId& app_id) const {
}

bool AppServiceWrapper::IsAppInstalled(const std::string& app_id) {
return GetAppCache().GetAppType(app_id) != apps::mojom::AppType::kUnknown;
return GetAppCache().GetAppType(app_id) != apps::AppType::kUnknown;
}

AppId AppServiceWrapper::AppIdFromAppServiceId(
Expand Down

0 comments on commit f2fcc07

Please sign in to comment.