#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
+#include "base/scoped_observer.h"
#include "chrome/browser/tab_contents/background_contents.h"
#include "components/keyed_service/core/keyed_service.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/common/window_container_type.h"
+#include "extensions/browser/extension_registry_observer.h"
#include "ui/base/window_open_disposition.h"
#include "url/gurl.h"
namespace extensions {
class Extension;
+class ExtensionRegistry;
}
namespace gfx {
// BackgroundContents and their parent app, and shutting them down when the
// parent app is unloaded.
class BackgroundContentsService : private content::NotificationObserver,
+ public extensions::ExtensionRegistryObserver,
public BackgroundContents::Delegate,
public KeyedService {
public:
BackgroundContentsService(Profile* profile,
const base::CommandLine* command_line);
- virtual ~BackgroundContentsService();
+ ~BackgroundContentsService() override;
// Allows tests to reduce the time between a force-installed app/extension
// crashing and when we reload it.
static void SetRestartDelayForForceInstalledAppsAndExtensionsForTesting(
int restart_delay_in_ms);
- // Get the crash notification's id for the extension.
- static std::string GetNotificationIdForExtensionForTesting(
+ // Get the crash notification's delegate id for the extension.
+ static std::string GetNotificationDelegateIdForExtensionForTesting(
const std::string& extension_id);
// Show a popup notification balloon with a crash message for a given app/
std::vector<BackgroundContents*> GetBackgroundContents() const;
// BackgroundContents::Delegate implementation.
- virtual void AddWebContents(content::WebContents* new_contents,
- WindowOpenDisposition disposition,
- const gfx::Rect& initial_pos,
- bool user_gesture,
- bool* was_blocked) OVERRIDE;
+ void AddWebContents(content::WebContents* new_contents,
+ WindowOpenDisposition disposition,
+ const gfx::Rect& initial_pos,
+ bool user_gesture,
+ bool* was_blocked) override;
// Gets the parent application id for the passed BackgroundContents. Returns
// an empty string if no parent application found (e.g. passed
void StartObserving(Profile* profile);
// content::NotificationObserver implementation.
- virtual void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) OVERRIDE;
+ void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) override;
+
+ // extensions::ExtensionRegistryObserver implementation.
+ void OnExtensionLoaded(content::BrowserContext* browser_context,
+ const extensions::Extension* extension) override;
+ void OnExtensionUnloaded(
+ content::BrowserContext* browser_context,
+ const extensions::Extension* extension,
+ extensions::UnloadedExtensionInfo::Reason reason) override;
+ void OnExtensionUninstalled(content::BrowserContext* browser_context,
+ const extensions::Extension* extension,
+ extensions::UninstallReason reason) override;
// Restarts a force-installed app/extension after a crash.
void RestartForceInstalledExtensionOnCrash(
const base::string16& appid);
// Invoked when a new BackgroundContents is opened.
- void BackgroundContentsOpened(BackgroundContentsOpenedDetails* details);
+ void BackgroundContentsOpened(BackgroundContentsOpenedDetails* details,
+ Profile* profile);
// Invoked when a BackgroundContents object is destroyed.
void BackgroundContentsShutdown(BackgroundContents* contents);
BackgroundContentsMap;
BackgroundContentsMap contents_map_;
+ ScopedObserver<extensions::ExtensionRegistry,
+ extensions::ExtensionRegistryObserver>
+ extension_registry_observer_;
+
DISALLOW_COPY_AND_ASSIGN(BackgroundContentsService);
};