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

Side by Side Diff: chrome/browser/extensions/extension_app_icon_loader.cc

Issue 2819413003: Refactor extension app icon. (Closed)
Patch Set: Devlin's comments 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extension_app_icon_loader.h" 5 #include "chrome/browser/extensions/extension_app_icon_loader.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "chrome/browser/extensions/extension_app_icon.h"
9 #include "chrome/browser/extensions/extension_app_icon_service.h"
8 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/extensions/extension_util.h" 11 #include "chrome/browser/extensions/extension_util.h"
10 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/extensions/extension_constants.h" 13 #include "chrome/common/extensions/extension_constants.h"
12 #include "extensions/browser/extension_system.h" 14 #include "extensions/browser/extension_system.h"
13 #include "extensions/common/extension.h" 15 #include "extensions/common/extension.h"
14 #include "extensions/common/manifest_handlers/icons_handler.h" 16 #include "extensions/common/manifest_handlers/icons_handler.h"
15 #include "ui/gfx/color_utils.h" 17 #include "ui/gfx/color_utils.h"
16 #include "ui/gfx/image/image_skia_operations.h" 18 #include "ui/gfx/image/image_skia_operations.h"
17 19
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 } 53 }
52 54
53 void ExtensionAppIconLoader::FetchImage(const std::string& id) { 55 void ExtensionAppIconLoader::FetchImage(const std::string& id) {
54 if (map_.find(id) != map_.end()) 56 if (map_.find(id) != map_.end())
55 return; // Already loading the image. 57 return; // Already loading the image.
56 58
57 const extensions::Extension* extension = GetExtensionByID(profile(), id); 59 const extensions::Extension* extension = GetExtensionByID(profile(), id);
58 if (!extension) 60 if (!extension)
59 return; 61 return;
60 62
61 std::unique_ptr<extensions::IconImage> image(new extensions::IconImage( 63 std::unique_ptr<ExtensionAppIcon> icon =
62 profile(), extension, extensions::IconsInfo::GetIcons(extension), 64 ExtensionAppIconService::Get(profile())->CreateIcon(this, id,
63 icon_size(), extensions::util::GetDefaultAppIcon(), this)); 65 icon_size());
64 66
65 // Triggers image loading now instead of depending on paint message. This 67 // Triggers image loading now instead of depending on paint message. This
66 // makes the temp blank image be shown for shorter time and improves user 68 // makes the temp blank image be shown for shorter time and improves user
67 // experience. See http://crbug.com/146114. 69 // experience. See http://crbug.com/146114.
68 image->image_skia().EnsureRepsForSupportedScales(); 70 icon->EnsureRepsForSupportedScales();
69 map_[id] = std::move(image); 71 map_[id] = std::move(icon);
70 } 72 }
71 73
72 void ExtensionAppIconLoader::ClearImage(const std::string& id) { 74 void ExtensionAppIconLoader::ClearImage(const std::string& id) {
73 map_.erase(id); 75 map_.erase(id);
74 } 76 }
75 77
76 void ExtensionAppIconLoader::UpdateImage(const std::string& id) { 78 void ExtensionAppIconLoader::UpdateImage(const std::string& id) {
77 ExtensionIDToImageMap::iterator it = map_.find(id); 79 ExtensionIDToImageMap::iterator it = map_.find(id);
78 if (it == map_.end()) 80 if (it == map_.end())
79 return; 81 return;
80 82
81 BuildImage(it->first, it->second->image_skia()); 83 it->second->UpdateIcon();
82 } 84 }
83 85
84 void ExtensionAppIconLoader::OnExtensionIconImageChanged( 86 void ExtensionAppIconLoader::OnIconUpdated(ExtensionAppIcon* icon) {
85 extensions::IconImage* image) { 87 delegate()->OnAppImageUpdated(icon->app_id(), icon->image_skia());
86 for (const auto& pair : map_) {
87 if (pair.second.get() == image) {
88 BuildImage(pair.first, pair.second->image_skia());
89 return;
90 }
91 }
92 // The image has been removed, do nothing.
93 }
94
95 void ExtensionAppIconLoader::BuildImage(const std::string& id,
96 const gfx::ImageSkia& icon) {
97 gfx::ImageSkia image = icon;
98
99 #if defined(OS_CHROMEOS)
100 util::MaybeApplyChromeBadge(profile(), id, &image);
101 #endif
102
103 if (!util::IsAppLaunchable(id, profile())) {
104 const color_utils::HSL shift = {-1, 0, 0.6};
105 image = gfx::ImageSkiaOperations::CreateHSLShiftedImage(image, shift);
106 }
107
108 delegate()->OnAppImageUpdated(id, image);
109 } 88 }
110 89
111 } // namespace extensions 90 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698