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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_service.cc
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc
index 1754e6c9552253ece72380cc3c55fcc974c33623..baf866a087c6327cc4e6c48ebd4c8ed43ee627d8 100644
--- a/chrome/browser/extensions/extension_service.cc
+++ b/chrome/browser/extensions/extension_service.cc
@@ -35,6 +35,7 @@
#include "chrome/browser/extensions/extension_data_deleter.h"
#include "chrome/browser/extensions/extension_downloads_api.h"
#include "chrome/browser/extensions/extension_error_reporter.h"
+#include "chrome/browser/extensions/extension_global_error.h"
#include "chrome/browser/extensions/extension_history_api.h"
#include "chrome/browser/extensions/extension_host.h"
#include "chrome/browser/extensions/extension_input_ime_api.h"
@@ -59,6 +60,8 @@
#include "chrome/browser/sync/api/sync_change.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
+#include "chrome/browser/ui/global_error_service.h"
+#include "chrome/browser/ui/global_error_service_factory.h"
#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
#include "chrome/browser/ui/webui/favicon_source.h"
#include "chrome/browser/ui/webui/ntp/shown_sections_handler.h"
@@ -213,6 +216,33 @@ void SimpleExtensionLoadPrompt::InstallUIAbort(bool user_initiated) {
} // namespace
+
+ExtensionServiceWarning::ExtensionServiceWarning()
+ : type_(ExtensionServiceWarning::kInvalid) {
+}
+
+ExtensionServiceWarning::ExtensionServiceWarning(
+ WarningType type,
+ const std::set<std::string>& extension_ids)
+ : type_(type), extension_ids_(extension_ids) {
+}
+
+ExtensionServiceWarning::~ExtensionServiceWarning() {
+}
+
+ExtensionServiceWarning::WarningType
+ExtensionServiceWarning::warning_type() const {
+ return type_;
+}
+
+const std::set<std::string> ExtensionServiceWarning::extension_ids() const {
+ return extension_ids_;
+}
+
+bool ExtensionServiceWarning::AffectsExtension(const std::string& id) const {
+ return extension_ids_.find(id) != extension_ids_.end();
+}
+
bool ExtensionService::ComponentExtensionInfo::Equals(
const ComponentExtensionInfo& other) const {
return other.manifest == manifest && other.root_directory == root_directory;
@@ -598,7 +628,8 @@ ExtensionService::ExtensionService(Profile* profile,
app_notification_manager_(new AppNotificationManager(profile)),
permissions_manager_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
apps_promo_(profile->GetPrefs()),
- event_routers_initialized_(false) {
+ event_routers_initialized_(false),
+ extension_global_error_(NULL) {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// Figure out if extension installation should be enabled.
@@ -968,6 +999,8 @@ bool ExtensionService::UninstallExtension(
UserMetrics::RecordAction(
UserMetricsAction("Extensions.ExtensionUninstalled"));
+ ClearWarningsAffectingExtension(extension_id);
+
return true;
}
@@ -1068,6 +1101,8 @@ void ExtensionService::DisableExtension(const std::string& extension_id) {
NotifyExtensionUnloaded(extension, extension_misc::UNLOAD_REASON_DISABLE);
SyncExtensionChangeIfNeeded(*extension);
+
+ ClearWarningsAffectingExtension(extension_id);
}
void ExtensionService::GrantPermissions(const Extension* extension) {
@@ -2912,3 +2947,78 @@ ExtensionService::NaClModuleInfoList::iterator
}
return nacl_module_list_.end();
}
+
+void ExtensionService::SetWarning(const ExtensionServiceWarning& warning) {
+ extension_warnings_[warning.warning_type()] = warning;
+ NotificationService::current()->Notify(
+ chrome::NOTIFICATION_EXTENSION_WARNING,
+ Source<Profile>(profile_),
+ NotificationService::NoDetails());
+ UpdateWarningBadge();
+}
+
+void ExtensionService::ClearWarning(ExtensionServiceWarning::WarningType type) {
+ if (extension_warnings_.erase(type)) {
+ NotificationService::current()->Notify(
+ chrome::NOTIFICATION_EXTENSION_WARNING,
+ Source<Profile>(profile_),
+ NotificationService::NoDetails());
+ }
+ UpdateWarningBadge();
+}
+
+void ExtensionService::ClearWarningsAffectingExtension(
+ const std::string& extension_id) {
+ typedef std::set<ExtensionServiceWarning::WarningType> WarningTypeSet;
+ WarningTypeSet to_clear;
+
+ for (ExtensionWarningsType::const_iterator i = extension_warnings_.begin();
+ i != extension_warnings_.end(); ++i) {
+ if (i->second.AffectsExtension(extension_id))
+ to_clear.insert(i->first);
+ }
+
+ for (WarningTypeSet::const_iterator i = to_clear.begin();
+ i != to_clear.end(); ++i) {
+ ClearWarning(*i);
+ }
+}
+
+ExtensionService::ExtensionWarningsType ExtensionService::GetWarnings() const {
+ return extension_warnings_;
+}
+
+bool ExtensionService::HasWarning(
+ ExtensionServiceWarning::WarningType type) const {
+ return extension_warnings_.find(type) != extension_warnings_.end();
+}
+
+void ExtensionService::SuppressWarning(
+ ExtensionServiceWarning::WarningType type) {
+ suppressed_warnings_.insert(type);
+ UpdateWarningBadge();
+}
+
+void ExtensionService::UpdateWarningBadge() {
+ // We need a badge if a warning exists that has not been suppressed.
+ bool need_warning_badge = false;
+ for (ExtensionWarningsType::const_iterator i = extension_warnings_.begin();
+ i != extension_warnings_.end(); ++i) {
+ if (suppressed_warnings_.find(i->first) == suppressed_warnings_.end()) {
+ need_warning_badge = true;
+ break;
+ }
+ }
+
+ // Activate or hide the warning bade in case the current state is incorrect.
+ if (extension_global_error_ && !need_warning_badge) {
+ GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError(
+ extension_global_error_);
+ delete extension_global_error_;
+ extension_global_error_ = NULL;
+ } else if (!extension_global_error_ && need_warning_badge) {
+ extension_global_error_ = new ExtensionGlobalError;
+ GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError(
+ extension_global_error_);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698