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> |
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 "components/keyed_service/core/keyed_service.h" |
15 #include "extensions/browser/extension_registry_observer.h" | 16 #include "extensions/browser/extension_registry_observer.h" |
16 #include "extensions/browser/warning_set.h" | 17 #include "extensions/browser/warning_set.h" |
17 | 18 |
18 // TODO(battre) Remove the Extension prefix. | 19 // TODO(battre) Remove the Extension prefix. |
19 | 20 |
20 namespace content { | 21 namespace content { |
21 class BrowserContext; | 22 class BrowserContext; |
22 class NotificationDetails; | 23 class NotificationDetails; |
23 class NotificationSource; | 24 class NotificationSource; |
24 } | 25 } |
25 | 26 |
26 namespace extensions { | 27 namespace extensions { |
27 | 28 |
28 class ExtensionRegistry; | 29 class ExtensionRegistry; |
29 | 30 |
30 // Manages a set of warnings caused by extensions. These warnings (e.g. | 31 // Manages a set of warnings caused by extensions. These warnings (e.g. |
31 // conflicting modifications of network requests by extensions, slow extensions, | 32 // 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 // 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 // them. This class must be used on the UI thread only. |
34 class WarningService : public ExtensionRegistryObserver, | 35 class WarningService : public KeyedService, |
| 36 public ExtensionRegistryObserver, |
35 public base::NonThreadSafe { | 37 public base::NonThreadSafe { |
36 public: | 38 public: |
37 class Observer { | 39 class Observer { |
38 public: | 40 public: |
39 virtual void ExtensionWarningsChanged() = 0; | 41 virtual void ExtensionWarningsChanged() = 0; |
40 }; | 42 }; |
41 | 43 |
42 // |browser_context| may be NULL for testing. In this case, be sure to not | 44 // |browser_context| may be NULL for testing. In this case, be sure to not |
43 // insert any warnings. | 45 // insert any warnings. |
44 explicit WarningService(content::BrowserContext* browser_context); | 46 explicit WarningService(content::BrowserContext* browser_context); |
45 ~WarningService() override; | 47 ~WarningService() override; |
46 | 48 |
| 49 // Get the instance of the WarningService for |browser_context|. |
| 50 // Redirected in incognito. |
| 51 static WarningService* Get(content::BrowserContext* browser_context); |
| 52 |
47 // Clears all warnings of types contained in |types| and notifies observers | 53 // Clears all warnings of types contained in |types| and notifies observers |
48 // of the changed warnings. | 54 // of the changed warnings. |
49 void ClearWarnings(const std::set<Warning::WarningType>& types); | 55 void ClearWarnings(const std::set<Warning::WarningType>& types); |
50 | 56 |
51 // Returns all types of warnings effecting extension |extension_id|. | 57 // Returns all types of warnings effecting extension |extension_id|. |
52 std::set<Warning::WarningType> GetWarningTypesAffectingExtension( | 58 std::set<Warning::WarningType> GetWarningTypesAffectingExtension( |
53 const std::string& extension_id) const; | 59 const std::string& extension_id) const; |
54 | 60 |
55 // Returns all localized warnings for extension |extension_id| in |result|. | 61 // Returns all localized warnings for extension |extension_id| in |result|. |
56 std::vector<std::string> GetWarningMessagesForExtension( | 62 std::vector<std::string> GetWarningMessagesForExtension( |
(...skipping 27 matching lines...) Expand all Loading... |
84 // Listen to extension unloaded notifications. | 90 // Listen to extension unloaded notifications. |
85 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 91 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
86 extension_registry_observer_; | 92 extension_registry_observer_; |
87 | 93 |
88 ObserverList<Observer> observer_list_; | 94 ObserverList<Observer> observer_list_; |
89 }; | 95 }; |
90 | 96 |
91 } // namespace extensions | 97 } // namespace extensions |
92 | 98 |
93 #endif // EXTENSIONS_BROWSER_WARNING_SERVICE_H_ | 99 #endif // EXTENSIONS_BROWSER_WARNING_SERVICE_H_ |
OLD | NEW |