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

Side by Side Diff: chrome/browser/extensions/extension_service.cc

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 #include "chrome/browser/extensions/extension_service.h" 5 #include "chrome/browser/extensions/extension_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 17 matching lines...) Expand all
28 #include "chrome/browser/extensions/app_notification_manager.h" 28 #include "chrome/browser/extensions/app_notification_manager.h"
29 #include "chrome/browser/extensions/apps_promo.h" 29 #include "chrome/browser/extensions/apps_promo.h"
30 #include "chrome/browser/extensions/crx_installer.h" 30 #include "chrome/browser/extensions/crx_installer.h"
31 #include "chrome/browser/extensions/extension_accessibility_api.h" 31 #include "chrome/browser/extensions/extension_accessibility_api.h"
32 #include "chrome/browser/extensions/extension_bookmarks_module.h" 32 #include "chrome/browser/extensions/extension_bookmarks_module.h"
33 #include "chrome/browser/extensions/extension_browser_event_router.h" 33 #include "chrome/browser/extensions/extension_browser_event_router.h"
34 #include "chrome/browser/extensions/extension_cookies_api.h" 34 #include "chrome/browser/extensions/extension_cookies_api.h"
35 #include "chrome/browser/extensions/extension_data_deleter.h" 35 #include "chrome/browser/extensions/extension_data_deleter.h"
36 #include "chrome/browser/extensions/extension_downloads_api.h" 36 #include "chrome/browser/extensions/extension_downloads_api.h"
37 #include "chrome/browser/extensions/extension_error_reporter.h" 37 #include "chrome/browser/extensions/extension_error_reporter.h"
38 #include "chrome/browser/extensions/extension_global_error.h"
38 #include "chrome/browser/extensions/extension_history_api.h" 39 #include "chrome/browser/extensions/extension_history_api.h"
39 #include "chrome/browser/extensions/extension_host.h" 40 #include "chrome/browser/extensions/extension_host.h"
40 #include "chrome/browser/extensions/extension_input_ime_api.h" 41 #include "chrome/browser/extensions/extension_input_ime_api.h"
41 #include "chrome/browser/extensions/extension_install_ui.h" 42 #include "chrome/browser/extensions/extension_install_ui.h"
42 #include "chrome/browser/extensions/extension_management_api.h" 43 #include "chrome/browser/extensions/extension_management_api.h"
43 #include "chrome/browser/extensions/extension_preference_api.h" 44 #include "chrome/browser/extensions/extension_preference_api.h"
44 #include "chrome/browser/extensions/extension_process_manager.h" 45 #include "chrome/browser/extensions/extension_process_manager.h"
45 #include "chrome/browser/extensions/extension_processes_api.h" 46 #include "chrome/browser/extensions/extension_processes_api.h"
46 #include "chrome/browser/extensions/extension_special_storage_policy.h" 47 #include "chrome/browser/extensions/extension_special_storage_policy.h"
47 #include "chrome/browser/extensions/extension_sync_data.h" 48 #include "chrome/browser/extensions/extension_sync_data.h"
48 #include "chrome/browser/extensions/extension_updater.h" 49 #include "chrome/browser/extensions/extension_updater.h"
49 #include "chrome/browser/extensions/extension_web_ui.h" 50 #include "chrome/browser/extensions/extension_web_ui.h"
50 #include "chrome/browser/extensions/extension_webnavigation_api.h" 51 #include "chrome/browser/extensions/extension_webnavigation_api.h"
51 #include "chrome/browser/extensions/external_extension_provider_impl.h" 52 #include "chrome/browser/extensions/external_extension_provider_impl.h"
52 #include "chrome/browser/extensions/external_extension_provider_interface.h" 53 #include "chrome/browser/extensions/external_extension_provider_interface.h"
53 #include "chrome/browser/extensions/pending_extension_manager.h" 54 #include "chrome/browser/extensions/pending_extension_manager.h"
54 #include "chrome/browser/net/chrome_url_request_context.h" 55 #include "chrome/browser/net/chrome_url_request_context.h"
55 #include "chrome/browser/prefs/pref_service.h" 56 #include "chrome/browser/prefs/pref_service.h"
56 #include "chrome/browser/profiles/profile.h" 57 #include "chrome/browser/profiles/profile.h"
57 #include "chrome/browser/search_engines/template_url_service.h" 58 #include "chrome/browser/search_engines/template_url_service.h"
58 #include "chrome/browser/search_engines/template_url_service_factory.h" 59 #include "chrome/browser/search_engines/template_url_service_factory.h"
59 #include "chrome/browser/sync/api/sync_change.h" 60 #include "chrome/browser/sync/api/sync_change.h"
60 #include "chrome/browser/themes/theme_service.h" 61 #include "chrome/browser/themes/theme_service.h"
61 #include "chrome/browser/themes/theme_service_factory.h" 62 #include "chrome/browser/themes/theme_service_factory.h"
63 #include "chrome/browser/ui/global_error_service.h"
64 #include "chrome/browser/ui/global_error_service_factory.h"
62 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 65 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
63 #include "chrome/browser/ui/webui/favicon_source.h" 66 #include "chrome/browser/ui/webui/favicon_source.h"
64 #include "chrome/browser/ui/webui/ntp/shown_sections_handler.h" 67 #include "chrome/browser/ui/webui/ntp/shown_sections_handler.h"
65 #include "chrome/common/child_process_logging.h" 68 #include "chrome/common/child_process_logging.h"
66 #include "chrome/common/chrome_notification_types.h" 69 #include "chrome/common/chrome_notification_types.h"
67 #include "chrome/common/chrome_paths.h" 70 #include "chrome/common/chrome_paths.h"
68 #include "chrome/common/chrome_switches.h" 71 #include "chrome/common/chrome_switches.h"
69 #include "chrome/common/extensions/extension.h" 72 #include "chrome/common/extensions/extension.h"
70 #include "chrome/common/extensions/extension_constants.h" 73 #include "chrome/common/extensions/extension_constants.h"
71 #include "chrome/common/extensions/extension_error_utils.h" 74 #include "chrome/common/extensions/extension_error_utils.h"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 extension_, false, -1); // Not from web store. 209 extension_, false, -1); // Not from web store.
207 delete this; 210 delete this;
208 } 211 }
209 212
210 void SimpleExtensionLoadPrompt::InstallUIAbort(bool user_initiated) { 213 void SimpleExtensionLoadPrompt::InstallUIAbort(bool user_initiated) {
211 delete this; 214 delete this;
212 } 215 }
213 216
214 } // namespace 217 } // namespace
215 218
219
220 ExtensionServiceWarning::ExtensionServiceWarning()
221 : type_(ExtensionServiceWarning::kInvalid) {
222 }
223
224 ExtensionServiceWarning::ExtensionServiceWarning(
225 WarningType type,
226 const std::set<std::string>& extension_ids)
227 : type_(type), extension_ids_(extension_ids) {
228 }
229
230 ExtensionServiceWarning::~ExtensionServiceWarning() {
231 }
232
233 ExtensionServiceWarning::WarningType
234 ExtensionServiceWarning::warning_type() const {
235 return type_;
236 }
237
238 const std::set<std::string> ExtensionServiceWarning::extension_ids() const {
239 return extension_ids_;
240 }
241
242 bool ExtensionServiceWarning::AffectsExtension(const std::string& id) const {
243 return extension_ids_.find(id) != extension_ids_.end();
244 }
245
216 bool ExtensionService::ComponentExtensionInfo::Equals( 246 bool ExtensionService::ComponentExtensionInfo::Equals(
217 const ComponentExtensionInfo& other) const { 247 const ComponentExtensionInfo& other) const {
218 return other.manifest == manifest && other.root_directory == root_directory; 248 return other.manifest == manifest && other.root_directory == root_directory;
219 } 249 }
220 250
221 ExtensionService::ExtensionRuntimeData::ExtensionRuntimeData() 251 ExtensionService::ExtensionRuntimeData::ExtensionRuntimeData()
222 : background_page_ready(false), 252 : background_page_ready(false),
223 being_upgraded(false) { 253 being_upgraded(false) {
224 } 254 }
225 255
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 profile->GetPath().AppendASCII(kSettingsDirectoryName)), 621 profile->GetPath().AppendASCII(kSettingsDirectoryName)),
592 pending_extension_manager_(*ALLOW_THIS_IN_INITIALIZER_LIST(this)), 622 pending_extension_manager_(*ALLOW_THIS_IN_INITIALIZER_LIST(this)),
593 install_directory_(install_directory), 623 install_directory_(install_directory),
594 extensions_enabled_(extensions_enabled), 624 extensions_enabled_(extensions_enabled),
595 show_extensions_prompts_(true), 625 show_extensions_prompts_(true),
596 ready_(false), 626 ready_(false),
597 toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 627 toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
598 app_notification_manager_(new AppNotificationManager(profile)), 628 app_notification_manager_(new AppNotificationManager(profile)),
599 permissions_manager_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 629 permissions_manager_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
600 apps_promo_(profile->GetPrefs()), 630 apps_promo_(profile->GetPrefs()),
601 event_routers_initialized_(false) { 631 event_routers_initialized_(false),
632 extension_global_error_(NULL) {
602 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 633 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
603 634
604 // Figure out if extension installation should be enabled. 635 // Figure out if extension installation should be enabled.
605 if (command_line->HasSwitch(switches::kDisableExtensions)) { 636 if (command_line->HasSwitch(switches::kDisableExtensions)) {
606 extensions_enabled_ = false; 637 extensions_enabled_ = false;
607 } else if (profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions)) { 638 } else if (profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions)) {
608 extensions_enabled_ = false; 639 extensions_enabled_ = false;
609 } 640 }
610 641
611 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, 642 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 if (sync_bundle && sync_bundle->HasExtensionId(extension_id)) { 992 if (sync_bundle && sync_bundle->HasExtensionId(extension_id)) {
962 sync_bundle->sync_processor->ProcessSyncChanges( 993 sync_bundle->sync_processor->ProcessSyncChanges(
963 FROM_HERE, SyncChangeList(1, sync_change)); 994 FROM_HERE, SyncChangeList(1, sync_change));
964 sync_bundle->synced_extensions.erase(extension_id); 995 sync_bundle->synced_extensions.erase(extension_id);
965 } 996 }
966 997
967 // Track the uninstallation. 998 // Track the uninstallation.
968 UserMetrics::RecordAction( 999 UserMetrics::RecordAction(
969 UserMetricsAction("Extensions.ExtensionUninstalled")); 1000 UserMetricsAction("Extensions.ExtensionUninstalled"));
970 1001
1002 ClearWarningsAffectingExtension(extension_id);
1003
971 return true; 1004 return true;
972 } 1005 }
973 1006
974 void ExtensionService::ClearExtensionData(const std::string& extension_id, 1007 void ExtensionService::ClearExtensionData(const std::string& extension_id,
975 const GURL& storage_url, 1008 const GURL& storage_url,
976 bool is_storage_isolated) { 1009 bool is_storage_isolated) {
977 scoped_refptr<ExtensionDataDeleter> deleter(new ExtensionDataDeleter( 1010 scoped_refptr<ExtensionDataDeleter> deleter(new ExtensionDataDeleter(
978 profile_, extension_id, storage_url, is_storage_isolated)); 1011 profile_, extension_id, storage_url, is_storage_isolated));
979 deleter->StartDeleting(); 1012 deleter->StartDeleting();
980 } 1013 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 } else { 1094 } else {
1062 iter = std::find(terminated_extensions_.begin(), 1095 iter = std::find(terminated_extensions_.begin(),
1063 terminated_extensions_.end(), 1096 terminated_extensions_.end(),
1064 extension); 1097 extension);
1065 terminated_extensions_.erase(iter); 1098 terminated_extensions_.erase(iter);
1066 } 1099 }
1067 1100
1068 NotifyExtensionUnloaded(extension, extension_misc::UNLOAD_REASON_DISABLE); 1101 NotifyExtensionUnloaded(extension, extension_misc::UNLOAD_REASON_DISABLE);
1069 1102
1070 SyncExtensionChangeIfNeeded(*extension); 1103 SyncExtensionChangeIfNeeded(*extension);
1104
1105 ClearWarningsAffectingExtension(extension_id);
1071 } 1106 }
1072 1107
1073 void ExtensionService::GrantPermissions(const Extension* extension) { 1108 void ExtensionService::GrantPermissions(const Extension* extension) {
1074 CHECK(extension); 1109 CHECK(extension);
1075 1110
1076 // We only maintain the granted permissions prefs for extensions that can't 1111 // We only maintain the granted permissions prefs for extensions that can't
1077 // silently increase their permissions. 1112 // silently increase their permissions.
1078 if (extension->CanSilentlyIncreasePermissions()) 1113 if (extension->CanSilentlyIncreasePermissions())
1079 return; 1114 return;
1080 1115
(...skipping 1824 matching lines...) Expand 10 before | Expand all | Expand 10 after
2905 2940
2906 ExtensionService::NaClModuleInfoList::iterator 2941 ExtensionService::NaClModuleInfoList::iterator
2907 ExtensionService::FindNaClModule(const GURL& url) { 2942 ExtensionService::FindNaClModule(const GURL& url) {
2908 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); 2943 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin();
2909 iter != nacl_module_list_.end(); ++iter) { 2944 iter != nacl_module_list_.end(); ++iter) {
2910 if (iter->url == url) 2945 if (iter->url == url)
2911 return iter; 2946 return iter;
2912 } 2947 }
2913 return nacl_module_list_.end(); 2948 return nacl_module_list_.end();
2914 } 2949 }
2950
2951 void ExtensionService::SetWarning(const ExtensionServiceWarning& warning) {
2952 extension_warnings_[warning.warning_type()] = warning;
2953 NotificationService::current()->Notify(
2954 chrome::NOTIFICATION_EXTENSION_WARNING,
2955 Source<Profile>(profile_),
2956 NotificationService::NoDetails());
2957 UpdateWarningBadge();
2958 }
2959
2960 void ExtensionService::ClearWarning(ExtensionServiceWarning::WarningType type) {
2961 if (extension_warnings_.erase(type)) {
2962 NotificationService::current()->Notify(
2963 chrome::NOTIFICATION_EXTENSION_WARNING,
2964 Source<Profile>(profile_),
2965 NotificationService::NoDetails());
2966 }
2967 UpdateWarningBadge();
2968 }
2969
2970 void ExtensionService::ClearWarningsAffectingExtension(
2971 const std::string& extension_id) {
2972 typedef std::set<ExtensionServiceWarning::WarningType> WarningTypeSet;
2973 WarningTypeSet to_clear;
2974
2975 for (ExtensionWarningsType::const_iterator i = extension_warnings_.begin();
2976 i != extension_warnings_.end(); ++i) {
2977 if (i->second.AffectsExtension(extension_id))
2978 to_clear.insert(i->first);
2979 }
2980
2981 for (WarningTypeSet::const_iterator i = to_clear.begin();
2982 i != to_clear.end(); ++i) {
2983 ClearWarning(*i);
2984 }
2985 }
2986
2987 ExtensionService::ExtensionWarningsType ExtensionService::GetWarnings() const {
2988 return extension_warnings_;
2989 }
2990
2991 bool ExtensionService::HasWarning(
2992 ExtensionServiceWarning::WarningType type) const {
2993 return extension_warnings_.find(type) != extension_warnings_.end();
2994 }
2995
2996 void ExtensionService::SuppressWarning(
2997 ExtensionServiceWarning::WarningType type) {
2998 suppressed_warnings_.insert(type);
2999 UpdateWarningBadge();
3000 }
3001
3002 void ExtensionService::UpdateWarningBadge() {
3003 // We need a badge if a warning exists that has not been suppressed.
3004 bool need_warning_badge = false;
3005 for (ExtensionWarningsType::const_iterator i = extension_warnings_.begin();
3006 i != extension_warnings_.end(); ++i) {
3007 if (suppressed_warnings_.find(i->first) == suppressed_warnings_.end()) {
3008 need_warning_badge = true;
3009 break;
3010 }
3011 }
3012
3013 // Activate or hide the warning bade in case the current state is incorrect.
3014 if (extension_global_error_ && !need_warning_badge) {
3015 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError(
3016 extension_global_error_);
3017 delete extension_global_error_;
3018 extension_global_error_ = NULL;
3019 } else if (!extension_global_error_ && need_warning_badge) {
3020 extension_global_error_ = new ExtensionGlobalError;
3021 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError(
3022 extension_global_error_);
3023 }
3024 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698