Commit 1d7b1ead authored by nancylingwang's avatar nancylingwang Committed by Commit Bot

Modify ArcAppIcon to handle non-adaptive icons and migration.

When there is only 1 icon file(icon_xxx.png) for the app, there could be
2 cases:
1. The icon is not the adaptive icon
2. The system just migrated from the adaptive icon feature disabled to
enabled.
To distinguish these 2 scenarios, modify the arc_app_list_prefs. If the
adaptive icon feature is enabled, for non-adaptive icons, save the image
to both icon_xxx.png and foreground_icon_xxx.png. Then ArcAppIcon can
check the files to know whether the current icon is non-adaptive icon or
the system migration case. If there is no foreground icon, that means
the system migration case, then we should request the icon. Otherwise,
that means the icon is a non-adaptive icon.

This is also preparing for the next step, removing the icon_xxx.png, so
that we can have 2 png files only:
foreground_icon_xxx.png: Present the foreground image for the adaptive
icon or the image for the non-adaptive icon.
background_icon_xxx.png: Present the background image for the adaptive
icon.

TODO: Add the metric to verify whether we have non-adaptive icon
scenario. If all icons return from ARC side are 2 layer, for the next
step, we can add some DCHECK and remove the icon_xxx.png, and force
checking both the foreground and background images.

BUG=1083331

Change-Id: I516c4a317040da03902f80ddbaa9876325bfbd35
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2318885Reviewed-by: default avatarLong Cheng <lgcheng@google.com>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792122}
parent 4422ec66
......@@ -105,8 +105,12 @@ void OnArcAppIconCompletelyLoaded(
FALLTHROUGH;
case apps::mojom::IconType::kStandard: {
if (base::FeatureList::IsEnabled(features::kAppServiceAdaptiveIcon)) {
iv->uncompressed = gfx::ImageSkiaOperations::CreateSuperimposedImage(
icon->background_image_skia(), icon->foreground_image_skia());
iv->uncompressed =
icon->is_adaptive_icon()
? gfx::ImageSkiaOperations::CreateSuperimposedImage(
icon->background_image_skia(),
icon->foreground_image_skia())
: icon->foreground_image_skia();
} else {
iv->uncompressed = icon->image_skia();
}
......
......@@ -445,26 +445,39 @@ std::unique_ptr<ArcAppIcon::ReadResult> ArcAppIcon::ReadAdaptiveIconFiles(
const base::FilePath& foreground_path = paths[0];
const base::FilePath& background_path = paths[1];
if (!base::PathExists(foreground_path) ||
!base::PathExists(background_path)) {
if (!base::PathExists(foreground_path)) {
DCHECK_EQ(2u, default_app_paths.size());
const base::FilePath& default_app_foreground_path = default_app_paths[0];
const base::FilePath& default_app_background_path = default_app_paths[1];
if (default_app_foreground_path.empty() ||
!base::PathExists(default_app_foreground_path) ||
default_app_background_path.empty() ||
!base::PathExists(default_app_background_path)) {
!base::PathExists(default_app_foreground_path)) {
return std::make_unique<ArcAppIcon::ReadResult>(
false /* error */, true /* request_to_install */, scale_factor,
false /* resize_allowed */,
std::vector<std::string>() /* unsafe_icon_data */);
}
if (default_app_background_path.empty() ||
!base::PathExists(default_app_background_path)) {
// For non-adaptive icon, there could be a |default_app_foreground_path|
// file only without a |default_app_background_path| file.
return ArcAppIcon::ReadFile(true /* request_to_install */, scale_factor,
true /* resize_allowed */,
default_app_foreground_path);
}
return ArcAppIcon::ReadFiles(
true /* request_to_install */, scale_factor, true /* resize_allowed */,
default_app_foreground_path, default_app_background_path);
}
if (!base::PathExists(background_path)) {
// For non-adaptive icon, there could be a |foreground_icon_path| file
// only without a |background_icon_path| file.
return ArcAppIcon::ReadFile(false /* request_to_install */, scale_factor,
false /* resize_allowed */, foreground_path);
}
return ArcAppIcon::ReadFiles(false /* request_to_install */, scale_factor,
false /* resize_allowed */, foreground_path,
background_path);
......@@ -570,6 +583,21 @@ void ArcAppIcon::OnIconRead(
return;
}
case IconType::kAdaptive: {
// For non-adaptive icons, |foreground_icon_path| is used to save the icon
// without |background_icon_path|, so |unsafe_icon_data| could have one
// element for |foreground_icon_path| only.
if (read_result->unsafe_icon_data.size() == 1) {
is_adaptive_icon_ = false;
DecodeImage(read_result->unsafe_icon_data[0],
ArcAppIconDescriptor(resource_size_in_dip_,
read_result->scale_factor),
read_result->resize_allowed, foreground_image_skia_,
foreground_incomplete_scale_factors_);
background_incomplete_scale_factors_.clear();
return;
}
is_adaptive_icon_ = true;
DCHECK_EQ(2u, read_result->unsafe_icon_data.size());
DecodeImage(read_result->unsafe_icon_data[0],
ArcAppIconDescriptor(resource_size_in_dip_,
......
......@@ -75,6 +75,8 @@ class ArcAppIcon {
const std::string& app_id() const { return app_id_; }
bool is_adaptive_icon() const { return is_adaptive_icon_; }
// Returns |image_skia_| and valid if the |icon_type_| is
// IconType::kUncompressed.
const gfx::ImageSkia& image_skia() const {
......@@ -191,6 +193,8 @@ class ArcAppIcon {
// only one counter is needed.
int icon_loaded_count_ = 0;
bool is_adaptive_icon_ = false;
gfx::ImageSkia image_skia_;
std::map<ui::ScaleFactor, std::string> compressed_images_;
gfx::ImageSkia foreground_image_skia_;
......
......@@ -154,8 +154,21 @@ bool InstallIconFromFileThread(const base::FilePath& icon_path,
if (!WriteIconFile(icon_path, icon_png_data))
return false;
if (!base::FeatureList::IsEnabled(features::kAppServiceAdaptiveIcon) ||
!icon->is_adaptive_icon) {
if (!base::FeatureList::IsEnabled(features::kAppServiceAdaptiveIcon))
return true;
if (!icon->is_adaptive_icon) {
// For non-adaptive icon, save the |icon_png_data| to the
// |foreground_icon_path|, to identify the difference between migrating to
// the adaptive icon feature enabled and the non-adaptive icon case. If
// there is a |foreground_icon_path| file without a |background_icon_path|
// file, that means the icon is a non-adaptive icon. Otherwise, if there is
// no |foreground_icon_path| file, that means we haven't fetched the
// adaptive icon yet, then we should request the icon.
if (!WriteIconFile(foreground_icon_path, icon->icon_png_data.value())) {
return false;
}
return true;
}
......
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