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

Side by Side Diff: chrome/browser/ui/ash/launcher/launcher_app_icon_loader.cc

Issue 10868003: chromeos: Fix pixelated icons in app list and launcher (part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win compile Created 8 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/ash/launcher/launcher_app_icon_loader.h" 5 #include "chrome/browser/ui/ash/launcher/launcher_app_icon_loader.h"
6 6
7 #include "base/stl_util.h"
7 #include "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/tab_contents/tab_contents.h" 10 #include "chrome/browser/ui/tab_contents/tab_contents.h"
10 #include "chrome/common/extensions/extension.h" 11 #include "chrome/common/extensions/extension.h"
11 #include "chrome/common/extensions/extension_constants.h" 12 #include "chrome/common/extensions/extension_constants.h"
12 13
13 namespace { 14 namespace {
14 15
15 const extensions::Extension* GetExtensionByID(Profile* profile, 16 const extensions::Extension* GetExtensionByID(Profile* profile,
16 const std::string& id) { 17 const std::string& id) {
17 ExtensionService* service = profile->GetExtensionService(); 18 ExtensionService* service = profile->GetExtensionService();
18 if (!service) 19 if (!service)
19 return NULL; 20 return NULL;
20 return service->extensions()->GetByID(id); 21 return service->extensions()->GetByID(id);
21 } 22 }
22 23
23 } // namespace 24 } // namespace
24 25
25 26
26 LauncherAppIconLoader::LauncherAppIconLoader( 27 LauncherAppIconLoader::LauncherAppIconLoader(
27 Profile* profile, 28 Profile* profile,
28 ChromeLauncherController* controller) 29 ChromeLauncherController* controller)
29 : profile_(profile), 30 : profile_(profile),
30 host_(controller) { 31 host_(controller) {
31 } 32 }
32 33
33 LauncherAppIconLoader::~LauncherAppIconLoader() { 34 LauncherAppIconLoader::~LauncherAppIconLoader() {
35 STLDeleteContainerPairFirstPointers(map_.begin(), map_.end());
34 } 36 }
35 37
36 void LauncherAppIconLoader::FetchImage(const std::string& id) { 38 void LauncherAppIconLoader::FetchImage(const std::string& id) {
37 for (ImageLoaderIDToExtensionIDMap::const_iterator i = map_.begin(); 39 for (ImageToExtensionIDMap::const_iterator i = map_.begin();
38 i != map_.end(); ++i) { 40 i != map_.end(); ++i) {
39 if (i->second == id) 41 if (i->second == id)
40 return; // Already loading the image. 42 return; // Already loading the image.
41 } 43 }
42 44
43 const extensions::Extension* extension = GetExtensionByID(profile_, id); 45 const extensions::Extension* extension = GetExtensionByID(profile_, id);
44 if (!extension) 46 if (!extension)
45 return; 47 return;
46 if (!image_loader_.get()) 48
47 image_loader_.reset(new ImageLoadingTracker(this)); 49 extensions::IconImage* image = new extensions::IconImage(
48 map_[image_loader_->next_id()] = id;
49 image_loader_->LoadImage(
50 extension, 50 extension,
51 extension->GetIconResource(extension_misc::EXTENSION_ICON_SMALL, 51 extension->icons(),
52 ExtensionIconSet::MATCH_BIGGER), 52 extension_misc::EXTENSION_ICON_SMALL,
53 gfx::Size(extension_misc::EXTENSION_ICON_SMALL, 53 extensions::Extension::GetDefaultIcon(true),
54 extension_misc::EXTENSION_ICON_SMALL), 54 this);
55 ImageLoadingTracker::CACHE); 55 // |map_| takes ownership of |image|.
56 map_[image] = id;
57
58 host_->SetAppImage(id, image->image_skia());
56 } 59 }
57 60
58 void LauncherAppIconLoader::OnImageLoaded(const gfx::Image& image, 61 void LauncherAppIconLoader::ClearImage(const std::string& id) {
59 const std::string& extension_id, 62 for (ImageToExtensionIDMap::iterator i = map_.begin();
60 int index) { 63 i != map_.end(); ++i) {
61 ImageLoaderIDToExtensionIDMap::iterator i = map_.find(index); 64 if (i->second == id) {
65 delete i->first;
66 map_.erase(i);
67 break;
68 }
69 }
70 }
71
72 void LauncherAppIconLoader::OnExtensionIconImageChanged(
73 extensions::IconImage* image) {
74 ImageToExtensionIDMap::iterator i = map_.find(image);
62 if (i == map_.end()) 75 if (i == map_.end())
63 return; // The tab has since been removed, do nothing. 76 return; // The image has been removed, do nothing.
64 77
65 std::string id = i->second; 78 host_->SetAppImage(i->second, image->image_skia());
66 map_.erase(i);
67 if (image.IsEmpty())
68 host_->SetAppImage(id, extensions::Extension::GetDefaultIcon(true));
69 else
70 host_->SetAppImage(id, *image.ToImageSkia());
71 } 79 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/launcher/launcher_app_icon_loader.h ('k') | chrome/browser/ui/views/app_list/app_list_controller_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698