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

Unified Diff: chrome/browser/extensions/extension_service.h

Issue 8176001: Warn user in case extension delays network traffic too much. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Addressed Glen's comments Created 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_service.h
diff --git a/chrome/browser/extensions/extension_service.h b/chrome/browser/extensions/extension_service.h
index 1f5782b70ffe2376cdabd1a295412ba42f0f9d5c..9674d78e34162e6ea42ff5369655265595a1f9a3 100644
--- a/chrome/browser/extensions/extension_service.h
+++ b/chrome/browser/extensions/extension_service.h
@@ -52,6 +52,7 @@ class ExtensionContentSettingsStore;
class ExtensionCookiesEventRouter;
class ExtensionDownloadsEventRouter;
class ExtensionFileBrowserEventRouter;
+class ExtensionGlobalError;
class ExtensionHistoryEventRouter;
class ExtensionInstallUI;
class ExtensionManagementEventRouter;
@@ -71,6 +72,45 @@ namespace chromeos {
class ExtensionInputMethodEventRouter;
} // namespace chromeos
+// This class is used to represent warnings if extensions misbehave.
+class ExtensionServiceWarning {
Matt Perry 2011/10/06 22:55:54 The warning stuff isn't really related to the Exte
battre 2011/10/07 14:09:24 Done.
+ public:
+ enum WarningType {
+ // Don't use!
+ kInvalid = 0,
+ // An extension caused excessive network delays.
+ kNetworkDelay,
+ kMaxWarningType
+ };
+
+ // Default constructor for storing ExtensionServiceWarning in STL containers
+ // do not use.
+ ExtensionServiceWarning();
+
+ // Constructs and indication that a warning of type |type| is active for
+ // all extensions listed in |extension_ids|. This list could comprise
+ // for example all extensions that conflict with each other.
+ ExtensionServiceWarning(WarningType type,
+ const std::set<std::string>& extension_ids);
+
+ ~ExtensionServiceWarning();
+
+ // Returns the specific warning type.
+ WarningType warning_type() const;
+
+ // Returns the ids of all extensions for which this warning is valid.
+ const std::set<std::string> extension_ids() const;
Matt Perry 2011/10/06 22:55:54 underscore_style methods must be inline. also, whe
battre 2011/10/07 14:09:24 Done.
+
+ // Returns whether the warning affects the extension |id|.
+ bool AffectsExtension(const std::string& id) const;
+
+ private:
+ WarningType type_;
+ std::set<std::string> extension_ids_;
+
+ // Allow implicit copy and assign operator.
+};
+
// This is an interface class to encapsulate the dependencies that
// various classes have on ExtensionService. This allows easy mocking.
class ExtensionServiceInterface : public SyncableService {
@@ -135,6 +175,9 @@ class ExtensionService
FilePath root_directory;
};
+ typedef std::map<ExtensionServiceWarning::WarningType,
+ ExtensionServiceWarning> ExtensionWarningsType;
+
// The name of the directory inside the profile where extensions are
// installed to.
static const char* kInstallDirectoryName;
@@ -541,6 +584,32 @@ class ExtensionService
}
#endif
+ // Overrides previous warnings of type |warning.warning_type()| and
+ // triggers a chrome::NOTIFICATION_EXTENSION_WARING message.
Matt Perry 2011/10/06 22:55:54 typo: WARING (and below)
battre 2011/10/07 14:09:24 Done.
+ void SetWarning(const ExtensionServiceWarning& warning);
+
+ // Clears a warning of |type| and triggers a
+ // chrome::NOTIFICATION_EXTENSION_WARING message if such a warning existed.
+ void ClearWarning(ExtensionServiceWarning::WarningType type);
+
+ // Clears all warnings that affected extension |extension_id| and trigger
+ // chrome::NOTIFICATION_EXTENSION_WARING messages in case the warning state
+ // changed.
+ void ClearWarningsAffectingExtension(const std::string& extension_id);
+
+ // Returns all current warnings.
+ ExtensionWarningsType GetWarnings() const;
+
+ // Returns whether a warning of |type| exists.
+ bool HasWarning(ExtensionServiceWarning::WarningType type) const;
+
+ // Suppresses showing a warning in the future.
+ void SuppressWarning(ExtensionServiceWarning::WarningType type);
+
+ // Shows or hides the warning badge on the wrench menu depending on whether
+ // any non-suppressed warnings exist.
+ void UpdateWarningBadge();
+
private:
// Bundle of type (app or extension)-specific sync stuff.
struct SyncBundle {
@@ -804,6 +873,16 @@ class ExtensionService
SyncBundle app_sync_bundle_;
SyncBundle extension_sync_bundle_;
+ // Contains an entry for each warning that shall be currently shown.
+ ExtensionWarningsType extension_warnings_;
+ std::set<ExtensionServiceWarning::WarningType> suppressed_warnings_;
+
+ // Track 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_;
+
FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
InstallAppsWithUnlimtedStorage);
FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,

Powered by Google App Engine
This is Rietveld 408576698