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 EXTENSIONS_BROWSER_WARNING_SET_H_
6 #define EXTENSIONS_BROWSER_WARNING_SET_H_
18 namespace extensions
{
22 // This class is used by the WarningService to represent warnings if extensions
23 // misbehave. Note that the WarningService deals only with specific warnings
24 // that should trigger a badge on the Chrome menu button.
28 // Don't use this, it is only intended for the default constructor and
29 // does not have localized warning messages for the UI.
31 // An extension caused excessive network delays.
33 // This extension failed to modify a network request because the
34 // modification conflicted with a modification of another extension.
36 // This extension failed to redirect a network request because another
37 // extension with higher precedence redirected to a different target.
39 // The extension repeatedly flushed WebKit's in-memory cache, which slows
40 // down the overall performance.
41 kRepeatedCacheFlushes
,
42 // The extension failed to determine the filename of a download because
43 // another extension with higher precedence determined a different filename.
44 kDownloadFilenameConflict
,
49 // We allow copy&assign for passing containers of Warnings between threads.
50 Warning(const Warning
& other
);
52 Warning
& operator=(const Warning
& other
);
54 // Factory methods for various warning types.
55 static Warning
CreateNetworkDelayWarning(
56 const std::string
& extension_id
);
57 static Warning
CreateNetworkConflictWarning(
58 const std::string
& extension_id
);
59 static Warning
CreateRedirectConflictWarning(
60 const std::string
& extension_id
,
61 const std::string
& winning_extension_id
,
62 const GURL
& attempted_redirect_url
,
63 const GURL
& winning_redirect_url
);
64 static Warning
CreateRequestHeaderConflictWarning(
65 const std::string
& extension_id
,
66 const std::string
& winning_extension_id
,
67 const std::string
& conflicting_header
);
68 static Warning
CreateResponseHeaderConflictWarning(
69 const std::string
& extension_id
,
70 const std::string
& winning_extension_id
,
71 const std::string
& conflicting_header
);
72 static Warning
CreateCredentialsConflictWarning(
73 const std::string
& extension_id
,
74 const std::string
& winning_extension_id
);
75 static Warning
CreateRepeatedCacheFlushesWarning(
76 const std::string
& extension_id
);
77 static Warning
CreateDownloadFilenameConflictWarning(
78 const std::string
& losing_extension_id
,
79 const std::string
& winning_extension_id
,
80 const base::FilePath
& losing_filename
,
81 const base::FilePath
& winning_filename
);
82 static Warning
CreateReloadTooFrequentWarning(
83 const std::string
& extension_id
);
85 // Returns the specific warning type.
86 WarningType
warning_type() const { return type_
; }
88 // Returns the id of the extension for which this warning is valid.
89 const std::string
& extension_id() const { return extension_id_
; }
91 // Returns a localized warning message.
92 std::string
GetLocalizedMessage(const ExtensionSet
* extensions
) const;
95 // Constructs a warning of type |type| for extension |extension_id|. This
96 // could indicate for example the fact that an extension conflicted with
97 // others. The |message_id| refers to an IDS_ string ID. The
98 // |message_parameters| are filled into the message template.
99 Warning(WarningType type
,
100 const std::string
& extension_id
,
102 const std::vector
<std::string
>& message_parameters
);
105 std::string extension_id_
;
106 // IDS_* resource ID.
108 // Parameters to be filled into the string identified by |message_id_|.
109 std::vector
<std::string
> message_parameters_
;
112 // Compare Warnings based on the tuple of (extension_id, type).
113 // The message associated with Warnings is purely informational
114 // and does not contribute to distinguishing extensions.
115 bool operator<(const Warning
& a
, const Warning
& b
);
117 typedef std::set
<Warning
> WarningSet
;
119 } // namespace extensions
121 #endif // EXTENSIONS_BROWSER_WARNING_SET_H_