Chromium Code Reviews| Index: chrome/browser/extensions/extension_warning_set.h |
| diff --git a/chrome/browser/extensions/extension_warning_set.h b/chrome/browser/extensions/extension_warning_set.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..db97485978c515365fd57f2fd82eaa8a94d9754c |
| --- /dev/null |
| +++ b/chrome/browser/extensions/extension_warning_set.h |
| @@ -0,0 +1,108 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_ |
| +#define CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_ |
| +#pragma once |
| + |
| +#include <set> |
| +#include <string> |
| + |
| +class ExtensionGlobalError; |
| +class Profile; |
| + |
| +// This class is used to represent warnings if extensions misbehave. |
| +class ExtensionWarning { |
|
Matt Perry
2011/10/07 19:18:38
This class should be an implementation detail of E
battre
2011/10/10 13:16:36
Done.
I have moved the definition of ExtensionWar
|
| + public: |
| + enum WarningType { |
| + // Don't use this, it is only intended for the default constructor and |
| + // does not have localized warning messages for the UI. |
| + kInvalid = 0, |
| + // An extension caused excessive network delays. |
| + kNetworkDelay, |
| + kMaxWarningType |
| + }; |
| + |
| + // Default constructor for storing ExtensionServiceWarning in STL containers |
| + // do not use. |
| + ExtensionWarning(); |
| + |
| + // Constructs a warning of type |type| for extension |extension_id|. This |
| + // could be for example the fact that an extension conflicted with others. |
| + ExtensionWarning(WarningType type, const std::string& extension_id); |
| + |
| + ~ExtensionWarning(); |
| + |
| + // Returns the specific warning type. |
| + WarningType warning_type() const { return type_; } |
| + |
| + // Returns the id of the extension for which this warning is valid. |
| + const std::string& extension_id() const { return extension_id_; } |
| + |
| + private: |
| + WarningType type_; |
| + std::string extension_id_; |
| + |
| + // Allow implicit copy and assign operator. |
| +}; |
| + |
| +bool operator<(const ExtensionWarning& a, const ExtensionWarning& b); |
| + |
| +class ExtensionWarningSet { |
| + public: |
| + // |profile| may be NULL for testing. In this case, be sure to not insert |
| + // any warnings. |
| + explicit ExtensionWarningSet(Profile* profile); |
| + virtual ~ExtensionWarningSet(); |
| + |
| + // Adds a warning and triggers a chrome::NOTIFICATION_EXTENSION_WARNING |
| + // message if this warning is is new. If the warning is new and has not |
| + // been suppressed, this may activate a badge on the wrench menu. |
| + void SetWarning(const ExtensionWarning& warning); |
| + |
| + // Clears all warnings of types contained in |types| and triggers a |
| + // chrome::NOTIFICATION_EXTENSION_WARNING message if such warnings existed. |
| + // If no warning remains that is not suppressed, this may deactivate a |
| + // warning badge on the wrench mennu. |
| + void ClearWarnings(const std::set<ExtensionWarning::WarningType>& types); |
| + |
| + // Suppresses showing a badge for all currently existing warnings in the |
| + // future. |
| + void SuppressBadgeForCurrentWarnings(); |
| + |
| + // Stores all warnings for extension |extension_id| in |result|. The previous |
| + // content of |result| is erased. |
| + void GetWarningsAffectingExtension( |
| + const std::string& extension_id, |
| + std::set<ExtensionWarning::WarningType>* result) const; |
| + |
| + protected: |
| + // Virtual for testing. |
| + virtual void NotifyWarningsChanged(); |
| + virtual void ActivateBadge(); |
| + virtual void DeactivateBadge(); |
| + |
| + // Tracks the currently existing ExtensionGlobalError that indicates in the |
| + // UI that there are |extension_warnings_|. Weak pointer as the object |
| + // is owned by the GlobalErrorService. NULL if there is no warning to be |
| + // displayed on the wrench menu currently. |
| + ExtensionGlobalError* extension_global_error_; |
| + |
| + private: |
| + typedef std::set<ExtensionWarning>::const_iterator const_iterator; |
| + |
| + // Shows or hides the warning badge on the wrench menu depending on whether |
| + // any non-suppressed warnings exist. |
| + void UpdateWarningBadge(); |
| + |
| + // Currently existing warnings. |
| + std::set<ExtensionWarning> warnings_; |
| + |
| + // Warnings that do not trigger a badge on the wrench menu. |
| + std::set<ExtensionWarning> badge_suppressions_; |
| + |
| + Profile* profile_; |
| +}; |
| + |
| +#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_ |