From 21103034ad3f39ca1b24a254e97ff91776ea9a9e Mon Sep 17 00:00:00 2001 From: "akalin@chromium.org" Date: Thu, 30 Sep 2010 18:41:06 +0000 Subject: Changed EXTENSION_UNINSTALLED notification to happen after uninstallation. The important part is that it comes after the EXTENSION_UNLOADED notification is sent. This makes it easier on the listeners, as they can assume that extension notifications other than EXTENSION_UNINSTALLED are sent for currently-installed extensions. BUG=54415 TEST=BackgroundModeManagerTest Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=60834 Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=60848 Review URL: http://codereview.chromium.org/3461025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61089 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/background_mode_manager.cc | 35 ++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'chrome/browser/background_mode_manager.cc') diff --git a/chrome/browser/background_mode_manager.cc b/chrome/browser/background_mode_manager.cc index ba952cb..8946e3c 100644 --- a/chrome/browser/background_mode_manager.cc +++ b/chrome/browser/background_mode_manager.cc @@ -188,6 +188,20 @@ void BackgroundModeManager::SetLaunchOnStartupResetAllowed(bool allowed) { allowed); } +namespace { + +bool HasBackgroundAppPermission( + const std::set& api_permissions) { + return Extension::HasApiPermission( + api_permissions, Extension::kBackgroundPermission); +} + +bool IsBackgroundApp(const Extension& extension) { + return HasBackgroundAppPermission(extension.api_permissions()); +} + +} // namespace + void BackgroundModeManager::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { @@ -202,19 +216,21 @@ void BackgroundModeManager::Observe(NotificationType type, #endif break; case NotificationType::EXTENSION_LOADED: - if (IsBackgroundApp(Details(details).ptr())) + if (IsBackgroundApp(*Details(details).ptr())) OnBackgroundAppLoaded(); break; case NotificationType::EXTENSION_UNLOADED: - if (IsBackgroundApp(Details(details).ptr())) + if (IsBackgroundApp(*Details(details).ptr())) OnBackgroundAppUnloaded(); break; case NotificationType::EXTENSION_INSTALLED: - if (IsBackgroundApp(Details(details).ptr())) + if (IsBackgroundApp(*Details(details).ptr())) OnBackgroundAppInstalled(); break; case NotificationType::EXTENSION_UNINSTALLED: - if (IsBackgroundApp(Details(details).ptr())) + if (HasBackgroundAppPermission( + Details(details).ptr()-> + extension_api_permissions)) OnBackgroundAppUninstalled(); break; case NotificationType::APP_TERMINATING: @@ -236,11 +252,6 @@ void BackgroundModeManager::Observe(NotificationType type, } } -bool BackgroundModeManager::IsBackgroundApp(Extension* extension) { - return extension->HasApiPermission(Extension::kBackgroundPermission); -} - - void BackgroundModeManager::OnBackgroundModePrefChanged() { // Background mode has been enabled/disabled in preferences, so update our // state accordingly. @@ -308,9 +319,9 @@ void BackgroundModeManager::OnBackgroundAppInstalled() { } void BackgroundModeManager::OnBackgroundAppUninstalled() { - // When uninstalling a background app, disable launch on startup if it's the - // last one. - if (IsBackgroundModeEnabled() && background_app_count_ == 1) + // When uninstalling a background app, disable launch on startup if + // we have no more background apps. + if (IsBackgroundModeEnabled() && background_app_count_ == 0) EnableLaunchOnStartup(false); } -- cgit v1.1