diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-30 20:40:18 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-30 20:40:18 +0000 |
commit | d9ad80fce90880db9b63f59206ba106d203a4976 (patch) | |
tree | 57107f54ee4db32ed51ea5116f4faef575c209ae /chrome/common/extensions | |
parent | 94c682ee504e8ea9e74a051e9b172468f62b1526 (diff) | |
download | chromium_src-d9ad80fce90880db9b63f59206ba106d203a4976.zip chromium_src-d9ad80fce90880db9b63f59206ba106d203a4976.tar.gz chromium_src-d9ad80fce90880db9b63f59206ba106d203a4976.tar.bz2 |
Attempt 2 at landing this. Patch is exactly same as last time around.
Adds ability for ImageLoadingTracker to cache images.
BUG=none
TEST=none
TBR=aa@chromium.org
Review URL: http://codereview.chromium.org/1534006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43130 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions')
-rw-r--r-- | chrome/common/extensions/extension.cc | 22 | ||||
-rw-r--r-- | chrome/common/extensions/extension.h | 13 | ||||
-rw-r--r-- | chrome/common/extensions/extension_extent.cc | 2 | ||||
-rw-r--r-- | chrome/common/extensions/extension_extent.h | 2 |
4 files changed, 37 insertions, 2 deletions
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index 98a2f84..7deff53 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -1474,6 +1474,28 @@ void Extension::SetBackgroundPageReady() { NotificationService::NoDetails()); } +void Extension::SetCachedImage(const ExtensionResource& source, + const SkBitmap& image) { + DCHECK(source.extension_root() == path()); // The resource must come from + // this extension. + image_cache_[source.relative_path()] = image; + +} +bool Extension::HasCachedImage(const ExtensionResource& source) { + DCHECK(source.extension_root() == path()); // The resource must come from + // this extension. + return image_cache_.find(source.relative_path()) != image_cache_.end(); +} + +SkBitmap Extension::GetCachedImage(const ExtensionResource& source) { + DCHECK(source.extension_root() == path()); // The resource must come from + // this extension. + ImageCache::iterator i = image_cache_.find(source.relative_path()); + if (i == image_cache_.end()) + return SkBitmap(); + return i->second; +} + ExtensionResource Extension::GetIconPath(Icons icon) { std::map<int, std::string>::const_iterator iter = icons_.find(icon); if (iter == icons_.end()) diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h index 0129858..f4c797e 100644 --- a/chrome/common/extensions/extension.h +++ b/chrome/common/extensions/extension.h @@ -21,6 +21,7 @@ #include "chrome/common/extensions/url_pattern.h" #include "googleurl/src/gurl.h" #include "testing/gtest/include/gtest/gtest_prod.h" +#include "third_party/skia/include/core/SkBitmap.h" // Represents a Chrome extension. class Extension { @@ -323,7 +324,16 @@ class Extension { bool being_upgraded() const { return being_upgraded_; } void set_being_upgraded(bool value) { being_upgraded_ = value; } + // Image cache related methods. These are only valid on the UI thread and + // not maintained by this class. See ImageLoadingTracker for usage. + void SetCachedImage(const ExtensionResource& source, + const SkBitmap& image); + bool HasCachedImage(const ExtensionResource& source); + SkBitmap GetCachedImage(const ExtensionResource& source); + private: + typedef std::map<FilePath, SkBitmap> ImageCache; + // Helper method that loads a UserScript object from a // dictionary in the content_script list of the manifest. bool LoadUserScriptHelper(const DictionaryValue* content_script, @@ -478,6 +488,9 @@ class Extension { // The type of container to launch into. LaunchContainer launch_container_; + // Cached images for this extension. This maps from the relative_path of the + // resource to the cached image. + ImageCache image_cache_; // Runtime data: diff --git a/chrome/common/extensions/extension_extent.cc b/chrome/common/extensions/extension_extent.cc index 310673e..3fbb994 100644 --- a/chrome/common/extensions/extension_extent.cc +++ b/chrome/common/extensions/extension_extent.cc @@ -6,7 +6,7 @@ #include "base/string_util.h" -bool ExtensionExtent::ContainsURL(const GURL& url) { +bool ExtensionExtent::ContainsURL(const GURL& url) const { if (!url.is_valid()) return false; diff --git a/chrome/common/extensions/extension_extent.h b/chrome/common/extensions/extension_extent.h index 76670ab..187303d 100644 --- a/chrome/common/extensions/extension_extent.h +++ b/chrome/common/extensions/extension_extent.h @@ -20,7 +20,7 @@ class ExtensionExtent { const GURL& origin() const { return origin_; } void set_origin(const GURL& val) { origin_ = val; } - bool ContainsURL(const GURL& url); + bool ContainsURL(const GURL& url) const; private: // The security origin (scheme+host+port) of the extent. |