| 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/aura/launcher/launcher_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_wrapper.h" | |
| 10 #include "chrome/common/extensions/extension.h" | |
| 11 #include "chrome/common/extensions/extension_resource.h" | |
| 12 #include "content/public/browser/web_contents.h" | |
| 13 | |
| 14 LauncherIconLoader::LauncherIconLoader(Profile* profile, | |
| 15 ChromeLauncherDelegate* delegate) | |
| 16 : profile_(profile), | |
| 17 host_(delegate) { | |
| 18 } | |
| 19 | |
| 20 LauncherIconLoader::~LauncherIconLoader() { | |
| 21 } | |
| 22 | |
| 23 std::string LauncherIconLoader::GetAppID(TabContentsWrapper* tab) { | |
| 24 const Extension* extension = GetExtensionForTab(tab); | |
| 25 return extension ? extension->id() : std::string(); | |
| 26 } | |
| 27 | |
| 28 bool LauncherIconLoader::IsValidID(const std::string& id) { | |
| 29 return GetExtensionByID(id) != NULL; | |
| 30 } | |
| 31 | |
| 32 void LauncherIconLoader::FetchImage(const std::string& id) { | |
| 33 for (ImageLoaderIDToExtensionIDMap::const_iterator i = map_.begin(); | |
| 34 i != map_.end(); ++i) { | |
| 35 if (i->second == id) | |
| 36 return; // Already loading the image. | |
| 37 } | |
| 38 | |
| 39 const Extension* extension = GetExtensionByID(id); | |
| 40 if (!extension) | |
| 41 return; | |
| 42 if (!image_loader_.get()) | |
| 43 image_loader_.reset(new ImageLoadingTracker(this)); | |
| 44 map_[image_loader_->next_id()] = id; | |
| 45 image_loader_->LoadImage( | |
| 46 extension, | |
| 47 extension->GetIconResource(ExtensionIconSet::EXTENSION_ICON_SMALL, | |
| 48 ExtensionIconSet::MATCH_BIGGER), | |
| 49 gfx::Size(ExtensionIconSet::EXTENSION_ICON_SMALL, | |
| 50 ExtensionIconSet::EXTENSION_ICON_SMALL), | |
| 51 ImageLoadingTracker::CACHE); | |
| 52 } | |
| 53 | |
| 54 void LauncherIconLoader::OnImageLoaded(SkBitmap* image, | |
| 55 const ExtensionResource& resource, | |
| 56 int index) { | |
| 57 ImageLoaderIDToExtensionIDMap::iterator i = map_.find(index); | |
| 58 if (i == map_.end()) | |
| 59 return; // The tab has since been removed, do nothing. | |
| 60 | |
| 61 std::string id = i->second; | |
| 62 map_.erase(i); | |
| 63 host_->SetAppImage(id, image); | |
| 64 } | |
| 65 | |
| 66 const Extension* LauncherIconLoader::GetExtensionForTab( | |
| 67 TabContentsWrapper* tab) { | |
| 68 ExtensionService* extension_service = profile_->GetExtensionService(); | |
| 69 if (!extension_service) | |
| 70 return NULL; | |
| 71 return extension_service->GetInstalledApp(tab->web_contents()->GetURL()); | |
| 72 } | |
| 73 | |
| 74 const Extension* LauncherIconLoader::GetExtensionByID(const std::string& id) { | |
| 75 ExtensionService* service = profile_->GetExtensionService(); | |
| 76 if (!service) | |
| 77 return NULL; | |
| 78 return service->GetInstalledExtension(id); | |
| 79 } | |
| OLD | NEW |