Index: chrome/browser/themes/theme_service.cc |
diff --git a/chrome/browser/themes/theme_service.cc b/chrome/browser/themes/theme_service.cc |
index 3a0161e9881e235d2e307ff2307da9b772a3538d..81bfd59b512183c723fbdb9ed2f693e63f12aa8d 100644 |
--- a/chrome/browser/themes/theme_service.cc |
+++ b/chrome/browser/themes/theme_service.cc |
@@ -49,6 +49,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 |
@@ -160,35 +161,24 @@ 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: |
- 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). |
- theme_service_->installed_pending_load_id_ = extension->id(); |
- } |
- } |
- |
+ // extensions::ExtensionRegistryObserver:: |
void OnExtensionLoaded(content::BrowserContext* browser_context, |
const extensions::Extension* extension) override { |
pkotwicz
2017/05/25 20:52:25
On startup, OnExtensionLoaded() is not guaranteed
lazyboy
2017/05/30 23:38:35
I've added the exception to bail out if extension-
|
- if (extension->is_theme() && |
- theme_service_->installed_pending_load_id_ != kDefaultThemeID && |
- theme_service_->installed_pending_load_id_ == extension->id()) { |
+ // Set the new theme during extension load. |
+ // Even if the theme was an update of a disabled extension, it shouldn't be |
+ // loaded. |
+ if (extension->is_theme()) |
theme_service_->SetTheme(extension); |
- } |
- theme_service_->installed_pending_load_id_ = kDefaultThemeID; |
} |
void OnExtensionUnloaded( |
@@ -204,6 +194,12 @@ class ThemeService::ThemeObserver |
} |
ThemeService* theme_service_; |
+ |
+ ScopedObserver<extensions::ExtensionRegistry, |
+ extensions::ExtensionRegistryObserver> |
+ extension_registry_observer_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ThemeObserver); |
}; |
#endif // BUILDFLAG(ENABLE_EXTENSIONS) |
@@ -218,7 +214,6 @@ ThemeService::ThemeService() |
: ready_(false), |
rb_(ResourceBundle::GetSharedInstance()), |
profile_(nullptr), |
- installed_pending_load_id_(kDefaultThemeID), |
number_of_infobars_(0), |
original_theme_provider_(*this, false), |
incognito_theme_provider_(*this, true), |
@@ -258,12 +253,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()) |
- SetTheme(extension); |
- break; |
- } |
default: |
NOTREACHED(); |
} |
@@ -791,13 +780,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), |