#include "chrome/browser/apps/app_service/package_id_util.h"
#include <optional>
#include <string>
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
#include "chrome/browser/profiles/profile.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/app_update.h"
#include "components/services/app_service/public/cpp/package_id.h"
#include "components/services/app_service/public/cpp/types_util.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ash/apps/apk_web_app_service.h"
#endif
namespace apps_util {
#if BUILDFLAG(IS_CHROMEOS_ASH)
std::optional<apps::PackageId> GetPackageIdForApp(
Profile* profile,
const apps::AppUpdate& update) {
if (update.AppType() != apps::AppType::kArc &&
update.AppType() != apps::AppType::kWeb) {
return std::nullopt;
}
if (update.PublisherId().empty()) {
return std::nullopt;
}
ash::ApkWebAppService* apk_web_app_service =
ash::ApkWebAppService::Get(profile);
if (apk_web_app_service && update.AppType() == apps::AppType::kWeb) {
std::optional<std::string> package_name =
apk_web_app_service->GetPackageNameForWebApp(
update.AppId(), true);
if (package_name.has_value()) {
return apps::PackageId(apps::PackageType::kArc, package_name.value());
}
}
return apps::PackageId(ConvertAppTypeToPackageType(update.AppType()).value(),
update.PublisherId());
}
#endif
std::optional<std::string> GetAppWithPackageId(
Profile* profile,
const apps::PackageId& package_id) { … }
}