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_
12 #include "base/observer_list.h"
13 #include "base/scoped_observer.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"
18 // TODO(battre) Remove the Extension prefix.
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 ExtensionWarningService
: public ExtensionRegistryObserver
,
36 public base::NonThreadSafe
{
40 virtual void ExtensionWarningsChanged() = 0;
43 // |profile| may be NULL for testing. In this case, be sure to not insert
45 explicit ExtensionWarningService(Profile
* profile
);
46 virtual ~ExtensionWarningService();
48 // Clears all warnings of types contained in |types| and notifies observers
49 // of the changed warnings.
50 void ClearWarnings(const std::set
<ExtensionWarning::WarningType
>& types
);
52 // Returns all types of warnings effecting extension |extension_id|.
53 std::set
<ExtensionWarning::WarningType
> GetWarningTypesAffectingExtension(
54 const std::string
& extension_id
) const;
56 // Returns all localized warnings for extension |extension_id| in |result|.
57 std::vector
<std::string
> GetWarningMessagesForExtension(
58 const std::string
& extension_id
) const;
60 const ExtensionWarningSet
& warnings() const { return warnings_
; }
62 // Adds a set of warnings and notifies observers if any warning is new.
63 void AddWarnings(const ExtensionWarningSet
& warnings
);
65 // Notifies the ExtensionWarningService of profile |profile_id| that new
66 // |warnings| occurred and triggers a warning badge.
67 static void NotifyWarningsOnUI(void* profile_id
,
68 const ExtensionWarningSet
& warnings
);
70 void AddObserver(Observer
* observer
);
71 void RemoveObserver(Observer
* observer
);
74 void NotifyWarningsChanged();
76 // ExtensionRegistryObserver implementation.
77 virtual void OnExtensionUnloaded(content::BrowserContext
* browser_context
,
78 const Extension
* extension
,
79 UnloadedExtensionInfo::Reason reason
)
82 // Currently existing warnings.
83 ExtensionWarningSet warnings_
;
87 // Listen to extension unloaded notifications.
88 ScopedObserver
<ExtensionRegistry
, ExtensionRegistryObserver
>
89 extension_registry_observer_
;
91 ObserverList
<Observer
> observer_list_
;
94 } // namespace extensions
96 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SERVICE_H_