Commit 5ba3b6cf authored by limasdf@gmail.com's avatar limasdf@gmail.com

This CL does small refactoring extension_toolbar_model.cc before removing...

This CL does small refactoring extension_toolbar_model.cc before removing NOTIFICATION_EXTENSION_UNLOADED and NOTIFICATION_EXTENSION_LOADED.

BUG=354046
TEST=browser_tests --gtest_filter=ExtensionToolbarModelTest.*

Review URL: https://codereview.chromium.org/256783003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266349 0039d316-1c4b-4281-b951-d872f2087c98
parent 3dc0c774
...@@ -185,27 +185,18 @@ void ExtensionToolbarModel::Observe( ...@@ -185,27 +185,18 @@ void ExtensionToolbarModel::Observe(
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) { const content::NotificationDetails& details) {
ExtensionService* extension_service = ExtensionService* extension_service =
extensions::ExtensionSystem::Get(profile_)->extension_service(); ExtensionSystem::Get(profile_)->extension_service();
if (!extension_service || !extension_service->is_ready()) DCHECK(extension_service);
if (!extension_service->is_ready())
return; return;
if (type == chrome::NOTIFICATION_EXTENSIONS_READY) { switch (type) {
case chrome::NOTIFICATION_EXTENSIONS_READY:
InitializeExtensionList(extension_service); InitializeExtensionList(extension_service);
return; break;
} case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: {
const Extension* extension =
const Extension* extension = NULL; content::Details<const Extension>(details).ptr();
if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED) {
extension = content::Details<extensions::UnloadedExtensionInfo>(
details)->extension;
} else if (type ==
chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED) {
extension = extension_service->GetExtensionById(
*content::Details<const std::string>(details).ptr(), true);
} else {
extension = content::Details<const Extension>(details).ptr();
}
if (type == chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED) {
// We don't want to add the same extension twice. It may have already been // We don't want to add the same extension twice. It may have already been
// added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user // added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user
// hides the browser action and then disables and enables the extension. // hides the browser action and then disables and enables the extension.
...@@ -213,23 +204,37 @@ void ExtensionToolbarModel::Observe( ...@@ -213,23 +204,37 @@ void ExtensionToolbarModel::Observe(
if (toolbar_items_[i].get() == extension) if (toolbar_items_[i].get() == extension)
return; // Already exists. return; // Already exists.
} }
if (ExtensionActionAPI::GetBrowserActionVisibility( if (ExtensionActionAPI::GetBrowserActionVisibility(extension_prefs_,
extension_prefs_, extension->id())) { extension->id())) {
AddExtension(extension); AddExtension(extension);
} }
} else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED) { break;
}
case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
const Extension* extension =
content::Details<extensions::UnloadedExtensionInfo>(details)
->extension;
RemoveExtension(extension); RemoveExtension(extension);
} else if (type == chrome::NOTIFICATION_EXTENSION_UNINSTALLED) { break;
}
case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: {
const Extension* extension =
content::Details<const Extension>(details).ptr();
UninstalledExtension(extension); UninstalledExtension(extension);
} else if (type == break;
chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED) { }
if (ExtensionActionAPI::GetBrowserActionVisibility( case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: {
extension_prefs_, extension->id())) { const Extension* extension = extension_service->GetExtensionById(
*content::Details<const std::string>(details).ptr(), true);
if (ExtensionActionAPI::GetBrowserActionVisibility(extension_prefs_,
extension->id())) {
AddExtension(extension); AddExtension(extension);
} else { } else {
RemoveExtension(extension); RemoveExtension(extension);
} }
} else { break;
}
default:
NOTREACHED() << "Received unexpected notification"; NOTREACHED() << "Received unexpected notification";
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment