| 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 EXTENSIONS_BROWSER_WARNING_SERVICE_H_ | 5 #ifndef EXTENSIONS_BROWSER_WARNING_SERVICE_H_ |
| 6 #define EXTENSIONS_BROWSER_WARNING_SERVICE_H_ | 6 #define EXTENSIONS_BROWSER_WARNING_SERVICE_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 public base::NonThreadSafe { | 35 public base::NonThreadSafe { |
| 36 public: | 36 public: |
| 37 class Observer { | 37 class Observer { |
| 38 public: | 38 public: |
| 39 virtual void ExtensionWarningsChanged() = 0; | 39 virtual void ExtensionWarningsChanged() = 0; |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 // |browser_context| may be NULL for testing. In this case, be sure to not | 42 // |browser_context| may be NULL for testing. In this case, be sure to not |
| 43 // insert any warnings. | 43 // insert any warnings. |
| 44 explicit WarningService(content::BrowserContext* browser_context); | 44 explicit WarningService(content::BrowserContext* browser_context); |
| 45 virtual ~WarningService(); | 45 ~WarningService() override; |
| 46 | 46 |
| 47 // Clears all warnings of types contained in |types| and notifies observers | 47 // Clears all warnings of types contained in |types| and notifies observers |
| 48 // of the changed warnings. | 48 // of the changed warnings. |
| 49 void ClearWarnings(const std::set<Warning::WarningType>& types); | 49 void ClearWarnings(const std::set<Warning::WarningType>& types); |
| 50 | 50 |
| 51 // Returns all types of warnings effecting extension |extension_id|. | 51 // Returns all types of warnings effecting extension |extension_id|. |
| 52 std::set<Warning::WarningType> GetWarningTypesAffectingExtension( | 52 std::set<Warning::WarningType> GetWarningTypesAffectingExtension( |
| 53 const std::string& extension_id) const; | 53 const std::string& extension_id) const; |
| 54 | 54 |
| 55 // Returns all localized warnings for extension |extension_id| in |result|. | 55 // Returns all localized warnings for extension |extension_id| in |result|. |
| 56 std::vector<std::string> GetWarningMessagesForExtension( | 56 std::vector<std::string> GetWarningMessagesForExtension( |
| 57 const std::string& extension_id) const; | 57 const std::string& extension_id) const; |
| 58 | 58 |
| 59 const WarningSet& warnings() const { return warnings_; } | 59 const WarningSet& warnings() const { return warnings_; } |
| 60 | 60 |
| 61 // Adds a set of warnings and notifies observers if any warning is new. | 61 // Adds a set of warnings and notifies observers if any warning is new. |
| 62 void AddWarnings(const WarningSet& warnings); | 62 void AddWarnings(const WarningSet& warnings); |
| 63 | 63 |
| 64 // Notifies the WarningService of browser_context |browser_context_id| that | 64 // Notifies the WarningService of browser_context |browser_context_id| that |
| 65 // new |warnings| occurred and triggers a warning badge. | 65 // new |warnings| occurred and triggers a warning badge. |
| 66 static void NotifyWarningsOnUI(void* profile_id, const WarningSet& warnings); | 66 static void NotifyWarningsOnUI(void* profile_id, const WarningSet& warnings); |
| 67 | 67 |
| 68 void AddObserver(Observer* observer); | 68 void AddObserver(Observer* observer); |
| 69 void RemoveObserver(Observer* observer); | 69 void RemoveObserver(Observer* observer); |
| 70 | 70 |
| 71 private: | 71 private: |
| 72 void NotifyWarningsChanged(); | 72 void NotifyWarningsChanged(); |
| 73 | 73 |
| 74 // ExtensionRegistryObserver implementation. | 74 // ExtensionRegistryObserver implementation. |
| 75 virtual void OnExtensionUnloaded(content::BrowserContext* browser_context, | 75 void OnExtensionUnloaded(content::BrowserContext* browser_context, |
| 76 const Extension* extension, | 76 const Extension* extension, |
| 77 UnloadedExtensionInfo::Reason reason) | 77 UnloadedExtensionInfo::Reason reason) override; |
| 78 override; | |
| 79 | 78 |
| 80 // Currently existing warnings. | 79 // Currently existing warnings. |
| 81 WarningSet warnings_; | 80 WarningSet warnings_; |
| 82 | 81 |
| 83 content::BrowserContext* const browser_context_; | 82 content::BrowserContext* const browser_context_; |
| 84 | 83 |
| 85 // Listen to extension unloaded notifications. | 84 // Listen to extension unloaded notifications. |
| 86 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 85 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 87 extension_registry_observer_; | 86 extension_registry_observer_; |
| 88 | 87 |
| 89 ObserverList<Observer> observer_list_; | 88 ObserverList<Observer> observer_list_; |
| 90 }; | 89 }; |
| 91 | 90 |
| 92 } // namespace extensions | 91 } // namespace extensions |
| 93 | 92 |
| 94 #endif // EXTENSIONS_BROWSER_WARNING_SERVICE_H_ | 93 #endif // EXTENSIONS_BROWSER_WARNING_SERVICE_H_ |
| OLD | NEW |