Commit 8f89ebbc authored by nancylingwang's avatar nancylingwang Committed by Commit Bot

Modify ARC icon code to use the new mojom interfaces.

This is the follow up for CL:2251600. Modify the ARC code to use the
new mojom interfaces and structure RawIconPngData.

TODO: Add some test cases for the adaptive icon.

Design doc: go/appservice-adaptive-icon

BUG=1083331

Change-Id: I1600d11af9a6477e6923f8e1f43d79fa52cf79f3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2286251
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Reviewed-by: default avatarHidehiko Abe <hidehiko@chromium.org>
Reviewed-by: default avatarYury Khmel <khmel@chromium.org>
Reviewed-by: default avatarLong Cheng <lgcheng@google.com>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790631}
parent 38b672ae
...@@ -48,14 +48,10 @@ const char kAppActivity[] = "test.app.activity"; ...@@ -48,14 +48,10 @@ const char kAppActivity[] = "test.app.activity";
const char kAppActivity1[] = "test.app1.activity"; const char kAppActivity1[] = "test.app1.activity";
const char kPackageName1[] = "com.test.app"; const char kPackageName1[] = "com.test.app";
const std::vector<uint8_t> GetFakeIconBytes() { arc::mojom::RawIconPngDataPtr GetFakeIconBytes() {
auto fake_app_instance = auto fake_app_instance =
std::make_unique<arc::FakeAppInstance>(/*app_host=*/nullptr); std::make_unique<arc::FakeAppInstance>(/*app_host=*/nullptr);
std::string png_data_as_string; return fake_app_instance->GenerateIconResponse(128, /*app_icon=*/true);
EXPECT_TRUE(fake_app_instance->GenerateIconResponse(128, /*app_icon=*/true,
&png_data_as_string));
return std::vector<uint8_t>(png_data_as_string.begin(),
png_data_as_string.end());
} }
} // namespace } // namespace
......
...@@ -32,13 +32,11 @@ constexpr int kGeneratedIconSize = 128; ...@@ -32,13 +32,11 @@ constexpr int kGeneratedIconSize = 128;
arc::mojom::RawIconPngDataPtr GetIconBytes() { arc::mojom::RawIconPngDataPtr GetIconBytes() {
auto fake_app_instance = auto fake_app_instance =
std::make_unique<arc::FakeAppInstance>(/*app_host=*/nullptr); std::make_unique<arc::FakeAppInstance>(/*app_host=*/nullptr);
std::string png_data_as_string; arc::mojom::RawIconPngDataPtr icon = fake_app_instance->GenerateIconResponse(
EXPECT_TRUE(fake_app_instance->GenerateIconResponse( kGeneratedIconSize, /*app_icon=*/true);
kGeneratedIconSize, /*app_icon=*/true, &png_data_as_string)); EXPECT_TRUE(icon);
arc::mojom::RawIconPngDataPtr icon = arc::mojom::RawIconPngData::New(); if (icon)
icon->is_adaptive_icon = false; EXPECT_TRUE(icon->icon_png_data.has_value());
icon->icon_png_data = std::vector<uint8_t>(png_data_as_string.begin(),
png_data_as_string.end());
return icon; return icon;
} }
......
...@@ -299,11 +299,24 @@ void ApkWebAppService::OnPackageInstalled( ...@@ -299,11 +299,24 @@ void ApkWebAppService::OnPackageInstalled(
// The package is a web app but we don't have a corresponding browser-side // The package is a web app but we don't have a corresponding browser-side
// artifact. Install it. // artifact. Install it.
auto* instance = ARC_GET_INSTANCE_FOR_METHOD( auto* instance = ARC_GET_INSTANCE_FOR_METHOD(
arc_app_list_prefs_->app_connection_holder(), RequestPackageIcon); arc_app_list_prefs_->app_connection_holder(), GetPackageIcon);
if (!instance) if (!instance) {
// TODO(crbug.com/1083331): Remove the RequestPackageIcon related code,
// when the ARC change is rolled in Chrome OS.
ARC_GET_INSTANCE_FOR_METHOD(arc_app_list_prefs_->app_connection_holder(),
RequestPackageIcon);
if (!instance)
return;
instance->RequestPackageIcon(
package_info.package_name, kDefaultIconSize, /*normalize=*/false,
base::BindOnce(
&ApkWebAppService::OnGetWebAppIcon, weak_ptr_factory_.GetWeakPtr(),
package_info.package_name, package_info.web_app_info.Clone()));
return; return;
}
instance->RequestPackageIcon( instance->GetPackageIcon(
package_info.package_name, kDefaultIconSize, /*normalize=*/false, package_info.package_name, kDefaultIconSize, /*normalize=*/false,
base::BindOnce(&ApkWebAppService::OnDidGetWebAppIcon, base::BindOnce(&ApkWebAppService::OnDidGetWebAppIcon,
weak_ptr_factory_.GetWeakPtr(), package_info.package_name, weak_ptr_factory_.GetWeakPtr(), package_info.package_name,
...@@ -439,13 +452,20 @@ void ApkWebAppService::OnWebAppUninstalled(const web_app::AppId& web_app_id) { ...@@ -439,13 +452,20 @@ void ApkWebAppService::OnWebAppUninstalled(const web_app::AppId& web_app_id) {
} }
} }
void ApkWebAppService::OnDidGetWebAppIcon( void ApkWebAppService::OnGetWebAppIcon(
const std::string& package_name, const std::string& package_name,
arc::mojom::WebAppInfoPtr web_app_info, arc::mojom::WebAppInfoPtr web_app_info,
const std::vector<uint8_t>& icon_png_data) { const std::vector<uint8_t>& icon_png_data) {
arc::mojom::RawIconPngDataPtr icon = arc::mojom::RawIconPngData::New(); arc::mojom::RawIconPngDataPtr icon = arc::mojom::RawIconPngData::New();
icon->is_adaptive_icon = false; icon->is_adaptive_icon = false;
icon->icon_png_data = std::vector<uint8_t>(icon_png_data); icon->icon_png_data = std::vector<uint8_t>(icon_png_data);
OnDidGetWebAppIcon(package_name, std::move(web_app_info), std::move(icon));
}
void ApkWebAppService::OnDidGetWebAppIcon(
const std::string& package_name,
arc::mojom::WebAppInfoPtr web_app_info,
arc::mojom::RawIconPngDataPtr icon) {
ApkWebAppInstaller::Install( ApkWebAppInstaller::Install(
profile_, std::move(web_app_info), std::move(icon), profile_, std::move(web_app_info), std::move(icon),
base::BindOnce(&ApkWebAppService::OnDidFinishInstall, base::BindOnce(&ApkWebAppService::OnDidFinishInstall,
......
...@@ -94,9 +94,14 @@ class ApkWebAppService : public KeyedService, ...@@ -94,9 +94,14 @@ class ApkWebAppService : public KeyedService,
// web_app::AppRegistrarObserver overrides. // web_app::AppRegistrarObserver overrides.
void OnWebAppUninstalled(const web_app::AppId& web_app_id) override; void OnWebAppUninstalled(const web_app::AppId& web_app_id) override;
// TODO(crbug.com/1083331): Remove this function, when the ARC change is
// rolled in Chrome OS.
void OnGetWebAppIcon(const std::string& package_name,
arc::mojom::WebAppInfoPtr web_app_info,
const std::vector<uint8_t>& icon_png_data);
void OnDidGetWebAppIcon(const std::string& package_name, void OnDidGetWebAppIcon(const std::string& package_name,
arc::mojom::WebAppInfoPtr web_app_info, arc::mojom::WebAppInfoPtr web_app_info,
const std::vector<uint8_t>& icon_png_data); arc::mojom::RawIconPngDataPtr icon);
void OnDidFinishInstall(const std::string& package_name, void OnDidFinishInstall(const std::string& package_name,
const web_app::AppId& web_app_id, const web_app::AppId& web_app_id,
bool is_web_only_twa, bool is_web_only_twa,
......
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
#include "base/barrier_closure.h" #include "base/barrier_closure.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/apps/app_service/app_icon_factory.h"
#include "chrome/browser/chromeos/arc/icon_decode_request.h" #include "chrome/browser/chromeos/arc/icon_decode_request.h"
#include "chrome/common/chrome_features.h"
#include "components/arc/arc_service_manager.h" #include "components/arc/arc_service_manager.h"
#include "components/arc/session/arc_bridge_service.h" #include "components/arc/session/arc_bridge_service.h"
...@@ -77,11 +79,33 @@ void ArcAppShortcutsRequest::OnGetAppShortcutItems( ...@@ -77,11 +79,33 @@ void ArcAppShortcutsRequest::OnGetAppShortcutItems(
item.rank = shortcut_item_ptr->rank; item.rank = shortcut_item_ptr->rank;
items_->emplace_back(std::move(item)); items_->emplace_back(std::move(item));
if (base::FeatureList::IsEnabled(features::kAppServiceAdaptiveIcon)) {
apps::ArcRawIconPngDataToImageSkia(
std::move(shortcut_item_ptr->icon), kAppShortcutIconSize,
base::BindOnce(&ArcAppShortcutsRequest::OnSingleIconDecodeRequestDone,
weak_ptr_factory_.GetWeakPtr(), items_->size() - 1));
continue;
}
if (!shortcut_item_ptr->icon || !shortcut_item_ptr->icon->icon_png_data ||
shortcut_item_ptr->icon->icon_png_data->empty()) {
// TODO(crbug.com/1083331): Remove the icon_png related change, when the
// ARC change is rolled in Chrome OS.
icon_decode_requests_.emplace_back(std::make_unique<IconDecodeRequest>(
base::BindOnce(&ArcAppShortcutsRequest::OnSingleIconDecodeRequestDone,
weak_ptr_factory_.GetWeakPtr(), items_->size() - 1),
kAppShortcutIconSize));
icon_decode_requests_.back()->StartWithOptions(
shortcut_item_ptr->icon_png);
continue;
}
icon_decode_requests_.emplace_back(std::make_unique<IconDecodeRequest>( icon_decode_requests_.emplace_back(std::make_unique<IconDecodeRequest>(
base::BindOnce(&ArcAppShortcutsRequest::OnSingleIconDecodeRequestDone, base::BindOnce(&ArcAppShortcutsRequest::OnSingleIconDecodeRequestDone,
weak_ptr_factory_.GetWeakPtr(), items_->size() - 1), weak_ptr_factory_.GetWeakPtr(), items_->size() - 1),
kAppShortcutIconSize)); kAppShortcutIconSize));
icon_decode_requests_.back()->StartWithOptions(shortcut_item_ptr->icon_png); icon_decode_requests_.back()->StartWithOptions(
shortcut_item_ptr->icon->icon_png_data.value());
} }
} }
......
...@@ -537,26 +537,50 @@ void ArcAppListPrefs::RequestIcon(const std::string& app_id, ...@@ -537,26 +537,50 @@ void ArcAppListPrefs::RequestIcon(const std::string& app_id,
void ArcAppListPrefs::SendIconRequest(const std::string& app_id, void ArcAppListPrefs::SendIconRequest(const std::string& app_id,
const AppInfo& app_info, const AppInfo& app_info,
const ArcAppIconDescriptor& descriptor) { const ArcAppIconDescriptor& descriptor) {
base::OnceCallback<void(const std::vector<uint8_t>& /* icon_png_data */)> auto callback =
callback = base::BindOnce(&ArcAppListPrefs::OnIcon, weak_ptr_factory_.GetWeakPtr(),
base::BindOnce(&ArcAppListPrefs::OnIcon, app_id, descriptor);
weak_ptr_factory_.GetWeakPtr(), app_id, descriptor);
if (app_info.icon_resource_id.empty()) { if (app_info.icon_resource_id.empty()) {
auto* app_instance = auto* app_instance =
ARC_GET_INSTANCE_FOR_METHOD(app_connection_holder(), RequestAppIcon); ARC_GET_INSTANCE_FOR_METHOD(app_connection_holder(), GetAppIcon);
if (!app_instance) if (!app_instance) {
// TODO(crbug.com/1083331): Remove the RequestAppIcon related change, when
// the ARC change is rolled in Chrome OS.
app_instance =
ARC_GET_INSTANCE_FOR_METHOD(app_connection_holder(), RequestAppIcon);
if (app_instance) {
auto callback =
base::BindOnce(&ArcAppListPrefs::OnGetIcon,
weak_ptr_factory_.GetWeakPtr(), app_id, descriptor);
app_instance->RequestAppIcon(app_info.package_name, app_info.activity,
descriptor.GetSizeInPixels(),
std::move(callback));
}
return; // Error is logged in macro. return; // Error is logged in macro.
app_instance->RequestAppIcon(app_info.package_name, app_info.activity, }
descriptor.GetSizeInPixels(), app_instance->GetAppIcon(app_info.package_name, app_info.activity,
std::move(callback)); descriptor.GetSizeInPixels(), std::move(callback));
} else { } else {
auto* app_instance = ARC_GET_INSTANCE_FOR_METHOD(app_connection_holder(), auto* app_instance = ARC_GET_INSTANCE_FOR_METHOD(app_connection_holder(),
RequestShortcutIcon); GetAppShortcutIcon);
if (!app_instance) if (!app_instance) {
// TODO(crbug.com/1083331): Remove the RequestAppIcon related change, when
// the ARC change is rolled in Chrome OS.
app_instance = ARC_GET_INSTANCE_FOR_METHOD(app_connection_holder(),
RequestShortcutIcon);
if (app_instance) {
auto callback =
base::BindOnce(&ArcAppListPrefs::OnGetIcon,
weak_ptr_factory_.GetWeakPtr(), app_id, descriptor);
app_instance->RequestAppIcon(app_info.package_name, app_info.activity,
descriptor.GetSizeInPixels(),
std::move(callback));
}
return; // Error is logged in macro. return; // Error is logged in macro.
app_instance->RequestShortcutIcon(app_info.icon_resource_id, }
descriptor.GetSizeInPixels(), app_instance->GetAppShortcutIcon(app_info.icon_resource_id,
std::move(callback)); descriptor.GetSizeInPixels(),
std::move(callback));
} }
} }
...@@ -1634,12 +1658,25 @@ void ArcAppListPrefs::OnPackageRemoved(const std::string& package_name) { ...@@ -1634,12 +1658,25 @@ void ArcAppListPrefs::OnPackageRemoved(const std::string& package_name) {
observer.OnPackageRemoved(package_name, true); observer.OnPackageRemoved(package_name, true);
} }
void ArcAppListPrefs::OnGetIcon(const std::string& app_id,
const ArcAppIconDescriptor& descriptor,
const std::vector<uint8_t>& icon_png_data) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
arc::mojom::RawIconPngDataPtr icon = arc::mojom::RawIconPngData::New();
icon->is_adaptive_icon = false;
icon->icon_png_data =
std::vector<uint8_t>(icon_png_data.begin(), icon_png_data.end());
OnIcon(app_id, descriptor, std::move(icon));
}
void ArcAppListPrefs::OnIcon(const std::string& app_id, void ArcAppListPrefs::OnIcon(const std::string& app_id,
const ArcAppIconDescriptor& descriptor, const ArcAppIconDescriptor& descriptor,
const std::vector<uint8_t>& icon_png_data) { arc::mojom::RawIconPngDataPtr icon) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (icon_png_data.empty()) { if (!icon || !icon->icon_png_data.has_value() ||
icon->icon_png_data->empty()) {
LOG(WARNING) << "Cannot fetch icon for " << app_id; LOG(WARNING) << "Cannot fetch icon for " << app_id;
return; return;
} }
...@@ -1649,10 +1686,6 @@ void ArcAppListPrefs::OnIcon(const std::string& app_id, ...@@ -1649,10 +1686,6 @@ void ArcAppListPrefs::OnIcon(const std::string& app_id,
return; return;
} }
arc::mojom::RawIconPngDataPtr icon = arc::mojom::RawIconPngData::New();
icon->is_adaptive_icon = false;
icon->icon_png_data =
std::vector<uint8_t>(icon_png_data.begin(), icon_png_data.end());
InstallIcon(app_id, descriptor, std::move(icon)); InstallIcon(app_id, descriptor, std::move(icon));
} }
......
...@@ -396,9 +396,14 @@ class ArcAppListPrefs : public KeyedService, ...@@ -396,9 +396,14 @@ class ArcAppListPrefs : public KeyedService,
void OnUninstallShortcut(const std::string& package_name, void OnUninstallShortcut(const std::string& package_name,
const std::string& intent_uri) override; const std::string& intent_uri) override;
void OnPackageRemoved(const std::string& package_name) override; void OnPackageRemoved(const std::string& package_name) override;
// TODO(crbug.com/1083331): Remove this function, when the ARC change is
// rolled in Chrome OS.
void OnGetIcon(const std::string& app_id,
const ArcAppIconDescriptor& descriptor,
const std::vector<uint8_t>& icon_png_data);
void OnIcon(const std::string& app_id, void OnIcon(const std::string& app_id,
const ArcAppIconDescriptor& descriptor, const ArcAppIconDescriptor& descriptor,
const std::vector<uint8_t>& icon_png_data); arc::mojom::RawIconPngDataPtr icon);
void OnIconLoaded(const std::string& app_id, void OnIconLoaded(const std::string& app_id,
const ArcAppIconDescriptor& descriptor, const ArcAppIconDescriptor& descriptor,
arc::mojom::RawIconPngDataPtr icon); arc::mojom::RawIconPngDataPtr icon);
......
...@@ -34,10 +34,10 @@ class MockArcAppListPrefsObserver : public ArcAppListPrefs::Observer { ...@@ -34,10 +34,10 @@ class MockArcAppListPrefsObserver : public ArcAppListPrefs::Observer {
const std::string& package_name, const std::string& package_name,
const std::string& activity, const std::string& activity,
const std::string& intent)); const std::string& intent));
MOCK_METHOD3(OnTaskDescriptionUpdated, MOCK_METHOD3(OnTaskDescriptionChanged,
void(int32_t task_id, void(int32_t task_id,
const std::string& label, const std::string& label,
const arc::mojom::RawIconPngDataPtr& icon)); const arc::mojom::RawIconPngData& icon));
MOCK_METHOD1(OnTaskDestroyed, void(int32_t task_id)); MOCK_METHOD1(OnTaskDestroyed, void(int32_t task_id));
MOCK_METHOD1(OnTaskSetActive, void(int32_t task_id)); MOCK_METHOD1(OnTaskSetActive, void(int32_t task_id));
MOCK_METHOD2(OnNotificationsEnabledChanged, MOCK_METHOD2(OnNotificationsEnabledChanged,
......
...@@ -9,8 +9,10 @@ ...@@ -9,8 +9,10 @@
#include "ash/public/cpp/app_list/app_list_config.h" #include "ash/public/cpp/app_list/app_list_config.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/apps/app_service/app_icon_factory.h"
#include "chrome/browser/chromeos/arc/icon_decode_request.h" #include "chrome/browser/chromeos/arc/icon_decode_request.h"
#include "chrome/browser/ui/app_list/app_list_controller_delegate.h" #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
#include "chrome/common/chrome_features.h"
#include "components/arc/arc_service_manager.h" #include "components/arc/arc_service_manager.h"
#include "components/arc/session/arc_bridge_service.h" #include "components/arc/session/arc_bridge_service.h"
#include "third_party/skia/include/core/SkPath.h" #include "third_party/skia/include/core/SkPath.h"
...@@ -90,7 +92,25 @@ ArcAppDataSearchResult::ArcAppDataSearchResult( ...@@ -90,7 +92,25 @@ ArcAppDataSearchResult::ArcAppDataSearchResult(
} }
// TODO(warx): set default images when icon_png_data() is not available. // TODO(warx): set default images when icon_png_data() is not available.
if (!icon_png_data()) { if (base::FeatureList::IsEnabled(features::kAppServiceAdaptiveIcon)) {
if (!data_->icon) {
SetIcon(gfx::ImageSkia());
return;
}
apps::ArcRawIconPngDataToImageSkia(
std::move(data_->icon),
ash::AppListConfig::instance().search_tile_icon_dimension(),
base::BindOnce(&ArcAppDataSearchResult::ApplyIcon,
weak_ptr_factory_.GetWeakPtr()));
return;
}
// TODO(crbug.com/1083331): Remove the checking !data_->icon_png_data, when
// the ARC change is rolled in Chrome OS.
if ((!data_->icon || !data_->icon->icon_png_data ||
data_->icon->icon_png_data->empty()) &&
!data_->icon_png_data) {
SetIcon(gfx::ImageSkia()); SetIcon(gfx::ImageSkia());
return; return;
} }
......
...@@ -39,7 +39,13 @@ class ArcAppDataSearchResult : public ChromeSearchResult { ...@@ -39,7 +39,13 @@ class ArcAppDataSearchResult : public ChromeSearchResult {
return data_->launch_intent_uri; return data_->launch_intent_uri;
} }
const base::Optional<std::vector<uint8_t>>& icon_png_data() const { const base::Optional<std::vector<uint8_t>>& icon_png_data() const {
return data_->icon_png_data; // TODO(crbug.com/1083331): Remove the checking, when the ARC change is
// rolled in Chrome OS.
if (!data_->icon || !data_->icon->icon_png_data ||
data_->icon->icon_png_data->empty()) {
return data_->icon_png_data;
}
return data_->icon->icon_png_data;
} }
// Set |icon| to SearchResult. |icon| may be customized based on |data_|. // Set |icon| to SearchResult. |icon| may be customized based on |data_|.
......
...@@ -11,12 +11,14 @@ ...@@ -11,12 +11,14 @@
#include "ash/public/cpp/app_list/app_list_types.h" #include "ash/public/cpp/app_list/app_list_types.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/apps/app_service/app_icon_factory.h"
#include "chrome/browser/chromeos/arc/icon_decode_request.h" #include "chrome/browser/chromeos/arc/icon_decode_request.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/app_list_controller_delegate.h" #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
#include "chrome/browser/ui/app_list/app_service/app_service_app_icon_loader.h" #include "chrome/browser/ui/app_list/app_service/app_service_app_icon_loader.h"
#include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
#include "chrome/browser/ui/app_list/arc/arc_app_utils.h" #include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
#include "chrome/common/chrome_features.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
...@@ -43,11 +45,28 @@ ArcAppShortcutSearchResult::ArcAppShortcutSearchResult( ...@@ -43,11 +45,28 @@ ArcAppShortcutSearchResult::ArcAppShortcutSearchResult(
const int icon_dimension = const int icon_dimension =
ash::AppListConfig::instance().search_tile_icon_dimension(); ash::AppListConfig::instance().search_tile_icon_dimension();
icon_decode_request_ = std::make_unique<arc::IconDecodeRequest>( if (base::FeatureList::IsEnabled(features::kAppServiceAdaptiveIcon)) {
base::BindOnce(&ArcAppShortcutSearchResult::SetIcon, DCHECK(data_->icon);
base::Unretained(this)), apps::ArcRawIconPngDataToImageSkia(
icon_dimension); std::move(data_->icon), icon_dimension,
icon_decode_request_->StartWithOptions(data_->icon_png); base::BindOnce(&ArcAppShortcutSearchResult::SetIcon,
base::Unretained(this)));
} else if (data_->icon && data_->icon->icon_png_data &&
!data_->icon->icon_png_data->empty()) {
icon_decode_request_ = std::make_unique<arc::IconDecodeRequest>(
base::BindOnce(&ArcAppShortcutSearchResult::SetIcon,
base::Unretained(this)),
icon_dimension);
icon_decode_request_->StartWithOptions(data_->icon->icon_png_data.value());
} else {
// TODO(crbug.com/1083331): Remove when the ARC change is rolled in Chrome
// OS.
icon_decode_request_ = std::make_unique<arc::IconDecodeRequest>(
base::BindOnce(&ArcAppShortcutSearchResult::SetIcon,
base::Unretained(this)),
icon_dimension);
icon_decode_request_->StartWithOptions(data_->icon_png);
}
badge_icon_loader_ = std::make_unique<AppServiceAppIconLoader>( badge_icon_loader_ = std::make_unique<AppServiceAppIconLoader>(
profile_, profile_,
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
#include "chrome/browser/ui/app_list/search/arc/arc_playstore_search_result.h" #include "chrome/browser/ui/app_list/search/arc/arc_playstore_search_result.h"
#include "chrome/common/chrome_features.h"
#include "chromeos/constants/chromeos_features.h" #include "chromeos/constants/chromeos_features.h"
#include "chromeos/constants/chromeos_pref_names.h" #include "chromeos/constants/chromeos_pref_names.h"
#include "components/arc/app/arc_playstore_search_request_state.h" #include "components/arc/app/arc_playstore_search_request_state.h"
...@@ -72,8 +73,17 @@ bool IsInvalidResult(const arc::mojom::AppDiscoveryResult& result) { ...@@ -72,8 +73,17 @@ bool IsInvalidResult(const arc::mojom::AppDiscoveryResult& result) {
return true; return true;
// The result doesn't have a valid launcher icon. // The result doesn't have a valid launcher icon.
if (result.icon_png_data.empty()) //
// TODO(crbug.com/1083331): Remove the checking result.icon_png_data.empty(),
// when the ARC change is rolled in Chrome OS.
if (base::FeatureList::IsEnabled(features::kAppServiceAdaptiveIcon)) {
if (!result.icon)
return true;
} else if ((!result.icon || !result.icon->icon_png_data ||
result.icon->icon_png_data->empty()) &&
result.icon_png_data.empty()) {
return true; return true;
}
// The result doesn't have a valid package name. // The result doesn't have a valid package name.
if (!result.package_name || result.package_name->empty()) if (!result.package_name || result.package_name->empty())
......
...@@ -11,10 +11,12 @@ ...@@ -11,10 +11,12 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/metrics/user_metrics.h" #include "base/metrics/user_metrics.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/apps/app_service/app_icon_factory.h"
#include "chrome/browser/chromeos/arc/icon_decode_request.h" #include "chrome/browser/chromeos/arc/icon_decode_request.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/app_list_controller_delegate.h" #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
#include "chrome/browser/ui/app_list/arc/arc_playstore_app_context_menu.h" #include "chrome/browser/ui/app_list/arc/arc_playstore_app_context_menu.h"
#include "chrome/common/chrome_features.h"
#include "components/arc/arc_service_manager.h" #include "components/arc/arc_service_manager.h"
#include "components/arc/mojom/app.mojom.h" #include "components/arc/mojom/app.mojom.h"
#include "components/arc/session/arc_bridge_service.h" #include "components/arc/session/arc_bridge_service.h"
...@@ -121,6 +123,28 @@ ArcPlayStoreSearchResult::ArcPlayStoreSearchResult( ...@@ -121,6 +123,28 @@ ArcPlayStoreSearchResult::ArcPlayStoreSearchResult(
SetResultType(is_instant_app() ? ash::AppListSearchResultType::kInstantApp SetResultType(is_instant_app() ? ash::AppListSearchResultType::kInstantApp
: ash::AppListSearchResultType::kPlayStoreApp); : ash::AppListSearchResultType::kPlayStoreApp);
if (base::FeatureList::IsEnabled(features::kAppServiceAdaptiveIcon)) {
apps::ArcRawIconPngDataToImageSkia(
std::move(data_->icon),
ash::AppListConfig::instance().search_tile_icon_dimension(),
base::BindOnce(&ArcPlayStoreSearchResult::SetIcon,
weak_ptr_factory_.GetWeakPtr()));
return;
}
if (!data_->icon || !data_->icon->icon_png_data ||
data_->icon->icon_png_data->empty()) {
// TODO(crbug.com/1083331): Remove the icon_png related change, when the ARC
// change is rolled in Chrome OS.
icon_decode_request_ = std::make_unique<arc::IconDecodeRequest>(
base::BindOnce(&ArcPlayStoreSearchResult::SetIcon,
weak_ptr_factory_.GetWeakPtr()),
ash::AppListConfig::instance().search_tile_icon_dimension());
icon_decode_request_->set_normalized(true);
icon_decode_request_->StartWithOptions(data_->icon_png_data);
return;
}
icon_decode_request_ = std::make_unique<arc::IconDecodeRequest>( icon_decode_request_ = std::make_unique<arc::IconDecodeRequest>(
base::BindOnce(&ArcPlayStoreSearchResult::SetIcon, base::BindOnce(&ArcPlayStoreSearchResult::SetIcon,
weak_ptr_factory_.GetWeakPtr()), weak_ptr_factory_.GetWeakPtr()),
......
...@@ -53,7 +53,7 @@ class ArcPlayStoreSearchResult : public ChromeSearchResult, ...@@ -53,7 +53,7 @@ class ArcPlayStoreSearchResult : public ChromeSearchResult,
} }
float review_score() const { return data_->review_score; } float review_score() const { return data_->review_score; }
const std::vector<uint8_t>& icon_png_data() const { const std::vector<uint8_t>& icon_png_data() const {
return data_->icon_png_data; return data_->icon->icon_png_data.value();
} }
// ChromeSearchResult overrides: // ChromeSearchResult overrides:
......
...@@ -97,6 +97,7 @@ constexpr char kTestWindowTitle[] = "window1"; ...@@ -97,6 +97,7 @@ constexpr char kTestWindowTitle[] = "window1";
constexpr char kTestWindowTitle2[] = "window2"; constexpr char kTestWindowTitle2[] = "window2";
constexpr char kTestWindowTitle3[] = "window3"; constexpr char kTestWindowTitle3[] = "window3";
constexpr int kAppAnimatedThresholdMs = 100; constexpr int kAppAnimatedThresholdMs = 100;
constexpr int kGeneratedIconSize = 32;
std::string GetTestApp1Id(const std::string& package_name) { std::string GetTestApp1Id(const std::string& package_name) {
return ArcAppListPrefs::GetAppId(package_name, kTestAppActivity); return ArcAppListPrefs::GetAppId(package_name, kTestAppActivity);
...@@ -345,6 +346,8 @@ class ArcAppLauncherBrowserTest : public extensions::ExtensionBrowserTest { ...@@ -345,6 +346,8 @@ class ArcAppLauncherBrowserTest : public extensions::ExtensionBrowserTest {
return arc::ArcServiceManager::Get()->arc_bridge_service(); return arc::ArcServiceManager::Get()->arc_bridge_service();
} }
arc::FakeAppInstance* arc_instance() { return app_instance_.get(); }
private: private:
std::unique_ptr<arc::FakeAppInstance> app_instance_; std::unique_ptr<arc::FakeAppInstance> app_instance_;
std::unique_ptr<exo::WMHelper> wm_helper_; std::unique_ptr<exo::WMHelper> wm_helper_;
...@@ -713,8 +716,12 @@ IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, LogicalWindow) { ...@@ -713,8 +716,12 @@ IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, LogicalWindow) {
app_host()->OnTaskCreated(1, info->package_name, info->activity, info->name, app_host()->OnTaskCreated(1, info->package_name, info->activity, info->name,
CreateIntentUriWithShelfGroupAndLogicalWindow( CreateIntentUriWithShelfGroupAndLogicalWindow(
kTestShelfGroups[1], kTestLogicalWindows[1])); kTestShelfGroups[1], kTestLogicalWindows[1]));
app_host()->OnTaskDescriptionUpdated(1, kTestWindowTitles[1], arc_instance()->set_icon_response_type(
std::vector<uint8_t>()); arc::FakeAppInstance::IconResponseType::ICON_RESPONSE_SEND_EMPTY);
app_host()->OnTaskDescriptionChanged(
1, kTestWindowTitles[1],
arc_instance()->GenerateIconResponse(kGeneratedIconSize,
false /* app_icon */));
WaitForDecompressTask(); WaitForDecompressTask();
ash::ShelfItemDelegate* delegate1 = GetShelfItemDelegate(shelf_id1); ash::ShelfItemDelegate* delegate1 = GetShelfItemDelegate(shelf_id1);
...@@ -725,8 +732,10 @@ IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, LogicalWindow) { ...@@ -725,8 +732,10 @@ IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, LogicalWindow) {
app_host()->OnTaskCreated(2, info->package_name, info->activity, info->name, app_host()->OnTaskCreated(2, info->package_name, info->activity, info->name,
CreateIntentUriWithShelfGroupAndLogicalWindow( CreateIntentUriWithShelfGroupAndLogicalWindow(
kTestShelfGroups[2], kTestLogicalWindows[2])); kTestShelfGroups[2], kTestLogicalWindows[2]));
app_host()->OnTaskDescriptionUpdated(2, kTestWindowTitles[2], app_host()->OnTaskDescriptionChanged(
std::vector<uint8_t>()); 2, kTestWindowTitles[2],
arc_instance()->GenerateIconResponse(kGeneratedIconSize,
false /* app_icon */));
WaitForDecompressTask(); WaitForDecompressTask();
ASSERT_EQ(delegate1, GetShelfItemDelegate(shelf_id1)); ASSERT_EQ(delegate1, GetShelfItemDelegate(shelf_id1));
...@@ -739,8 +748,10 @@ IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, LogicalWindow) { ...@@ -739,8 +748,10 @@ IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, LogicalWindow) {
task_id, info->package_name, info->activity, info->name, task_id, info->package_name, info->activity, info->name,
CreateIntentUriWithShelfGroupAndLogicalWindow( CreateIntentUriWithShelfGroupAndLogicalWindow(
kTestShelfGroups[task_id], kTestLogicalWindows[task_id])); kTestShelfGroups[task_id], kTestLogicalWindows[task_id]));
app_host()->OnTaskDescriptionUpdated(task_id, kTestWindowTitles[task_id], app_host()->OnTaskDescriptionChanged(
std::vector<uint8_t>()); task_id, kTestWindowTitles[task_id],
arc_instance()->GenerateIconResponse(kGeneratedIconSize,
false /* app_icon */));
} }
WaitForDecompressTask(); WaitForDecompressTask();
...@@ -753,8 +764,10 @@ IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, LogicalWindow) { ...@@ -753,8 +764,10 @@ IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, LogicalWindow) {
app_host()->OnTaskCreated(6, info->package_name, info->activity, info->name, app_host()->OnTaskCreated(6, info->package_name, info->activity, info->name,
CreateIntentUriWithShelfGroupAndLogicalWindow( CreateIntentUriWithShelfGroupAndLogicalWindow(
kTestShelfGroups[6], kTestLogicalWindows[6])); kTestShelfGroups[6], kTestLogicalWindows[6]));
app_host()->OnTaskDescriptionUpdated(6, kTestWindowTitles[6], app_host()->OnTaskDescriptionChanged(
std::vector<uint8_t>()); 6, kTestWindowTitles[6],
arc_instance()->GenerateIconResponse(kGeneratedIconSize,
false /* app_icon */));
ash::ShelfItemDelegate* delegate2 = GetShelfItemDelegate(shelf_id2); ash::ShelfItemDelegate* delegate2 = GetShelfItemDelegate(shelf_id2);
WaitForDecompressTask(); WaitForDecompressTask();
...@@ -766,8 +779,10 @@ IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, LogicalWindow) { ...@@ -766,8 +779,10 @@ IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, LogicalWindow) {
app_host()->OnTaskCreated(7, info->package_name, info->activity, info->name, app_host()->OnTaskCreated(7, info->package_name, info->activity, info->name,
CreateIntentUriWithShelfGroupAndLogicalWindow( CreateIntentUriWithShelfGroupAndLogicalWindow(
kTestShelfGroups[7], kTestLogicalWindows[7])); kTestShelfGroups[7], kTestLogicalWindows[7]));
app_host()->OnTaskDescriptionUpdated(7, kTestWindowTitles[7], app_host()->OnTaskDescriptionChanged(
std::vector<uint8_t>()); 7, kTestWindowTitles[7],
arc_instance()->GenerateIconResponse(kGeneratedIconSize,
false /* app_icon */));
WaitForDecompressTask(); WaitForDecompressTask();
ASSERT_EQ(delegate2, GetShelfItemDelegate(shelf_id2)); ASSERT_EQ(delegate2, GetShelfItemDelegate(shelf_id2));
......
...@@ -2544,10 +2544,13 @@ TEST_P(ChromeLauncherControllerWithArcTest, DISABLED_ArcCustomAppIcon) { ...@@ -2544,10 +2544,13 @@ TEST_P(ChromeLauncherControllerWithArcTest, DISABLED_ArcCustomAppIcon) {
// Generate icon for the testing app and use compressed png content as test // Generate icon for the testing app and use compressed png content as test
// input. Take shortcut to separate from default app icon. // input. Take shortcut to separate from default app icon.
std::string png_data; auto icon = arc_test_.app_instance()->GenerateIconResponse(
EXPECT_TRUE(arc_test_.app_instance()->GenerateIconResponse( extension_misc::EXTENSION_ICON_SMALL, false /* app_icon */);
extension_misc::EXTENSION_ICON_SMALL, false /* app_icon */, &png_data)); ASSERT_TRUE(icon);
EXPECT_FALSE(png_data.empty()); ASSERT_TRUE(icon->icon_png_data.has_value());
EXPECT_FALSE(icon->icon_png_data->empty());
std::string png_data(icon->icon_png_data->begin(),
icon->icon_png_data->end());
// Some input that represents invalid png content. // Some input that represents invalid png content.
std::string invalid_png_data("aaaaaa"); std::string invalid_png_data("aaaaaa");
......
This diff is collapsed.
...@@ -22,6 +22,8 @@ class FakeAppInstance : public mojom::AppInstance { ...@@ -22,6 +22,8 @@ class FakeAppInstance : public mojom::AppInstance {
enum class IconResponseType { enum class IconResponseType {
// Generate and send good icon. // Generate and send good icon.
ICON_RESPONSE_SEND_GOOD, ICON_RESPONSE_SEND_GOOD,
// Generate an empty icon.
ICON_RESPONSE_SEND_EMPTY,
// Generate broken bad icon. // Generate broken bad icon.
ICON_RESPONSE_SEND_BAD, ICON_RESPONSE_SEND_BAD,
// Don't send icon. // Don't send icon.
...@@ -207,14 +209,13 @@ class FakeAppInstance : public mojom::AppInstance { ...@@ -207,14 +209,13 @@ class FakeAppInstance : public mojom::AppInstance {
// fill |png_data_as_string| if icon for |dimension| was generated. // fill |png_data_as_string| if icon for |dimension| was generated.
bool GetIconResponse(int dimension, std::string* png_data_as_string); bool GetIconResponse(int dimension, std::string* png_data_as_string);
// Generates an icon for app or shorcut, determined by |app_icon| and returns: // Generates an icon for app or shorcut, determined by |app_icon| and returns:
// false if |icon_response_type_| is IconResponseType::ICON_RESPONSE_SKIP. // nullptr if |icon_response_type_| is IconResponseType::ICON_RESPONSE_SKIP.
// true and valid png content in |png_data_as_string| if // valid raw icon png data if
// |icon_response_type_| is IconResponseType::ICON_RESPONSE_SEND_GOOD. // |icon_response_type_| is IconResponseType::ICON_RESPONSE_SEND_GOOD.
// true and invalid png content in |png_data_as_string| if // invalid raw icon png data in |png_data_as_string| if
// |icon_response_type_| is IconResponseType::ICON_RESPONSE_SEND_BAD. // |icon_response_type_| is IconResponseType::ICON_RESPONSE_SEND_BAD.
bool GenerateIconResponse(int dimension, arc::mojom::RawIconPngDataPtr GenerateIconResponse(int dimension,
bool app_icon, bool app_icon);
std::string* png_data_as_string);
int start_pai_request_count() const { return start_pai_request_count_; } int start_pai_request_count() const { return start_pai_request_count_; }
...@@ -305,8 +306,7 @@ class FakeAppInstance : public mojom::AppInstance { ...@@ -305,8 +306,7 @@ class FakeAppInstance : public mojom::AppInstance {
// routed. // routed.
mojo::Remote<mojom::AppHost> host_remote_; mojo::Remote<mojom::AppHost> host_remote_;
bool GetFakeIcon(mojom::ScaleFactor scale_factor, arc::mojom::RawIconPngDataPtr GetFakeIcon(mojom::ScaleFactor scale_factor);
std::string* png_data_as_string);
DISALLOW_COPY_AND_ASSIGN(FakeAppInstance); DISALLOW_COPY_AND_ASSIGN(FakeAppInstance);
}; };
......
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