OLD | NEW |
---|---|
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/extensions/image_loading_tracker.h" | 5 #include "chrome/browser/extensions/image_loading_tracker.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | |
9 #include "chrome/common/chrome_notification_types.h" | 10 #include "chrome/common/chrome_notification_types.h" |
10 #include "chrome/common/extensions/extension.h" | 11 #include "chrome/common/extensions/extension.h" |
12 #include "chrome/common/extensions/extension_constants.h" | |
11 #include "chrome/common/extensions/extension_resource.h" | 13 #include "chrome/common/extensions/extension_resource.h" |
12 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
13 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" |
16 #include "grit/component_extension_resources_map.h" | |
17 #include "grit/theme_resources.h" | |
14 #include "skia/ext/image_operations.h" | 18 #include "skia/ext/image_operations.h" |
15 #include "third_party/skia/include/core/SkBitmap.h" | 19 #include "third_party/skia/include/core/SkBitmap.h" |
16 #include "ui/gfx/image/image.h" | 20 #include "ui/gfx/image/image.h" |
17 #include "webkit/glue/image_decoder.h" | 21 #include "webkit/glue/image_decoder.h" |
18 | 22 |
19 using content::BrowserThread; | 23 using content::BrowserThread; |
20 | 24 |
21 //////////////////////////////////////////////////////////////////////////////// | 25 //////////////////////////////////////////////////////////////////////////////// |
22 // ImageLoadingTracker::Observer | 26 // ImageLoadingTracker::Observer |
23 | 27 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 PendingLoadInfo load_info; | 181 PendingLoadInfo load_info; |
178 load_info.extension = extension; | 182 load_info.extension = extension; |
179 load_info.cache = cache; | 183 load_info.cache = cache; |
180 load_info.extension_id = extension->id(); | 184 load_info.extension_id = extension->id(); |
181 load_info.pending_count = info_list.size(); | 185 load_info.pending_count = info_list.size(); |
182 int id = next_id_++; | 186 int id = next_id_++; |
183 load_map_[id] = load_info; | 187 load_map_[id] = load_info; |
184 | 188 |
185 for (std::vector<ImageInfo>::const_iterator it = info_list.begin(); | 189 for (std::vector<ImageInfo>::const_iterator it = info_list.begin(); |
186 it != info_list.end(); ++it) { | 190 it != info_list.end(); ++it) { |
191 // Load resources for component extensions. | |
192 if (load_info.extension_id == extension_misc::kWebStoreAppId) { | |
193 OnImageLoaded( | |
194 ExtensionIconSource::LoadImageByResourceId(IDR_WEBSTORE_ICON), | |
195 it->resource, it->max_size, id, false); | |
196 continue; | |
197 } | |
198 | |
187 // If we don't have a path we don't need to do any further work, just | 199 // If we don't have a path we don't need to do any further work, just |
188 // respond back. | 200 // respond back. |
189 if (it->resource.relative_path().empty()) { | 201 if (it->resource.relative_path().empty()) { |
190 OnImageLoaded(NULL, it->resource, it->max_size, id, false); | 202 OnImageLoaded(NULL, it->resource, it->max_size, id, false); |
191 continue; | 203 continue; |
192 } | 204 } |
193 | 205 |
206 SkBitmap* from_resources = TryLoadingComponentExtensionImage(extension, | |
207 it->resource); | |
208 if (from_resources) { | |
209 OnImageLoaded(from_resources, it->resource, it->max_size, id, false); | |
Finnur
2012/04/10 13:46:39
You've selected in both cases to not honor the |ca
dgozman
2012/04/10 14:19:48
Why do we cache icon available locally and waste s
Finnur
2012/04/10 14:32:21
All the files this class deals with are local, so
dgozman
2012/04/10 16:59:51
Oh, now I see. Changed so the |CacheParam| decides
| |
210 continue; | |
211 } | |
212 | |
194 DCHECK(extension->path() == it->resource.extension_root()); | 213 DCHECK(extension->path() == it->resource.extension_root()); |
195 | 214 |
196 // See if the extension has the image already. | 215 // See if the extension has the image already. |
197 if (extension->HasCachedImage(it->resource, it->max_size)) { | 216 if (extension->HasCachedImage(it->resource, it->max_size)) { |
198 SkBitmap image = extension->GetCachedImage(it->resource, it->max_size); | 217 SkBitmap image = extension->GetCachedImage(it->resource, it->max_size); |
199 OnImageLoaded(&image, it->resource, it->max_size, id, false); | 218 OnImageLoaded(&image, it->resource, it->max_size, id, false); |
200 continue; | 219 continue; |
201 } | 220 } |
202 | 221 |
203 // Instruct the ImageLoader to load this on the File thread. LoadImage does | 222 // Instruct the ImageLoader to load this on the File thread. LoadImage does |
204 // not block. | 223 // not block. |
205 if (!loader_) | 224 if (!loader_) |
206 loader_ = new ImageLoader(this); | 225 loader_ = new ImageLoader(this); |
207 loader_->LoadImage(it->resource, it->max_size, id); | 226 loader_->LoadImage(it->resource, it->max_size, id); |
208 } | 227 } |
209 } | 228 } |
210 | 229 |
230 SkBitmap* ImageLoadingTracker::TryLoadingComponentExtensionImage( | |
231 const Extension* extension, | |
232 const ExtensionResource& resource) { | |
233 if (extension->location() != Extension::COMPONENT) | |
234 return NULL; | |
235 | |
236 FilePath directory_path = extension->path(); | |
237 FilePath relative_path = directory_path.BaseName().Append( | |
238 resource.relative_path()); | |
239 | |
240 for (size_t i = 0; i < kComponentExtensionResourcesSize; ++i) { | |
241 FilePath bm_resource_path = | |
242 FilePath().AppendASCII(kComponentExtensionResources[i].name); | |
243 bm_resource_path = bm_resource_path.NormalizePathSeparators(); | |
244 | |
245 if (relative_path == bm_resource_path) { | |
246 return ExtensionIconSource::LoadImageByResourceId( | |
247 kComponentExtensionResources[i].value); | |
Finnur
2012/04/10 14:32:21
Wait, we're on the UI thread here so we should not
dgozman
2012/04/10 16:59:51
Done.
| |
248 } | |
249 } | |
250 return NULL; | |
251 } | |
252 | |
211 void ImageLoadingTracker::OnImageLoaded( | 253 void ImageLoadingTracker::OnImageLoaded( |
212 SkBitmap* image, | 254 SkBitmap* image, |
213 const ExtensionResource& resource, | 255 const ExtensionResource& resource, |
214 const gfx::Size& original_size, | 256 const gfx::Size& original_size, |
215 int id, | 257 int id, |
216 bool should_cache) { | 258 bool should_cache) { |
217 LoadMap::iterator load_map_it = load_map_.find(id); | 259 LoadMap::iterator load_map_it = load_map_.find(id); |
218 DCHECK(load_map_it != load_map_.end()); | 260 DCHECK(load_map_it != load_map_.end()); |
219 PendingLoadInfo* info = &load_map_it->second; | 261 PendingLoadInfo* info = &load_map_it->second; |
220 | 262 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
266 // Remove reference to this extension from all pending load entries. This | 308 // Remove reference to this extension from all pending load entries. This |
267 // ensures we don't attempt to cache the image when the load completes. | 309 // ensures we don't attempt to cache the image when the load completes. |
268 for (LoadMap::iterator i = load_map_.begin(); i != load_map_.end(); ++i) { | 310 for (LoadMap::iterator i = load_map_.begin(); i != load_map_.end(); ++i) { |
269 PendingLoadInfo* info = &i->second; | 311 PendingLoadInfo* info = &i->second; |
270 if (info->extension == extension) { | 312 if (info->extension == extension) { |
271 info->extension = NULL; | 313 info->extension = NULL; |
272 info->cache = DONT_CACHE; | 314 info->cache = DONT_CACHE; |
273 } | 315 } |
274 } | 316 } |
275 } | 317 } |
OLD | NEW |