OLD | NEW |
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_BACKGROUND_BACKGROUND_APPLICATION_LIST_MODEL_H_ | 5 #ifndef CHROME_BROWSER_BACKGROUND_BACKGROUND_APPLICATION_LIST_MODEL_H_ |
6 #define CHROME_BROWSER_BACKGROUND_BACKGROUND_APPLICATION_LIST_MODEL_H_ | 6 #define CHROME_BROWSER_BACKGROUND_BACKGROUND_APPLICATION_LIST_MODEL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
(...skipping 13 matching lines...) Expand all Loading... |
24 public: | 24 public: |
25 // Observer is informed of changes to the model. Users of the | 25 // Observer is informed of changes to the model. Users of the |
26 // BackgroundApplicationListModel should anticipate that associated data, | 26 // BackgroundApplicationListModel should anticipate that associated data, |
27 // e. g. the Icon, may exist and yet not be immediately available. When the | 27 // e. g. the Icon, may exist and yet not be immediately available. When the |
28 // data becomes available, OnApplicationDataChanged will be invoked for all | 28 // data becomes available, OnApplicationDataChanged will be invoked for all |
29 // Observers of the model. | 29 // Observers of the model. |
30 class Observer { | 30 class Observer { |
31 public: | 31 public: |
32 // Invoked when data that the model associates with the extension, such as | 32 // Invoked when data that the model associates with the extension, such as |
33 // the Icon, has changed. | 33 // the Icon, has changed. |
34 virtual void OnApplicationDataChanged(const Extension* extension, | 34 virtual void OnApplicationDataChanged( |
35 Profile* profile); | 35 const extensions::Extension* extension, |
| 36 Profile* profile); |
36 | 37 |
37 // Invoked when the model detects a previously unknown extension and/or when | 38 // Invoked when the model detects a previously unknown extension and/or when |
38 // it no longer detects a previously known extension. | 39 // it no longer detects a previously known extension. |
39 virtual void OnApplicationListChanged(Profile* profile); | 40 virtual void OnApplicationListChanged(Profile* profile); |
40 | 41 |
41 protected: | 42 protected: |
42 virtual ~Observer(); | 43 virtual ~Observer(); |
43 }; | 44 }; |
44 | 45 |
45 // Create a new model associated with profile. | 46 // Create a new model associated with profile. |
46 explicit BackgroundApplicationListModel(Profile* profile); | 47 explicit BackgroundApplicationListModel(Profile* profile); |
47 | 48 |
48 virtual ~BackgroundApplicationListModel(); | 49 virtual ~BackgroundApplicationListModel(); |
49 | 50 |
50 // Associate observer with this model. | 51 // Associate observer with this model. |
51 void AddObserver(Observer* observer); | 52 void AddObserver(Observer* observer); |
52 | 53 |
53 // Return the icon associated with |extension| or NULL. NULL indicates either | 54 // Return the icon associated with |extension| or NULL. NULL indicates either |
54 // that there is no icon associated with the extension, or that a pending | 55 // that there is no icon associated with the extension, or that a pending |
55 // task to retrieve the icon has not completed. See the Observer class above. | 56 // task to retrieve the icon has not completed. See the Observer class above. |
56 // | 57 // |
57 // NOTE: The model manages the SkBitmap result, that is it "owns" the memory, | 58 // NOTE: The model manages the SkBitmap result, that is it "owns" the memory, |
58 // releasing it if the associated background application is unloaded. | 59 // releasing it if the associated background application is unloaded. |
59 // NOTE: All icons are currently sized as | 60 // NOTE: All icons are currently sized as |
60 // ExtensionIconSet::EXTENSION_ICON_BITTY. | 61 // ExtensionIconSet::EXTENSION_ICON_BITTY. |
61 const SkBitmap* GetIcon(const Extension* extension); | 62 const SkBitmap* GetIcon(const extensions::Extension* extension); |
62 | 63 |
63 // Return the position of |extension| within this list model. | 64 // Return the position of |extension| within this list model. |
64 int GetPosition(const Extension* extension) const; | 65 int GetPosition(const extensions::Extension* extension) const; |
65 | 66 |
66 // Return the extension at the specified |position| in this list model. | 67 // Return the extension at the specified |position| in this list model. |
67 const Extension* GetExtension(int position) const; | 68 const extensions::Extension* GetExtension(int position) const; |
68 | 69 |
69 // Returns true if the passed extension is a background app. | 70 // Returns true if the passed extension is a background app. |
70 static bool IsBackgroundApp(const Extension& extension, | 71 static bool IsBackgroundApp(const extensions::Extension& extension, |
71 Profile* profile); | 72 Profile* profile); |
72 | 73 |
73 // Dissociate observer from this model. | 74 // Dissociate observer from this model. |
74 void RemoveObserver(Observer* observer); | 75 void RemoveObserver(Observer* observer); |
75 | 76 |
76 ExtensionList::const_iterator begin() const { | 77 extensions::ExtensionList::const_iterator begin() const { |
77 return extensions_.begin(); | 78 return extensions_.begin(); |
78 } | 79 } |
79 | 80 |
80 ExtensionList::const_iterator end() const { | 81 extensions::ExtensionList::const_iterator end() const { |
81 return extensions_.end(); | 82 return extensions_.end(); |
82 } | 83 } |
83 | 84 |
84 size_t size() const { | 85 size_t size() const { |
85 return extensions_.size(); | 86 return extensions_.size(); |
86 } | 87 } |
87 | 88 |
88 private: | 89 private: |
89 // Contains data associated with a background application that is not | 90 // Contains data associated with a background application that is not |
90 // represented by the Extension class. | 91 // represented by the Extension class. |
91 class Application; | 92 class Application; |
92 | 93 |
93 // Associates extension id strings with Application objects. | 94 // Associates extension id strings with Application objects. |
94 typedef std::map<std::string, Application*> ApplicationMap; | 95 typedef std::map<std::string, Application*> ApplicationMap; |
95 | 96 |
96 // Identifies and caches data related to the extension. | 97 // Identifies and caches data related to the extension. |
97 void AssociateApplicationData(const Extension* extension); | 98 void AssociateApplicationData(const extensions::Extension* extension); |
98 | 99 |
99 // Clears cached data related to |extension|. | 100 // Clears cached data related to |extension|. |
100 void DissociateApplicationData(const Extension* extension); | 101 void DissociateApplicationData(const extensions::Extension* extension); |
101 | 102 |
102 // Returns the Application associated with |extension| or NULL. | 103 // Returns the Application associated with |extension| or NULL. |
103 const Application* FindApplication(const Extension* extension) const; | 104 const Application* FindApplication( |
| 105 const extensions::Extension* extension) const; |
104 | 106 |
105 // Returns the Application associated with |extension| or NULL. | 107 // Returns the Application associated with |extension| or NULL. |
106 Application* FindApplication(const Extension* extension); | 108 Application* FindApplication(const extensions::Extension* extension); |
107 | 109 |
108 // content::NotificationObserver implementation. | 110 // content::NotificationObserver implementation. |
109 virtual void Observe(int type, | 111 virtual void Observe(int type, |
110 const content::NotificationSource& source, | 112 const content::NotificationSource& source, |
111 const content::NotificationDetails& details) OVERRIDE; | 113 const content::NotificationDetails& details) OVERRIDE; |
112 | 114 |
113 // Notifies observers that some of the data associated with this background | 115 // Notifies observers that some of the data associated with this background |
114 // application, e. g. the Icon, has changed. | 116 // application, e. g. the Icon, has changed. |
115 void SendApplicationDataChangedNotifications(const Extension* extension); | 117 void SendApplicationDataChangedNotifications( |
| 118 const extensions::Extension* extension); |
116 | 119 |
117 // Notifies observers that at least one background application has been added | 120 // Notifies observers that at least one background application has been added |
118 // or removed. | 121 // or removed. |
119 void SendApplicationListChangedNotifications(); | 122 void SendApplicationListChangedNotifications(); |
120 | 123 |
121 // Invoked by Observe for NOTIFICATION_EXTENSION_LOADED. | 124 // Invoked by Observe for NOTIFICATION_EXTENSION_LOADED. |
122 void OnExtensionLoaded(const Extension* extension); | 125 void OnExtensionLoaded(const extensions::Extension* extension); |
123 | 126 |
124 // Invoked by Observe for NOTIFICATION_EXTENSION_UNLOADED. | 127 // Invoked by Observe for NOTIFICATION_EXTENSION_UNLOADED. |
125 void OnExtensionUnloaded(const Extension* extension); | 128 void OnExtensionUnloaded(const extensions::Extension* extension); |
126 | 129 |
127 // Invoked by Observe for NOTIFICATION_EXTENSION_PERMISSIONS_UPDATED. | 130 // Invoked by Observe for NOTIFICATION_EXTENSION_PERMISSIONS_UPDATED. |
128 void OnExtensionPermissionsUpdated( | 131 void OnExtensionPermissionsUpdated( |
129 const Extension* extension, | 132 const extensions::Extension* extension, |
130 UpdatedExtensionPermissionsInfo::Reason reason, | 133 extensions::UpdatedExtensionPermissionsInfo::Reason reason, |
131 const ExtensionPermissionSet* permissions); | 134 const ExtensionPermissionSet* permissions); |
132 | 135 |
133 // Refresh the list of background applications and generate notifications. | 136 // Refresh the list of background applications and generate notifications. |
134 void Update(); | 137 void Update(); |
135 | 138 |
136 ApplicationMap applications_; | 139 ApplicationMap applications_; |
137 ExtensionList extensions_; | 140 extensions::ExtensionList extensions_; |
138 ObserverList<Observer> observers_; | 141 ObserverList<Observer> observers_; |
139 Profile* profile_; | 142 Profile* profile_; |
140 content::NotificationRegistrar registrar_; | 143 content::NotificationRegistrar registrar_; |
141 | 144 |
142 DISALLOW_COPY_AND_ASSIGN(BackgroundApplicationListModel); | 145 DISALLOW_COPY_AND_ASSIGN(BackgroundApplicationListModel); |
143 }; | 146 }; |
144 | 147 |
145 #endif // CHROME_BROWSER_BACKGROUND_BACKGROUND_APPLICATION_LIST_MODEL_H_ | 148 #endif // CHROME_BROWSER_BACKGROUND_BACKGROUND_APPLICATION_LIST_MODEL_H_ |
OLD | NEW |