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

Unified Diff: chrome/browser/extensions/extension_warning_set.h

Issue 10407105: Improve error messaging of webRequest API in case of conflicts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged with ToT Created 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_warning_set.h
diff --git a/chrome/browser/extensions/extension_warning_set.h b/chrome/browser/extensions/extension_warning_set.h
index d366c816c5d2174a167dc7c4e15225d73a7c2289..60c196950f3a600c684de3b621dbbb45272ca07a 100644
--- a/chrome/browser/extensions/extension_warning_set.h
+++ b/chrome/browser/extensions/extension_warning_set.h
@@ -7,17 +7,32 @@
#include <set>
#include <string>
+#include <vector>
+#include "base/memory/linked_ptr.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/observer_list.h"
#include "base/string16.h"
+#include "base/threading/non_thread_safe.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
+#include "googleurl/src/gurl.h"
-class ExtensionWarning;
class ExtensionGlobalErrorBadge;
+class ExtensionSet;
class Profile;
-// 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.
-class ExtensionWarningSet {
+// TODO(battre) Remove the Extension prefix.
+
+namespace content {
+class NotificationDetails;
+class NotificationSource;
+}
+
+namespace extensions {
+
+// This class is used to represent warnings if extensions misbehave.
+class ExtensionWarning {
public:
enum WarningType {
// Don't use this, it is only intended for the default constructor and
@@ -28,68 +43,142 @@ class ExtensionWarningSet {
// This extension failed to modify a network request because the
// modification conflicted with a modification of another extension.
kNetworkConflict,
+ // This extension failed to redirect a network request because another
+ // extension with higher precedence redirected to a different target.
+ kRedirectConflict,
// The extension repeatedly flushed WebKit's in-memory cache, which slows
// down the overall performance.
kRepeatedCacheFlushes,
kMaxWarningType
};
- // Returns a localized string describing |warning_type|.
- static string16 GetLocalizedWarning(WarningType warning_type);
+ ExtensionWarning(const ExtensionWarning& other);
+ ~ExtensionWarning();
+ ExtensionWarning& operator=(const ExtensionWarning& other);
+
+ // Factory methods for various warning types.
+ static ExtensionWarning CreateNetworkDelayWarning(
+ const std::string& extension_id);
+ static ExtensionWarning CreateNetworkConflictWarning(
+ const std::string& extension_id);
+ static ExtensionWarning CreateRedirectConflictWarning(
+ const std::string& extension_id,
+ const std::string& winning_extension_id,
+ const GURL& attempted_redirect_url,
+ const GURL& winning_redirect_url);
+ static ExtensionWarning CreateRequestHeaderConflictWarning(
+ const std::string& extension_id,
+ const std::string& winning_extension_id,
+ const std::string& conflicting_header);
+ static ExtensionWarning CreateResponseHeaderConflictWarning(
+ const std::string& extension_id,
+ const std::string& winning_extension_id,
+ const std::string& conflicting_header);
+ static ExtensionWarning CreateCredentialsConflictWarning(
+ const std::string& extension_id,
+ const std::string& winning_extension_id);
+ static ExtensionWarning CreateRepeatedCacheFlushesWarning(
+ const std::string& extension_id);
+
+ // Returns the specific warning type.
+ WarningType warning_type() const { return type_; }
+
+ // Returns the id of the extension for which this warning is valid.
+ const std::string& extension_id() const { return extension_id_; }
+
+ // Returns a localized warning message.
+ const std::string GetMessage(const ExtensionSet* extensions) const;
+
+ private:
+ // Constructs a warning of type |type| for extension |extension_id|. This
+ // could indicate for example the fact that an extension conflicted with
+ // others. The |message_id| refers to an IDS_ string ID. The
+ // |message_parameters| are filled into the message template.
+ ExtensionWarning(WarningType type,
+ const std::string& extension_id,
+ int message_id,
+ const std::vector<std::string>& message_parameters);
+
+ WarningType type_;
+ std::string extension_id_;
+ // IDS_* resource ID.
+ int message_id_;
+ // Parameters to be filled into the string identified by |message_id_|.
+ std::vector<std::string> message_parameters_;
+};
+
+// Compare ExtensionWarnings based on the tuple of (extension_id, type).
+// The message associated with ExtensionWarnings is purely informational
+// and does not contribute to distinguishing extensions.
+bool operator<(const ExtensionWarning& a, const ExtensionWarning& b);
+
+// Manages a set of warnings caused by extensions. These warnings (e.g.
+// conflicting modifications of network requests by extensions, slow extensions,
+// etc.) may be used for example to 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 ExtensionWarningSet : public content::NotificationObserver,
+ public base::NonThreadSafe {
+ public:
+ class Observer {
+ public:
+ virtual void ExtensionWarningsChanged() = 0;
+ };
// |profile| may be NULL for testing. In this case, be sure to not insert
// any warnings.
explicit ExtensionWarningSet(Profile* profile);
virtual ~ExtensionWarningSet();
- // Adds a warning and triggers a chrome::NOTIFICATION_EXTENSION_WARNING
- // message if this warning is is new. If the warning is new and has not
- // been suppressed, this may activate a badge on the wrench menu.
- void SetWarning(ExtensionWarningSet::WarningType type,
- const std::string& extension_id);
-
- // Clears all warnings of types contained in |types| and triggers a
- // chrome::NOTIFICATION_EXTENSION_WARNING message if such warnings existed.
- // If no warning remains that is not suppressed, this may deactivate a
- // warning badge on the wrench mennu.
- void ClearWarnings(const std::set<WarningType>& types);
-
- // Suppresses showing a badge for all currently existing warnings in the
- // future.
- void SuppressBadgeForCurrentWarnings();
-
- // Stores all warnings for extension |extension_id| in |result|. The previous
- // content of |result| is erased.
- void GetWarningsAffectingExtension(
+ // Clears all warnings of types contained in |types| and notifies observers
+ // of the changed warnings.
+ void ClearWarnings(const std::set<ExtensionWarning::WarningType>& types);
+
+ // Stores all types of warnings effecting extension |extension_id| in
+ // |result|. The previous content of |result| is erased.
+ void GetWarningTypesAffectingExtension(
+ const std::string& extension_id,
+ std::set<ExtensionWarning::WarningType>* result) const;
+
+ // Stores all localized warnings for extension |extension_id| in |result|.
+ // The previous content of |result| is erased.
+ void GetWarningMessagesForExtension(
const std::string& extension_id,
- std::set<WarningType>* result) const;
+ std::vector<std::string>* result) const;
+
+ const std::set<ExtensionWarning>& warnings() const { return warnings_; }
+
+ // Adds a set of warnings and notifies observers if any warning is new.
+ void AddWarnings(const std::set<ExtensionWarning>& warnings);
- // Notifies the ExtensionWarningSet of profile |profile_id| that
- // |extension_ids| caused warning |warning_type|. This function must only be
- // called on the UI thread.
+ // Notifies the ExtensionWarningSet of profile |profile_id| that new
+ // |warnings| occurred and triggers a warning badge.
static void NotifyWarningsOnUI(void* profile_id,
- std::set<std::string> extension_ids,
- WarningType warning_type);
+ std::set<ExtensionWarning> warnings);
- protected:
- // Virtual for testing.
- virtual void NotifyWarningsChanged();
+ void AddObserver(Observer* observer);
+ void RemoveObserver(Observer* observer);
private:
typedef std::set<ExtensionWarning>::const_iterator const_iterator;
typedef std::set<ExtensionWarning>::iterator iterator;
- // Shows or hides the warning badge on the wrench menu depending on whether
- // any non-suppressed warnings exist.
- void UpdateWarningBadge();
+ void NotifyWarningsChanged();
+
+ // Implementation for content::NotificationObserver.
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
// Currently existing warnings.
std::set<ExtensionWarning> warnings_;
- // Warnings that do not trigger a badge on the wrench menu.
- std::set<ExtensionWarning> badge_suppressions_;
+ content::NotificationRegistrar registrar_;
Profile* profile_;
+
+ ObserverList<Observer> observer_list_;
};
+} // namespace extensions
+
#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_

Powered by Google App Engine
This is Rietveld 408576698