| 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 23 matching lines...) Expand all Loading... |
| 34 #include "extensions/browser/extension_registry.h" | 34 #include "extensions/browser/extension_registry.h" |
| 35 #include "extensions/browser/extension_system.h" | 35 #include "extensions/browser/extension_system.h" |
| 36 #include "extensions/browser/uninstall_reason.h" | 36 #include "extensions/browser/uninstall_reason.h" |
| 37 #include "extensions/common/extension.h" | 37 #include "extensions/common/extension.h" |
| 38 #include "extensions/common/extension_set.h" | 38 #include "extensions/common/extension_set.h" |
| 39 #include "grit/components_scaled_resources.h" | 39 #include "grit/components_scaled_resources.h" |
| 40 #include "grit/theme_resources.h" | 40 #include "grit/theme_resources.h" |
| 41 #include "ui/base/layout.h" | 41 #include "ui/base/layout.h" |
| 42 #include "ui/base/material_design/material_design_controller.h" | 42 #include "ui/base/material_design/material_design_controller.h" |
| 43 #include "ui/base/resource/resource_bundle.h" | 43 #include "ui/base/resource/resource_bundle.h" |
| 44 #include "ui/events/devices/device_data_manager.h" |
| 44 #include "ui/gfx/color_palette.h" | 45 #include "ui/gfx/color_palette.h" |
| 45 #include "ui/gfx/image/image_skia.h" | 46 #include "ui/gfx/image/image_skia.h" |
| 46 #include "ui/native_theme/common_theme.h" | 47 #include "ui/native_theme/common_theme.h" |
| 47 #include "ui/native_theme/native_theme.h" | 48 #include "ui/native_theme/native_theme.h" |
| 48 | 49 |
| 49 #if defined(ENABLE_EXTENSIONS) | 50 #if defined(ENABLE_EXTENSIONS) |
| 50 #include "extensions/browser/extension_registry_observer.h" | 51 #include "extensions/browser/extension_registry_observer.h" |
| 51 #endif | 52 #endif |
| 52 | 53 |
| 53 #if defined(ENABLE_SUPERVISED_USERS) | 54 #if defined(ENABLE_SUPERVISED_USERS) |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 : ready_(false), | 207 : ready_(false), |
| 207 rb_(ResourceBundle::GetSharedInstance()), | 208 rb_(ResourceBundle::GetSharedInstance()), |
| 208 profile_(nullptr), | 209 profile_(nullptr), |
| 209 installed_pending_load_id_(kDefaultThemeID), | 210 installed_pending_load_id_(kDefaultThemeID), |
| 210 number_of_infobars_(0), | 211 number_of_infobars_(0), |
| 211 original_theme_provider_(*this, false), | 212 original_theme_provider_(*this, false), |
| 212 incognito_theme_provider_(*this, true), | 213 incognito_theme_provider_(*this, true), |
| 213 weak_ptr_factory_(this) {} | 214 weak_ptr_factory_(this) {} |
| 214 | 215 |
| 215 ThemeService::~ThemeService() { | 216 ThemeService::~ThemeService() { |
| 217 if (ui::DeviceDataManager::HasInstance()) |
| 218 ui::DeviceDataManager::GetInstance()->RemoveObserver(this); |
| 216 FreePlatformCaches(); | 219 FreePlatformCaches(); |
| 217 } | 220 } |
| 218 | 221 |
| 219 void ThemeService::Init(Profile* profile) { | 222 void ThemeService::Init(Profile* profile) { |
| 220 DCHECK(CalledOnValidThread()); | 223 DCHECK(CalledOnValidThread()); |
| 221 profile_ = profile; | 224 profile_ = profile; |
| 222 | 225 |
| 226 if (ui::DeviceDataManager::HasInstance()) |
| 227 ui::DeviceDataManager::GetInstance()->AddObserver(this); // move to ctor? |
| 228 |
| 223 LoadThemePrefs(); | 229 LoadThemePrefs(); |
| 224 | 230 |
| 225 registrar_.Add(this, | 231 registrar_.Add(this, |
| 226 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, | 232 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, |
| 227 content::Source<Profile>(profile_)); | 233 content::Source<Profile>(profile_)); |
| 228 | 234 |
| 229 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this)); | 235 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this)); |
| 230 } | 236 } |
| 231 | 237 |
| 232 void ThemeService::Shutdown() { | 238 void ThemeService::Shutdown() { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 250 const Extension* extension = Details<const Extension>(details).ptr(); | 256 const Extension* extension = Details<const Extension>(details).ptr(); |
| 251 if (extension->is_theme()) | 257 if (extension->is_theme()) |
| 252 SetTheme(extension); | 258 SetTheme(extension); |
| 253 break; | 259 break; |
| 254 } | 260 } |
| 255 default: | 261 default: |
| 256 NOTREACHED(); | 262 NOTREACHED(); |
| 257 } | 263 } |
| 258 } | 264 } |
| 259 | 265 |
| 266 void ThemeService::OnDeviceListsComplete() { |
| 267 if (ui::MaterialDesignController::DeviceListsComplete()) |
| 268 NotifyThemeChanged(); |
| 269 } |
| 270 |
| 260 void ThemeService::SetTheme(const Extension* extension) { | 271 void ThemeService::SetTheme(const Extension* extension) { |
| 261 DCHECK(extension->is_theme()); | 272 DCHECK(extension->is_theme()); |
| 262 ExtensionService* service = | 273 ExtensionService* service = |
| 263 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 274 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 264 if (!service->IsExtensionEnabled(extension->id())) { | 275 if (!service->IsExtensionEnabled(extension->id())) { |
| 265 // |extension| is disabled when reverting to the previous theme via an | 276 // |extension| is disabled when reverting to the previous theme via an |
| 266 // infobar. | 277 // infobar. |
| 267 service->EnableExtension(extension->id()); | 278 service->EnableExtension(extension->id()); |
| 268 // Enabling the extension will call back to SetTheme(). | 279 // Enabling the extension will call back to SetTheme(). |
| 269 return; | 280 return; |
| (...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 | 870 |
| 860 #if defined(ENABLE_SUPERVISED_USERS) | 871 #if defined(ENABLE_SUPERVISED_USERS) |
| 861 bool ThemeService::IsSupervisedUser() const { | 872 bool ThemeService::IsSupervisedUser() const { |
| 862 return profile_->IsSupervised(); | 873 return profile_->IsSupervised(); |
| 863 } | 874 } |
| 864 | 875 |
| 865 void ThemeService::SetSupervisedUserTheme() { | 876 void ThemeService::SetSupervisedUserTheme() { |
| 866 SetCustomDefaultTheme(new SupervisedUserTheme); | 877 SetCustomDefaultTheme(new SupervisedUserTheme); |
| 867 } | 878 } |
| 868 #endif | 879 #endif |
| OLD | NEW |