Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3505)

Unified Diff: chrome/browser/ui/app_list/search/extension_app_result.cc

Issue 2819413003: Refactor extension app icon. (Closed)
Patch Set: nit Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/app_list/search/extension_app_result.cc
diff --git a/chrome/browser/ui/app_list/search/extension_app_result.cc b/chrome/browser/ui/app_list/search/extension_app_result.cc
index 376c4a1fdd13501c6d6f9f21731a326aa60dbc87..8d4a39352a67fe8d94e72fcc08c3a8537964245c 100644
--- a/chrome/browser/ui/app_list/search/extension_app_result.cc
+++ b/chrome/browser/ui/app_list/search/extension_app_result.cc
@@ -5,6 +5,8 @@
#include "chrome/browser/ui/app_list/search/extension_app_result.h"
#include "base/metrics/user_metrics.h"
+#include "chrome/browser/extensions/chrome_app_icon.h"
+#include "chrome/browser/extensions/chrome_app_icon_service.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
@@ -21,9 +23,6 @@
#include "extensions/common/manifest_handlers/icons_handler.h"
#include "ui/app_list/app_list_switches.h"
#include "ui/events/event_constants.h"
-#include "ui/gfx/color_utils.h"
-#include "ui/gfx/image/image_skia_operations.h"
-#include "chrome/browser/chromeos/extensions/gfx_utils.h"
namespace app_list {
@@ -40,8 +39,8 @@ ExtensionAppResult::ExtensionAppResult(Profile* profile,
DCHECK(extension);
is_platform_app_ = extension->is_platform_app();
-
- CreateOrUpdateIcon();
+ icon_ = extensions::ChromeAppIconService::Get(profile)->CreateIcon(
+ this, app_id, GetPreferredIconDimension());
StartObservingExtensionRegistry();
}
@@ -50,23 +49,6 @@ ExtensionAppResult::~ExtensionAppResult() {
StopObservingExtensionRegistry();
}
-void ExtensionAppResult::CreateOrUpdateIcon() {
- if (icon_ && icon_->is_valid()) {
- UpdateIcon();
- return;
- }
-
- const extensions::Extension* extension =
- extensions::ExtensionRegistry::Get(profile())->GetInstalledExtension(
- app_id());
- DCHECK(extension);
-
- icon_ = base::MakeUnique<extensions::IconImage>(
- profile(), extension, extensions::IconsInfo::GetIcons(extension),
- GetPreferredIconDimension(), extensions::util::GetDefaultAppIcon(), this);
- UpdateIcon();
-}
-
void ExtensionAppResult::Open(int event_flags) {
RecordHistogram(APP_SEARCH_RESULT);
const extensions::Extension* extension =
@@ -144,28 +126,8 @@ bool ExtensionAppResult::RunExtensionEnableFlow() {
return true;
}
-void ExtensionAppResult::UpdateIcon() {
- gfx::ImageSkia icon = icon_->image_skia();
-
- extensions::util::MaybeApplyChromeBadge(profile(), app_id(), &icon);
-
- if (!extensions::util::IsAppLaunchable(app_id(), profile())) {
- const color_utils::HSL shift = {-1, 0, 0.6};
- icon = gfx::ImageSkiaOperations::CreateHSLShiftedImage(icon, shift);
- }
-
- SetIcon(icon);
-}
-
-void ExtensionAppResult::OnExtensionIconImageChanged(
- extensions::IconImage* image) {
- DCHECK_EQ(icon_.get(), image);
- UpdateIcon();
-}
-
-void ExtensionAppResult::OnExtensionIconImageDestroyed(
- extensions::IconImage* image) {
- SetIcon(gfx::ImageSkia());
+void ExtensionAppResult::OnIconUpdated(extensions::ChromeAppIcon* icon) {
+ SetIcon(icon->image_skia());
}
void ExtensionAppResult::ExecuteLaunchCommand(int event_flags) {
@@ -190,7 +152,8 @@ void ExtensionAppResult::OnExtensionLoaded(
const extensions::Extension* extension) {
// Old |icon_| might be invalidated for forever in case extension gets
// updated. In this case we need re-create icon again.
- CreateOrUpdateIcon();
+ if (!icon_->IsValid())
+ icon_->Reload();
}
void ExtensionAppResult::OnShutdown(extensions::ExtensionRegistry* registry) {

Powered by Google App Engine
This is Rietveld 408576698