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

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: Merged with ToT 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 #include "base/string16.h"
13
14 class ExtensionWarning;
15 class ExtensionGlobalErrorBadge;
16 class Profile;
17
18 // A set of warnings caused by extensions. These warnings (e.g. conflicting
19 // modifications of network requests by extensions, slow extensions, etc.)
20 // trigger a warning badge in the UI and and provide means to resolve them.
21 class ExtensionWarningSet {
22 public:
23 enum WarningType {
24 // Don't use this, it is only intended for the default constructor and
25 // does not have localized warning messages for the UI.
26 kInvalid = 0,
27 // An extension caused excessive network delays.
28 kNetworkDelay,
29 kMaxWarningType
30 };
31
32 // Returns a localized string describing |warning_type|.
33 static string16 GetLocalizedWarning(WarningType warning_type);
34
35 // |profile| may be NULL for testing. In this case, be sure to not insert
36 // any warnings.
37 explicit ExtensionWarningSet(Profile* profile);
38 virtual ~ExtensionWarningSet();
39
40 // Adds a warning and triggers a chrome::NOTIFICATION_EXTENSION_WARNING
41 // message if this warning is is new. If the warning is new and has not
42 // been suppressed, this may activate a badge on the wrench menu.
43 void SetWarning(ExtensionWarningSet::WarningType type,
44 const std::string& extension_id);
45
46 // Clears all warnings of types contained in |types| and triggers a
47 // chrome::NOTIFICATION_EXTENSION_WARNING message if such warnings existed.
48 // If no warning remains that is not suppressed, this may deactivate a
49 // warning badge on the wrench mennu.
50 void ClearWarnings(const std::set<WarningType>& types);
51
52 // Suppresses showing a badge for all currently existing warnings in the
53 // future.
54 void SuppressBadgeForCurrentWarnings();
55
56 // Stores all warnings for extension |extension_id| in |result|. The previous
57 // content of |result| is erased.
58 void GetWarningsAffectingExtension(
59 const std::string& extension_id,
60 std::set<WarningType>* result) const;
61
62 protected:
63 // Virtual for testing.
64 virtual void NotifyWarningsChanged();
65 virtual void ActivateBadge();
66 virtual void DeactivateBadge();
67
68 // Tracks the currently existing ExtensionGlobalErrorBadge that indicates in
69 // the UI that there are |extension_warnings_|. Weak pointer as the object is
70 // owned by the GlobalErrorService. NULL if there is no warning to be
71 // displayed on the wrench menu currently.
72 ExtensionGlobalErrorBadge* extension_global_error_badge_;
73
74 private:
75 typedef std::set<ExtensionWarning>::const_iterator const_iterator;
76
77 // Shows or hides the warning badge on the wrench menu depending on whether
78 // any non-suppressed warnings exist.
79 void UpdateWarningBadge();
80
81 // Currently existing warnings.
82 std::set<ExtensionWarning> warnings_;
83
84 // Warnings that do not trigger a badge on the wrench menu.
85 std::set<ExtensionWarning> badge_suppressions_;
86
87 Profile* profile_;
88 };
89
90 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_ui_unittest.cc ('k') | chrome/browser/extensions/extension_warning_set.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698