Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/themes/theme_service.h" | 5 #include "chrome/browser/themes/theme_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 #include "extensions/common/extension_set.h" | 42 #include "extensions/common/extension_set.h" |
| 43 #include "extensions/features/features.h" | 43 #include "extensions/features/features.h" |
| 44 #include "ui/base/layout.h" | 44 #include "ui/base/layout.h" |
| 45 #include "ui/base/resource/resource_bundle.h" | 45 #include "ui/base/resource/resource_bundle.h" |
| 46 #include "ui/gfx/color_palette.h" | 46 #include "ui/gfx/color_palette.h" |
| 47 #include "ui/gfx/image/image_skia.h" | 47 #include "ui/gfx/image/image_skia.h" |
| 48 #include "ui/native_theme/common_theme.h" | 48 #include "ui/native_theme/common_theme.h" |
| 49 #include "ui/native_theme/native_theme.h" | 49 #include "ui/native_theme/native_theme.h" |
| 50 | 50 |
| 51 #if BUILDFLAG(ENABLE_EXTENSIONS) | 51 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 52 #include "base/scoped_observer.h" | |
| 52 #include "extensions/browser/extension_registry_observer.h" | 53 #include "extensions/browser/extension_registry_observer.h" |
| 53 #endif | 54 #endif |
| 54 | 55 |
| 55 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) | 56 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 56 #include "chrome/browser/supervised_user/supervised_user_theme.h" | 57 #include "chrome/browser/supervised_user/supervised_user_theme.h" |
| 57 #endif | 58 #endif |
| 58 | 59 |
| 59 using base::UserMetricsAction; | 60 using base::UserMetricsAction; |
| 60 using content::BrowserThread; | 61 using content::BrowserThread; |
| 61 using extensions::Extension; | 62 using extensions::Extension; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 return theme_service_.GetRawData(id, scale_factor); | 154 return theme_service_.GetRawData(id, scale_factor); |
| 154 } | 155 } |
| 155 | 156 |
| 156 | 157 |
| 157 // ThemeService::ThemeObserver ------------------------------------------------ | 158 // ThemeService::ThemeObserver ------------------------------------------------ |
| 158 | 159 |
| 159 #if BUILDFLAG(ENABLE_EXTENSIONS) | 160 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 160 class ThemeService::ThemeObserver | 161 class ThemeService::ThemeObserver |
| 161 : public extensions::ExtensionRegistryObserver { | 162 : public extensions::ExtensionRegistryObserver { |
| 162 public: | 163 public: |
| 163 explicit ThemeObserver(ThemeService* service) : theme_service_(service) { | 164 explicit ThemeObserver(ThemeService* service) |
| 164 extensions::ExtensionRegistry::Get(theme_service_->profile_) | 165 : theme_service_(service), extension_registry_observer_(this) { |
| 165 ->AddObserver(this); | 166 extension_registry_observer_.Add( |
| 167 extensions::ExtensionRegistry::Get(theme_service_->profile_)); | |
| 166 } | 168 } |
| 167 | 169 |
| 168 ~ThemeObserver() override { | 170 ~ThemeObserver() override { |
| 169 extensions::ExtensionRegistry::Get(theme_service_->profile_) | |
| 170 ->RemoveObserver(this); | |
| 171 } | 171 } |
| 172 | 172 |
| 173 private: | 173 private: |
| 174 // extensions::ExtensionRegistryObserver:: | |
| 174 void OnExtensionWillBeInstalled(content::BrowserContext* browser_context, | 175 void OnExtensionWillBeInstalled(content::BrowserContext* browser_context, |
| 175 const extensions::Extension* extension, | 176 const extensions::Extension* extension, |
| 176 bool is_update, | 177 bool is_update, |
| 177 const std::string& old_name) override { | 178 const std::string& old_name) override { |
| 178 if (extension->is_theme()) { | 179 if (extension->is_theme()) { |
| 179 // The theme may be initially disabled. Wait till it is loaded (if ever). | 180 // The theme may be initially disabled. Wait till it is loaded (if ever). |
| 180 theme_service_->installed_pending_load_id_ = extension->id(); | 181 theme_service_->installed_pending_load_id_ = extension->id(); |
| 181 } | 182 } |
| 182 } | 183 } |
| 183 | 184 |
| 184 void OnExtensionLoaded(content::BrowserContext* browser_context, | 185 void OnExtensionLoaded(content::BrowserContext* browser_context, |
| 185 const extensions::Extension* extension) override { | 186 const extensions::Extension* extension) override { |
| 186 if (extension->is_theme() && | 187 if (extension->is_theme() && |
| 187 theme_service_->installed_pending_load_id_ != kDefaultThemeID && | 188 theme_service_->installed_pending_load_id_ != kDefaultThemeID && |
| 188 theme_service_->installed_pending_load_id_ == extension->id()) { | 189 theme_service_->installed_pending_load_id_ == extension->id()) { |
| 189 theme_service_->SetTheme(extension); | 190 theme_service_->SetTheme(extension); |
| 190 } | 191 } |
| 191 theme_service_->installed_pending_load_id_ = kDefaultThemeID; | 192 theme_service_->installed_pending_load_id_ = kDefaultThemeID; |
| 192 } | 193 } |
| 193 | 194 |
| 195 void OnExtensionEnabled(content::BrowserContext* browser_context, | |
|
Devlin
2017/05/17 18:37:48
Hmm... does this care about enablement?
OnExtensi
lazyboy
2017/05/17 22:23:25
Is it possible for a theme to be loaded but it sta
Devlin
2017/05/18 01:34:45
I don't know how it could be. If it's disabled, w
lazyboy
2017/05/18 18:10:52
I missed the comments over installed_pending_load_
| |
| 196 const extensions::Extension* extension) override { | |
| 197 if (extension->is_theme()) | |
| 198 theme_service_->SetTheme(extension); | |
| 199 } | |
| 200 | |
| 194 void OnExtensionUnloaded( | 201 void OnExtensionUnloaded( |
| 195 content::BrowserContext* browser_context, | 202 content::BrowserContext* browser_context, |
| 196 const extensions::Extension* extension, | 203 const extensions::Extension* extension, |
| 197 extensions::UnloadedExtensionReason reason) override { | 204 extensions::UnloadedExtensionReason reason) override { |
| 198 if (reason != extensions::UnloadedExtensionReason::UPDATE && | 205 if (reason != extensions::UnloadedExtensionReason::UPDATE && |
| 199 reason != extensions::UnloadedExtensionReason::LOCK_ALL && | 206 reason != extensions::UnloadedExtensionReason::LOCK_ALL && |
| 200 extension->is_theme() && | 207 extension->is_theme() && |
| 201 extension->id() == theme_service_->GetThemeID()) { | 208 extension->id() == theme_service_->GetThemeID()) { |
| 202 theme_service_->UseDefaultTheme(); | 209 theme_service_->UseDefaultTheme(); |
| 203 } | 210 } |
| 204 } | 211 } |
| 205 | 212 |
| 206 ThemeService* theme_service_; | 213 ThemeService* theme_service_; |
| 214 | |
| 215 ScopedObserver<extensions::ExtensionRegistry, | |
| 216 extensions::ExtensionRegistryObserver> | |
| 217 extension_registry_observer_; | |
| 218 | |
| 219 DISALLOW_COPY_AND_ASSIGN(ThemeObserver); | |
| 207 }; | 220 }; |
| 208 #endif // BUILDFLAG(ENABLE_EXTENSIONS) | 221 #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 209 | 222 |
| 210 | 223 |
| 211 // ThemeService --------------------------------------------------------------- | 224 // ThemeService --------------------------------------------------------------- |
| 212 | 225 |
| 213 // The default theme if we haven't installed a theme yet or if we've clicked | 226 // The default theme if we haven't installed a theme yet or if we've clicked |
| 214 // the "Use Classic" button. | 227 // the "Use Classic" button. |
| 215 const char ThemeService::kDefaultThemeID[] = ""; | 228 const char ThemeService::kDefaultThemeID[] = ""; |
| 216 | 229 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 const content::NotificationSource& source, | 264 const content::NotificationSource& source, |
| 252 const content::NotificationDetails& details) { | 265 const content::NotificationDetails& details) { |
| 253 using content::Details; | 266 using content::Details; |
| 254 switch (type) { | 267 switch (type) { |
| 255 case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED: | 268 case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED: |
| 256 registrar_.Remove(this, | 269 registrar_.Remove(this, |
| 257 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, | 270 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, |
| 258 content::Source<Profile>(profile_)); | 271 content::Source<Profile>(profile_)); |
| 259 OnExtensionServiceReady(); | 272 OnExtensionServiceReady(); |
| 260 break; | 273 break; |
| 261 case extensions::NOTIFICATION_EXTENSION_ENABLED: { | |
| 262 const Extension* extension = Details<const Extension>(details).ptr(); | |
| 263 if (extension->is_theme()) | |
| 264 SetTheme(extension); | |
| 265 break; | |
| 266 } | |
| 267 default: | 274 default: |
| 268 NOTREACHED(); | 275 NOTREACHED(); |
| 269 } | 276 } |
| 270 } | 277 } |
| 271 | 278 |
| 272 void ThemeService::SetTheme(const Extension* extension) { | 279 void ThemeService::SetTheme(const Extension* extension) { |
| 273 DCHECK(extension->is_theme()); | 280 DCHECK(extension->is_theme()); |
| 274 ExtensionService* service = | 281 ExtensionService* service = |
| 275 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 282 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 276 if (!service->IsExtensionEnabled(extension->id())) { | 283 if (!service->IsExtensionEnabled(extension->id())) { |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 784 // be recreated from the extension. | 791 // be recreated from the extension. |
| 785 MigrateTheme(); | 792 MigrateTheme(); |
| 786 set_ready(); | 793 set_ready(); |
| 787 | 794 |
| 788 // Send notification in case anyone requested data and cached it when the | 795 // Send notification in case anyone requested data and cached it when the |
| 789 // theme service was not ready yet. | 796 // theme service was not ready yet. |
| 790 NotifyThemeChanged(); | 797 NotifyThemeChanged(); |
| 791 } | 798 } |
| 792 | 799 |
| 793 #if BUILDFLAG(ENABLE_EXTENSIONS) | 800 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 794 theme_observer_.reset(new ThemeObserver(this)); | 801 theme_observer_ = base::MakeUnique<ThemeObserver>(this); |
| 795 #endif | 802 #endif |
| 796 | 803 |
| 797 registrar_.Add(this, | |
| 798 extensions::NOTIFICATION_EXTENSION_ENABLED, | |
| 799 content::Source<Profile>(profile_)); | |
| 800 | |
| 801 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 804 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 802 FROM_HERE, base::Bind(&ThemeService::RemoveUnusedThemes, | 805 FROM_HERE, base::Bind(&ThemeService::RemoveUnusedThemes, |
| 803 weak_ptr_factory_.GetWeakPtr(), false), | 806 weak_ptr_factory_.GetWeakPtr(), false), |
| 804 base::TimeDelta::FromSeconds(kRemoveUnusedThemesStartupDelay)); | 807 base::TimeDelta::FromSeconds(kRemoveUnusedThemesStartupDelay)); |
| 805 } | 808 } |
| 806 | 809 |
| 807 void ThemeService::MigrateTheme() { | 810 void ThemeService::MigrateTheme() { |
| 808 // TODO(erg): We need to pop up a dialog informing the user that their | 811 // TODO(erg): We need to pop up a dialog informing the user that their |
| 809 // theme is being migrated. | 812 // theme is being migrated. |
| 810 ExtensionService* service = | 813 ExtensionService* service = |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 868 | 871 |
| 869 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) | 872 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 870 bool ThemeService::IsSupervisedUser() const { | 873 bool ThemeService::IsSupervisedUser() const { |
| 871 return profile_->IsSupervised(); | 874 return profile_->IsSupervised(); |
| 872 } | 875 } |
| 873 | 876 |
| 874 void ThemeService::SetSupervisedUserTheme() { | 877 void ThemeService::SetSupervisedUserTheme() { |
| 875 SetCustomDefaultTheme(new SupervisedUserTheme); | 878 SetCustomDefaultTheme(new SupervisedUserTheme); |
| 876 } | 879 } |
| 877 #endif | 880 #endif |
| OLD | NEW |