OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_ICON_FACTORY_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_ICON_FACTORY_H_ |
| 7 |
| 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "chrome/browser/extensions/extension_icon_image.h" |
| 10 #include "chrome/common/extensions/extension_icon_factory_delegate.h" |
| 11 |
| 12 class ExtensionIconSet; |
| 13 |
| 14 namespace extensions { |
| 15 class Extension; |
| 16 } |
| 17 |
| 18 // Used to creates new image skia icon for extension actions using |
| 19 // extensions::IconImage. |
| 20 // It observes underlaying IconImage and notifies its own observer when the icon |
| 21 // image changes. |
| 22 class ExtensionActionIconFactory : public extensions::IconImage::Observer, |
| 23 public ExtensionIconFactoryDelegate { |
| 24 public: |
| 25 class Observer { |
| 26 public: |
| 27 virtual ~Observer() {} |
| 28 // Called when the underlying image changes. |
| 29 virtual void OnIconUpdated() = 0; |
| 30 }; |
| 31 |
| 32 // Observer should outlive this. |
| 33 ExtensionActionIconFactory(const extensions::Extension* extension, |
| 34 Observer* observer); |
| 35 virtual ~ExtensionActionIconFactory(); |
| 36 |
| 37 // extensions::IconImage override. |
| 38 virtual void OnExtensionIconImageChanged( |
| 39 extensions::IconImage* image) OVERRIDE; |
| 40 |
| 41 // ExtensionIconFactoryDelegate override. |
| 42 // Returns icon created using extensions::IconImage from |icon_set| with the |
| 43 // desired size. If the previous requested icon had the same icon set, that |
| 44 // icon is returned. Else, new IconImage is created. |
| 45 // It is assumed that request with the same |icon_set| also have the same |
| 46 // |desired_size|. |
| 47 // The icon can be loaded asynchronously. In that case the observer will be |
| 48 // notified when the icon gets updated. |
| 49 virtual gfx::ImageSkia GetIcon(const ExtensionIconSet* icon_set, |
| 50 int desired_size) OVERRIDE; |
| 51 |
| 52 private: |
| 53 const extensions::Extension* extension_; |
| 54 Observer* observer_; |
| 55 const ExtensionIconSet* last_icon_set_; |
| 56 int last_size_; |
| 57 scoped_ptr<extensions::IconImage> icon_; |
| 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(ExtensionActionIconFactory); |
| 60 }; |
| 61 |
| 62 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_ICON_FACTORY_H_ |
OLD | NEW |