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

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

Issue 2893693002: Remove NOTIFICATION_EXTENSION_ENABLED. (Closed)
Patch Set: address comments Created 3 years, 6 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 34cd1053fbd51d4ae03e1dbf51ca3ad023cda019..0b7525c2f0d2db3a9d9d5f21a40412aa23ab0470 100644
--- a/chrome/browser/themes/theme_service.cc
+++ b/chrome/browser/themes/theme_service.cc
@@ -51,6 +51,7 @@
#include "ui/native_theme/native_theme.h"
#if BUILDFLAG(ENABLE_EXTENSIONS)
+#include "base/scoped_observer.h"
#include "extensions/browser/extension_registry_observer.h"
#endif
@@ -162,35 +163,45 @@ base::RefCountedMemory* ThemeService::BrowserThemeProvider::GetRawData(
class ThemeService::ThemeObserver
: public extensions::ExtensionRegistryObserver {
public:
- explicit ThemeObserver(ThemeService* service) : theme_service_(service) {
- extensions::ExtensionRegistry::Get(theme_service_->profile_)
- ->AddObserver(this);
+ explicit ThemeObserver(ThemeService* service)
+ : theme_service_(service), extension_registry_observer_(this) {
+ extension_registry_observer_.Add(
+ extensions::ExtensionRegistry::Get(theme_service_->profile_));
}
~ThemeObserver() override {
- extensions::ExtensionRegistry::Get(theme_service_->profile_)
- ->RemoveObserver(this);
}
private:
+ // extensions::ExtensionRegistryObserver:
void OnExtensionWillBeInstalled(content::BrowserContext* browser_context,
const extensions::Extension* extension,
bool is_update,
const std::string& old_name) override {
if (extension->is_theme()) {
- // The theme may be initially disabled. Wait till it is loaded (if ever).
+ // Remember ID of the newly installed theme.
theme_service_->installed_pending_load_id_ = extension->id();
}
}
void OnExtensionLoaded(content::BrowserContext* browser_context,
const extensions::Extension* extension) override {
- if (extension->is_theme() &&
+ if (!extension->is_theme())
+ return;
+
+ bool is_new_version =
theme_service_->installed_pending_load_id_ != kDefaultThemeID &&
- theme_service_->installed_pending_load_id_ == extension->id()) {
- theme_service_->SetTheme(extension);
- }
+ theme_service_->installed_pending_load_id_ == extension->id();
theme_service_->installed_pending_load_id_ = kDefaultThemeID;
+
+ // Do not load already loaded theme.
+ if (!is_new_version && extension->id() == theme_service_->GetThemeID())
+ return;
+
+ // Set the new theme during extension load:
+ // This includes: a) installing a new theme, b) enabling a disabled theme.
+ // We shouldn't get here for the update of a disabled theme.
+ theme_service_->DoSetTheme(extension, !is_new_version);
}
void OnExtensionUnloaded(
@@ -206,6 +217,12 @@ class ThemeService::ThemeObserver
}
ThemeService* theme_service_;
+
+ ScopedObserver<extensions::ExtensionRegistry,
+ extensions::ExtensionRegistryObserver>
+ extension_registry_observer_;
+
+ DISALLOW_COPY_AND_ASSIGN(ThemeObserver);
};
#endif // BUILDFLAG(ENABLE_EXTENSIONS)
@@ -261,12 +278,6 @@ void ThemeService::Observe(int type,
content::Source<Profile>(profile_));
OnExtensionServiceReady();
break;
- case extensions::NOTIFICATION_EXTENSION_ENABLED: {
- const Extension* extension = Details<const Extension>(details).ptr();
- if (extension->is_theme())
- DoSetTheme(extension, true);
- break;
- }
default:
NOTREACHED();
}
@@ -779,13 +790,9 @@ void ThemeService::OnExtensionServiceReady() {
}
#if BUILDFLAG(ENABLE_EXTENSIONS)
- theme_observer_.reset(new ThemeObserver(this));
+ theme_observer_ = base::MakeUnique<ThemeObserver>(this);
#endif
- registrar_.Add(this,
- extensions::NOTIFICATION_EXTENSION_ENABLED,
- content::Source<Profile>(profile_));
-
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, base::Bind(&ThemeService::RemoveUnusedThemes,
weak_ptr_factory_.GetWeakPtr(), false),

Powered by Google App Engine
This is Rietveld 408576698