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

Side by Side Diff: chrome/browser/ui/webui/extensions/extension_icon_source.h

Issue 11027044: Add a class to replace ImageLoadingTracker with a nicer API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix include order Created 8 years, 1 month 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 #ifndef CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_ICON_SOURCE_H_ 5 #ifndef CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_ICON_SOURCE_H_
6 #define CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_ICON_SOURCE_H_ 6 #define CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_ICON_SOURCE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "chrome/browser/extensions/image_loading_tracker.h"
13 #include "chrome/browser/favicon/favicon_service.h" 12 #include "chrome/browser/favicon/favicon_service.h"
14 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 13 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
15 #include "chrome/common/extensions/extension_icon_set.h" 14 #include "chrome/common/extensions/extension_icon_set.h"
15 #include "chrome/common/extensions/extension_resource.h"
16 #include "third_party/skia/include/core/SkBitmap.h" 16 #include "third_party/skia/include/core/SkBitmap.h"
17 17
18 class ExtensionIconSet; 18 class ExtensionIconSet;
19 class Profile; 19 class Profile;
20 20
21 namespace extensions { 21 namespace extensions {
22 class Extension; 22 class Extension;
23 } 23 }
24 24
25 // ExtensionIconSource serves extension icons through network level chrome: 25 // ExtensionIconSource serves extension icons through network level chrome:
(...skipping 15 matching lines...) Expand all
41 // chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/32/1?grayscale=true 41 // chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/32/1?grayscale=true
42 // (ICON_SMALL, MATCH_BIGGER, grayscale) 42 // (ICON_SMALL, MATCH_BIGGER, grayscale)
43 // chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/128/0 43 // chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/128/0
44 // (ICON_LARGE, MATCH_EXACTLY) 44 // (ICON_LARGE, MATCH_EXACTLY)
45 // 45 //
46 // We attempt to load icons from the following sources in order: 46 // We attempt to load icons from the following sources in order:
47 // 1) The icons as listed in the extension / app manifests. 47 // 1) The icons as listed in the extension / app manifests.
48 // 2) If a 16px icon was requested, the favicon for extension's launch URL. 48 // 2) If a 16px icon was requested, the favicon for extension's launch URL.
49 // 3) The default extension / application icon if there are still no matches. 49 // 3) The default extension / application icon if there are still no matches.
50 // 50 //
51 class ExtensionIconSource : public ChromeURLDataManager::DataSource, 51 class ExtensionIconSource : public ChromeURLDataManager::DataSource {
52 public ImageLoadingTracker::Observer {
53 public: 52 public:
54 explicit ExtensionIconSource(Profile* profile); 53 explicit ExtensionIconSource(Profile* profile);
55 54
56 // Gets the URL of the |extension| icon in the given |icon_size|, falling back 55 // Gets the URL of the |extension| icon in the given |icon_size|, falling back
57 // based on the |match| type. If |grayscale|, the URL will be for the 56 // based on the |match| type. If |grayscale|, the URL will be for the
58 // desaturated version of the icon. |exists|, if non-NULL, will be set to true 57 // desaturated version of the icon. |exists|, if non-NULL, will be set to true
59 // if the icon exists; false if it will lead to a default or not-present 58 // if the icon exists; false if it will lead to a default or not-present
60 // image. 59 // image.
61 static GURL GetIconURL(const extensions::Extension* extension, 60 static GURL GetIconURL(const extensions::Extension* extension,
62 int icon_size, 61 int icon_size,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 101
103 // Loads the favicon image for the app associated with the |request_id|. If 102 // Loads the favicon image for the app associated with the |request_id|. If
104 // the image does not exist, we fall back to the default image. 103 // the image does not exist, we fall back to the default image.
105 void LoadFaviconImage(int request_id); 104 void LoadFaviconImage(int request_id);
106 105
107 // FaviconService callback 106 // FaviconService callback
108 void OnFaviconDataAvailable( 107 void OnFaviconDataAvailable(
109 FaviconService::Handle request_handle, 108 FaviconService::Handle request_handle,
110 const history::FaviconBitmapResult& bitmap_result); 109 const history::FaviconBitmapResult& bitmap_result);
111 110
112 // ImageLoadingTracker::Observer 111 // ImageLoader callback
113 virtual void OnImageLoaded(const gfx::Image& image, 112 void OnImageLoaded(int request_id, const gfx::Image& image);
114 const std::string& extension_id,
115 int id) OVERRIDE;
116 113
117 // Called when the extension doesn't have an icon. We fall back to multiple 114 // Called when the extension doesn't have an icon. We fall back to multiple
118 // sources, using the following order: 115 // sources, using the following order:
119 // 1) The icons as listed in the extension / app manifests. 116 // 1) The icons as listed in the extension / app manifests.
120 // 2) If a 16px icon and the extension has a launch URL, see if Chrome 117 // 2) If a 16px icon and the extension has a launch URL, see if Chrome
121 // has a corresponding favicon. 118 // has a corresponding favicon.
122 // 3) If still no matches, load the default extension / application icon. 119 // 3) If still no matches, load the default extension / application icon.
123 void LoadIconFailed(int request_id); 120 void LoadIconFailed(int request_id);
124 121
125 // Parses and savse an ExtensionIconRequest for the URL |path| for the 122 // Parses and savse an ExtensionIconRequest for the URL |path| for the
(...skipping 18 matching lines...) Expand all
144 void ClearData(int request_id); 141 void ClearData(int request_id);
145 142
146 Profile* profile_; 143 Profile* profile_;
147 144
148 // Maps tracker ids to request ids. 145 // Maps tracker ids to request ids.
149 std::map<int, int> tracker_map_; 146 std::map<int, int> tracker_map_;
150 147
151 // Maps request_ids to ExtensionIconRequests. 148 // Maps request_ids to ExtensionIconRequests.
152 std::map<int, ExtensionIconRequest*> request_map_; 149 std::map<int, ExtensionIconRequest*> request_map_;
153 150
154 scoped_ptr<ImageLoadingTracker> tracker_;
155
156 int next_tracker_id_;
157
158 scoped_ptr<SkBitmap> default_app_data_; 151 scoped_ptr<SkBitmap> default_app_data_;
159 152
160 scoped_ptr<SkBitmap> default_extension_data_; 153 scoped_ptr<SkBitmap> default_extension_data_;
161 154
162 CancelableRequestConsumerT<int, 0> cancelable_consumer_; 155 CancelableRequestConsumerT<int, 0> cancelable_consumer_;
163 156
164 DISALLOW_COPY_AND_ASSIGN(ExtensionIconSource); 157 DISALLOW_COPY_AND_ASSIGN(ExtensionIconSource);
165 }; 158 };
166 159
167 #endif // CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_ICON_SOURCE_H_ 160 #endif // CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_ICON_SOURCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698