summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--extensions/browser/api/runtime/runtime_api.cc48
-rw-r--r--extensions/browser/api/runtime/runtime_api.h14
2 files changed, 27 insertions, 35 deletions
diff --git a/extensions/browser/api/runtime/runtime_api.cc b/extensions/browser/api/runtime/runtime_api.cc
index b028aee..808955d 100644
--- a/extensions/browser/api/runtime/runtime_api.cc
+++ b/extensions/browser/api/runtime/runtime_api.cc
@@ -12,10 +12,8 @@
#include "base/metrics/histogram.h"
#include "base/values.h"
#include "base/version.h"
-#include "chrome/browser/chrome_notification_types.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/child_process_security_policy.h"
-#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "extensions/browser/api/runtime/runtime_api_delegate.h"
@@ -33,6 +31,7 @@
#include "extensions/common/extension.h"
#include "extensions/common/manifest_handlers/background_info.h"
#include "extensions/common/manifest_handlers/shared_module_info.h"
+#include "extensions/common/one_shot_event.h"
#include "url/gurl.h"
#include "webkit/browser/fileapi/isolated_context.h"
@@ -139,11 +138,13 @@ BrowserContextKeyedAPIFactory<RuntimeAPI>* RuntimeAPI::GetFactoryInstance() {
RuntimeAPI::RuntimeAPI(content::BrowserContext* context)
: browser_context_(context),
dispatch_chrome_updated_event_(false),
- extension_registry_observer_(this) {
- registrar_.Add(this,
- chrome::NOTIFICATION_EXTENSIONS_READY,
- content::Source<BrowserContext>(context));
+ extension_registry_observer_(this),
+ weak_ptr_factory_(this) {
extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_));
+ ExtensionSystem::Get(browser_context_)->ready().Post(
+ FROM_HERE,
+ base::Bind(&RuntimeAPI::OnExtensionReady,
+ weak_ptr_factory_.GetWeakPtr()));
delegate_ = ExtensionsBrowserClient::Get()->CreateRuntimeAPIDelegate(
browser_context_);
@@ -158,25 +159,6 @@ RuntimeAPI::~RuntimeAPI() {
delegate_->RemoveUpdateObserver(this);
}
-void RuntimeAPI::Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- DCHECK_EQ(chrome::NOTIFICATION_EXTENSIONS_READY, type);
- // We're done restarting Chrome after an update.
- dispatch_chrome_updated_event_ = false;
-
- delegate_->AddUpdateObserver(this);
-
- // RuntimeAPI is redirected in incognito, so |browser_context_| is never
- // incognito. We don't observe incognito ProcessManagers but that is OK
- // because we don't send onStartup events to incognito browser contexts.
- DCHECK(!browser_context_->IsOffTheRecord());
- // Some tests use partially constructed Profiles without a process manager.
- ExtensionSystem* extension_system = ExtensionSystem::Get(browser_context_);
- if (extension_system->process_manager())
- extension_system->process_manager()->AddObserver(this);
-}
-
void RuntimeAPI::OnExtensionLoaded(content::BrowserContext* browser_context,
const Extension* extension) {
if (!dispatch_chrome_updated_event_)
@@ -228,6 +210,22 @@ void RuntimeAPI::OnExtensionUninstalled(
browser_context_, extension->id(), reason);
}
+void RuntimeAPI::OnExtensionReady() {
+ // We're done restarting Chrome after an update.
+ dispatch_chrome_updated_event_ = false;
+
+ delegate_->AddUpdateObserver(this);
+
+ // RuntimeAPI is redirected in incognito, so |browser_context_| is never
+ // incognito. We don't observe incognito ProcessManagers but that is OK
+ // because we don't send onStartup events to incognito browser contexts.
+ DCHECK(!browser_context_->IsOffTheRecord());
+ // Some tests use partially constructed Profiles without a process manager.
+ ExtensionSystem* extension_system = ExtensionSystem::Get(browser_context_);
+ if (extension_system->process_manager())
+ extension_system->process_manager()->AddObserver(this);
+}
+
void RuntimeAPI::Shutdown() {
// ExtensionSystem deletes its ProcessManager during the Shutdown() phase, so
// the observer must be removed here and not in the RuntimeAPI destructor.
diff --git a/extensions/browser/api/runtime/runtime_api.h b/extensions/browser/api/runtime/runtime_api.h
index 244ef14..44d8d54 100644
--- a/extensions/browser/api/runtime/runtime_api.h
+++ b/extensions/browser/api/runtime/runtime_api.h
@@ -7,9 +7,8 @@
#include <string>
+#include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h"
-#include "content/public/browser/notification_observer.h"
-#include "content/public/browser/notification_registrar.h"
#include "extensions/browser/api/runtime/runtime_api_delegate.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/extension_function.h"
@@ -42,7 +41,6 @@ class ExtensionRegistry;
// extensions. There is one instance shared between a browser context and
// its related incognito instance.
class RuntimeAPI : public BrowserContextKeyedAPI,
- public content::NotificationObserver,
public ExtensionRegistryObserver,
public UpdateObserver,
public ProcessManagerObserver {
@@ -52,11 +50,6 @@ class RuntimeAPI : public BrowserContextKeyedAPI,
explicit RuntimeAPI(content::BrowserContext* context);
virtual ~RuntimeAPI();
- // content::NotificationObserver overrides:
- virtual void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) OVERRIDE;
-
void ReloadExtension(const std::string& extension_id);
bool CheckForUpdates(const std::string& extension_id,
const RuntimeAPIDelegate::UpdateCheckCallback& callback);
@@ -79,6 +72,7 @@ class RuntimeAPI : public BrowserContextKeyedAPI,
virtual void OnExtensionUninstalled(content::BrowserContext* browser_context,
const Extension* extension,
UninstallReason reason) OVERRIDE;
+ void OnExtensionReady();
// BrowserContextKeyedAPI implementation:
static const char* service_name() { return "RuntimeAPI"; }
@@ -101,12 +95,12 @@ class RuntimeAPI : public BrowserContextKeyedAPI,
// reason "chrome_update" upon loading each extension.
bool dispatch_chrome_updated_event_;
- content::NotificationRegistrar registrar_;
-
// Listen to extension notifications.
ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
extension_registry_observer_;
+ base::WeakPtrFactory<RuntimeAPI> weak_ptr_factory_;
+
DISALLOW_COPY_AND_ASSIGN(RuntimeAPI);
};