Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / extension_warning_service.h
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 "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h"
17
18 // TODO(battre) Remove the Extension prefix.
19
20 class Profile;
21
22 namespace content {
23 class NotificationDetails;
24 class NotificationSource;
25 }
26
27 namespace extensions {
28
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;
39   };
40
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();
45
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);
49
50   // Returns all types of warnings effecting extension |extension_id|.
51   std::set<ExtensionWarning::WarningType> GetWarningTypesAffectingExtension(
52       const std::string& extension_id) const;
53
54   // Returns all localized warnings for extension |extension_id| in |result|.
55   std::vector<std::string> GetWarningMessagesForExtension(
56       const std::string& extension_id) const;
57
58   const ExtensionWarningSet& warnings() const { return warnings_; }
59
60   // Adds a set of warnings and notifies observers if any warning is new.
61   void AddWarnings(const ExtensionWarningSet& warnings);
62
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);
67
68   void AddObserver(Observer* observer);
69   void RemoveObserver(Observer* observer);
70
71  private:
72   void NotifyWarningsChanged();
73
74   // Implementation for content::NotificationObserver.
75   virtual void Observe(int type,
76                        const content::NotificationSource& source,
77                        const content::NotificationDetails& details) OVERRIDE;
78
79   // Currently existing warnings.
80   ExtensionWarningSet warnings_;
81
82   content::NotificationRegistrar registrar_;
83
84   Profile* profile_;
85
86   ObserverList<Observer> observer_list_;
87 };
88
89 }  // namespace extensions
90
91 #endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SERVICE_H_