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

Unified Diff: chrome/browser/extensions/extensions_service.cc

Issue 255047: Ensure ChromeURLRequestContext finds out first about extension loading (Closed)
Patch Set: cr changes Created 11 years, 3 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: chrome/browser/extensions/extensions_service.cc
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc
index 1258e84946f91582e015b2807dfd8af8eaa6385e..4f61ac4f34854a5dd40028b1808a2f11f7bd6103 100644
--- a/chrome/browser/extensions/extensions_service.cc
+++ b/chrome/browser/extensions/extensions_service.cc
@@ -18,6 +18,7 @@
#include "chrome/browser/extensions/external_extension_provider.h"
#include "chrome/browser/extensions/external_pref_extension_provider.h"
#include "chrome/browser/profile.h"
+#include "chrome/browser/net/chrome_url_request_context.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_error_reporter.h"
@@ -242,10 +243,7 @@ void ExtensionsService::EnableExtension(const std::string& extension_id) {
ExtensionDOMUI::RegisterChromeURLOverrides(profile_,
extension->GetChromeURLOverrides());
- NotificationService::current()->Notify(
- NotificationType::EXTENSION_LOADED,
- Source<ExtensionsService>(this),
- Details<Extension>(extension));
+ NotifyExtensionLoaded(extension);
}
void ExtensionsService::DisableExtension(const std::string& extension_id) {
@@ -269,10 +267,7 @@ void ExtensionsService::DisableExtension(const std::string& extension_id) {
ExtensionDOMUI::UnregisterChromeURLOverrides(profile_,
extension->GetChromeURLOverrides());
- NotificationService::current()->Notify(
- NotificationType::EXTENSION_UNLOADED,
- Source<ExtensionsService>(this),
- Details<Extension>(extension));
+ NotifyExtensionUnloaded(extension);
}
void ExtensionsService::LoadExtension(const FilePath& extension_path) {
@@ -324,6 +319,51 @@ void ExtensionsService::LoadInstalledExtension(
}
}
+void ExtensionsService::NotifyExtensionLoaded(Extension* extension) {
+ LOG(INFO) << "Sending EXTENSION_LOADED";
+
+ // The ChromeURLRequestContext needs to be first to know that the extension
+ // was loaded, otherwise a race can arise where a renderer that is created
+ // for the extension may try to load an extension URL with an extension id
+ // that the request context doesn't yet know about.
+ if (profile_ && !profile_->IsOffTheRecord()) {
+ ChromeURLRequestContext* context = static_cast<ChromeURLRequestContext*>(
+ profile_->GetRequestContext());
+ if (context) {
+ g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
+ NewRunnableMethod(context,
+ &ChromeURLRequestContext::OnNewExtensions,
+ extension->id(),
+ extension->path()));
+ }
+ }
+
+ NotificationService::current()->Notify(
+ NotificationType::EXTENSION_LOADED,
+ Source<ExtensionsService>(this),
+ Details<Extension>(extension));
+}
+
+void ExtensionsService::NotifyExtensionUnloaded(Extension* extension) {
+ LOG(INFO) << "Sending EXTENSION_UNLOADED";
+
+ NotificationService::current()->Notify(
+ NotificationType::EXTENSION_UNLOADED,
+ Source<ExtensionsService>(this),
+ Details<Extension>(extension));
+
+ if (profile_ && !profile_->IsOffTheRecord()) {
+ ChromeURLRequestContext* context = static_cast<ChromeURLRequestContext*>(
+ profile_->GetRequestContext());
+ if (context) {
+ g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
+ NewRunnableMethod(context,
+ &ChromeURLRequestContext::OnUnloadedExtension,
+ extension->id()));
+ }
+ }
+}
+
std::vector<ExtensionAction*> ExtensionsService::GetExtensionActions(
ExtensionAction::ExtensionActionType action_type) const {
std::vector<ExtensionAction*> result;
@@ -413,10 +453,7 @@ void ExtensionsService::UnloadExtension(const std::string& extension_id) {
// Remove the extension from our list.
extensions_.erase(iter);
- // Tell other services the extension is gone.
- NotificationService::current()->Notify(NotificationType::EXTENSION_UNLOADED,
- Source<ExtensionsService>(this),
- Details<Extension>(extension.get()));
+ NotifyExtensionUnloaded(extension.get());
}
void ExtensionsService::UnloadAllExtensions() {
@@ -498,11 +535,7 @@ void ExtensionsService::OnExtensionLoaded(Extension* extension,
if (extension->location() != Extension::LOAD)
extension_prefs_->MigrateToPrefs(extension);
- LOG(INFO) << "Sending EXTENSION_LOADED";
- NotificationService::current()->Notify(
- NotificationType::EXTENSION_LOADED,
- Source<ExtensionsService>(this),
- Details<Extension>(extension));
+ NotifyExtensionLoaded(extension);
if (extension->IsTheme() && extension->location() == Extension::LOAD) {
NotificationService::current()->Notify(

Powered by Google App Engine
This is Rietveld 408576698