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_SERVICE_H_ | 5 #ifndef EXTENSIONS_BROWSER_EXTENSION_WARNING_SERVICE_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SERVICE_H_ | 6 #define EXTENSIONS_BROWSER_EXTENSION_WARNING_SERVICE_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/observer_list.h" | 12 #include "base/observer_list.h" |
13 #include "base/scoped_observer.h" | 13 #include "base/scoped_observer.h" |
14 #include "base/threading/non_thread_safe.h" | 14 #include "base/threading/non_thread_safe.h" |
15 #include "chrome/browser/extensions/extension_warning_set.h" | |
16 #include "extensions/browser/extension_registry_observer.h" | 15 #include "extensions/browser/extension_registry_observer.h" |
16 #include "extensions/browser/extension_warning_set.h" | |
17 | 17 |
18 // TODO(battre) Remove the Extension prefix. | 18 // TODO(battre) Remove the Extension prefix. |
19 | 19 |
20 class Profile; | |
21 | |
22 namespace content { | 20 namespace content { |
23 class NotificationDetails; | 21 class NotificationDetails; |
James Cook
2014/08/25 20:58:11
nit: forward declare BrowserContext, even though s
Xi Han
2014/08/26 18:21:40
Done.
| |
24 class NotificationSource; | 22 class NotificationSource; |
25 } | 23 } |
26 | 24 |
27 namespace extensions { | 25 namespace extensions { |
28 | 26 |
29 class ExtensionRegistry; | 27 class ExtensionRegistry; |
30 | 28 |
31 // Manages a set of warnings caused by extensions. These warnings (e.g. | 29 // Manages a set of warnings caused by extensions. These warnings (e.g. |
32 // conflicting modifications of network requests by extensions, slow extensions, | 30 // conflicting modifications of network requests by extensions, slow extensions, |
33 // etc.) trigger a warning badge in the UI and and provide means to resolve | 31 // etc.) trigger a warning badge in the UI and and provide means to resolve |
34 // them. This class must be used on the UI thread only. | 32 // them. This class must be used on the UI thread only. |
35 class ExtensionWarningService : public ExtensionRegistryObserver, | 33 class ExtensionWarningService : public ExtensionRegistryObserver, |
James Cook
2014/08/25 20:58:11
Did you consider renaming this class to just "Warn
Fady Samuel
2014/08/25 21:15:38
I agree, it makes sense to do the rename.
| |
36 public base::NonThreadSafe { | 34 public base::NonThreadSafe { |
37 public: | 35 public: |
38 class Observer { | 36 class Observer { |
39 public: | 37 public: |
40 virtual void ExtensionWarningsChanged() = 0; | 38 virtual void ExtensionWarningsChanged() = 0; |
41 }; | 39 }; |
42 | 40 |
43 // |profile| may be NULL for testing. In this case, be sure to not insert | 41 // |browser_context| may be NULL for testing. In this case, be sure to not |
44 // any warnings. | 42 // insert any warnings. |
45 explicit ExtensionWarningService(Profile* profile); | 43 explicit ExtensionWarningService(content::BrowserContext* browser_context); |
46 virtual ~ExtensionWarningService(); | 44 virtual ~ExtensionWarningService(); |
47 | 45 |
48 // Clears all warnings of types contained in |types| and notifies observers | 46 // Clears all warnings of types contained in |types| and notifies observers |
49 // of the changed warnings. | 47 // of the changed warnings. |
50 void ClearWarnings(const std::set<ExtensionWarning::WarningType>& types); | 48 void ClearWarnings(const std::set<ExtensionWarning::WarningType>& types); |
51 | 49 |
52 // Returns all types of warnings effecting extension |extension_id|. | 50 // Returns all types of warnings effecting extension |extension_id|. |
53 std::set<ExtensionWarning::WarningType> GetWarningTypesAffectingExtension( | 51 std::set<ExtensionWarning::WarningType> GetWarningTypesAffectingExtension( |
54 const std::string& extension_id) const; | 52 const std::string& extension_id) const; |
55 | 53 |
56 // Returns all localized warnings for extension |extension_id| in |result|. | 54 // Returns all localized warnings for extension |extension_id| in |result|. |
57 std::vector<std::string> GetWarningMessagesForExtension( | 55 std::vector<std::string> GetWarningMessagesForExtension( |
58 const std::string& extension_id) const; | 56 const std::string& extension_id) const; |
59 | 57 |
60 const ExtensionWarningSet& warnings() const { return warnings_; } | 58 const ExtensionWarningSet& warnings() const { return warnings_; } |
61 | 59 |
62 // Adds a set of warnings and notifies observers if any warning is new. | 60 // Adds a set of warnings and notifies observers if any warning is new. |
63 void AddWarnings(const ExtensionWarningSet& warnings); | 61 void AddWarnings(const ExtensionWarningSet& warnings); |
64 | 62 |
65 // Notifies the ExtensionWarningService of profile |profile_id| that new | 63 // Notifies the ExtensionWarningService of browser_context |profile_id| that |
James Cook
2014/08/25 20:58:11
I might rename profile_id to browser_context_id.
Xi Han
2014/08/26 18:21:40
Done.
| |
66 // |warnings| occurred and triggers a warning badge. | 64 // new |warnings| occurred and triggers a warning badge. |
67 static void NotifyWarningsOnUI(void* profile_id, | 65 static void NotifyWarningsOnUI(void* profile_id, |
68 const ExtensionWarningSet& warnings); | 66 const ExtensionWarningSet& warnings); |
69 | 67 |
70 void AddObserver(Observer* observer); | 68 void AddObserver(Observer* observer); |
71 void RemoveObserver(Observer* observer); | 69 void RemoveObserver(Observer* observer); |
72 | 70 |
73 private: | 71 private: |
74 void NotifyWarningsChanged(); | 72 void NotifyWarningsChanged(); |
75 | 73 |
76 // ExtensionRegistryObserver implementation. | 74 // ExtensionRegistryObserver implementation. |
77 virtual void OnExtensionUnloaded(content::BrowserContext* browser_context, | 75 virtual void OnExtensionUnloaded(content::BrowserContext* browser_context, |
78 const Extension* extension, | 76 const Extension* extension, |
79 UnloadedExtensionInfo::Reason reason) | 77 UnloadedExtensionInfo::Reason reason) |
80 OVERRIDE; | 78 OVERRIDE; |
81 | 79 |
82 // Currently existing warnings. | 80 // Currently existing warnings. |
83 ExtensionWarningSet warnings_; | 81 ExtensionWarningSet warnings_; |
84 | 82 |
85 Profile* profile_; | 83 content::BrowserContext* browser_context_; |
Fady Samuel
2014/08/25 21:15:38
Does it make sense to make this const?
content::B
Xi Han
2014/08/26 18:21:40
Done.
| |
86 | 84 |
87 // Listen to extension unloaded notifications. | 85 // Listen to extension unloaded notifications. |
88 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 86 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
89 extension_registry_observer_; | 87 extension_registry_observer_; |
90 | 88 |
91 ObserverList<Observer> observer_list_; | 89 ObserverList<Observer> observer_list_; |
92 }; | 90 }; |
93 | 91 |
94 } // namespace extensions | 92 } // namespace extensions |
95 | 93 |
96 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SERVICE_H_ | 94 #endif // EXTENSIONS_BROWSER_EXTENSION_WARNING_SERVICE_H_ |
OLD | NEW |