summaryrefslogtreecommitdiffstats
path: root/extensions/browser/warning_service.h
diff options
context:
space:
mode:
authorhanxi <hanxi@chromium.org>2014-08-28 07:13:21 -0700
committerCommit bot <commit-bot@chromium.org>2014-08-28 14:14:30 +0000
commitc7e55208cda02430540652a0973071b54a8edb1e (patch)
tree238ae7df0f3e5e23f052ab576a7cbd881d843d1b /extensions/browser/warning_service.h
parent3074bba6ac72e209f68906839317508f4cbbc53a (diff)
downloadchromium_src-c7e55208cda02430540652a0973071b54a8edb1e.zip
chromium_src-c7e55208cda02430540652a0973071b54a8edb1e.tar.gz
chromium_src-c7e55208cda02430540652a0973071b54a8edb1e.tar.bz2
Move ExtensionWarningService and ExtensionsWarningSet, which are used by webrequest api, to extensions.
This cl resolve the dependencies of ExtensionsWarningSet of chrome strings: - move the declarations of IDS_EXTENSION_WARNINGS_XXX to extensions_strings.grd; - replace the usage of "IDS_PRODUCT_NAME" by creating GetProductName() function in ExtensionsClient and its subclasses. BUG=352293 Review URL: https://codereview.chromium.org/503033002 Cr-Commit-Position: refs/heads/master@{#292378}
Diffstat (limited to 'extensions/browser/warning_service.h')
-rw-r--r--extensions/browser/warning_service.h94
1 files changed, 94 insertions, 0 deletions
diff --git a/extensions/browser/warning_service.h b/extensions/browser/warning_service.h
new file mode 100644
index 0000000..f675e1f
--- /dev/null
+++ b/extensions/browser/warning_service.h
@@ -0,0 +1,94 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef EXTENSIONS_BROWSER_WARNING_SERVICE_H_
+#define EXTENSIONS_BROWSER_WARNING_SERVICE_H_
+
+#include <set>
+#include <string>
+#include <vector>
+
+#include "base/observer_list.h"
+#include "base/scoped_observer.h"
+#include "base/threading/non_thread_safe.h"
+#include "extensions/browser/extension_registry_observer.h"
+#include "extensions/browser/warning_set.h"
+
+// TODO(battre) Remove the Extension prefix.
+
+namespace content {
+class BrowserContext;
+class NotificationDetails;
+class NotificationSource;
+}
+
+namespace extensions {
+
+class ExtensionRegistry;
+
+// Manages a set of warnings caused by extensions. These warnings (e.g.
+// conflicting modifications of network requests by extensions, slow extensions,
+// etc.) trigger a warning badge in the UI and and provide means to resolve
+// them. This class must be used on the UI thread only.
+class WarningService : public ExtensionRegistryObserver,
+ public base::NonThreadSafe {
+ public:
+ class Observer {
+ public:
+ virtual void ExtensionWarningsChanged() = 0;
+ };
+
+ // |browser_context| may be NULL for testing. In this case, be sure to not
+ // insert any warnings.
+ explicit WarningService(content::BrowserContext* browser_context);
+ virtual ~WarningService();
+
+ // Clears all warnings of types contained in |types| and notifies observers
+ // of the changed warnings.
+ void ClearWarnings(const std::set<Warning::WarningType>& types);
+
+ // Returns all types of warnings effecting extension |extension_id|.
+ std::set<Warning::WarningType> GetWarningTypesAffectingExtension(
+ const std::string& extension_id) const;
+
+ // Returns all localized warnings for extension |extension_id| in |result|.
+ std::vector<std::string> GetWarningMessagesForExtension(
+ const std::string& extension_id) const;
+
+ const WarningSet& warnings() const { return warnings_; }
+
+ // Adds a set of warnings and notifies observers if any warning is new.
+ void AddWarnings(const WarningSet& warnings);
+
+ // Notifies the WarningService of browser_context |browser_context_id| that
+ // new |warnings| occurred and triggers a warning badge.
+ static void NotifyWarningsOnUI(void* profile_id, const WarningSet& warnings);
+
+ void AddObserver(Observer* observer);
+ void RemoveObserver(Observer* observer);
+
+ private:
+ void NotifyWarningsChanged();
+
+ // ExtensionRegistryObserver implementation.
+ virtual void OnExtensionUnloaded(content::BrowserContext* browser_context,
+ const Extension* extension,
+ UnloadedExtensionInfo::Reason reason)
+ OVERRIDE;
+
+ // Currently existing warnings.
+ WarningSet warnings_;
+
+ content::BrowserContext* const browser_context_;
+
+ // Listen to extension unloaded notifications.
+ ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
+ extension_registry_observer_;
+
+ ObserverList<Observer> observer_list_;
+};
+
+} // namespace extensions
+
+#endif // EXTENSIONS_BROWSER_WARNING_SERVICE_H_