Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / extensions / extension_warning_service.h
blob0062e5333f676086d34c35b765f8d359b031fe10
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 CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SERVICE_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SERVICE_H_
8 #include <set>
9 #include <string>
10 #include <vector>
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 "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h"
18 // TODO(battre) Remove the Extension prefix.
20 class Profile;
22 namespace content {
23 class NotificationDetails;
24 class NotificationSource;
27 namespace extensions {
29 // Manages a set of warnings caused by extensions. These warnings (e.g.
30 // conflicting modifications of network requests by extensions, slow extensions,
31 // etc.) trigger a warning badge in the UI and and provide means to resolve
32 // them. This class must be used on the UI thread only.
33 class ExtensionWarningService : public content::NotificationObserver,
34 public base::NonThreadSafe {
35 public:
36 class Observer {
37 public:
38 virtual void ExtensionWarningsChanged() = 0;
41 // |profile| may be NULL for testing. In this case, be sure to not insert
42 // any warnings.
43 explicit ExtensionWarningService(Profile* profile);
44 virtual ~ExtensionWarningService();
46 // Clears all warnings of types contained in |types| and notifies observers
47 // of the changed warnings.
48 void ClearWarnings(const std::set<ExtensionWarning::WarningType>& types);
50 // Returns all types of warnings effecting extension |extension_id|.
51 std::set<ExtensionWarning::WarningType> GetWarningTypesAffectingExtension(
52 const std::string& extension_id) const;
54 // Returns all localized warnings for extension |extension_id| in |result|.
55 std::vector<std::string> GetWarningMessagesForExtension(
56 const std::string& extension_id) const;
58 const ExtensionWarningSet& warnings() const { return warnings_; }
60 // Adds a set of warnings and notifies observers if any warning is new.
61 void AddWarnings(const ExtensionWarningSet& warnings);
63 // Notifies the ExtensionWarningService of profile |profile_id| that new
64 // |warnings| occurred and triggers a warning badge.
65 static void NotifyWarningsOnUI(void* profile_id,
66 const ExtensionWarningSet& warnings);
68 void AddObserver(Observer* observer);
69 void RemoveObserver(Observer* observer);
71 private:
72 void NotifyWarningsChanged();
74 // Implementation for content::NotificationObserver.
75 virtual void Observe(int type,
76 const content::NotificationSource& source,
77 const content::NotificationDetails& details) OVERRIDE;
79 // Currently existing warnings.
80 ExtensionWarningSet warnings_;
82 content::NotificationRegistrar registrar_;
84 Profile* profile_;
86 ObserverList<Observer> observer_list_;
89 } // namespace extensions
91 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SERVICE_H_