OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/views/ash/launcher/launcher_app_icon_loader.h" | |
6 | |
7 #include "chrome/browser/extensions/extension_service.h" | |
8 #include "chrome/browser/profiles/profile.h" | |
9 #include "chrome/browser/ui/tab_contents/tab_contents.h" | |
10 #include "chrome/common/extensions/extension.h" | |
11 | |
12 namespace { | |
13 | |
14 const extensions::Extension* GetExtensionByID(Profile* profile, | |
15 const std::string& id) { | |
16 ExtensionService* service = profile->GetExtensionService(); | |
17 if (!service) | |
18 return NULL; | |
19 return service->extensions()->GetByID(id); | |
20 } | |
21 | |
22 } // namespace | |
23 | |
24 | |
25 LauncherAppIconLoader::LauncherAppIconLoader( | |
26 Profile* profile, | |
27 ChromeLauncherController* controller) | |
28 : profile_(profile), | |
29 host_(controller) { | |
30 } | |
31 | |
32 LauncherAppIconLoader::~LauncherAppIconLoader() { | |
33 } | |
34 | |
35 void LauncherAppIconLoader::FetchImage(const std::string& id) { | |
36 for (ImageLoaderIDToExtensionIDMap::const_iterator i = map_.begin(); | |
37 i != map_.end(); ++i) { | |
38 if (i->second == id) | |
39 return; // Already loading the image. | |
40 } | |
41 | |
42 const extensions::Extension* extension = GetExtensionByID(profile_, id); | |
43 if (!extension) | |
44 return; | |
45 if (!image_loader_.get()) | |
46 image_loader_.reset(new ImageLoadingTracker(this)); | |
47 map_[image_loader_->next_id()] = id; | |
48 image_loader_->LoadImage( | |
49 extension, | |
50 extension->GetIconResource(ExtensionIconSet::EXTENSION_ICON_SMALL, | |
51 ExtensionIconSet::MATCH_BIGGER), | |
52 gfx::Size(ExtensionIconSet::EXTENSION_ICON_SMALL, | |
53 ExtensionIconSet::EXTENSION_ICON_SMALL), | |
54 ImageLoadingTracker::CACHE); | |
55 } | |
56 | |
57 void LauncherAppIconLoader::OnImageLoaded(const gfx::Image& image, | |
58 const std::string& extension_id, | |
59 int index) { | |
60 ImageLoaderIDToExtensionIDMap::iterator i = map_.find(index); | |
61 if (i == map_.end()) | |
62 return; // The tab has since been removed, do nothing. | |
63 | |
64 std::string id = i->second; | |
65 map_.erase(i); | |
66 if (image.IsEmpty()) | |
67 host_->SetAppImage(id, extensions::Extension::GetDefaultIcon(true)); | |
68 else | |
69 host_->SetAppImage(id, *image.ToImageSkia()); | |
70 } | |
OLD | NEW |