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

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

Issue 11027044: Add a class to replace ImageLoadingTracker with a nicer API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: SkBitmap* -> SkBitmap Created 8 years, 2 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 <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/path_service.h"
13 #include "base/threading/sequenced_worker_pool.h" 12 #include "base/threading/sequenced_worker_pool.h"
13 #include "chrome/browser/extensions/image_loader.h"
14 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" 14 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
15 #include "chrome/common/chrome_notification_types.h" 15 #include "chrome/common/chrome_notification_types.h"
16 #include "chrome/common/chrome_paths.h"
17 #include "chrome/common/extensions/extension.h" 16 #include "chrome/common/extensions/extension.h"
18 #include "chrome/common/extensions/extension_constants.h" 17 #include "chrome/common/extensions/extension_constants.h"
19 #include "chrome/common/extensions/extension_file_util.h" 18 #include "chrome/common/extensions/extension_file_util.h"
20 #include "chrome/common/extensions/extension_resource.h" 19 #include "chrome/common/extensions/extension_resource.h"
21 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/notification_service.h" 21 #include "content/public/browser/notification_service.h"
23 #include "grit/component_extension_resources_map.h"
24 #include "grit/theme_resources.h"
25 #include "skia/ext/image_operations.h" 22 #include "skia/ext/image_operations.h"
26 #include "third_party/skia/include/core/SkBitmap.h" 23 #include "third_party/skia/include/core/SkBitmap.h"
27 #include "ui/base/resource/resource_bundle.h" 24 #include "ui/base/resource/resource_bundle.h"
28 #include "ui/gfx/image/image.h" 25 #include "ui/gfx/image/image.h"
29 #include "ui/gfx/image/image_skia_rep.h" 26 #include "ui/gfx/image/image_skia_rep.h"
30 #include "webkit/glue/image_decoder.h" 27 #include "webkit/glue/image_decoder.h"
31 28
32 using content::BrowserThread; 29 using content::BrowserThread;
33 using extensions::Extension; 30 using extensions::Extension;
34 31
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 OnBitmapLoaded(&bitmap, *it, it->desired_size, id, false); 298 OnBitmapLoaded(&bitmap, *it, it->desired_size, id, false);
302 continue; 299 continue;
303 } 300 }
304 301
305 // Instruct the ImageLoader to load this on the File thread. LoadImage and 302 // Instruct the ImageLoader to load this on the File thread. LoadImage and
306 // LoadResource do not block. 303 // LoadResource do not block.
307 if (!loader_) 304 if (!loader_)
308 loader_ = new ImageLoader(this); 305 loader_ = new ImageLoader(this);
309 306
310 int resource_id = -1; 307 int resource_id = -1;
311 if (IsComponentExtensionResource(extension, it->resource.relative_path(), 308 if (extensions::ImageLoader::IsComponentExtensionResource(
312 &resource_id)) 309 extension, it->resource.relative_path(), &resource_id))
313 loader_->LoadResource(*it, id, resource_id); 310 loader_->LoadResource(*it, id, resource_id);
314 else 311 else
315 loader_->LoadImage(*it, id); 312 loader_->LoadImage(*it, id);
316 } 313 }
317 } 314 }
318 315
319 bool ImageLoadingTracker::IsComponentExtensionResource(
320 const Extension* extension,
321 const FilePath& resource_path,
322 int* resource_id) {
323 static const GritResourceMap kExtraComponentExtensionResources[] = {
324 {"web_store/webstore_icon_128.png", IDR_WEBSTORE_ICON},
325 {"web_store/webstore_icon_16.png", IDR_WEBSTORE_ICON_16},
326 {"chrome_app/product_logo_128.png", IDR_PRODUCT_LOGO_128},
327 {"chrome_app/product_logo_16.png", IDR_PRODUCT_LOGO_16},
328 };
329 static const size_t kExtraComponentExtensionResourcesSize =
330 arraysize(kExtraComponentExtensionResources);
331
332 if (extension->location() != Extension::COMPONENT)
333 return false;
334
335 FilePath directory_path = extension->path();
336 FilePath resources_dir;
337 FilePath relative_path;
338 if (!PathService::Get(chrome::DIR_RESOURCES, &resources_dir) ||
339 !resources_dir.AppendRelativePath(directory_path, &relative_path)) {
340 return false;
341 }
342 relative_path = relative_path.Append(resource_path);
343 relative_path = relative_path.NormalizePathSeparators();
344
345 // TODO(tc): Make a map of FilePath -> resource ids so we don't have to
346 // covert to FilePaths all the time. This will be more useful as we add
347 // more resources.
348 for (size_t i = 0; i < kComponentExtensionResourcesSize; ++i) {
349 FilePath resource_path =
350 FilePath().AppendASCII(kComponentExtensionResources[i].name);
351 resource_path = resource_path.NormalizePathSeparators();
352
353 if (relative_path == resource_path) {
354 *resource_id = kComponentExtensionResources[i].value;
355 return true;
356 }
357 }
358 for (size_t i = 0; i < kExtraComponentExtensionResourcesSize; ++i) {
359 FilePath resource_path =
360 FilePath().AppendASCII(kExtraComponentExtensionResources[i].name);
361 resource_path = resource_path.NormalizePathSeparators();
362
363 if (relative_path == resource_path) {
364 *resource_id = kExtraComponentExtensionResources[i].value;
365 return true;
366 }
367 }
368 return false;
369 }
370
371 void ImageLoadingTracker::OnBitmapLoaded( 316 void ImageLoadingTracker::OnBitmapLoaded(
372 const SkBitmap* bitmap, 317 const SkBitmap* bitmap,
373 const ImageRepresentation& image_info, 318 const ImageRepresentation& image_info,
374 const gfx::Size& original_size, 319 const gfx::Size& original_size,
375 int id, 320 int id,
376 bool should_cache) { 321 bool should_cache) {
377 LoadMap::iterator load_map_it = load_map_.find(id); 322 LoadMap::iterator load_map_it = load_map_.find(id);
378 DCHECK(load_map_it != load_map_.end()); 323 DCHECK(load_map_it != load_map_.end());
379 PendingLoadInfo* info = &load_map_it->second; 324 PendingLoadInfo* info = &load_map_it->second;
380 325
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 // Remove reference to this extension from all pending load entries. This 369 // Remove reference to this extension from all pending load entries. This
425 // ensures we don't attempt to cache the bitmap when the load completes. 370 // ensures we don't attempt to cache the bitmap when the load completes.
426 for (LoadMap::iterator i = load_map_.begin(); i != load_map_.end(); ++i) { 371 for (LoadMap::iterator i = load_map_.begin(); i != load_map_.end(); ++i) {
427 PendingLoadInfo* info = &i->second; 372 PendingLoadInfo* info = &i->second;
428 if (info->extension == extension) { 373 if (info->extension == extension) {
429 info->extension = NULL; 374 info->extension = NULL;
430 info->cache = DONT_CACHE; 375 info->cache = DONT_CACHE;
431 } 376 }
432 } 377 }
433 } 378 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698