Commit 7cf82869 authored by limasdf@gmail.com's avatar limasdf@gmail.com

Remove DEPRECATED extension notification from background_contents_service.*

R=atwilson@chromium.org
BUG=354458

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285633 0039d316-1c4b-4281-b951-d872f2087c98
parent 32c5a54e
...@@ -261,7 +261,7 @@ int BackgroundContentsService::restart_delay_in_ms_ = 3000; // 3 seconds. ...@@ -261,7 +261,7 @@ int BackgroundContentsService::restart_delay_in_ms_ = 3000; // 3 seconds.
BackgroundContentsService::BackgroundContentsService( BackgroundContentsService::BackgroundContentsService(
Profile* profile, const CommandLine* command_line) Profile* profile, const CommandLine* command_line)
: prefs_(NULL) { : prefs_(NULL), extension_registry_observer_(this) {
// Don't load/store preferences if the parent profile is incognito. // Don't load/store preferences if the parent profile is incognito.
if (!profile->IsOffTheRecord()) if (!profile->IsOffTheRecord())
prefs_ = profile->GetPrefs(); prefs_ = profile->GetPrefs();
...@@ -329,12 +329,6 @@ void BackgroundContentsService::StartObserving(Profile* profile) { ...@@ -329,12 +329,6 @@ void BackgroundContentsService::StartObserving(Profile* profile) {
registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED,
content::Source<Profile>(profile)); content::Source<Profile>(profile));
// Listen for new extension installs so that we can load any associated
// background page.
registrar_.Add(this,
chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
content::Source<Profile>(profile));
// Track when the extensions crash so that the user can be notified // Track when the extensions crash so that the user can be notified
// about it, and the crashed contents can be restarted. // about it, and the crashed contents can be restarted.
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
...@@ -342,18 +336,8 @@ void BackgroundContentsService::StartObserving(Profile* profile) { ...@@ -342,18 +336,8 @@ void BackgroundContentsService::StartObserving(Profile* profile) {
registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED, registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED,
content::Source<Profile>(profile)); content::Source<Profile>(profile));
// Listen for extensions to be unloaded so we can shutdown associated // Listen for extension uninstall, load, unloaded notification.
// BackgroundContents. extension_registry_observer_.Add(extensions::ExtensionRegistry::Get(profile));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
content::Source<Profile>(profile));
// Make sure the extension-crash balloons are removed when the extension is
// uninstalled/reloaded. We cannot do this from UNLOADED since a crashed
// extension is unloaded immediately after the crash, not when user reloads or
// uninstalls the extension.
registrar_.Add(this,
chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED,
content::Source<Profile>(profile));
} }
void BackgroundContentsService::Observe( void BackgroundContentsService::Observe(
...@@ -401,35 +385,6 @@ void BackgroundContentsService::Observe( ...@@ -401,35 +385,6 @@ void BackgroundContentsService::Observe(
RegisterBackgroundContents(bgcontents); RegisterBackgroundContents(bgcontents);
break; break;
} }
case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: {
const Extension* extension =
content::Details<const Extension>(details).ptr();
Profile* profile = content::Source<Profile>(source).ptr();
if (extension->is_hosted_app() &&
BackgroundInfo::HasBackgroundPage(extension)) {
// If there is a background page specified in the manifest for a hosted
// app, then blow away registered urls in the pref.
ShutdownAssociatedBackgroundContents(
base::ASCIIToUTF16(extension->id()));
ExtensionService* service =
extensions::ExtensionSystem::Get(profile)->extension_service();
if (service && service->is_ready()) {
// Now load the manifest-specified background page. If service isn't
// ready, then the background page will be loaded from the
// EXTENSIONS_READY callback.
LoadBackgroundContents(profile,
BackgroundInfo::GetBackgroundURL(extension),
base::ASCIIToUTF16("background"),
base::UTF8ToUTF16(extension->id()));
}
}
// Close the crash notification balloon for the app/extension, if any.
ScheduleCloseBalloon(extension->id());
SendChangeNotification(profile);
break;
}
case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED:
case chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED: { case chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED: {
Profile* profile = content::Source<Profile>(source).ptr(); Profile* profile = content::Source<Profile>(source).ptr();
...@@ -462,55 +417,85 @@ void BackgroundContentsService::Observe( ...@@ -462,55 +417,85 @@ void BackgroundContentsService::Observe(
} }
break; break;
} }
case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED:
switch (content::Details<UnloadedExtensionInfo>(details)->reason) {
case UnloadedExtensionInfo::REASON_DISABLE: // Fall through.
case UnloadedExtensionInfo::REASON_TERMINATE: // Fall through.
case UnloadedExtensionInfo::REASON_UNINSTALL: // Fall through.
case UnloadedExtensionInfo::REASON_BLACKLIST: // Fall through.
case UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN:
ShutdownAssociatedBackgroundContents(base::ASCIIToUTF16(
content::Details<UnloadedExtensionInfo>(details)->
extension->id()));
SendChangeNotification(content::Source<Profile>(source).ptr());
break;
case UnloadedExtensionInfo::REASON_UPDATE: {
// If there is a manifest specified background page, then shut it down
// here, since if the updated extension still has the background page,
// then it will be loaded from LOADED callback. Otherwise, leave
// BackgroundContents in place.
// We don't call SendChangeNotification here - it will be generated
// from the LOADED callback.
const Extension* extension =
content::Details<UnloadedExtensionInfo>(details)->extension;
if (BackgroundInfo::HasBackgroundPage(extension)) {
ShutdownAssociatedBackgroundContents(
base::ASCIIToUTF16(extension->id()));
}
break;
}
default:
NOTREACHED();
ShutdownAssociatedBackgroundContents(base::ASCIIToUTF16(
content::Details<UnloadedExtensionInfo>(details)->
extension->id()));
break;
}
break;
case chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED: { default:
// Close the crash notification balloon for the app/extension, if any. NOTREACHED();
ScheduleCloseBalloon(
content::Details<const Extension>(details).ptr()->id());
break; break;
}
}
void BackgroundContentsService::OnExtensionLoaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension) {
Profile* profile = Profile::FromBrowserContext(browser_context);
if (extension->is_hosted_app() &&
BackgroundInfo::HasBackgroundPage(extension)) {
// If there is a background page specified in the manifest for a hosted
// app, then blow away registered urls in the pref.
ShutdownAssociatedBackgroundContents(base::ASCIIToUTF16(extension->id()));
ExtensionService* service =
extensions::ExtensionSystem::Get(browser_context)->extension_service();
if (service && service->is_ready()) {
// Now load the manifest-specified background page. If service isn't
// ready, then the background page will be loaded from the
// EXTENSIONS_READY callback.
LoadBackgroundContents(profile,
BackgroundInfo::GetBackgroundURL(extension),
base::ASCIIToUTF16("background"),
base::UTF8ToUTF16(extension->id()));
} }
}
// Close the crash notification balloon for the app/extension, if any.
ScheduleCloseBalloon(extension->id());
SendChangeNotification(profile);
}
void BackgroundContentsService::OnExtensionUnloaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension,
extensions::UnloadedExtensionInfo::Reason reason) {
switch (reason) {
case UnloadedExtensionInfo::REASON_DISABLE: // Fall through.
case UnloadedExtensionInfo::REASON_TERMINATE: // Fall through.
case UnloadedExtensionInfo::REASON_UNINSTALL: // Fall through.
case UnloadedExtensionInfo::REASON_BLACKLIST: // Fall through.
case UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN:
ShutdownAssociatedBackgroundContents(base::ASCIIToUTF16(extension->id()));
SendChangeNotification(Profile::FromBrowserContext(browser_context));
break;
case UnloadedExtensionInfo::REASON_UPDATE: {
// If there is a manifest specified background page, then shut it down
// here, since if the updated extension still has the background page,
// then it will be loaded from LOADED callback. Otherwise, leave
// BackgroundContents in place.
// We don't call SendChangeNotification here - it will be generated
// from the LOADED callback.
if (BackgroundInfo::HasBackgroundPage(extension)) {
ShutdownAssociatedBackgroundContents(
base::ASCIIToUTF16(extension->id()));
}
break;
}
default: default:
NOTREACHED(); NOTREACHED();
ShutdownAssociatedBackgroundContents(base::ASCIIToUTF16(extension->id()));
break; break;
} }
} }
void BackgroundContentsService::OnExtensionUninstalled(
content::BrowserContext* browser_context,
const extensions::Extension* extension,
extensions::UninstallReason reason) {
// Make sure the extension-crash balloons are removed when the extension is
// uninstalled/reloaded. We cannot do this from UNLOADED since a crashed
// extension is unloaded immediately after the crash, not when user reloads or
// uninstalls the extension.
ScheduleCloseBalloon(extension->id());
}
void BackgroundContentsService::RestartForceInstalledExtensionOnCrash( void BackgroundContentsService::RestartForceInstalledExtensionOnCrash(
const Extension* extension, const Extension* extension,
Profile* profile) { Profile* profile) {
......
...@@ -11,11 +11,13 @@ ...@@ -11,11 +11,13 @@
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/scoped_observer.h"
#include "chrome/browser/tab_contents/background_contents.h" #include "chrome/browser/tab_contents/background_contents.h"
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "content/public/common/window_container_type.h" #include "content/public/common/window_container_type.h"
#include "extensions/browser/extension_registry_observer.h"
#include "ui/base/window_open_disposition.h" #include "ui/base/window_open_disposition.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -33,6 +35,7 @@ class SessionStorageNamespace; ...@@ -33,6 +35,7 @@ class SessionStorageNamespace;
namespace extensions { namespace extensions {
class Extension; class Extension;
class ExtensionRegistry;
} }
namespace gfx { namespace gfx {
...@@ -50,6 +53,7 @@ struct BackgroundContentsOpenedDetails; ...@@ -50,6 +53,7 @@ struct BackgroundContentsOpenedDetails;
// BackgroundContents and their parent app, and shutting them down when the // BackgroundContents and their parent app, and shutting them down when the
// parent app is unloaded. // parent app is unloaded.
class BackgroundContentsService : private content::NotificationObserver, class BackgroundContentsService : private content::NotificationObserver,
public extensions::ExtensionRegistryObserver,
public BackgroundContents::Delegate, public BackgroundContents::Delegate,
public KeyedService { public KeyedService {
public: public:
...@@ -140,6 +144,19 @@ class BackgroundContentsService : private content::NotificationObserver, ...@@ -140,6 +144,19 @@ class BackgroundContentsService : private content::NotificationObserver,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE; const content::NotificationDetails& details) OVERRIDE;
// extensions::ExtensionRegistryObserver implementation.
virtual void OnExtensionLoaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension) OVERRIDE;
virtual void OnExtensionUnloaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension,
extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE;
virtual void OnExtensionUninstalled(
content::BrowserContext* browser_context,
const extensions::Extension* extension,
extensions::UninstallReason reason) OVERRIDE;
// Restarts a force-installed app/extension after a crash. // Restarts a force-installed app/extension after a crash.
void RestartForceInstalledExtensionOnCrash( void RestartForceInstalledExtensionOnCrash(
const extensions::Extension* extension, const extensions::Extension* extension,
...@@ -218,6 +235,10 @@ class BackgroundContentsService : private content::NotificationObserver, ...@@ -218,6 +235,10 @@ class BackgroundContentsService : private content::NotificationObserver,
BackgroundContentsMap; BackgroundContentsMap;
BackgroundContentsMap contents_map_; BackgroundContentsMap contents_map_;
ScopedObserver<extensions::ExtensionRegistry,
extensions::ExtensionRegistryObserver>
extension_registry_observer_;
DISALLOW_COPY_AND_ASSIGN(BackgroundContentsService); DISALLOW_COPY_AND_ASSIGN(BackgroundContentsService);
}; };
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/pref_registry/pref_registry_syncable.h" #include "components/pref_registry/pref_registry_syncable.h"
#include "extensions/browser/extension_registry_factory.h"
// static // static
BackgroundContentsService* BackgroundContentsServiceFactory::GetForProfile( BackgroundContentsService* BackgroundContentsServiceFactory::GetForProfile(
...@@ -30,6 +31,7 @@ BackgroundContentsServiceFactory::BackgroundContentsServiceFactory() ...@@ -30,6 +31,7 @@ BackgroundContentsServiceFactory::BackgroundContentsServiceFactory()
: BrowserContextKeyedServiceFactory( : BrowserContextKeyedServiceFactory(
"BackgroundContentsService", "BackgroundContentsService",
BrowserContextDependencyManager::GetInstance()) { BrowserContextDependencyManager::GetInstance()) {
DependsOn(extensions::ExtensionRegistryFactory::GetInstance());
} }
BackgroundContentsServiceFactory::~BackgroundContentsServiceFactory() { BackgroundContentsServiceFactory::~BackgroundContentsServiceFactory() {
......
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