Index: chrome/browser/extensions/extension_action_icon_factory.h |
diff --git a/chrome/browser/extensions/extension_action_icon_factory.h b/chrome/browser/extensions/extension_action_icon_factory.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..fe7ec546e83d8d7508172fe7e744e047970d0726 |
--- /dev/null |
+++ b/chrome/browser/extensions/extension_action_icon_factory.h |
@@ -0,0 +1,60 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_ICON_FACTORY_H_ |
+#define CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_ICON_FACTORY_H_ |
+ |
+#include "base/memory/scoped_ptr.h" |
+#include "chrome/browser/extensions/extension_icon_image.h" |
+#include "chrome/common/extensions/extension_icon_factory_delegate.h" |
+ |
+class ExtensionIconSet; |
+ |
+namespace extensions { |
+class Extension; |
+} |
+ |
+// Used to creates new image skia icon for extension actions using |
+// extensions::IconImage. |
+// It observes underlaying IconImage and notifies its own observer when the icon |
+// image changes. |
+class ExtensionActionIconFactory : public extensions::IconImage::Observer, |
+ public ExtensionIconFactoryDelegate { |
+ public: |
+ class Observer { |
+ public: |
+ virtual ~Observer() {} |
+ // Called when the underlying image changes. |
+ virtual void OnIconUpdated() = 0; |
+ }; |
+ |
+ // Observer should outlive this. |
+ ExtensionActionIconFactory(const extensions::Extension* extension, |
+ Observer* observer); |
+ virtual ~ExtensionActionIconFactory(); |
+ |
+ // extensions::IconImage override. |
+ virtual void OnExtensionIconImageChanged( |
+ extensions::IconImage* image) OVERRIDE; |
+ |
+ // ExtensionIconFactoryDelegate override. |
+ // Returns icon created using extensions::IconImage from |icon_set| with the |
+ // desired size. If the previous icon was requested using the same icon set |
+ // and desired size, that icon is returned. Else, new IconImage is created. |
+ // The icon can be loaded asynchronously. In that case the observer will be |
+ // notified when the icon gets updated. |
+ virtual gfx::ImageSkia GetIcon(const ExtensionIconSet* icon_set, |
+ const gfx::Size& desired_size) OVERRIDE; |
+ |
+ private: |
+ const extensions::Extension* extension_; |
+ Observer* observer_; |
+ const ExtensionIconSet* last_icon_set_; |
+ gfx::Size last_size_; |
+ scoped_ptr<extensions::IconImage> icon_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ExtensionActionIconFactory); |
+}; |
+ |
+#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_ICON_FACTORY_H_ |