Index: chrome/browser/themes/theme_service.cc |
diff --git a/chrome/browser/themes/theme_service.cc b/chrome/browser/themes/theme_service.cc |
index 7b20d395050affc0ef04d13c678e325166625070..b9ee2841fbb682d56fa9efeb76bc3bddeb894f8a 100644 |
--- a/chrome/browser/themes/theme_service.cc |
+++ b/chrome/browser/themes/theme_service.cc |
@@ -102,6 +102,7 @@ ThemeService::ThemeService() |
profile_(NULL), |
installed_pending_load_id_(kDefaultThemeID), |
number_of_infobars_(0), |
+ extension_registry_(NULL), |
weak_ptr_factory_(this) { |
} |
@@ -115,6 +116,8 @@ void ThemeService::Init(Profile* profile) { |
LoadThemePrefs(); |
+ extension_registry_ = extensions::ExtensionRegistry::Get(profile_); |
+ |
registrar_.Add(this, |
extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, |
content::Source<Profile>(profile_)); |
@@ -268,43 +271,49 @@ void ThemeService::Observe(int type, |
content::Source<Profile>(profile_)); |
OnExtensionServiceReady(); |
break; |
- case extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED: { |
- // The theme may be initially disabled. Wait till it is loaded (if ever). |
- Details<const extensions::InstalledExtensionInfo> installed_details( |
- details); |
- if (installed_details->extension->is_theme()) |
- installed_pending_load_id_ = installed_details->extension->id(); |
- break; |
- } |
- case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: { |
- const Extension* extension = Details<const Extension>(details).ptr(); |
- if (extension->is_theme() && |
- installed_pending_load_id_ != kDefaultThemeID && |
- installed_pending_load_id_ == extension->id()) { |
- SetTheme(extension); |
- } |
- installed_pending_load_id_ = kDefaultThemeID; |
- break; |
- } |
case extensions::NOTIFICATION_EXTENSION_ENABLED: { |
const Extension* extension = Details<const Extension>(details).ptr(); |
if (extension->is_theme()) |
SetTheme(extension); |
break; |
} |
- case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { |
- Details<const UnloadedExtensionInfo> unloaded_details(details); |
- if (unloaded_details->reason != UnloadedExtensionInfo::REASON_UPDATE && |
- unloaded_details->reason != UnloadedExtensionInfo::REASON_LOCK_ALL && |
- unloaded_details->extension->is_theme() && |
- unloaded_details->extension->id() == GetThemeID()) { |
- UseDefaultTheme(); |
- } |
- break; |
- } |
} |
} |
+void ThemeService::OnExtensionLoaded(content::BrowserContext* browser_context, |
+ const extensions::Extension* extension) { |
+ if (extension->is_theme() && installed_pending_load_id_ != kDefaultThemeID && |
+ installed_pending_load_id_ == extension->id()) { |
+ SetTheme(extension); |
+ } |
+ installed_pending_load_id_ = kDefaultThemeID; |
+} |
+ |
+void ThemeService::OnExtensionUnloaded( |
+ content::BrowserContext* browser_context, |
+ const extensions::Extension* extension, |
+ extensions::UnloadedExtensionInfo::Reason reason) { |
+ if (reason != UnloadedExtensionInfo::REASON_UPDATE && extension->is_theme() && |
+ extension->id() == GetThemeID()) { |
+ UseDefaultTheme(); |
+ } |
+} |
+ |
+void ThemeService::OnExtensionWillBeInstalled( |
+ content::BrowserContext* browser_context, |
+ const extensions::Extension* extension, |
+ bool is_update, |
+ bool from_ephemeral, |
+ const std::string& old_name) { |
+ // The theme may be initially disabled. Wait till it is loaded (if ever). |
+ if (extension->is_theme()) |
+ installed_pending_load_id_ = extension->id(); |
+} |
+ |
+void ThemeService::Shutdown() { |
+ extension_registry_->RemoveObserver(this); |
+} |
+ |
void ThemeService::SetTheme(const Extension* extension) { |
DCHECK(extension->is_theme()); |
ExtensionService* service = |
@@ -529,19 +538,10 @@ void ThemeService::OnExtensionServiceReady() { |
NotifyThemeChanged(); |
} |
- registrar_.Add( |
- this, |
- extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, |
- content::Source<Profile>(profile_)); |
- registrar_.Add(this, |
- extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
- content::Source<Profile>(profile_)); |
+ extension_registry_->AddObserver(this); |
registrar_.Add(this, |
extensions::NOTIFICATION_EXTENSION_ENABLED, |
content::Source<Profile>(profile_)); |
- registrar_.Add(this, |
- extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
- content::Source<Profile>(profile_)); |
base::MessageLoop::current()->PostDelayedTask(FROM_HERE, |
base::Bind(&ThemeService::RemoveUnusedThemes, |