[email protected] | b20729fe | 2012-01-25 21:42:52 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 7c1490da | 2011-10-11 18:53:25 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
hanxi | c7e5520 | 2014-08-28 14:13:21 | [diff] [blame] | 5 | #ifndef EXTENSIONS_BROWSER_WARNING_SET_H_ |
| 6 | #define EXTENSIONS_BROWSER_WARNING_SET_H_ |
[email protected] | 7c1490da | 2011-10-11 18:53:25 | [diff] [blame] | 7 | |
| 8 | #include <set> |
| 9 | #include <string> |
[email protected] | b4d3771d | 2012-11-14 14:44:10 | [diff] [blame] | 10 | #include <vector> |
[email protected] | 7c1490da | 2011-10-11 18:53:25 | [diff] [blame] | 11 | |
Karan Bhatia | 8213005 | 2018-07-12 21:41:47 | [diff] [blame] | 12 | #include "extensions/common/extension_id.h" |
[email protected] | a6483d2 | 2013-07-03 22:11:00 | [diff] [blame] | 13 | #include "url/gurl.h" |
[email protected] | 7c1490da | 2011-10-11 18:53:25 | [diff] [blame] | 14 | |
[email protected] | dc6cb14 | 2013-08-10 18:14:52 | [diff] [blame] | 15 | namespace base { |
| 16 | class FilePath; |
| 17 | } |
| 18 | |
[email protected] | b4d3771d | 2012-11-14 14:44:10 | [diff] [blame] | 19 | namespace extensions { |
| 20 | |
[email protected] | 289c44b | 2013-12-17 03:26:57 | [diff] [blame] | 21 | class ExtensionSet; |
| 22 | |
hanxi | c7e5520 | 2014-08-28 14:13:21 | [diff] [blame] | 23 | // This class is used by the WarningService to represent warnings if extensions |
| 24 | // misbehave. Note that the WarningService deals only with specific warnings |
| 25 | // that should trigger a badge on the Chrome menu button. |
| 26 | class Warning { |
[email protected] | 7c1490da | 2011-10-11 18:53:25 | [diff] [blame] | 27 | public: |
| 28 | enum WarningType { |
| 29 | // Don't use this, it is only intended for the default constructor and |
| 30 | // does not have localized warning messages for the UI. |
| 31 | kInvalid = 0, |
| 32 | // An extension caused excessive network delays. |
| 33 | kNetworkDelay, |
[email protected] | fd50e7b | 2011-11-03 09:20:25 | [diff] [blame] | 34 | // The extension repeatedly flushed WebKit's in-memory cache, which slows |
| 35 | // down the overall performance. |
| 36 | kRepeatedCacheFlushes, |
[email protected] | dc6cb14 | 2013-08-10 18:14:52 | [diff] [blame] | 37 | // The extension failed to determine the filename of a download because |
| 38 | // another extension with higher precedence determined a different filename. |
| 39 | kDownloadFilenameConflict, |
[email protected] | e9d7496e | 2014-04-18 01:25:46 | [diff] [blame] | 40 | kReloadTooFrequent, |
Karan Bhatia | 8213005 | 2018-07-12 21:41:47 | [diff] [blame] | 41 | // The declarative net request ruleset for the extension failed to load. |
| 42 | kRulesetFailedToLoad, |
[email protected] | 7c1490da | 2011-10-11 18:53:25 | [diff] [blame] | 43 | kMaxWarningType |
| 44 | }; |
| 45 | |
hanxi | c7e5520 | 2014-08-28 14:13:21 | [diff] [blame] | 46 | // We allow copy&assign for passing containers of Warnings between threads. |
| 47 | Warning(const Warning& other); |
| 48 | ~Warning(); |
| 49 | Warning& operator=(const Warning& other); |
[email protected] | 7c1490da | 2011-10-11 18:53:25 | [diff] [blame] | 50 | |
[email protected] | b4d3771d | 2012-11-14 14:44:10 | [diff] [blame] | 51 | // Factory methods for various warning types. |
hanxi | c7e5520 | 2014-08-28 14:13:21 | [diff] [blame] | 52 | static Warning CreateNetworkDelayWarning( |
[email protected] | b4d3771d | 2012-11-14 14:44:10 | [diff] [blame] | 53 | const std::string& extension_id); |
hanxi | c7e5520 | 2014-08-28 14:13:21 | [diff] [blame] | 54 | static Warning CreateRepeatedCacheFlushesWarning( |
[email protected] | b4d3771d | 2012-11-14 14:44:10 | [diff] [blame] | 55 | const std::string& extension_id); |
hanxi | c7e5520 | 2014-08-28 14:13:21 | [diff] [blame] | 56 | static Warning CreateDownloadFilenameConflictWarning( |
[email protected] | dc6cb14 | 2013-08-10 18:14:52 | [diff] [blame] | 57 | const std::string& losing_extension_id, |
| 58 | const std::string& winning_extension_id, |
| 59 | const base::FilePath& losing_filename, |
| 60 | const base::FilePath& winning_filename); |
hanxi | c7e5520 | 2014-08-28 14:13:21 | [diff] [blame] | 61 | static Warning CreateReloadTooFrequentWarning( |
[email protected] | e9d7496e | 2014-04-18 01:25:46 | [diff] [blame] | 62 | const std::string& extension_id); |
Karan Bhatia | 8213005 | 2018-07-12 21:41:47 | [diff] [blame] | 63 | static Warning CreateRulesetFailedToLoadWarning( |
| 64 | const ExtensionId& extension_id); |
[email protected] | 7c1490da | 2011-10-11 18:53:25 | [diff] [blame] | 65 | |
Istiaque Ahmed | 8680d31 | 2019-02-08 21:34:01 | [diff] [blame] | 66 | // Compare Warnings based on the tuple of (extension_id, type). |
| 67 | // The message associated with Warnings is purely informational |
| 68 | // and does not contribute to distinguishing extensions. |
| 69 | bool operator<(const Warning& other) const; |
| 70 | |
[email protected] | b4d3771d | 2012-11-14 14:44:10 | [diff] [blame] | 71 | // Returns the specific warning type. |
| 72 | WarningType warning_type() const { return type_; } |
[email protected] | a9632c9f | 2011-10-26 16:04:16 | [diff] [blame] | 73 | |
[email protected] | b4d3771d | 2012-11-14 14:44:10 | [diff] [blame] | 74 | // Returns the id of the extension for which this warning is valid. |
| 75 | const std::string& extension_id() const { return extension_id_; } |
| 76 | |
| 77 | // Returns a localized warning message. |
| 78 | std::string GetLocalizedMessage(const ExtensionSet* extensions) const; |
[email protected] | 7c1490da | 2011-10-11 18:53:25 | [diff] [blame] | 79 | |
| 80 | private: |
[email protected] | b4d3771d | 2012-11-14 14:44:10 | [diff] [blame] | 81 | // Constructs a warning of type |type| for extension |extension_id|. This |
| 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. |
hanxi | c7e5520 | 2014-08-28 14:13:21 | [diff] [blame] | 85 | Warning(WarningType type, |
[email protected] | b4d3771d | 2012-11-14 14:44:10 | [diff] [blame] | 86 | const std::string& extension_id, |
| 87 | int message_id, |
| 88 | const std::vector<std::string>& message_parameters); |
[email protected] | 7c1490da | 2011-10-11 18:53:25 | [diff] [blame] | 89 | |
[email protected] | b4d3771d | 2012-11-14 14:44:10 | [diff] [blame] | 90 | WarningType type_; |
| 91 | std::string extension_id_; |
| 92 | // IDS_* resource ID. |
| 93 | int message_id_; |
| 94 | // Parameters to be filled into the string identified by |message_id_|. |
| 95 | std::vector<std::string> message_parameters_; |
[email protected] | 7c1490da | 2011-10-11 18:53:25 | [diff] [blame] | 96 | }; |
| 97 | |
hanxi | c7e5520 | 2014-08-28 14:13:21 | [diff] [blame] | 98 | typedef std::set<Warning> WarningSet; |
[email protected] | b4d3771d | 2012-11-14 14:44:10 | [diff] [blame] | 99 | |
| 100 | } // namespace extensions |
| 101 | |
hanxi | c7e5520 | 2014-08-28 14:13:21 | [diff] [blame] | 102 | #endif // EXTENSIONS_BROWSER_WARNING_SET_H_ |