diff options
-rw-r--r-- | chrome/browser/background_mode_manager.cc | 35 | ||||
-rw-r--r-- | chrome/browser/background_mode_manager.h | 3 | ||||
-rw-r--r-- | chrome/browser/background_mode_manager_unittest.cc | 10 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service.cc | 13 | ||||
-rw-r--r-- | chrome/common/extensions/extension.cc | 5 | ||||
-rw-r--r-- | chrome/common/extensions/extension.h | 9 | ||||
-rw-r--r-- | chrome/common/notification_type.h | 7 |
7 files changed, 31 insertions, 51 deletions
diff --git a/chrome/browser/background_mode_manager.cc b/chrome/browser/background_mode_manager.cc index b3bf83a..01a9a36 100644 --- a/chrome/browser/background_mode_manager.cc +++ b/chrome/browser/background_mode_manager.cc @@ -191,20 +191,6 @@ 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) { @@ -219,21 +205,19 @@ 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 (HasBackgroundAppPermission( - Details<UninstalledExtensionInfo>(details).ptr()-> - extension_api_permissions)) + if (IsBackgroundApp(Details<Extension>(details).ptr())) OnBackgroundAppUninstalled(); break; case NotificationType::APP_TERMINATING: @@ -255,6 +239,11 @@ 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. @@ -322,9 +311,9 @@ void BackgroundModeManager::OnBackgroundAppInstalled() { } void BackgroundModeManager::OnBackgroundAppUninstalled() { - // When uninstalling a background app, disable launch on startup if - // we have no more background apps. - if (IsBackgroundModeEnabled() && background_app_count_ == 0) + // When uninstalling a background app, disable launch on startup if it's the + // last one. + if (IsBackgroundModeEnabled() && background_app_count_ == 1) EnableLaunchOnStartup(false); } diff --git a/chrome/browser/background_mode_manager.h b/chrome/browser/background_mode_manager.h index 27e710f..46e8847 100644 --- a/chrome/browser/background_mode_manager.h +++ b/chrome/browser/background_mode_manager.h @@ -85,6 +85,9 @@ class BackgroundModeManager // Invoked when the kBackgroundModeEnabled preference has changed. void OnBackgroundModePrefChanged(); + // Returns true if the passed extension is a background app. + bool IsBackgroundApp(Extension* extension); + // Returns true if the background mode preference is enabled bool IsBackgroundModeEnabled(); diff --git a/chrome/browser/background_mode_manager_unittest.cc b/chrome/browser/background_mode_manager_unittest.cc index 4c43610..075db814 100644 --- a/chrome/browser/background_mode_manager_unittest.cc +++ b/chrome/browser/background_mode_manager_unittest.cc @@ -56,15 +56,15 @@ TEST_F(BackgroundModeManagerTest, BackgroundAppInstallUninstall) { TestingProfile profile; TestBackgroundModeManager manager(&profile, command_line_.get()); // Call to AppInstalled() will cause chrome to be set to launch on startup, - // and call to AppUninstalled() set chrome to not launch on startup. + // and call to AppUninstalling() set chrome to not launch on startup. EXPECT_CALL(manager, EnableLaunchOnStartup(true)); EXPECT_CALL(manager, CreateStatusTrayIcon()); - EXPECT_CALL(manager, RemoveStatusTrayIcon()); EXPECT_CALL(manager, EnableLaunchOnStartup(false)); + EXPECT_CALL(manager, RemoveStatusTrayIcon()); manager.OnBackgroundAppInstalled(); manager.OnBackgroundAppLoaded(); - manager.OnBackgroundAppUnloaded(); manager.OnBackgroundAppUninstalled(); + manager.OnBackgroundAppUnloaded(); } TEST_F(BackgroundModeManagerTest, BackgroundPrefDisabled) { @@ -72,15 +72,15 @@ TEST_F(BackgroundModeManagerTest, BackgroundPrefDisabled) { TestingProfile profile; profile.GetPrefs()->SetBoolean(prefs::kBackgroundModeEnabled, false); TestBackgroundModeManager manager(&profile, command_line_.get()); - EXPECT_CALL(manager, CreateStatusTrayIcon()).Times(0); // Should not change launch on startup status when installing/uninstalling // if background mode is disabled. EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(0); + EXPECT_CALL(manager, CreateStatusTrayIcon()).Times(0); manager.OnBackgroundAppInstalled(); manager.OnBackgroundAppLoaded(); EXPECT_FALSE(BrowserList::WillKeepAlive()); - manager.OnBackgroundAppUnloaded(); manager.OnBackgroundAppUninstalled(); + manager.OnBackgroundAppUnloaded(); } TEST_F(BackgroundModeManagerTest, BackgroundPrefDynamicDisable) { diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index d572f0f..e2e6342 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -758,11 +758,16 @@ void ExtensionsService::UninstallExtension(const std::string& extension_id, // Callers should not send us nonexistent extensions. DCHECK(extension); + // Notify interested parties that we're uninstalling this extension. + NotificationService::current()->Notify( + NotificationType::EXTENSION_UNINSTALLED, + Source<Profile>(profile_), + Details<Extension>(extension)); + // Get hold of information we need after unloading, since the extension // pointer will be invalid then. GURL extension_url(extension->url()); Extension::Location location(extension->location()); - UninstalledExtensionInfo uninstalled_extension_info(*extension); // Also copy the extension identifier since the reference might have been // obtained via Extension::id(). @@ -789,12 +794,6 @@ void ExtensionsService::UninstallExtension(const std::string& extension_id, } ClearExtensionData(extension_url); - - // Notify interested parties that we've uninstalled this extension. - NotificationService::current()->Notify( - NotificationType::EXTENSION_UNINSTALLED, - Source<Profile>(profile_), - Details<UninstalledExtensionInfo>(&uninstalled_extension_info)); } void ExtensionsService::ClearExtensionData(const GURL& extension_url) { diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index 375bfa6..a236809 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -1958,8 +1958,3 @@ ExtensionInfo::ExtensionInfo(const DictionaryValue* manifest, ExtensionInfo::~ExtensionInfo() { } - -UninstalledExtensionInfo::UninstalledExtensionInfo( - const Extension& extension) - : extension_id(extension.id()), - extension_api_permissions(extension.api_permissions()) {} diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h index 8e9d2d1..79f9156 100644 --- a/chrome/common/extensions/extension.h +++ b/chrome/common/extensions/extension.h @@ -610,13 +610,4 @@ struct ExtensionInfo { DISALLOW_COPY_AND_ASSIGN(ExtensionInfo); }; -// Struct used for the details of the EXTENSION_UNINSTALLED -// notification. -struct UninstalledExtensionInfo { - explicit UninstalledExtensionInfo(const Extension& extension); - - std::string extension_id; - std::set<std::string> extension_api_permissions; -}; - #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ diff --git a/chrome/common/notification_type.h b/chrome/common/notification_type.h index d903ffb..541aaa9 100644 --- a/chrome/common/notification_type.h +++ b/chrome/common/notification_type.h @@ -797,8 +797,11 @@ class NotificationType { // details about why the install failed. EXTENSION_INSTALL_ERROR, - // Sent when an extension has been uninstalled. The details are - // an UninstalledExtensionInfo struct and the source is a Profile. + // Sent when a new extension is being uninstalled. When this notification + // is sent, the ExtensionsService still is tracking this extension (it has + // not been unloaded yet). This will be followed by an EXTENSION_UNLOADED + // or EXTENSION_UNLOADED_DISABLED when the extension is actually unloaded. + // The details are an Extension and the source is a Profile. EXTENSION_UNINSTALLED, // Sent when an extension is unloaded. This happens when an extension is |