| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 44 #include "extensions/common/extension_set.h" | 44 #include "extensions/common/extension_set.h" | 
| 45 #include "extensions/features/features.h" | 45 #include "extensions/features/features.h" | 
| 46 #include "ui/base/layout.h" | 46 #include "ui/base/layout.h" | 
| 47 #include "ui/base/resource/resource_bundle.h" | 47 #include "ui/base/resource/resource_bundle.h" | 
| 48 #include "ui/gfx/color_palette.h" | 48 #include "ui/gfx/color_palette.h" | 
| 49 #include "ui/gfx/image/image_skia.h" | 49 #include "ui/gfx/image/image_skia.h" | 
| 50 #include "ui/native_theme/common_theme.h" | 50 #include "ui/native_theme/common_theme.h" | 
| 51 #include "ui/native_theme/native_theme.h" | 51 #include "ui/native_theme/native_theme.h" | 
| 52 | 52 | 
| 53 #if BUILDFLAG(ENABLE_EXTENSIONS) | 53 #if BUILDFLAG(ENABLE_EXTENSIONS) | 
|  | 54 #include "base/scoped_observer.h" | 
| 54 #include "extensions/browser/extension_registry_observer.h" | 55 #include "extensions/browser/extension_registry_observer.h" | 
| 55 #endif | 56 #endif | 
| 56 | 57 | 
| 57 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) | 58 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) | 
| 58 #include "chrome/browser/supervised_user/supervised_user_theme.h" | 59 #include "chrome/browser/supervised_user/supervised_user_theme.h" | 
| 59 #endif | 60 #endif | 
| 60 | 61 | 
| 61 using base::UserMetricsAction; | 62 using base::UserMetricsAction; | 
| 62 using content::BrowserThread; | 63 using content::BrowserThread; | 
| 63 using extensions::Extension; | 64 using extensions::Extension; | 
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 155   return theme_service_.GetRawData(id, scale_factor); | 156   return theme_service_.GetRawData(id, scale_factor); | 
| 156 } | 157 } | 
| 157 | 158 | 
| 158 | 159 | 
| 159 // ThemeService::ThemeObserver ------------------------------------------------ | 160 // ThemeService::ThemeObserver ------------------------------------------------ | 
| 160 | 161 | 
| 161 #if BUILDFLAG(ENABLE_EXTENSIONS) | 162 #if BUILDFLAG(ENABLE_EXTENSIONS) | 
| 162 class ThemeService::ThemeObserver | 163 class ThemeService::ThemeObserver | 
| 163     : public extensions::ExtensionRegistryObserver { | 164     : public extensions::ExtensionRegistryObserver { | 
| 164  public: | 165  public: | 
| 165   explicit ThemeObserver(ThemeService* service) : theme_service_(service) { | 166   explicit ThemeObserver(ThemeService* service) | 
| 166     extensions::ExtensionRegistry::Get(theme_service_->profile_) | 167       : theme_service_(service), extension_registry_observer_(this) { | 
| 167         ->AddObserver(this); | 168     extension_registry_observer_.Add( | 
|  | 169         extensions::ExtensionRegistry::Get(theme_service_->profile_)); | 
| 168   } | 170   } | 
| 169 | 171 | 
| 170   ~ThemeObserver() override { | 172   ~ThemeObserver() override { | 
| 171     extensions::ExtensionRegistry::Get(theme_service_->profile_) |  | 
| 172         ->RemoveObserver(this); |  | 
| 173   } | 173   } | 
| 174 | 174 | 
| 175  private: | 175  private: | 
|  | 176   // extensions::ExtensionRegistryObserver: | 
| 176   void OnExtensionWillBeInstalled(content::BrowserContext* browser_context, | 177   void OnExtensionWillBeInstalled(content::BrowserContext* browser_context, | 
| 177                                   const extensions::Extension* extension, | 178                                   const extensions::Extension* extension, | 
| 178                                   bool is_update, | 179                                   bool is_update, | 
| 179                                   const std::string& old_name) override { | 180                                   const std::string& old_name) override { | 
| 180     if (extension->is_theme()) { | 181     if (extension->is_theme()) { | 
| 181       // The theme may be initially disabled. Wait till it is loaded (if ever). | 182       // Remember ID of the newly installed theme. | 
| 182       theme_service_->installed_pending_load_id_ = extension->id(); | 183       theme_service_->installed_pending_load_id_ = extension->id(); | 
| 183     } | 184     } | 
| 184   } | 185   } | 
| 185 | 186 | 
| 186   void OnExtensionLoaded(content::BrowserContext* browser_context, | 187   void OnExtensionLoaded(content::BrowserContext* browser_context, | 
| 187                          const extensions::Extension* extension) override { | 188                          const extensions::Extension* extension) override { | 
| 188     if (extension->is_theme() && | 189     if (!extension->is_theme()) | 
|  | 190       return; | 
|  | 191 | 
|  | 192     bool is_new_version = | 
| 189         theme_service_->installed_pending_load_id_ != kDefaultThemeID && | 193         theme_service_->installed_pending_load_id_ != kDefaultThemeID && | 
| 190         theme_service_->installed_pending_load_id_ == extension->id()) { | 194         theme_service_->installed_pending_load_id_ == extension->id(); | 
| 191       theme_service_->SetTheme(extension); |  | 
| 192     } |  | 
| 193     theme_service_->installed_pending_load_id_ = kDefaultThemeID; | 195     theme_service_->installed_pending_load_id_ = kDefaultThemeID; | 
|  | 196 | 
|  | 197     // Do not load already loaded theme. | 
|  | 198     if (!is_new_version && extension->id() == theme_service_->GetThemeID()) | 
|  | 199       return; | 
|  | 200 | 
|  | 201     // Set the new theme during extension load: | 
|  | 202     // This includes: a) installing a new theme, b) enabling a disabled theme. | 
|  | 203     // We shouldn't get here for the update of a disabled theme. | 
|  | 204     theme_service_->DoSetTheme(extension, !is_new_version); | 
| 194   } | 205   } | 
| 195 | 206 | 
| 196   void OnExtensionUnloaded( | 207   void OnExtensionUnloaded( | 
| 197       content::BrowserContext* browser_context, | 208       content::BrowserContext* browser_context, | 
| 198       const extensions::Extension* extension, | 209       const extensions::Extension* extension, | 
| 199       extensions::UnloadedExtensionReason reason) override { | 210       extensions::UnloadedExtensionReason reason) override { | 
| 200     if (reason != extensions::UnloadedExtensionReason::UPDATE && | 211     if (reason != extensions::UnloadedExtensionReason::UPDATE && | 
| 201         reason != extensions::UnloadedExtensionReason::LOCK_ALL && | 212         reason != extensions::UnloadedExtensionReason::LOCK_ALL && | 
| 202         extension->is_theme() && | 213         extension->is_theme() && | 
| 203         extension->id() == theme_service_->GetThemeID()) { | 214         extension->id() == theme_service_->GetThemeID()) { | 
| 204       theme_service_->UseDefaultTheme(); | 215       theme_service_->UseDefaultTheme(); | 
| 205     } | 216     } | 
| 206   } | 217   } | 
| 207 | 218 | 
| 208   ThemeService* theme_service_; | 219   ThemeService* theme_service_; | 
|  | 220 | 
|  | 221   ScopedObserver<extensions::ExtensionRegistry, | 
|  | 222                  extensions::ExtensionRegistryObserver> | 
|  | 223       extension_registry_observer_; | 
|  | 224 | 
|  | 225   DISALLOW_COPY_AND_ASSIGN(ThemeObserver); | 
| 209 }; | 226 }; | 
| 210 #endif  // BUILDFLAG(ENABLE_EXTENSIONS) | 227 #endif  // BUILDFLAG(ENABLE_EXTENSIONS) | 
| 211 | 228 | 
| 212 | 229 | 
| 213 // ThemeService --------------------------------------------------------------- | 230 // ThemeService --------------------------------------------------------------- | 
| 214 | 231 | 
| 215 // The default theme if we haven't installed a theme yet or if we've clicked | 232 // The default theme if we haven't installed a theme yet or if we've clicked | 
| 216 // the "Use Classic" button. | 233 // the "Use Classic" button. | 
| 217 const char ThemeService::kDefaultThemeID[] = ""; | 234 const char ThemeService::kDefaultThemeID[] = ""; | 
| 218 | 235 | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 254                            const content::NotificationSource& source, | 271                            const content::NotificationSource& source, | 
| 255                            const content::NotificationDetails& details) { | 272                            const content::NotificationDetails& details) { | 
| 256   using content::Details; | 273   using content::Details; | 
| 257   switch (type) { | 274   switch (type) { | 
| 258     case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED: | 275     case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED: | 
| 259       registrar_.Remove(this, | 276       registrar_.Remove(this, | 
| 260                         extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, | 277                         extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, | 
| 261                         content::Source<Profile>(profile_)); | 278                         content::Source<Profile>(profile_)); | 
| 262       OnExtensionServiceReady(); | 279       OnExtensionServiceReady(); | 
| 263       break; | 280       break; | 
| 264     case extensions::NOTIFICATION_EXTENSION_ENABLED: { |  | 
| 265       const Extension* extension = Details<const Extension>(details).ptr(); |  | 
| 266       if (extension->is_theme()) |  | 
| 267         DoSetTheme(extension, true); |  | 
| 268       break; |  | 
| 269     } |  | 
| 270     default: | 281     default: | 
| 271       NOTREACHED(); | 282       NOTREACHED(); | 
| 272   } | 283   } | 
| 273 } | 284 } | 
| 274 | 285 | 
| 275 void ThemeService::SetTheme(const Extension* extension) { | 286 void ThemeService::SetTheme(const Extension* extension) { | 
| 276   DoSetTheme(extension, false); | 287   DoSetTheme(extension, false); | 
| 277 } | 288 } | 
| 278 | 289 | 
| 279 void ThemeService::RevertToTheme(const Extension* extension) { | 290 void ThemeService::RevertToTheme(const Extension* extension) { | 
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 772 | 783 | 
| 773 void ThemeService::OnExtensionServiceReady() { | 784 void ThemeService::OnExtensionServiceReady() { | 
| 774   if (!ready_) { | 785   if (!ready_) { | 
| 775     // If the ThemeService is not ready yet, the custom theme data pack needs to | 786     // If the ThemeService is not ready yet, the custom theme data pack needs to | 
| 776     // be recreated from the extension. | 787     // be recreated from the extension. | 
| 777     MigrateTheme(); | 788     MigrateTheme(); | 
| 778     set_ready(); | 789     set_ready(); | 
| 779   } | 790   } | 
| 780 | 791 | 
| 781 #if BUILDFLAG(ENABLE_EXTENSIONS) | 792 #if BUILDFLAG(ENABLE_EXTENSIONS) | 
| 782   theme_observer_.reset(new ThemeObserver(this)); | 793   theme_observer_ = base::MakeUnique<ThemeObserver>(this); | 
| 783 #endif | 794 #endif | 
| 784 | 795 | 
| 785   registrar_.Add(this, |  | 
| 786                  extensions::NOTIFICATION_EXTENSION_ENABLED, |  | 
| 787                  content::Source<Profile>(profile_)); |  | 
| 788 |  | 
| 789   base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 796   base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 
| 790       FROM_HERE, base::Bind(&ThemeService::RemoveUnusedThemes, | 797       FROM_HERE, base::Bind(&ThemeService::RemoveUnusedThemes, | 
| 791                             weak_ptr_factory_.GetWeakPtr(), false), | 798                             weak_ptr_factory_.GetWeakPtr(), false), | 
| 792       base::TimeDelta::FromSeconds(kRemoveUnusedThemesStartupDelay)); | 799       base::TimeDelta::FromSeconds(kRemoveUnusedThemesStartupDelay)); | 
| 793 } | 800 } | 
| 794 | 801 | 
| 795 void ThemeService::MigrateTheme() { | 802 void ThemeService::MigrateTheme() { | 
| 796   ExtensionService* service = | 803   ExtensionService* service = | 
| 797       extensions::ExtensionSystem::Get(profile_)->extension_service(); | 804       extensions::ExtensionSystem::Get(profile_)->extension_service(); | 
| 798   const Extension* extension = | 805   const Extension* extension = | 
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 916 | 923 | 
| 917 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) | 924 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) | 
| 918 bool ThemeService::IsSupervisedUser() const { | 925 bool ThemeService::IsSupervisedUser() const { | 
| 919   return profile_->IsSupervised(); | 926   return profile_->IsSupervised(); | 
| 920 } | 927 } | 
| 921 | 928 | 
| 922 void ThemeService::SetSupervisedUserTheme() { | 929 void ThemeService::SetSupervisedUserTheme() { | 
| 923   SetCustomDefaultTheme(new SupervisedUserTheme); | 930   SetCustomDefaultTheme(new SupervisedUserTheme); | 
| 924 } | 931 } | 
| 925 #endif | 932 #endif | 
| OLD | NEW | 
|---|