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

Unified Diff: chrome/browser/themes/theme_service.cc

Issue 566573004: Remove deprecated extension notification from themeservice. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unittest error and review comments Created 6 years, 2 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/themes/theme_service.cc
diff --git a/chrome/browser/themes/theme_service.cc b/chrome/browser/themes/theme_service.cc
index 1dba96f3942c8ba2eb9da04364133930dcdf980c..eb0b6b7a877a08eb24dcdf129d9c41ec18ff0c3d 100644
--- a/chrome/browser/themes/theme_service.cc
+++ b/chrome/browser/themes/theme_service.cc
@@ -86,6 +86,7 @@ ThemeService::ThemeService()
profile_(NULL),
installed_pending_load_id_(kDefaultThemeID),
number_of_infobars_(0),
+ extension_registry_(NULL),
weak_ptr_factory_(this) {
}
@@ -99,6 +100,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_));
@@ -252,39 +255,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->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 &&
Bernhard Bauer 2014/10/15 12:32:45 Please put each of these conditions on a separate
Jitu( very slow this week) 2014/10/15 13:01:12 Done.
+ 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() {
+ if (extension_registry_) {
Bernhard Bauer 2014/10/15 12:32:45 When is this NULL?
Jitu( very slow this week) 2014/10/15 13:01:12 This was added for safer side. Let say we created
Bernhard Bauer 2014/10/15 13:21:04 That would be a bug. If we silently accept NULL he
+ extension_registry_->RemoveObserver(this);
+ extension_registry_ = NULL;
}
}
@@ -505,19 +518,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,

Powered by Google App Engine
This is Rietveld 408576698