| OLD | NEW |
| 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 EXTENSIONS_BROWSER_WARNING_SET_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_ | 6 #define EXTENSIONS_BROWSER_WARNING_SET_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 13 | 13 |
| 14 // TODO(battre) Remove the Extension prefix. | |
| 15 | |
| 16 namespace base { | 14 namespace base { |
| 17 class FilePath; | 15 class FilePath; |
| 18 } | 16 } |
| 19 | 17 |
| 20 namespace extensions { | 18 namespace extensions { |
| 21 | 19 |
| 22 class ExtensionSet; | 20 class ExtensionSet; |
| 23 | 21 |
| 24 // This class is used by the ExtensionWarningService to represent warnings if | 22 // This class is used by the WarningService to represent warnings if extensions |
| 25 // extensions misbehave. Note that the ExtensionWarningService deals only with | 23 // misbehave. Note that the WarningService deals only with specific warnings |
| 26 // specific warnings that should trigger a badge on the Chrome menu button. | 24 // that should trigger a badge on the Chrome menu button. |
| 27 class ExtensionWarning { | 25 class Warning { |
| 28 public: | 26 public: |
| 29 enum WarningType { | 27 enum WarningType { |
| 30 // Don't use this, it is only intended for the default constructor and | 28 // Don't use this, it is only intended for the default constructor and |
| 31 // does not have localized warning messages for the UI. | 29 // does not have localized warning messages for the UI. |
| 32 kInvalid = 0, | 30 kInvalid = 0, |
| 33 // An extension caused excessive network delays. | 31 // An extension caused excessive network delays. |
| 34 kNetworkDelay, | 32 kNetworkDelay, |
| 35 // This extension failed to modify a network request because the | 33 // This extension failed to modify a network request because the |
| 36 // modification conflicted with a modification of another extension. | 34 // modification conflicted with a modification of another extension. |
| 37 kNetworkConflict, | 35 kNetworkConflict, |
| 38 // This extension failed to redirect a network request because another | 36 // This extension failed to redirect a network request because another |
| 39 // extension with higher precedence redirected to a different target. | 37 // extension with higher precedence redirected to a different target. |
| 40 kRedirectConflict, | 38 kRedirectConflict, |
| 41 // The extension repeatedly flushed WebKit's in-memory cache, which slows | 39 // The extension repeatedly flushed WebKit's in-memory cache, which slows |
| 42 // down the overall performance. | 40 // down the overall performance. |
| 43 kRepeatedCacheFlushes, | 41 kRepeatedCacheFlushes, |
| 44 // The extension failed to determine the filename of a download because | 42 // The extension failed to determine the filename of a download because |
| 45 // another extension with higher precedence determined a different filename. | 43 // another extension with higher precedence determined a different filename. |
| 46 kDownloadFilenameConflict, | 44 kDownloadFilenameConflict, |
| 47 kReloadTooFrequent, | 45 kReloadTooFrequent, |
| 48 kMaxWarningType | 46 kMaxWarningType |
| 49 }; | 47 }; |
| 50 | 48 |
| 51 // We allow copy&assign for passing containers of ExtensionWarnings between | 49 // We allow copy&assign for passing containers of Warnings between threads. |
| 52 // threads. | 50 Warning(const Warning& other); |
| 53 ExtensionWarning(const ExtensionWarning& other); | 51 ~Warning(); |
| 54 ~ExtensionWarning(); | 52 Warning& operator=(const Warning& other); |
| 55 ExtensionWarning& operator=(const ExtensionWarning& other); | |
| 56 | 53 |
| 57 // Factory methods for various warning types. | 54 // Factory methods for various warning types. |
| 58 static ExtensionWarning CreateNetworkDelayWarning( | 55 static Warning CreateNetworkDelayWarning( |
| 59 const std::string& extension_id); | 56 const std::string& extension_id); |
| 60 static ExtensionWarning CreateNetworkConflictWarning( | 57 static Warning CreateNetworkConflictWarning( |
| 61 const std::string& extension_id); | 58 const std::string& extension_id); |
| 62 static ExtensionWarning CreateRedirectConflictWarning( | 59 static Warning CreateRedirectConflictWarning( |
| 63 const std::string& extension_id, | 60 const std::string& extension_id, |
| 64 const std::string& winning_extension_id, | 61 const std::string& winning_extension_id, |
| 65 const GURL& attempted_redirect_url, | 62 const GURL& attempted_redirect_url, |
| 66 const GURL& winning_redirect_url); | 63 const GURL& winning_redirect_url); |
| 67 static ExtensionWarning CreateRequestHeaderConflictWarning( | 64 static Warning CreateRequestHeaderConflictWarning( |
| 68 const std::string& extension_id, | 65 const std::string& extension_id, |
| 69 const std::string& winning_extension_id, | 66 const std::string& winning_extension_id, |
| 70 const std::string& conflicting_header); | 67 const std::string& conflicting_header); |
| 71 static ExtensionWarning CreateResponseHeaderConflictWarning( | 68 static Warning CreateResponseHeaderConflictWarning( |
| 72 const std::string& extension_id, | 69 const std::string& extension_id, |
| 73 const std::string& winning_extension_id, | 70 const std::string& winning_extension_id, |
| 74 const std::string& conflicting_header); | 71 const std::string& conflicting_header); |
| 75 static ExtensionWarning CreateCredentialsConflictWarning( | 72 static Warning CreateCredentialsConflictWarning( |
| 76 const std::string& extension_id, | 73 const std::string& extension_id, |
| 77 const std::string& winning_extension_id); | 74 const std::string& winning_extension_id); |
| 78 static ExtensionWarning CreateRepeatedCacheFlushesWarning( | 75 static Warning CreateRepeatedCacheFlushesWarning( |
| 79 const std::string& extension_id); | 76 const std::string& extension_id); |
| 80 static ExtensionWarning CreateDownloadFilenameConflictWarning( | 77 static Warning CreateDownloadFilenameConflictWarning( |
| 81 const std::string& losing_extension_id, | 78 const std::string& losing_extension_id, |
| 82 const std::string& winning_extension_id, | 79 const std::string& winning_extension_id, |
| 83 const base::FilePath& losing_filename, | 80 const base::FilePath& losing_filename, |
| 84 const base::FilePath& winning_filename); | 81 const base::FilePath& winning_filename); |
| 85 static ExtensionWarning CreateReloadTooFrequentWarning( | 82 static Warning CreateReloadTooFrequentWarning( |
| 86 const std::string& extension_id); | 83 const std::string& extension_id); |
| 87 | 84 |
| 88 // Returns the specific warning type. | 85 // Returns the specific warning type. |
| 89 WarningType warning_type() const { return type_; } | 86 WarningType warning_type() const { return type_; } |
| 90 | 87 |
| 91 // Returns the id of the extension for which this warning is valid. | 88 // Returns the id of the extension for which this warning is valid. |
| 92 const std::string& extension_id() const { return extension_id_; } | 89 const std::string& extension_id() const { return extension_id_; } |
| 93 | 90 |
| 94 // Returns a localized warning message. | 91 // Returns a localized warning message. |
| 95 std::string GetLocalizedMessage(const ExtensionSet* extensions) const; | 92 std::string GetLocalizedMessage(const ExtensionSet* extensions) const; |
| 96 | 93 |
| 97 private: | 94 private: |
| 98 // Constructs a warning of type |type| for extension |extension_id|. This | 95 // Constructs a warning of type |type| for extension |extension_id|. This |
| 99 // could indicate for example the fact that an extension conflicted with | 96 // could indicate for example the fact that an extension conflicted with |
| 100 // others. The |message_id| refers to an IDS_ string ID. The | 97 // others. The |message_id| refers to an IDS_ string ID. The |
| 101 // |message_parameters| are filled into the message template. | 98 // |message_parameters| are filled into the message template. |
| 102 ExtensionWarning(WarningType type, | 99 Warning(WarningType type, |
| 103 const std::string& extension_id, | 100 const std::string& extension_id, |
| 104 int message_id, | 101 int message_id, |
| 105 const std::vector<std::string>& message_parameters); | 102 const std::vector<std::string>& message_parameters); |
| 106 | 103 |
| 107 WarningType type_; | 104 WarningType type_; |
| 108 std::string extension_id_; | 105 std::string extension_id_; |
| 109 // IDS_* resource ID. | 106 // IDS_* resource ID. |
| 110 int message_id_; | 107 int message_id_; |
| 111 // Parameters to be filled into the string identified by |message_id_|. | 108 // Parameters to be filled into the string identified by |message_id_|. |
| 112 std::vector<std::string> message_parameters_; | 109 std::vector<std::string> message_parameters_; |
| 113 }; | 110 }; |
| 114 | 111 |
| 115 // Compare ExtensionWarnings based on the tuple of (extension_id, type). | 112 // Compare Warnings based on the tuple of (extension_id, type). |
| 116 // The message associated with ExtensionWarnings is purely informational | 113 // The message associated with Warnings is purely informational |
| 117 // and does not contribute to distinguishing extensions. | 114 // and does not contribute to distinguishing extensions. |
| 118 bool operator<(const ExtensionWarning& a, const ExtensionWarning& b); | 115 bool operator<(const Warning& a, const Warning& b); |
| 119 | 116 |
| 120 typedef std::set<ExtensionWarning> ExtensionWarningSet; | 117 typedef std::set<Warning> WarningSet; |
| 121 | 118 |
| 122 } // namespace extensions | 119 } // namespace extensions |
| 123 | 120 |
| 124 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_ | 121 #endif // EXTENSIONS_BROWSER_WARNING_SET_H_ |
| OLD | NEW |