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

Unified Diff: chrome/browser/extensions/extension_toolbar_model.cc

Issue 289073008: Add TriggerOnUninstalled to ExtensionRegistry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address review comment Created 6 years, 7 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
« no previous file with comments | « chrome/browser/extensions/extension_toolbar_model.h ('k') | extensions/browser/extension_registry.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_toolbar_model.cc
diff --git a/chrome/browser/extensions/extension_toolbar_model.cc b/chrome/browser/extensions/extension_toolbar_model.cc
index 7c9d5bfdd08beba10b31aa2edef74cecebfb399d..62050ab606cdcbdf920dc0d07ebe8f518d087a2e 100644
--- a/chrome/browser/extensions/extension_toolbar_model.cc
+++ b/chrome/browser/extensions/extension_toolbar_model.cc
@@ -191,32 +191,36 @@ void ExtensionToolbarModel::OnExtensionUnloaded(
RemoveExtension(extension);
}
+void ExtensionToolbarModel::OnExtensionUninstalled(
+ content::BrowserContext* browser_context,
+ const Extension* extension) {
+ // Remove the extension id from the ordered list, if it exists (the extension
+ // might not be represented in the list because it might not have an icon).
+ ExtensionIdList::iterator pos =
+ std::find(last_known_positions_.begin(),
+ last_known_positions_.end(), extension->id());
+
+ if (pos != last_known_positions_.end()) {
+ last_known_positions_.erase(pos);
+ UpdatePrefs();
+ }
+}
+
void ExtensionToolbarModel::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
- switch (type) {
- case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: {
- const Extension* extension =
- content::Details<const Extension>(details).ptr();
- UninstalledExtension(extension);
- break;
- }
- case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: {
- const Extension* extension =
- ExtensionRegistry::Get(profile_)->GetExtensionById(
- *content::Details<const std::string>(details).ptr(),
- ExtensionRegistry::EVERYTHING);
- if (ExtensionActionAPI::GetBrowserActionVisibility(extension_prefs_,
- extension->id())) {
- AddExtension(extension);
- } else {
- RemoveExtension(extension);
- }
- break;
- }
- default:
- NOTREACHED() << "Received unexpected notification";
+ DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED,
+ type);
+ const Extension* extension =
+ ExtensionRegistry::Get(profile_)->GetExtensionById(
+ *content::Details<const std::string>(details).ptr(),
+ ExtensionRegistry::EVERYTHING);
+ if (ExtensionActionAPI::GetBrowserActionVisibility(extension_prefs_,
+ extension->id())) {
+ AddExtension(extension);
+ } else {
+ RemoveExtension(extension);
}
}
@@ -227,9 +231,6 @@ void ExtensionToolbarModel::OnReady() {
// changes so that the toolbar buttons can be shown in their stable ordering
// taken from prefs.
extension_registry_observer_.Add(registry);
- registrar_.Add(this,
- chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
- content::Source<Profile>(profile_));
registrar_.Add(
this,
chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED,
@@ -325,19 +326,6 @@ void ExtensionToolbarModel::RemoveExtension(const Extension* extension) {
UpdatePrefs();
}
-void ExtensionToolbarModel::UninstalledExtension(const Extension* extension) {
- // Remove the extension id from the ordered list, if it exists (the extension
- // might not be represented in the list because it might not have an icon).
- ExtensionIdList::iterator pos =
- std::find(last_known_positions_.begin(),
- last_known_positions_.end(), extension->id());
-
- if (pos != last_known_positions_.end()) {
- last_known_positions_.erase(pos);
- UpdatePrefs();
- }
-}
-
// Combine the currently enabled extensions that have browser actions (which
// we get from the ExtensionRegistry) with the ordering we get from the
// pref service. For robustness we use a somewhat inefficient process:
@@ -589,6 +577,6 @@ void ExtensionToolbarModel::StopHighlighting() {
}
FOR_EACH_OBSERVER(Observer, observers_, HighlightModeChanged(false));
}
-};
+}
} // namespace extensions
« no previous file with comments | « chrome/browser/extensions/extension_toolbar_model.h ('k') | extensions/browser/extension_registry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698