| 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_EXTENSIONS_EXTENSION_WARNING_SET_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/memory/linked_ptr.h" | 12 #include "base/memory/linked_ptr.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/observer_list.h" |
| 14 #include "base/string16.h" | 15 #include "base/string16.h" |
| 15 #include "base/threading/non_thread_safe.h" | 16 #include "base/threading/non_thread_safe.h" |
| 16 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 17 | 18 |
| 18 class ExtensionGlobalErrorBadge; | 19 class ExtensionGlobalErrorBadge; |
| 19 class ExtensionService; | 20 class ExtensionService; |
| 20 class Profile; | 21 class Profile; |
| 21 | 22 |
| 22 // TODO(battre) Remove the Extension prefix. | 23 // TODO(battre) Remove the Extension prefix. |
| 23 | 24 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 129 |
| 129 DISALLOW_COPY_AND_ASSIGN(ExtensionWarningSet); | 130 DISALLOW_COPY_AND_ASSIGN(ExtensionWarningSet); |
| 130 }; | 131 }; |
| 131 | 132 |
| 132 // Manages a set of warnings caused by extensions. These warnings (e.g. | 133 // Manages a set of warnings caused by extensions. These warnings (e.g. |
| 133 // conflicting modifications of network requests by extensions, slow extensions, | 134 // conflicting modifications of network requests by extensions, slow extensions, |
| 134 // etc.) trigger a warning badge in the UI and and provide means to resolve | 135 // etc.) trigger a warning badge in the UI and and provide means to resolve |
| 135 // them. This class must be used on the UI thread only. | 136 // them. This class must be used on the UI thread only. |
| 136 class ExtensionWarningService : public base::NonThreadSafe { | 137 class ExtensionWarningService : public base::NonThreadSafe { |
| 137 public: | 138 public: |
| 139 class Observer { |
| 140 public: |
| 141 virtual void ExtensionWarningsChanged() = 0; |
| 142 }; |
| 143 |
| 138 // |profile| may be NULL for testing. In this case, be sure to not insert | 144 // |profile| may be NULL for testing. In this case, be sure to not insert |
| 139 // any warnings. | 145 // any warnings. |
| 140 explicit ExtensionWarningService(Profile* profile); | 146 explicit ExtensionWarningService(Profile* profile); |
| 141 virtual ~ExtensionWarningService(); | 147 virtual ~ExtensionWarningService(); |
| 142 | 148 |
| 143 // Clears all warnings of types contained in |types| and triggers a | 149 // Clears all warnings of types contained in |types| and triggers a |
| 144 // chrome::NOTIFICATION_EXTENSION_WARNING message if such warnings existed. | 150 // chrome::NOTIFICATION_EXTENSION_WARNING message if such warnings existed. |
| 145 // If no warning remains that is not suppressed, this may deactivate a | 151 // If no warning remains that is not suppressed, this may deactivate a |
| 146 // warning badge on the wrench mennu. | 152 // warning badge on the wrench mennu. |
| 147 void ClearWarnings(const std::set<ExtensionWarning::WarningType>& types); | 153 void ClearWarnings(const std::set<ExtensionWarning::WarningType>& types); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 167 // If the warning is new and has not been suppressed, this may activate a | 173 // If the warning is new and has not been suppressed, this may activate a |
| 168 // badge on the wrench menu. | 174 // badge on the wrench menu. |
| 169 void AddWarnings(scoped_ptr<ExtensionWarningSet> warnings); | 175 void AddWarnings(scoped_ptr<ExtensionWarningSet> warnings); |
| 170 | 176 |
| 171 // Notifies the ExtensionWarningService of profile |profile_id| that new | 177 // Notifies the ExtensionWarningService of profile |profile_id| that new |
| 172 // |warnings| occurred and triggers a warning badge. | 178 // |warnings| occurred and triggers a warning badge. |
| 173 static void NotifyWarningsOnUI( | 179 static void NotifyWarningsOnUI( |
| 174 void* profile_id, | 180 void* profile_id, |
| 175 scoped_ptr<ExtensionWarningSet> warnings); | 181 scoped_ptr<ExtensionWarningSet> warnings); |
| 176 | 182 |
| 183 void AddObserver(Observer* observer); |
| 184 void RemoveObserver(Observer* observer); |
| 185 |
| 177 protected: | 186 protected: |
| 178 // Virtual for testing. | 187 // Virtual for testing. |
| 179 virtual void NotifyWarningsChanged(); | 188 virtual void NotifyWarningsChanged(); |
| 180 | 189 |
| 181 private: | 190 private: |
| 182 typedef std::set<linked_ptr<ExtensionWarning> >::const_iterator | 191 typedef std::set<linked_ptr<ExtensionWarning> >::const_iterator |
| 183 const_iterator; | 192 const_iterator; |
| 184 typedef std::set<linked_ptr<ExtensionWarning> >::iterator iterator; | 193 typedef std::set<linked_ptr<ExtensionWarning> >::iterator iterator; |
| 185 | 194 |
| 186 // Shows or hides the warning badge on the wrench menu depending on whether | 195 // Shows or hides the warning badge on the wrench menu depending on whether |
| 187 // any non-suppressed warnings exist. | 196 // any non-suppressed warnings exist. |
| 188 void UpdateWarningBadge(); | 197 void UpdateWarningBadge(); |
| 189 | 198 |
| 190 // Currently existing warnings. | 199 // Currently existing warnings. |
| 191 std::set<linked_ptr<ExtensionWarning> > warnings_; | 200 std::set<linked_ptr<ExtensionWarning> > warnings_; |
| 192 | 201 |
| 193 // Warnings that do not trigger a badge on the wrench menu. | 202 // Warnings that do not trigger a badge on the wrench menu. |
| 194 std::set<linked_ptr<ExtensionWarning> > badge_suppressions_; | 203 std::set<linked_ptr<ExtensionWarning> > badge_suppressions_; |
| 195 | 204 |
| 196 Profile* profile_; | 205 Profile* profile_; |
| 206 |
| 207 ObserverList<Observer> observer_list_; |
| 197 }; | 208 }; |
| 198 | 209 |
| 199 } // namespace extensions | 210 } // namespace extensions |
| 200 | 211 |
| 201 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_ | 212 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_ |
| OLD | NEW |