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

Side by Side 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: Addressed Evan's comments Created 8 years, 1 month 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 | Annotate | Revision Log
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_SET_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector>
10 11
11 #include "base/string16.h" 12 #include "googleurl/src/gurl.h"
12 13
13 class ExtensionWarning; 14 // TODO(battre) Remove the Extension prefix.
14 class ExtensionGlobalErrorBadge;
15 class Profile;
16 15
17 // A set of warnings caused by extensions. These warnings (e.g. conflicting 16 class ExtensionSet;
18 // modifications of network requests by extensions, slow extensions, etc.) 17
19 // trigger a warning badge in the UI and and provide means to resolve them. 18 namespace extensions {
20 class ExtensionWarningSet { 19
20 // This class is used by the ExtensionWarningService to represent warnings if
21 // extensions misbehave. Note that the ExtensionWarningService deals only with
22 // specific warnings that should trigger a badge on the Chrome menu button.
23 class ExtensionWarning {
21 public: 24 public:
22 enum WarningType { 25 enum WarningType {
23 // Don't use this, it is only intended for the default constructor and 26 // Don't use this, it is only intended for the default constructor and
24 // does not have localized warning messages for the UI. 27 // does not have localized warning messages for the UI.
25 kInvalid = 0, 28 kInvalid = 0,
26 // An extension caused excessive network delays. 29 // An extension caused excessive network delays.
27 kNetworkDelay, 30 kNetworkDelay,
28 // This extension failed to modify a network request because the 31 // This extension failed to modify a network request because the
29 // modification conflicted with a modification of another extension. 32 // modification conflicted with a modification of another extension.
30 kNetworkConflict, 33 kNetworkConflict,
34 // This extension failed to redirect a network request because another
35 // extension with higher precedence redirected to a different target.
36 kRedirectConflict,
31 // The extension repeatedly flushed WebKit's in-memory cache, which slows 37 // The extension repeatedly flushed WebKit's in-memory cache, which slows
32 // down the overall performance. 38 // down the overall performance.
33 kRepeatedCacheFlushes, 39 kRepeatedCacheFlushes,
34 kMaxWarningType 40 kMaxWarningType
35 }; 41 };
36 42
37 // Returns a localized string describing |warning_type|. 43 // We allow copy&assign for passing containers of ExtensionWarnings between
38 static string16 GetLocalizedWarning(WarningType warning_type); 44 // threads.
45 ExtensionWarning(const ExtensionWarning& other);
46 ~ExtensionWarning();
47 ExtensionWarning& operator=(const ExtensionWarning& other);
39 48
40 // |profile| may be NULL for testing. In this case, be sure to not insert 49 // Factory methods for various warning types.
41 // any warnings. 50 static ExtensionWarning CreateNetworkDelayWarning(
42 explicit ExtensionWarningSet(Profile* profile); 51 const std::string& extension_id);
43 virtual ~ExtensionWarningSet(); 52 static ExtensionWarning CreateNetworkConflictWarning(
53 const std::string& extension_id);
54 static ExtensionWarning CreateRedirectConflictWarning(
55 const std::string& extension_id,
56 const std::string& winning_extension_id,
57 const GURL& attempted_redirect_url,
58 const GURL& winning_redirect_url);
59 static ExtensionWarning CreateRequestHeaderConflictWarning(
60 const std::string& extension_id,
61 const std::string& winning_extension_id,
62 const std::string& conflicting_header);
63 static ExtensionWarning CreateResponseHeaderConflictWarning(
64 const std::string& extension_id,
65 const std::string& winning_extension_id,
66 const std::string& conflicting_header);
67 static ExtensionWarning CreateCredentialsConflictWarning(
68 const std::string& extension_id,
69 const std::string& winning_extension_id);
70 static ExtensionWarning CreateRepeatedCacheFlushesWarning(
71 const std::string& extension_id);
44 72
45 // Adds a warning and triggers a chrome::NOTIFICATION_EXTENSION_WARNING 73 // Returns the specific warning type.
46 // message if this warning is is new. If the warning is new and has not 74 WarningType warning_type() const { return type_; }
47 // been suppressed, this may activate a badge on the wrench menu.
48 void SetWarning(ExtensionWarningSet::WarningType type,
49 const std::string& extension_id);
50 75
51 // Clears all warnings of types contained in |types| and triggers a 76 // Returns the id of the extension for which this warning is valid.
52 // chrome::NOTIFICATION_EXTENSION_WARNING message if such warnings existed. 77 const std::string& extension_id() const { return extension_id_; }
53 // If no warning remains that is not suppressed, this may deactivate a
54 // warning badge on the wrench mennu.
55 void ClearWarnings(const std::set<WarningType>& types);
56 78
57 // Suppresses showing a badge for all currently existing warnings in the 79 // Returns a localized warning message.
58 // future. 80 std::string GetLocalizedMessage(const ExtensionSet* extensions) const;
59 void SuppressBadgeForCurrentWarnings();
60
61 // Stores all warnings for extension |extension_id| in |result|. The previous
62 // content of |result| is erased.
63 void GetWarningsAffectingExtension(
64 const std::string& extension_id,
65 std::set<WarningType>* result) const;
66
67 // Notifies the ExtensionWarningSet of profile |profile_id| that
68 // |extension_ids| caused warning |warning_type|. This function must only be
69 // called on the UI thread.
70 static void NotifyWarningsOnUI(void* profile_id,
71 std::set<std::string> extension_ids,
72 WarningType warning_type);
73
74 protected:
75 // Virtual for testing.
76 virtual void NotifyWarningsChanged();
77 81
78 private: 82 private:
79 typedef std::set<ExtensionWarning>::const_iterator const_iterator; 83 // Constructs a warning of type |type| for extension |extension_id|. This
80 typedef std::set<ExtensionWarning>::iterator iterator; 84 // could indicate for example the fact that an extension conflicted with
85 // others. The |message_id| refers to an IDS_ string ID. The
86 // |message_parameters| are filled into the message template.
87 ExtensionWarning(WarningType type,
88 const std::string& extension_id,
89 int message_id,
90 const std::vector<std::string>& message_parameters);
81 91
82 // Shows or hides the warning badge on the wrench menu depending on whether 92 WarningType type_;
83 // any non-suppressed warnings exist. 93 std::string extension_id_;
84 void UpdateWarningBadge(); 94 // IDS_* resource ID.
85 95 int message_id_;
86 // Currently existing warnings. 96 // Parameters to be filled into the string identified by |message_id_|.
87 std::set<ExtensionWarning> warnings_; 97 std::vector<std::string> message_parameters_;
88
89 // Warnings that do not trigger a badge on the wrench menu.
90 std::set<ExtensionWarning> badge_suppressions_;
91
92 Profile* profile_;
93 }; 98 };
94 99
100 // Compare ExtensionWarnings based on the tuple of (extension_id, type).
101 // The message associated with ExtensionWarnings is purely informational
102 // and does not contribute to distinguishing extensions.
103 bool operator<(const ExtensionWarning& a, const ExtensionWarning& b);
104
105 typedef std::set<ExtensionWarning> ExtensionWarningSet;
106
107 } // namespace extensions
108
95 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_ 109 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698