Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Unified Diff: extensions/browser/api/runtime/runtime_api.cc

Issue 406063002: Hook up runtime API to implement ExtensionRegistryObserver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address code review feedback. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: extensions/browser/api/runtime/runtime_api.cc
diff --git a/extensions/browser/api/runtime/runtime_api.cc b/extensions/browser/api/runtime/runtime_api.cc
index fcd68014dede89b02ea7bb6adc0c105e0087b70e..6a1b6b5ab4e17281169366574a58eebb606d6452 100644
--- a/extensions/browser/api/runtime/runtime_api.cc
+++ b/extensions/browser/api/runtime/runtime_api.cc
@@ -137,19 +137,13 @@ BrowserContextKeyedAPIFactory<RuntimeAPI>* RuntimeAPI::GetFactoryInstance() {
}
RuntimeAPI::RuntimeAPI(content::BrowserContext* context)
- : browser_context_(context), dispatch_chrome_updated_event_(false) {
+ : browser_context_(context),
+ extension_registry_observer_(this),
+ dispatch_chrome_updated_event_(false) {
registrar_.Add(this,
chrome::NOTIFICATION_EXTENSIONS_READY,
content::Source<BrowserContext>(context));
- registrar_.Add(this,
- chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
- content::Source<BrowserContext>(context));
- registrar_.Add(this,
- chrome::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
- content::Source<BrowserContext>(context));
- registrar_.Add(this,
- chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED,
- content::Source<BrowserContext>(context));
+ extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_));
delegate_ = ExtensionsBrowserClient::Get()->CreateRuntimeAPIDelegate(
browser_context_);
@@ -167,33 +161,8 @@ RuntimeAPI::~RuntimeAPI() {
void RuntimeAPI::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
- switch (type) {
- case chrome::NOTIFICATION_EXTENSIONS_READY: {
- OnExtensionsReady();
- break;
- }
- case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: {
- const Extension* extension =
- content::Details<const Extension>(details).ptr();
- OnExtensionLoaded(extension);
- break;
- }
- case chrome::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED: {
- const Extension* extension =
- content::Details<const InstalledExtensionInfo>(details)->extension;
- OnExtensionInstalled(extension);
- break;
- }
- case chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED: {
- const Extension* extension =
- content::Details<const Extension>(details).ptr();
- OnExtensionUninstalled(extension);
- break;
- }
- default:
- NOTREACHED();
- break;
- }
+ DCHECK_EQ(chrome::NOTIFICATION_EXTENSIONS_READY, type);
+ OnExtensionsReady();
}
void RuntimeAPI::OnExtensionsReady() {
@@ -212,7 +181,8 @@ void RuntimeAPI::OnExtensionsReady() {
extension_system->process_manager()->AddObserver(this);
}
-void RuntimeAPI::OnExtensionLoaded(const Extension* extension) {
+void RuntimeAPI::OnExtensionLoaded(content::BrowserContext* browser_context,
+ const Extension* extension) {
if (!dispatch_chrome_updated_event_)
return;
@@ -226,7 +196,12 @@ void RuntimeAPI::OnExtensionLoaded(const Extension* extension) {
true));
}
-void RuntimeAPI::OnExtensionInstalled(const Extension* extension) {
+void RuntimeAPI::OnExtensionWillBeInstalled(
+ content::BrowserContext* browser_context,
+ const Extension* extension,
+ bool is_update,
+ bool from_ephemeral,
+ const std::string& old_name) {
// Ephemeral apps are not considered to be installed and do not receive
// the onInstalled() event.
if (util::IsEphemeralApp(extension->id(), browser_context_))
@@ -244,13 +219,17 @@ void RuntimeAPI::OnExtensionInstalled(const Extension* extension) {
false));
}
-void RuntimeAPI::OnExtensionUninstalled(const Extension* extension) {
+void RuntimeAPI::OnExtensionUninstalled(
+ content::BrowserContext* browser_context,
+ const Extension* extension,
+ UninstallReason reason) {
// Ephemeral apps are not considered to be installed, so the uninstall URL
// is not invoked when they are removed.
if (util::IsEphemeralApp(extension->id(), browser_context_))
return;
- RuntimeEventRouter::OnExtensionUninstalled(browser_context_, extension->id());
+ RuntimeEventRouter::OnExtensionUninstalled(
+ browser_context_, extension->id(), reason);
}
void RuntimeAPI::Shutdown() {
@@ -412,7 +391,13 @@ void RuntimeEventRouter::DispatchOnRestartRequiredEvent(
// static
void RuntimeEventRouter::OnExtensionUninstalled(
content::BrowserContext* context,
- const std::string& extension_id) {
+ const std::string& extension_id,
+ UninstallReason reason) {
+ if (!(reason == UNINSTALL_REASON_USER_INITIATED ||
+ reason == UNINSTALL_REASON_MANAGEMENT_API)) {
+ return;
+ }
+
GURL uninstall_url(
GetUninstallURL(ExtensionPrefs::Get(context), extension_id));
« extensions/browser/api/runtime/runtime_api.h ('K') | « extensions/browser/api/runtime/runtime_api.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698