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

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: Attempt to fix windows compilation Created 8 years, 2 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 | 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 to represent warnings if extensions misbehave.
Aaron Boodman 2012/11/08 23:02:55 We only use this class in certain kinds of misbeha
battre 2012/11/13 17:27:33 Done.
21 class ExtensionWarning {
21 public: 22 public:
22 enum WarningType { 23 enum WarningType {
23 // Don't use this, it is only intended for the default constructor and 24 // Don't use this, it is only intended for the default constructor and
24 // does not have localized warning messages for the UI. 25 // does not have localized warning messages for the UI.
25 kInvalid = 0, 26 kInvalid = 0,
26 // An extension caused excessive network delays. 27 // An extension caused excessive network delays.
27 kNetworkDelay, 28 kNetworkDelay,
28 // This extension failed to modify a network request because the 29 // This extension failed to modify a network request because the
29 // modification conflicted with a modification of another extension. 30 // modification conflicted with a modification of another extension.
30 kNetworkConflict, 31 kNetworkConflict,
32 // This extension failed to redirect a network request because another
33 // extension with higher precedence redirected to a different target.
34 kRedirectConflict,
31 // The extension repeatedly flushed WebKit's in-memory cache, which slows 35 // The extension repeatedly flushed WebKit's in-memory cache, which slows
32 // down the overall performance. 36 // down the overall performance.
33 kRepeatedCacheFlushes, 37 kRepeatedCacheFlushes,
34 kMaxWarningType 38 kMaxWarningType
35 }; 39 };
36 40
37 // Returns a localized string describing |warning_type|. 41 // We allow copy&assign for passing containers of ExtensionWarnings between
38 static string16 GetLocalizedWarning(WarningType warning_type); 42 // threads.
43 ExtensionWarning(const ExtensionWarning& other);
44 ~ExtensionWarning();
45 ExtensionWarning& operator=(const ExtensionWarning& other);
39 46
40 // |profile| may be NULL for testing. In this case, be sure to not insert 47 // Factory methods for various warning types.
41 // any warnings. 48 static ExtensionWarning CreateNetworkDelayWarning(
42 explicit ExtensionWarningSet(Profile* profile); 49 const std::string& extension_id);
43 virtual ~ExtensionWarningSet(); 50 static ExtensionWarning CreateNetworkConflictWarning(
51 const std::string& extension_id);
52 static ExtensionWarning CreateRedirectConflictWarning(
53 const std::string& extension_id,
54 const std::string& winning_extension_id,
55 const GURL& attempted_redirect_url,
56 const GURL& winning_redirect_url);
57 static ExtensionWarning CreateRequestHeaderConflictWarning(
58 const std::string& extension_id,
59 const std::string& winning_extension_id,
60 const std::string& conflicting_header);
61 static ExtensionWarning CreateResponseHeaderConflictWarning(
62 const std::string& extension_id,
63 const std::string& winning_extension_id,
64 const std::string& conflicting_header);
65 static ExtensionWarning CreateCredentialsConflictWarning(
66 const std::string& extension_id,
67 const std::string& winning_extension_id);
68 static ExtensionWarning CreateRepeatedCacheFlushesWarning(
69 const std::string& extension_id);
44 70
45 // Adds a warning and triggers a chrome::NOTIFICATION_EXTENSION_WARNING 71 // Returns the specific warning type.
46 // message if this warning is is new. If the warning is new and has not 72 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 73
51 // Clears all warnings of types contained in |types| and triggers a 74 // Returns the id of the extension for which this warning is valid.
52 // chrome::NOTIFICATION_EXTENSION_WARNING message if such warnings existed. 75 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 76
57 // Suppresses showing a badge for all currently existing warnings in the 77 // Returns a localized warning message.
58 // future. 78 std::string GetMessage(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 79
78 private: 80 private:
79 typedef std::set<ExtensionWarning>::const_iterator const_iterator; 81 // Constructs a warning of type |type| for extension |extension_id|. This
80 typedef std::set<ExtensionWarning>::iterator iterator; 82 // could indicate for example the fact that an extension conflicted with
83 // others. The |message_id| refers to an IDS_ string ID. The
84 // |message_parameters| are filled into the message template.
85 ExtensionWarning(WarningType type,
86 const std::string& extension_id,
87 int message_id,
88 const std::vector<std::string>& message_parameters);
81 89
82 // Shows or hides the warning badge on the wrench menu depending on whether 90 WarningType type_;
83 // any non-suppressed warnings exist. 91 std::string extension_id_;
84 void UpdateWarningBadge(); 92 // IDS_* resource ID.
85 93 int message_id_;
86 // Currently existing warnings. 94 // Parameters to be filled into the string identified by |message_id_|.
87 std::set<ExtensionWarning> warnings_; 95 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 }; 96 };
94 97
98 // Compare ExtensionWarnings based on the tuple of (extension_id, type).
99 // The message associated with ExtensionWarnings is purely informational
100 // and does not contribute to distinguishing extensions.
101 bool operator<(const ExtensionWarning& a, const ExtensionWarning& b);
102
103 typedef std::set<ExtensionWarning> ExtensionWarningSet;
104
105 } // namespace extensions
106
95 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_ 107 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698