Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: extensions/browser/warning_service.h

Issue 503033002: Move ExtensionWarningService and ExtensionsWarningSet to extensions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@3_web_view_internal
Patch Set: Rename. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_WARNING_SERVICE_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_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 "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/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 {
21 class BrowserContext;
23 class NotificationDetails; 22 class NotificationDetails;
24 class NotificationSource; 23 class NotificationSource;
25 } 24 }
26 25
27 namespace extensions { 26 namespace extensions {
28 27
29 class ExtensionRegistry; 28 class ExtensionRegistry;
30 29
31 // Manages a set of warnings caused by extensions. These warnings (e.g. 30 // Manages a set of warnings caused by extensions. These warnings (e.g.
32 // conflicting modifications of network requests by extensions, slow extensions, 31 // conflicting modifications of network requests by extensions, slow extensions,
33 // etc.) trigger a warning badge in the UI and and provide means to resolve 32 // 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. 33 // them. This class must be used on the UI thread only.
35 class ExtensionWarningService : public ExtensionRegistryObserver, 34 class WarningService : public ExtensionRegistryObserver,
36 public base::NonThreadSafe { 35 public base::NonThreadSafe {
37 public: 36 public:
38 class Observer { 37 class Observer {
39 public: 38 public:
40 virtual void ExtensionWarningsChanged() = 0; 39 virtual void ExtensionWarningsChanged() = 0;
41 }; 40 };
42 41
43 // |profile| may be NULL for testing. In this case, be sure to not insert 42 // |browser_context| may be NULL for testing. In this case, be sure to not
44 // any warnings. 43 // insert any warnings.
45 explicit ExtensionWarningService(Profile* profile); 44 explicit WarningService(content::BrowserContext* browser_context);
46 virtual ~ExtensionWarningService(); 45 virtual ~WarningService();
47 46
48 // Clears all warnings of types contained in |types| and notifies observers 47 // Clears all warnings of types contained in |types| and notifies observers
49 // of the changed warnings. 48 // of the changed warnings.
50 void ClearWarnings(const std::set<ExtensionWarning::WarningType>& types); 49 void ClearWarnings(const std::set<Warning::WarningType>& types);
51 50
52 // Returns all types of warnings effecting extension |extension_id|. 51 // Returns all types of warnings effecting extension |extension_id|.
53 std::set<ExtensionWarning::WarningType> GetWarningTypesAffectingExtension( 52 std::set<Warning::WarningType> GetWarningTypesAffectingExtension(
54 const std::string& extension_id) const; 53 const std::string& extension_id) const;
55 54
56 // Returns all localized warnings for extension |extension_id| in |result|. 55 // Returns all localized warnings for extension |extension_id| in |result|.
57 std::vector<std::string> GetWarningMessagesForExtension( 56 std::vector<std::string> GetWarningMessagesForExtension(
58 const std::string& extension_id) const; 57 const std::string& extension_id) const;
59 58
60 const ExtensionWarningSet& warnings() const { return warnings_; } 59 const WarningSet& warnings() const { return warnings_; }
61 60
62 // Adds a set of warnings and notifies observers if any warning is new. 61 // Adds a set of warnings and notifies observers if any warning is new.
63 void AddWarnings(const ExtensionWarningSet& warnings); 62 void AddWarnings(const WarningSet& warnings);
64 63
65 // Notifies the ExtensionWarningService of profile |profile_id| that new 64 // Notifies the WarningService of browser_context |browser_context_id| that
66 // |warnings| occurred and triggers a warning badge. 65 // new |warnings| occurred and triggers a warning badge.
67 static void NotifyWarningsOnUI(void* profile_id, 66 static void NotifyWarningsOnUI(void* profile_id, const WarningSet& warnings);
68 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 WarningSet warnings_;
84 82
85 Profile* profile_; 83 content::BrowserContext* const browser_context_;
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_WARNING_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698