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

Side by Side Diff: chrome/browser/extensions/extension_warning_set.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: Cleanup 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2011 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.
4
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_
7 #pragma once
8
9 #include <set>
10 #include <string>
11
12 class ExtensionGlobalError;
13 class Profile;
14
15 // This class is used to represent warnings if extensions misbehave.
16 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
17 public:
18 enum WarningType {
19 // Don't use this, it is only intended for the default constructor and
20 // does not have localized warning messages for the UI.
21 kInvalid = 0,
22 // An extension caused excessive network delays.
23 kNetworkDelay,
24 kMaxWarningType
25 };
26
27 // Default constructor for storing ExtensionServiceWarning in STL containers
28 // do not use.
29 ExtensionWarning();
30
31 // Constructs a warning of type |type| for extension |extension_id|. This
32 // could be for example the fact that an extension conflicted with others.
33 ExtensionWarning(WarningType type, const std::string& extension_id);
34
35 ~ExtensionWarning();
36
37 // Returns the specific warning type.
38 WarningType warning_type() const { return type_; }
39
40 // Returns the id of the extension for which this warning is valid.
41 const std::string& extension_id() const { return extension_id_; }
42
43 private:
44 WarningType type_;
45 std::string extension_id_;
46
47 // Allow implicit copy and assign operator.
48 };
49
50 bool operator<(const ExtensionWarning& a, const ExtensionWarning& b);
51
52 class ExtensionWarningSet {
53 public:
54 // |profile| may be NULL for testing. In this case, be sure to not insert
55 // any warnings.
56 explicit ExtensionWarningSet(Profile* profile);
57 virtual ~ExtensionWarningSet();
58
59 // Adds a warning and triggers a chrome::NOTIFICATION_EXTENSION_WARNING
60 // message if this warning is is new. If the warning is new and has not
61 // been suppressed, this may activate a badge on the wrench menu.
62 void SetWarning(const ExtensionWarning& warning);
63
64 // Clears all warnings of types contained in |types| and triggers a
65 // chrome::NOTIFICATION_EXTENSION_WARNING message if such warnings existed.
66 // If no warning remains that is not suppressed, this may deactivate a
67 // warning badge on the wrench mennu.
68 void ClearWarnings(const std::set<ExtensionWarning::WarningType>& types);
69
70 // Suppresses showing a badge for all currently existing warnings in the
71 // future.
72 void SuppressBadgeForCurrentWarnings();
73
74 // Stores all warnings for extension |extension_id| in |result|. The previous
75 // content of |result| is erased.
76 void GetWarningsAffectingExtension(
77 const std::string& extension_id,
78 std::set<ExtensionWarning::WarningType>* result) const;
79
80 protected:
81 // Virtual for testing.
82 virtual void NotifyWarningsChanged();
83 virtual void ActivateBadge();
84 virtual void DeactivateBadge();
85
86 // Tracks the currently existing ExtensionGlobalError that indicates in the
87 // UI that there are |extension_warnings_|. Weak pointer as the object
88 // is owned by the GlobalErrorService. NULL if there is no warning to be
89 // displayed on the wrench menu currently.
90 ExtensionGlobalError* extension_global_error_;
91
92 private:
93 typedef std::set<ExtensionWarning>::const_iterator const_iterator;
94
95 // Shows or hides the warning badge on the wrench menu depending on whether
96 // any non-suppressed warnings exist.
97 void UpdateWarningBadge();
98
99 // Currently existing warnings.
100 std::set<ExtensionWarning> warnings_;
101
102 // Warnings that do not trigger a badge on the wrench menu.
103 std::set<ExtensionWarning> badge_suppressions_;
104
105 Profile* profile_;
106 };
107
108 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698