diff options
Diffstat (limited to 'chrome/browser/background_mode_manager.cc')
-rw-r--r-- | chrome/browser/background_mode_manager.cc | 35 |
1 files changed, 23 insertions, 12 deletions
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<std::string>& 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<Extension>(details).ptr())) + if (IsBackgroundApp(*Details<Extension>(details).ptr())) OnBackgroundAppLoaded(); break; case NotificationType::EXTENSION_UNLOADED: - if (IsBackgroundApp(Details<Extension>(details).ptr())) + if (IsBackgroundApp(*Details<Extension>(details).ptr())) OnBackgroundAppUnloaded(); break; case NotificationType::EXTENSION_INSTALLED: - if (IsBackgroundApp(Details<Extension>(details).ptr())) + if (IsBackgroundApp(*Details<Extension>(details).ptr())) OnBackgroundAppInstalled(); break; case NotificationType::EXTENSION_UNINSTALLED: - if (IsBackgroundApp(Details<Extension>(details).ptr())) + if (HasBackgroundAppPermission( + Details<UninstalledExtensionInfo>(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); } |