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

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

Issue 10375021: Move Extension into extensions namespace (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Take 6 Created 8 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 (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/views/ash/launcher/launcher_app_icon_loader.h" 5 #include "chrome/browser/ui/views/ash/launcher/launcher_app_icon_loader.h"
6 6
7 #include "chrome/browser/extensions/extension_service.h" 7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 9 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
10 #include "chrome/common/extensions/extension.h" 10 #include "chrome/common/extensions/extension.h"
11 #include "chrome/common/extensions/extension_resource.h" 11 #include "chrome/common/extensions/extension_resource.h"
12 #include "content/public/browser/web_contents.h" 12 #include "content/public/browser/web_contents.h"
13 13
14 LauncherAppIconLoader::LauncherAppIconLoader( 14 LauncherAppIconLoader::LauncherAppIconLoader(
15 Profile* profile, 15 Profile* profile,
16 ChromeLauncherController* controller) 16 ChromeLauncherController* controller)
17 : profile_(profile), 17 : profile_(profile),
18 host_(controller) { 18 host_(controller) {
19 } 19 }
20 20
21 LauncherAppIconLoader::~LauncherAppIconLoader() { 21 LauncherAppIconLoader::~LauncherAppIconLoader() {
22 } 22 }
23 23
24 std::string LauncherAppIconLoader::GetAppID(TabContentsWrapper* tab) { 24 std::string LauncherAppIconLoader::GetAppID(TabContentsWrapper* tab) {
25 const Extension* extension = GetExtensionForTab(tab); 25 const extensions::Extension* extension = GetExtensionForTab(tab);
26 return extension ? extension->id() : std::string(); 26 return extension ? extension->id() : std::string();
27 } 27 }
28 28
29 bool LauncherAppIconLoader::IsValidID(const std::string& id) { 29 bool LauncherAppIconLoader::IsValidID(const std::string& id) {
30 return GetExtensionByID(id) != NULL; 30 return GetExtensionByID(id) != NULL;
31 } 31 }
32 32
33 void LauncherAppIconLoader::FetchImage(const std::string& id) { 33 void LauncherAppIconLoader::FetchImage(const std::string& id) {
34 for (ImageLoaderIDToExtensionIDMap::const_iterator i = map_.begin(); 34 for (ImageLoaderIDToExtensionIDMap::const_iterator i = map_.begin();
35 i != map_.end(); ++i) { 35 i != map_.end(); ++i) {
36 if (i->second == id) 36 if (i->second == id)
37 return; // Already loading the image. 37 return; // Already loading the image.
38 } 38 }
39 39
40 const Extension* extension = GetExtensionByID(id); 40 const extensions::Extension* extension = GetExtensionByID(id);
41 if (!extension) 41 if (!extension)
42 return; 42 return;
43 if (!image_loader_.get()) 43 if (!image_loader_.get())
44 image_loader_.reset(new ImageLoadingTracker(this)); 44 image_loader_.reset(new ImageLoadingTracker(this));
45 map_[image_loader_->next_id()] = id; 45 map_[image_loader_->next_id()] = id;
46 image_loader_->LoadImage( 46 image_loader_->LoadImage(
47 extension, 47 extension,
48 extension->GetIconResource(ExtensionIconSet::EXTENSION_ICON_SMALL, 48 extension->GetIconResource(ExtensionIconSet::EXTENSION_ICON_SMALL,
49 ExtensionIconSet::MATCH_BIGGER), 49 ExtensionIconSet::MATCH_BIGGER),
50 gfx::Size(ExtensionIconSet::EXTENSION_ICON_SMALL, 50 gfx::Size(ExtensionIconSet::EXTENSION_ICON_SMALL,
51 ExtensionIconSet::EXTENSION_ICON_SMALL), 51 ExtensionIconSet::EXTENSION_ICON_SMALL),
52 ImageLoadingTracker::CACHE); 52 ImageLoadingTracker::CACHE);
53 } 53 }
54 54
55 void LauncherAppIconLoader::OnImageLoaded(const gfx::Image& image, 55 void LauncherAppIconLoader::OnImageLoaded(const gfx::Image& image,
56 const std::string& extension_id, 56 const std::string& extension_id,
57 int index) { 57 int index) {
58 ImageLoaderIDToExtensionIDMap::iterator i = map_.find(index); 58 ImageLoaderIDToExtensionIDMap::iterator i = map_.find(index);
59 if (i == map_.end()) 59 if (i == map_.end())
60 return; // The tab has since been removed, do nothing. 60 return; // The tab has since been removed, do nothing.
61 61
62 std::string id = i->second; 62 std::string id = i->second;
63 map_.erase(i); 63 map_.erase(i);
64 if (image.IsEmpty()) 64 if (image.IsEmpty())
65 host_->SetAppImage(id, NULL); 65 host_->SetAppImage(id, NULL);
66 else 66 else
67 host_->SetAppImage(id, image.ToSkBitmap()); 67 host_->SetAppImage(id, image.ToSkBitmap());
68 } 68 }
69 69
70 const Extension* LauncherAppIconLoader::GetExtensionForTab( 70 const extensions::Extension* LauncherAppIconLoader::GetExtensionForTab(
71 TabContentsWrapper* tab) { 71 TabContentsWrapper* tab) {
72 ExtensionService* extension_service = profile_->GetExtensionService(); 72 ExtensionService* extension_service = profile_->GetExtensionService();
73 if (!extension_service) 73 if (!extension_service)
74 return NULL; 74 return NULL;
75 return extension_service->GetInstalledApp(tab->web_contents()->GetURL()); 75 return extension_service->GetInstalledApp(tab->web_contents()->GetURL());
76 } 76 }
77 77
78 const Extension* LauncherAppIconLoader::GetExtensionByID( 78 const extensions::Extension* LauncherAppIconLoader::GetExtensionByID(
79 const std::string& id) { 79 const std::string& id) {
80 ExtensionService* service = profile_->GetExtensionService(); 80 ExtensionService* service = profile_->GetExtensionService();
81 if (!service) 81 if (!service)
82 return NULL; 82 return NULL;
83 return service->GetInstalledExtension(id); 83 return service->GetInstalledExtension(id);
84 } 84 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/ash/launcher/launcher_app_icon_loader.h ('k') | chrome/browser/ui/views/browser_actions_container.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698