Chromium Code Reviews| 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_WARNING_SERVICE_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SERVICE_H_ | |
| 7 | |
| 8 #include <set> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/observer_list.h" | |
| 13 #include "base/threading/non_thread_safe.h" | |
| 14 #include "chrome/browser/extensions/extension_warning_set.h" | |
| 15 #include "chrome/common/extensions/extension_set.h" | |
| 16 #include "content/public/browser/notification_observer.h" | |
| 17 #include "content/public/browser/notification_registrar.h" | |
| 18 | |
| 19 // TODO(battre) Remove the Extension prefix. | |
| 20 | |
| 21 class Profile; | |
| 22 | |
| 23 namespace content { | |
| 24 class NotificationDetails; | |
| 25 class NotificationSource; | |
| 26 } | |
| 27 | |
| 28 namespace extensions { | |
| 29 | |
| 30 // Manages a set of warnings caused by extensions. These warnings (e.g. | |
| 31 // conflicting modifications of network requests by extensions, slow extensions, | |
| 32 // etc.) trigger a warning badge in the UI and and provide means to resolve | |
| 33 // them. This class must be used on the UI thread only. | |
| 34 class ExtensionWarningService : public content::NotificationObserver, | |
| 35 public base::NonThreadSafe { | |
| 36 public: | |
| 37 class Observer { | |
| 38 public: | |
| 39 virtual void ExtensionWarningsChanged() = 0; | |
| 40 }; | |
| 41 | |
| 42 // |profile| may be NULL for testing. In this case, be sure to not insert | |
| 43 // any warnings. | |
| 44 explicit ExtensionWarningService(Profile* profile); | |
| 45 virtual ~ExtensionWarningService(); | |
| 46 | |
| 47 // Clears all warnings of types contained in |types| and notifies observers | |
| 48 // of the changed warnings. | |
| 49 void ClearWarnings(const std::set<ExtensionWarning::WarningType>& types); | |
| 50 | |
| 51 // Stores all types of warnings effecting extension |extension_id| in | |
| 52 // |result|. The previous content of |result| is erased. | |
| 53 void GetWarningTypesAffectingExtension( | |
| 54 const std::string& extension_id, | |
| 55 std::set<ExtensionWarning::WarningType>* result) const; | |
|
Aaron Boodman
2012/11/08 23:02:55
Nit: You can just return this. The copy is optimiz
battre
2012/11/13 17:27:33
Done.
| |
| 56 | |
| 57 // Stores all localized warnings for extension |extension_id| in |result|. | |
| 58 // The previous content of |result| is erased. | |
| 59 void GetWarningMessagesForExtension( | |
| 60 const std::string& extension_id, | |
| 61 std::vector<std::string>* result) const; | |
| 62 | |
| 63 const ExtensionWarningSet& warnings() const { return warnings_; } | |
| 64 | |
| 65 // Adds a set of warnings and notifies observers if any warning is new. | |
| 66 void AddWarnings(const ExtensionWarningSet& warnings); | |
| 67 | |
| 68 // Notifies the ExtensionWarningService of profile |profile_id| that new | |
| 69 // |warnings| occurred and triggers a warning badge. | |
| 70 static void NotifyWarningsOnUI(void* profile_id, | |
| 71 const ExtensionWarningSet& warnings); | |
| 72 | |
| 73 void AddObserver(Observer* observer); | |
| 74 void RemoveObserver(Observer* observer); | |
| 75 | |
| 76 private: | |
| 77 void NotifyWarningsChanged(); | |
| 78 | |
| 79 // Implementation for content::NotificationObserver. | |
| 80 virtual void Observe(int type, | |
| 81 const content::NotificationSource& source, | |
| 82 const content::NotificationDetails& details) OVERRIDE; | |
| 83 | |
| 84 // Currently existing warnings. | |
| 85 ExtensionWarningSet warnings_; | |
| 86 | |
| 87 content::NotificationRegistrar registrar_; | |
| 88 | |
| 89 Profile* profile_; | |
| 90 | |
| 91 ObserverList<Observer> observer_list_; | |
| 92 }; | |
| 93 | |
| 94 } // namespace extensions | |
| 95 | |
| 96 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SERVICE_H_ | |
| OLD | NEW |