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

Side by Side Diff: chrome/browser/extensions/image_loading_tracker.cc

Issue 9979001: Attempt to load component extension favicon from the resources first. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Merge Created 8 years, 8 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 | 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 #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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 decoded->height() > max_size.height()) { 111 decoded->height() > max_size.height()) {
108 // The bitmap is too big, re-sample. 112 // The bitmap is too big, re-sample.
109 *decoded = skia::ImageOperations::Resize( 113 *decoded = skia::ImageOperations::Resize(
110 *decoded, skia::ImageOperations::RESIZE_LANCZOS3, 114 *decoded, skia::ImageOperations::RESIZE_LANCZOS3,
111 max_size.width(), max_size.height()); 115 max_size.width(), max_size.height());
112 } 116 }
113 117
114 ReportBack(decoded.release(), resource, original_size, id); 118 ReportBack(decoded.release(), resource, original_size, id);
115 } 119 }
116 120
121 // Instructs the loader to load a resource on the File thread.
122 void LoadResource(const ExtensionResource& resource,
123 const gfx::Size& max_size,
124 int id,
125 int resource_id) {
126 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::FILE));
127 BrowserThread::PostTask(
128 BrowserThread::FILE, FROM_HERE,
129 base::Bind(&ImageLoader::LoadResourceOnFileThread, this, resource,
130 max_size, id, resource_id));
131 }
132
133 void LoadResourceOnFileThread(const ExtensionResource& resource,
134 const gfx::Size& max_size,
135 int id,
136 int resource_id) {
137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
138 SkBitmap* image = ExtensionIconSource::LoadImageByResourceId(
139 resource_id);
140 ReportBack(image, resource, max_size, id);
141 }
142
117 void ReportBack(SkBitmap* image, const ExtensionResource& resource, 143 void ReportBack(SkBitmap* image, const ExtensionResource& resource,
118 const gfx::Size& original_size, int id) { 144 const gfx::Size& original_size, int id) {
119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 145 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
120 146
121 BrowserThread::PostTask( 147 BrowserThread::PostTask(
122 callback_thread_id_, FROM_HERE, 148 callback_thread_id_, FROM_HERE,
123 base::Bind(&ImageLoader::ReportOnUIThread, this, 149 base::Bind(&ImageLoader::ReportOnUIThread, this,
124 image, resource, original_size, id)); 150 image, resource, original_size, id));
125 } 151 }
126 152
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 PendingLoadInfo load_info; 203 PendingLoadInfo load_info;
178 load_info.extension = extension; 204 load_info.extension = extension;
179 load_info.cache = cache; 205 load_info.cache = cache;
180 load_info.extension_id = extension->id(); 206 load_info.extension_id = extension->id();
181 load_info.pending_count = info_list.size(); 207 load_info.pending_count = info_list.size();
182 int id = next_id_++; 208 int id = next_id_++;
183 load_map_[id] = load_info; 209 load_map_[id] = load_info;
184 210
185 for (std::vector<ImageInfo>::const_iterator it = info_list.begin(); 211 for (std::vector<ImageInfo>::const_iterator it = info_list.begin();
186 it != info_list.end(); ++it) { 212 it != info_list.end(); ++it) {
213 // Load resources for WebStore component extension.
214 if (load_info.extension_id == extension_misc::kWebStoreAppId) {
215 if (!loader_)
216 loader_ = new ImageLoader(this);
217 loader_->LoadResource(it->resource, it->max_size, id, IDR_WEBSTORE_ICON);
218 continue;
219 }
220
187 // If we don't have a path we don't need to do any further work, just 221 // If we don't have a path we don't need to do any further work, just
188 // respond back. 222 // respond back.
189 if (it->resource.relative_path().empty()) { 223 if (it->resource.relative_path().empty()) {
190 OnImageLoaded(NULL, it->resource, it->max_size, id, false); 224 OnImageLoaded(NULL, it->resource, it->max_size, id, false);
191 continue; 225 continue;
192 } 226 }
193 227
194 DCHECK(extension->path() == it->resource.extension_root()); 228 DCHECK(extension->path() == it->resource.extension_root());
195 229
196 // See if the extension has the image already. 230 // See if the extension has the image already.
197 if (extension->HasCachedImage(it->resource, it->max_size)) { 231 if (extension->HasCachedImage(it->resource, it->max_size)) {
198 SkBitmap image = extension->GetCachedImage(it->resource, it->max_size); 232 SkBitmap image = extension->GetCachedImage(it->resource, it->max_size);
199 OnImageLoaded(&image, it->resource, it->max_size, id, false); 233 OnImageLoaded(&image, it->resource, it->max_size, id, false);
200 continue; 234 continue;
201 } 235 }
202 236
203 // Instruct the ImageLoader to load this on the File thread. LoadImage does 237 // Instruct the ImageLoader to load this on the File thread. LoadImage and
204 // not block. 238 // LoadResource do not block.
205 if (!loader_) 239 if (!loader_)
206 loader_ = new ImageLoader(this); 240 loader_ = new ImageLoader(this);
207 loader_->LoadImage(it->resource, it->max_size, id); 241
242 int resource_id;
243 if (IsComponentExtensionResource(extension, it->resource, resource_id))
244 loader_->LoadResource(it->resource, it->max_size, id, resource_id);
245 else
246 loader_->LoadImage(it->resource, it->max_size, id);
208 } 247 }
209 } 248 }
210 249
250 bool ImageLoadingTracker::IsComponentExtensionResource(
251 const Extension* extension,
252 const ExtensionResource& resource,
253 int& resource_id) const {
254 if (extension->location() != Extension::COMPONENT)
255 return false;
256
257 FilePath directory_path = extension->path();
258 FilePath relative_path = directory_path.BaseName().Append(
259 resource.relative_path());
260
261 for (size_t i = 0; i < kComponentExtensionResourcesSize; ++i) {
262 FilePath resource_path =
263 FilePath().AppendASCII(kComponentExtensionResources[i].name);
264 resource_path = resource_path.NormalizePathSeparators();
265
266 if (relative_path == resource_path) {
267 resource_id = kComponentExtensionResources[i].value;
268 return true;
269 }
270 }
271 return false;
272 }
273
211 void ImageLoadingTracker::OnImageLoaded( 274 void ImageLoadingTracker::OnImageLoaded(
212 SkBitmap* image, 275 SkBitmap* image,
213 const ExtensionResource& resource, 276 const ExtensionResource& resource,
214 const gfx::Size& original_size, 277 const gfx::Size& original_size,
215 int id, 278 int id,
216 bool should_cache) { 279 bool should_cache) {
217 LoadMap::iterator load_map_it = load_map_.find(id); 280 LoadMap::iterator load_map_it = load_map_.find(id);
218 DCHECK(load_map_it != load_map_.end()); 281 DCHECK(load_map_it != load_map_.end());
219 PendingLoadInfo* info = &load_map_it->second; 282 PendingLoadInfo* info = &load_map_it->second;
220 283
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 // Remove reference to this extension from all pending load entries. This 329 // 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. 330 // 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) { 331 for (LoadMap::iterator i = load_map_.begin(); i != load_map_.end(); ++i) {
269 PendingLoadInfo* info = &i->second; 332 PendingLoadInfo* info = &i->second;
270 if (info->extension == extension) { 333 if (info->extension == extension) {
271 info->extension = NULL; 334 info->extension = NULL;
272 info->cache = DONT_CACHE; 335 info->cache = DONT_CACHE;
273 } 336 }
274 } 337 }
275 } 338 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/image_loading_tracker.h ('k') | chrome/browser/extensions/image_loading_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698