Add ICU message format support
[chromium-blink-merge.git] / extensions / browser / warning_service.h
blob1d6d89fc5bdcd745bddd828057ef5f8ab0132a5f
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.
5 #ifndef EXTENSIONS_BROWSER_WARNING_SERVICE_H_
6 #define EXTENSIONS_BROWSER_WARNING_SERVICE_H_
8 #include <set>
9 #include <string>
10 #include <vector>
12 #include "base/observer_list.h"
13 #include "base/scoped_observer.h"
14 #include "base/threading/non_thread_safe.h"
15 #include "components/keyed_service/core/keyed_service.h"
16 #include "extensions/browser/extension_registry_observer.h"
17 #include "extensions/browser/warning_set.h"
19 // TODO(battre) Remove the Extension prefix.
21 namespace content {
22 class BrowserContext;
23 class NotificationDetails;
24 class NotificationSource;
27 namespace extensions {
29 class ExtensionRegistry;
31 // Manages a set of warnings caused by extensions. These warnings (e.g.
32 // conflicting modifications of network requests by extensions, slow extensions,
33 // 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.
35 class WarningService : public KeyedService,
36 public ExtensionRegistryObserver,
37 public base::NonThreadSafe {
38 public:
39 class Observer {
40 public:
41 virtual void ExtensionWarningsChanged(
42 const ExtensionIdSet& affected_extensions) = 0;
45 // |browser_context| may be NULL for testing. In this case, be sure to not
46 // insert any warnings.
47 explicit WarningService(content::BrowserContext* browser_context);
48 ~WarningService() override;
50 // Get the instance of the WarningService for |browser_context|.
51 // Redirected in incognito.
52 static WarningService* Get(content::BrowserContext* browser_context);
54 // Clears all warnings of types contained in |types| and notifies observers
55 // of the changed warnings.
56 void ClearWarnings(const std::set<Warning::WarningType>& types);
58 // Returns all types of warnings effecting extension |extension_id|.
59 std::set<Warning::WarningType> GetWarningTypesAffectingExtension(
60 const std::string& extension_id) const;
62 // Returns all localized warnings for extension |extension_id| in |result|.
63 std::vector<std::string> GetWarningMessagesForExtension(
64 const std::string& extension_id) const;
66 const WarningSet& warnings() const { return warnings_; }
68 // Adds a set of warnings and notifies observers if any warning is new.
69 void AddWarnings(const WarningSet& warnings);
71 // Notifies the WarningService of browser_context |browser_context_id| that
72 // new |warnings| occurred and triggers a warning badge.
73 static void NotifyWarningsOnUI(void* profile_id, const WarningSet& warnings);
75 void AddObserver(Observer* observer);
76 void RemoveObserver(Observer* observer);
78 private:
79 void NotifyWarningsChanged(const ExtensionIdSet& affected_extensions);
81 // ExtensionRegistryObserver implementation.
82 void OnExtensionUnloaded(content::BrowserContext* browser_context,
83 const Extension* extension,
84 UnloadedExtensionInfo::Reason reason) override;
86 // Currently existing warnings.
87 WarningSet warnings_;
89 content::BrowserContext* const browser_context_;
91 // Listen to extension unloaded notifications.
92 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
93 extension_registry_observer_;
95 base::ObserverList<Observer> observer_list_;
98 } // namespace extensions
100 #endif // EXTENSIONS_BROWSER_WARNING_SERVICE_H_