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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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_SERVICE_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "content/common/property_bag.h" 45 #include "content/common/property_bag.h"
46 46
47 class AppNotificationManager; 47 class AppNotificationManager;
48 class CrxInstaller; 48 class CrxInstaller;
49 class ExtensionBookmarkEventRouter; 49 class ExtensionBookmarkEventRouter;
50 class ExtensionBrowserEventRouter; 50 class ExtensionBrowserEventRouter;
51 class ExtensionContentSettingsStore; 51 class ExtensionContentSettingsStore;
52 class ExtensionCookiesEventRouter; 52 class ExtensionCookiesEventRouter;
53 class ExtensionDownloadsEventRouter; 53 class ExtensionDownloadsEventRouter;
54 class ExtensionFileBrowserEventRouter; 54 class ExtensionFileBrowserEventRouter;
55 class ExtensionGlobalError;
55 class ExtensionHistoryEventRouter; 56 class ExtensionHistoryEventRouter;
56 class ExtensionInstallUI; 57 class ExtensionInstallUI;
57 class ExtensionManagementEventRouter; 58 class ExtensionManagementEventRouter;
58 class ExtensionPreferenceEventRouter; 59 class ExtensionPreferenceEventRouter;
59 class ExtensionServiceBackend; 60 class ExtensionServiceBackend;
60 class ExtensionSyncData; 61 class ExtensionSyncData;
61 class ExtensionToolbarModel; 62 class ExtensionToolbarModel;
62 class ExtensionUpdater; 63 class ExtensionUpdater;
63 class ExtensionWebNavigationEventRouter; 64 class ExtensionWebNavigationEventRouter;
64 class GURL; 65 class GURL;
65 class PendingExtensionManager; 66 class PendingExtensionManager;
66 class Profile; 67 class Profile;
67 class SyncData; 68 class SyncData;
68 class Version; 69 class Version;
69 70
70 namespace chromeos { 71 namespace chromeos {
71 class ExtensionInputMethodEventRouter; 72 class ExtensionInputMethodEventRouter;
72 } // namespace chromeos 73 } // namespace chromeos
73 74
75 // This class is used to represent warnings if extensions misbehave.
76 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.
77 public:
78 enum WarningType {
79 // Don't use!
80 kInvalid = 0,
81 // An extension caused excessive network delays.
82 kNetworkDelay,
83 kMaxWarningType
84 };
85
86 // Default constructor for storing ExtensionServiceWarning in STL containers
87 // do not use.
88 ExtensionServiceWarning();
89
90 // Constructs and indication that a warning of type |type| is active for
91 // all extensions listed in |extension_ids|. This list could comprise
92 // for example all extensions that conflict with each other.
93 ExtensionServiceWarning(WarningType type,
94 const std::set<std::string>& extension_ids);
95
96 ~ExtensionServiceWarning();
97
98 // Returns the specific warning type.
99 WarningType warning_type() const;
100
101 // Returns the ids of all extensions for which this warning is valid.
102 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.
103
104 // Returns whether the warning affects the extension |id|.
105 bool AffectsExtension(const std::string& id) const;
106
107 private:
108 WarningType type_;
109 std::set<std::string> extension_ids_;
110
111 // Allow implicit copy and assign operator.
112 };
113
74 // This is an interface class to encapsulate the dependencies that 114 // This is an interface class to encapsulate the dependencies that
75 // various classes have on ExtensionService. This allows easy mocking. 115 // various classes have on ExtensionService. This allows easy mocking.
76 class ExtensionServiceInterface : public SyncableService { 116 class ExtensionServiceInterface : public SyncableService {
77 public: 117 public:
78 // A function that returns true if the given extension should be 118 // A function that returns true if the given extension should be
79 // included and false if it should be filtered out. Identical to 119 // included and false if it should be filtered out. Identical to
80 // PendingExtensionInfo::ShouldAllowInstallPredicate. 120 // PendingExtensionInfo::ShouldAllowInstallPredicate.
81 typedef bool (*ExtensionFilter)(const Extension&); 121 typedef bool (*ExtensionFilter)(const Extension&);
82 122
83 virtual ~ExtensionServiceInterface() {} 123 virtual ~ExtensionServiceInterface() {}
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 bool Equals(const ComponentExtensionInfo& other) const; 168 bool Equals(const ComponentExtensionInfo& other) const;
129 169
130 // The extension's manifest. This is required for component extensions so 170 // The extension's manifest. This is required for component extensions so
131 // that ExtensionService doesn't need to go to disk to load them. 171 // that ExtensionService doesn't need to go to disk to load them.
132 std::string manifest; 172 std::string manifest;
133 173
134 // Directory where the extension is stored. 174 // Directory where the extension is stored.
135 FilePath root_directory; 175 FilePath root_directory;
136 }; 176 };
137 177
178 typedef std::map<ExtensionServiceWarning::WarningType,
179 ExtensionServiceWarning> ExtensionWarningsType;
180
138 // The name of the directory inside the profile where extensions are 181 // The name of the directory inside the profile where extensions are
139 // installed to. 182 // installed to.
140 static const char* kInstallDirectoryName; 183 static const char* kInstallDirectoryName;
141 184
142 // If auto-updates are turned on, default to running every 5 hours. 185 // If auto-updates are turned on, default to running every 5 hours.
143 static const int kDefaultUpdateFrequencySeconds = 60 * 60 * 5; 186 static const int kDefaultUpdateFrequencySeconds = 60 * 60 * 5;
144 187
145 // The name of the directory inside the profile where per-extension settings 188 // The name of the directory inside the profile where per-extension settings
146 // are stored. 189 // are stored.
147 static const char* kSettingsDirectoryName; 190 static const char* kSettingsDirectoryName;
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 577
535 // |client| can be NULL for a silent install. 578 // |client| can be NULL for a silent install.
536 scoped_refptr<CrxInstaller> MakeCrxInstaller(ExtensionInstallUI* client); 579 scoped_refptr<CrxInstaller> MakeCrxInstaller(ExtensionInstallUI* client);
537 580
538 #if defined(UNIT_TEST) 581 #if defined(UNIT_TEST)
539 void TrackTerminatedExtensionForTest(const Extension* extension) { 582 void TrackTerminatedExtensionForTest(const Extension* extension) {
540 TrackTerminatedExtension(extension); 583 TrackTerminatedExtension(extension);
541 } 584 }
542 #endif 585 #endif
543 586
587 // Overrides previous warnings of type |warning.warning_type()| and
588 // 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.
589 void SetWarning(const ExtensionServiceWarning& warning);
590
591 // Clears a warning of |type| and triggers a
592 // chrome::NOTIFICATION_EXTENSION_WARING message if such a warning existed.
593 void ClearWarning(ExtensionServiceWarning::WarningType type);
594
595 // Clears all warnings that affected extension |extension_id| and trigger
596 // chrome::NOTIFICATION_EXTENSION_WARING messages in case the warning state
597 // changed.
598 void ClearWarningsAffectingExtension(const std::string& extension_id);
599
600 // Returns all current warnings.
601 ExtensionWarningsType GetWarnings() const;
602
603 // Returns whether a warning of |type| exists.
604 bool HasWarning(ExtensionServiceWarning::WarningType type) const;
605
606 // Suppresses showing a warning in the future.
607 void SuppressWarning(ExtensionServiceWarning::WarningType type);
608
609 // Shows or hides the warning badge on the wrench menu depending on whether
610 // any non-suppressed warnings exist.
611 void UpdateWarningBadge();
612
544 private: 613 private:
545 // Bundle of type (app or extension)-specific sync stuff. 614 // Bundle of type (app or extension)-specific sync stuff.
546 struct SyncBundle { 615 struct SyncBundle {
547 SyncBundle(); 616 SyncBundle();
548 ~SyncBundle(); 617 ~SyncBundle();
549 618
550 bool HasExtensionId(const std::string& id) const; 619 bool HasExtensionId(const std::string& id) const;
551 bool HasPendingExtensionId(const std::string& id) const; 620 bool HasPendingExtensionId(const std::string& id) const;
552 621
553 ExtensionFilter filter; 622 ExtensionFilter filter;
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 // Set to true by OnExternalExtensionUpdateUrlFound() when an external 866 // Set to true by OnExternalExtensionUpdateUrlFound() when an external
798 // extension URL is found. Used in CheckForExternalUpdates() to see 867 // extension URL is found. Used in CheckForExternalUpdates() to see
799 // if an update check is needed to install pending extensions. 868 // if an update check is needed to install pending extensions.
800 bool external_extension_url_added_; 869 bool external_extension_url_added_;
801 870
802 NaClModuleInfoList nacl_module_list_; 871 NaClModuleInfoList nacl_module_list_;
803 872
804 SyncBundle app_sync_bundle_; 873 SyncBundle app_sync_bundle_;
805 SyncBundle extension_sync_bundle_; 874 SyncBundle extension_sync_bundle_;
806 875
876 // Contains an entry for each warning that shall be currently shown.
877 ExtensionWarningsType extension_warnings_;
878 std::set<ExtensionServiceWarning::WarningType> suppressed_warnings_;
879
880 // Track the currently existing ExtensionGlobalError that indicates in the
881 // UI that there are |extension_warnings_|. Weak pointer as the object
882 // is owned by the GlobalErrorService. NULL if there is no warning to be
883 // displayed on the wrench menu currently.
884 ExtensionGlobalError* extension_global_error_;
885
807 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 886 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
808 InstallAppsWithUnlimtedStorage); 887 InstallAppsWithUnlimtedStorage);
809 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 888 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
810 InstallAppsAndCheckStorageProtection); 889 InstallAppsAndCheckStorageProtection);
811 DISALLOW_COPY_AND_ASSIGN(ExtensionService); 890 DISALLOW_COPY_AND_ASSIGN(ExtensionService);
812 }; 891 };
813 892
814 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ 893 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698