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

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: 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 #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/chrome_unscaled_resources.h"
25 #include "grit/theme_resources.h"
26 #include "skia/ext/image_operations.h" 22 #include "skia/ext/image_operations.h"
27 #include "third_party/skia/include/core/SkBitmap.h" 23 #include "third_party/skia/include/core/SkBitmap.h"
28 #include "ui/base/resource/resource_bundle.h" 24 #include "ui/base/resource/resource_bundle.h"
29 #include "ui/gfx/image/image.h" 25 #include "ui/gfx/image/image.h"
30 #include "ui/gfx/image/image_skia_rep.h" 26 #include "ui/gfx/image/image_skia_rep.h"
31 #include "webkit/glue/image_decoder.h" 27 #include "webkit/glue/image_decoder.h"
32 28
33 using content::BrowserThread; 29 using content::BrowserThread;
34 using extensions::Extension; 30 using extensions::Extension;
35 31
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 OnBitmapLoaded(&bitmap, *it, it->desired_size, id, false); 298 OnBitmapLoaded(&bitmap, *it, it->desired_size, id, false);
303 continue; 299 continue;
304 } 300 }
305 301
306 // 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
307 // LoadResource do not block. 303 // LoadResource do not block.
308 if (!loader_) 304 if (!loader_)
309 loader_ = new ImageLoader(this); 305 loader_ = new ImageLoader(this);
310 306
311 int resource_id = -1; 307 int resource_id = -1;
312 if (IsComponentExtensionResource(extension, it->resource.relative_path(), 308 if (extensions::ImageLoader::IsComponentExtensionResource(
313 &resource_id)) 309 extension, it->resource.relative_path(), &resource_id))
314 loader_->LoadResource(*it, id, resource_id); 310 loader_->LoadResource(*it, id, resource_id);
315 else 311 else
316 loader_->LoadImage(*it, id); 312 loader_->LoadImage(*it, id);
317 } 313 }
318 } 314 }
319 315
320 bool ImageLoadingTracker::IsComponentExtensionResource(
321 const Extension* extension,
322 const FilePath& resource_path,
323 int* resource_id) {
324 static const GritResourceMap kExtraComponentExtensionResources[] = {
325 {"web_store/webstore_icon_128.png", IDR_WEBSTORE_ICON},
326 {"web_store/webstore_icon_16.png", IDR_WEBSTORE_ICON_16},
327 {"chrome_app/product_logo_128.png", IDR_PRODUCT_LOGO_128},
328 {"chrome_app/product_logo_16.png", IDR_PRODUCT_LOGO_16},
329 {"settings_app/settings_app_icon_128.png", IDR_SETTINGS_APP_ICON_128},
330 {"settings_app/settings_app_icon_16.png", IDR_SETTINGS_APP_ICON_16},
331 };
332 static const size_t kExtraComponentExtensionResourcesSize =
333 arraysize(kExtraComponentExtensionResources);
334
335 if (extension->location() != Extension::COMPONENT)
336 return false;
337
338 FilePath directory_path = extension->path();
339 FilePath resources_dir;
340 FilePath relative_path;
341 if (!PathService::Get(chrome::DIR_RESOURCES, &resources_dir) ||
342 !resources_dir.AppendRelativePath(directory_path, &relative_path)) {
343 return false;
344 }
345 relative_path = relative_path.Append(resource_path);
346 relative_path = relative_path.NormalizePathSeparators();
347
348 // TODO(tc): Make a map of FilePath -> resource ids so we don't have to
349 // covert to FilePaths all the time. This will be more useful as we add
350 // more resources.
351 for (size_t i = 0; i < kComponentExtensionResourcesSize; ++i) {
352 FilePath resource_path =
353 FilePath().AppendASCII(kComponentExtensionResources[i].name);
354 resource_path = resource_path.NormalizePathSeparators();
355
356 if (relative_path == resource_path) {
357 *resource_id = kComponentExtensionResources[i].value;
358 return true;
359 }
360 }
361 for (size_t i = 0; i < kExtraComponentExtensionResourcesSize; ++i) {
362 FilePath resource_path =
363 FilePath().AppendASCII(kExtraComponentExtensionResources[i].name);
364 resource_path = resource_path.NormalizePathSeparators();
365
366 if (relative_path == resource_path) {
367 *resource_id = kExtraComponentExtensionResources[i].value;
368 return true;
369 }
370 }
371 return false;
372 }
373
374 void ImageLoadingTracker::OnBitmapLoaded( 316 void ImageLoadingTracker::OnBitmapLoaded(
375 const SkBitmap* bitmap, 317 const SkBitmap* bitmap,
376 const ImageRepresentation& image_info, 318 const ImageRepresentation& image_info,
377 const gfx::Size& original_size, 319 const gfx::Size& original_size,
378 int id, 320 int id,
379 bool should_cache) { 321 bool should_cache) {
380 LoadMap::iterator load_map_it = load_map_.find(id); 322 LoadMap::iterator load_map_it = load_map_.find(id);
381 DCHECK(load_map_it != load_map_.end()); 323 DCHECK(load_map_it != load_map_.end());
382 PendingLoadInfo* info = &load_map_it->second; 324 PendingLoadInfo* info = &load_map_it->second;
383 325
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 // Remove reference to this extension from all pending load entries. This 369 // Remove reference to this extension from all pending load entries. This
428 // 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.
429 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) {
430 PendingLoadInfo* info = &i->second; 372 PendingLoadInfo* info = &i->second;
431 if (info->extension == extension) { 373 if (info->extension == extension) {
432 info->extension = NULL; 374 info->extension = NULL;
433 info->cache = DONT_CACHE; 375 info->cache = DONT_CACHE;
434 } 376 }
435 } 377 }
436 } 378 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698