Index: chrome/browser/themes/theme_service.cc |
diff --git a/chrome/browser/themes/theme_service.cc b/chrome/browser/themes/theme_service.cc |
index 5457f1bafcaa7c287b0b40c08222dce319ef22c9..4dfe640fbaf7bbd21c836b6cce67337c09b33d2a 100644 |
--- a/chrome/browser/themes/theme_service.cc |
+++ b/chrome/browser/themes/theme_service.cc |
@@ -224,6 +224,14 @@ void ThemeService::Init(Profile* profile) { |
DCHECK(CalledOnValidThread()); |
profile_ = profile; |
+ // Listen to EXTENSION_LOADED instead of EXTENSION_INSTALLED because |
+ // the extension cannot yet be found via GetExtensionById() if it is |
+ // installed but not loaded (which may confuse listeners to |
+ // BROWSER_THEME_CHANGED). |
+ registrar_.Add(this, |
+ chrome::NOTIFICATION_EXTENSION_LOADED, |
+ content::Source<Profile>(profile_)); |
+ |
LoadThemePrefs(); |
theme_syncable_service_.reset(new ThemeSyncableService(profile_, this)); |
@@ -340,12 +348,6 @@ void ThemeService::SetTheme(const Extension* extension) { |
DCHECK(extension); |
DCHECK(extension->is_theme()); |
- if (DCHECK_IS_ON()) { |
- ExtensionService* service = |
- extensions::ExtensionSystem::Get(profile_)->extension_service(); |
- DCHECK(service); |
- DCHECK(service->GetExtensionById(extension->id(), false)); |
- } |
BuildFromExtension(extension); |
SaveThemeID(extension->id()); |
@@ -654,6 +656,17 @@ void ThemeService::FreePlatformCaches() { |
} |
#endif |
+void ThemeService::Observe(int type, |
+ const content::NotificationSource& source, |
+ const content::NotificationDetails& details) { |
+ DCHECK(type == chrome::NOTIFICATION_EXTENSION_LOADED); |
+ const Extension* extension = content::Details<const Extension>(details).ptr(); |
+ if (!extension->is_theme()) { |
+ return; |
+ } |
+ SetTheme(extension); |
+} |
+ |
void ThemeService::SavePackName(const FilePath& pack_path) { |
profile_->GetPrefs()->SetFilePath( |
prefs::kCurrentThemePackFilename, pack_path); |