Index: chrome/browser/extensions/extensions_service.cc |
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc |
index 6dcc0150156b44e68de3537a18d338ba258687f9..c78b24e7f110930c9024ef191405083d096e3770 100644 |
--- a/chrome/browser/extensions/extensions_service.cc |
+++ b/chrome/browser/extensions/extensions_service.cc |
@@ -107,6 +107,9 @@ ExtensionsService::ExtensionsService(Profile* profile, |
} |
backend_ = new ExtensionsServiceBackend(install_directory_, frontend_loop); |
+ |
+ registrar_.Add(this, NotificationType::EXTENSION_PROCESS_CRASHED, |
+ Source<ExtensionsService>(this)); |
} |
ExtensionsService::~ExtensionsService() { |
@@ -159,11 +162,13 @@ void ExtensionsService::UpdateExtension(const std::string& id, |
} |
void ExtensionsService::ReloadExtension(const std::string& extension_id) { |
- Extension* extension = GetExtensionById(extension_id); |
- FilePath extension_path = extension->path(); |
+ // Unload the extension if it's loaded. |
+ if (GetExtensionById(extension_id)) |
+ UnloadExtension(extension_id); |
- UnloadExtension(extension_id); |
- LoadExtension(extension_path); |
+ // At this point we have to reconstruct the path from prefs, because |
+ // we have no information about this extension in memory. |
+ LoadExtension(extension_prefs_->GetExtensionPath(extension_id)); |
} |
void ExtensionsService::UninstallExtension(const std::string& extension_id, |
@@ -509,6 +514,25 @@ void ExtensionsService::OnExternalExtensionFound(const std::string& id, |
NULL); // no client (silent install) |
} |
+void ExtensionsService::Observe(NotificationType type, |
+ const NotificationSource& source, |
+ const NotificationDetails& details) { |
+ switch (type.value) { |
+ case NotificationType::EXTENSION_PROCESS_CRASHED: { |
+ DCHECK_EQ(this, Source<ExtensionsService>(source).ptr()); |
+ ExtensionHost* host = Details<ExtensionHost>(details).ptr(); |
+ |
+ // Unload the entire extension to make sure its state is consistent |
+ // (either fully operational, or fully unloaded, but not half-crashed). |
+ UnloadExtension(host->extension()->id()); |
+ } |
+ break; |
+ |
+ default: |
+ NOTREACHED(); |
+ } |
+} |
+ |
// ExtensionsServicesBackend |