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

Side by Side Diff: chrome/browser/extensions/extension_action_icon_factory.h

Issue 885443004: [Extensions] Cache extension action icons (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_ICON_FACTORY_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_ICON_FACTORY_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_ICON_FACTORY_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_ICON_FACTORY_H_
7 7
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/scoped_observer.h"
9 #include "extensions/browser/extension_icon_image.h" 10 #include "extensions/browser/extension_icon_image.h"
10 11
11 class ExtensionAction; 12 class ExtensionAction;
12 class ExtensionIconSet; 13 class ExtensionIconSet;
13 class Profile; 14 class Profile;
14 15
15 namespace extensions { 16 namespace extensions {
16 class Extension; 17 class Extension;
17 } 18 }
18 19
19 // Used to get an icon to be used in the UI for an extension action. 20 // Used to get an icon to be used in the UI for an extension action.
20 // If the extension action icon is the default icon defined in the extension's 21 // If the extension action icon is the default icon defined in the extension's
21 // manifest, it is loaded using extensions::IconImage. This icon can be loaded 22 // manifest, it is loaded using extensions::IconImage. This icon can be loaded
22 // asynchronously. The factory observes underlying IconImage and notifies its 23 // asynchronously. The factory observes underlying IconImage and notifies its
23 // own observer when the icon image changes. 24 // own observer when the icon image changes.
24 class ExtensionActionIconFactory : public extensions::IconImage::Observer { 25 class ExtensionActionIconFactory : public extensions::IconImage::Observer {
25 public: 26 public:
26 class Observer { 27 class Observer {
27 public: 28 public:
28 virtual ~Observer() {} 29 virtual ~Observer() {}
29 // Called when the underlying icon image changes. 30 // Called when the underlying icon image changes.
30 virtual void OnIconUpdated() = 0; 31 virtual void OnIconUpdated() = 0;
31 }; 32 };
32 33
33 // Observer should outlive this. 34 // Observer should outlive this.
34 ExtensionActionIconFactory(Profile* profile, 35 ExtensionActionIconFactory(Profile* profile,
35 const extensions::Extension* extension, 36 const extensions::Extension* extension,
36 const ExtensionAction* action, 37 ExtensionAction* action,
37 Observer* observer); 38 Observer* observer);
38 ~ExtensionActionIconFactory() override; 39 ~ExtensionActionIconFactory() override;
39 40
40 // extensions::IconImage override. 41 // extensions::IconImage override.
41 void OnExtensionIconImageChanged(extensions::IconImage* image) override; 42 void OnExtensionIconImageChanged(extensions::IconImage* image) override;
43 void OnExtensionIconImageDestroyed(extensions::IconImage* image) override;
42 44
43 // Gets the extension action icon for the tab. 45 // Gets the extension action icon for the tab.
44 // If there is an icon set using |SetIcon|, that icon is returned. 46 // If there is an icon set using |SetIcon|, that icon is returned.
45 // Else, if there is a default icon set for the extension action, the icon is 47 // Else, if there is a default icon set for the extension action, the icon is
46 // created using IconImage. Observer is triggered wheniever the icon gets 48 // created using IconImage. Observer is triggered wheniever the icon gets
47 // updated. 49 // updated.
48 // Else, extension favicon is returned. 50 // Else, extension favicon is returned.
49 // In all cases, action's attention and animation icon transformations are 51 // In all cases, action's attention and animation icon transformations are
50 // applied on the icon. 52 // applied on the icon.
51 gfx::Image GetIcon(int tab_id); 53 gfx::Image GetIcon(int tab_id);
52 54
53 private: 55 private:
54 // Gets the icon that should be returned by |GetIcon| (without the attention 56 // Gets the icon that should be returned by |GetIcon| (without the attention
55 // and animation transformations). 57 // and animation transformations).
56 gfx::ImageSkia GetBaseIconFromAction(int tab_id); 58 gfx::ImageSkia GetBaseIconFromAction(int tab_id);
57 59
58 const extensions::Extension* extension_; 60 const extensions::Extension* extension_;
59 const ExtensionAction* action_; 61 const ExtensionAction* action_;
60 Observer* observer_; 62 Observer* observer_;
61 // Underlying icon image for the default icon. 63
62 scoped_ptr<extensions::IconImage> default_icon_; 64 ScopedObserver<extensions::IconImage, extensions::IconImage::Observer>
65 icon_image_observer_;
63 66
64 DISALLOW_COPY_AND_ASSIGN(ExtensionActionIconFactory); 67 DISALLOW_COPY_AND_ASSIGN(ExtensionActionIconFactory);
65 }; 68 };
66 69
67 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_ICON_FACTORY_H_ 70 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_ICON_FACTORY_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_action.cc ('k') | chrome/browser/extensions/extension_action_icon_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698