| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ref_counted_memory.h" | 8 #include "base/memory/ref_counted_memory.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
| 15 #include "chrome/browser/extensions/extension_system.h" | 15 #include "chrome/browser/extensions/extension_system.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/themes/browser_theme_pack.h" | 17 #include "chrome/browser/themes/browser_theme_pack.h" |
| 18 #include "chrome/browser/themes/custom_theme_supplier.h" |
| 18 #include "chrome/browser/themes/theme_properties.h" | 19 #include "chrome/browser/themes/theme_properties.h" |
| 19 #include "chrome/browser/themes/theme_syncable_service.h" | 20 #include "chrome/browser/themes/theme_syncable_service.h" |
| 20 #include "chrome/common/chrome_constants.h" | 21 #include "chrome/common/chrome_constants.h" |
| 21 #include "chrome/common/extensions/extension_manifest_constants.h" | 22 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 23 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
| 24 #include "content/public/browser/user_metrics.h" | 25 #include "content/public/browser/user_metrics.h" |
| 25 #include "grit/theme_resources.h" | 26 #include "grit/theme_resources.h" |
| 26 #include "grit/ui_resources.h" | 27 #include "grit/ui_resources.h" |
| 27 #include "ui/base/layout.h" | 28 #include "ui/base/layout.h" |
| 28 #include "ui/base/resource/resource_bundle.h" | 29 #include "ui/base/resource/resource_bundle.h" |
| 29 #include "ui/gfx/image/image_skia.h" | 30 #include "ui/gfx/image/image_skia.h" |
| 30 | 31 |
| 31 #if defined(OS_WIN) | 32 #if defined(OS_WIN) |
| 32 #include "ui/base/win/shell.h" | 33 #include "ui/base/win/shell.h" |
| 33 #endif | 34 #endif |
| 34 | 35 |
| 35 #if defined(ENABLE_MANAGED_USERS) | 36 #if defined(ENABLE_MANAGED_USERS) |
| 36 #include "chrome/browser/managed_mode/managed_user_service.h" | 37 #include "chrome/browser/managed_mode/managed_user_service.h" |
| 38 #include "chrome/browser/managed_mode/managed_user_theme.h" |
| 37 #endif | 39 #endif |
| 38 | 40 |
| 39 using content::BrowserThread; | 41 using content::BrowserThread; |
| 40 using content::UserMetricsAction; | 42 using content::UserMetricsAction; |
| 41 using extensions::Extension; | 43 using extensions::Extension; |
| 42 using ui::ResourceBundle; | 44 using ui::ResourceBundle; |
| 43 | 45 |
| 44 typedef ThemeProperties Properties; | 46 typedef ThemeProperties Properties; |
| 45 | 47 |
| 46 // The default theme if we haven't installed a theme yet or if we've clicked | 48 // The default theme if we haven't installed a theme yet or if we've clicked |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 chrome::NOTIFICATION_EXTENSIONS_READY, | 99 chrome::NOTIFICATION_EXTENSIONS_READY, |
| 98 content::Source<Profile>(profile_)); | 100 content::Source<Profile>(profile_)); |
| 99 } | 101 } |
| 100 | 102 |
| 101 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this)); | 103 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this)); |
| 102 } | 104 } |
| 103 | 105 |
| 104 gfx::Image ThemeService::GetImageNamed(int id) const { | 106 gfx::Image ThemeService::GetImageNamed(int id) const { |
| 105 DCHECK(CalledOnValidThread()); | 107 DCHECK(CalledOnValidThread()); |
| 106 | 108 |
| 107 // For a managed user, use the special frame instead of the default one. | |
| 108 // TODO(akuegel): Remove this once we have the default managed user theme. | |
| 109 if (IsManagedUser()) { | |
| 110 if (id == IDR_THEME_FRAME) | |
| 111 id = IDR_MANAGED_USER_THEME_FRAME; | |
| 112 else if (id == IDR_THEME_FRAME_INACTIVE) | |
| 113 id = IDR_MANAGED_USER_THEME_FRAME_INACTIVE; | |
| 114 else if (id == IDR_THEME_TAB_BACKGROUND || id == IDR_THEME_TAB_BACKGROUND_V) | |
| 115 id = IDR_MANAGED_USER_THEME_TAB_BACKGROUND; | |
| 116 } | |
| 117 | |
| 118 gfx::Image image; | 109 gfx::Image image; |
| 119 if (theme_pack_.get()) | 110 if (theme_supplier_.get()) |
| 120 image = theme_pack_->GetImageNamed(id); | 111 image = theme_supplier_->GetImageNamed(id); |
| 121 | 112 |
| 122 if (image.IsEmpty()) | 113 if (image.IsEmpty()) |
| 123 image = rb_.GetNativeImageNamed(id); | 114 image = rb_.GetNativeImageNamed(id); |
| 124 | 115 |
| 125 return image; | 116 return image; |
| 126 } | 117 } |
| 127 | 118 |
| 128 gfx::ImageSkia* ThemeService::GetImageSkiaNamed(int id) const { | 119 gfx::ImageSkia* ThemeService::GetImageSkiaNamed(int id) const { |
| 129 gfx::Image image = GetImageNamed(id); | 120 gfx::Image image = GetImageNamed(id); |
| 130 if (image.IsEmpty()) | 121 if (image.IsEmpty()) |
| 131 return NULL; | 122 return NULL; |
| 132 // TODO(pkotwicz): Remove this const cast. The gfx::Image interface returns | 123 // TODO(pkotwicz): Remove this const cast. The gfx::Image interface returns |
| 133 // its images const. GetImageSkiaNamed() also should but has many callsites. | 124 // its images const. GetImageSkiaNamed() also should but has many callsites. |
| 134 return const_cast<gfx::ImageSkia*>(image.ToImageSkia()); | 125 return const_cast<gfx::ImageSkia*>(image.ToImageSkia()); |
| 135 } | 126 } |
| 136 | 127 |
| 137 SkColor ThemeService::GetColor(int id) const { | 128 SkColor ThemeService::GetColor(int id) const { |
| 138 DCHECK(CalledOnValidThread()); | 129 DCHECK(CalledOnValidThread()); |
| 139 | |
| 140 // TODO(akuegel): Remove this once we have the default managed user theme. | |
| 141 if (IsManagedUser()) { | |
| 142 if (id == Properties::COLOR_FRAME) | |
| 143 id = Properties::COLOR_FRAME_MANAGED_USER; | |
| 144 else if (id == Properties::COLOR_FRAME_INACTIVE) | |
| 145 id = Properties::COLOR_FRAME_MANAGED_USER_INACTIVE; | |
| 146 } | |
| 147 | |
| 148 SkColor color; | 130 SkColor color; |
| 149 if (theme_pack_.get() && theme_pack_->GetColor(id, &color)) | 131 if (theme_supplier_.get() && theme_supplier_->GetColor(id, &color)) |
| 150 return color; | 132 return color; |
| 151 | 133 |
| 152 // For backward compat with older themes, some newer colors are generated from | 134 // For backward compat with older themes, some newer colors are generated from |
| 153 // older ones if they are missing. | 135 // older ones if they are missing. |
| 154 switch (id) { | 136 switch (id) { |
| 155 case Properties::COLOR_NTP_SECTION_HEADER_TEXT: | 137 case Properties::COLOR_NTP_SECTION_HEADER_TEXT: |
| 156 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.30); | 138 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.30); |
| 157 case Properties::COLOR_NTP_SECTION_HEADER_TEXT_HOVER: | 139 case Properties::COLOR_NTP_SECTION_HEADER_TEXT_HOVER: |
| 158 return GetColor(Properties::COLOR_NTP_TEXT); | 140 return GetColor(Properties::COLOR_NTP_TEXT); |
| 159 case Properties::COLOR_NTP_SECTION_HEADER_RULE: | 141 case Properties::COLOR_NTP_SECTION_HEADER_RULE: |
| 160 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.70); | 142 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.70); |
| 161 case Properties::COLOR_NTP_SECTION_HEADER_RULE_LIGHT: | 143 case Properties::COLOR_NTP_SECTION_HEADER_RULE_LIGHT: |
| 162 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.86); | 144 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.86); |
| 163 case Properties::COLOR_NTP_TEXT_LIGHT: | 145 case Properties::COLOR_NTP_TEXT_LIGHT: |
| 164 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.40); | 146 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.40); |
| 165 case Properties::COLOR_MANAGED_USER_LABEL: | 147 case Properties::COLOR_MANAGED_USER_LABEL: |
| 166 // TODO(akuegel): Use GetReadableColor() once we want to support other | 148 return color_utils::GetReadableColor( |
| 167 // themes as well. | 149 SK_ColorWHITE, |
| 168 return SkColorSetRGB(231, 245, 255); | 150 GetColor(Properties::COLOR_MANAGED_USER_LABEL_BACKGROUND)); |
| 169 case Properties::COLOR_MANAGED_USER_LABEL_BACKGROUND: | 151 case Properties::COLOR_MANAGED_USER_LABEL_BACKGROUND: |
| 170 // TODO(akuegel): Replace this constant by a color calculated from the | 152 return color_utils::BlendTowardOppositeLuminance( |
| 171 // frame color once the default managed user theme is finished and we | 153 GetColor(Properties::COLOR_FRAME), 0x80); |
| 172 // allow managed users to install other themes. | |
| 173 return SkColorSetRGB(108, 167, 210); | |
| 174 } | 154 } |
| 175 | 155 |
| 176 return Properties::GetDefaultColor(id); | 156 return Properties::GetDefaultColor(id); |
| 177 } | 157 } |
| 178 | 158 |
| 179 bool ThemeService::GetDisplayProperty(int id, int* result) const { | 159 bool ThemeService::GetDisplayProperty(int id, int* result) const { |
| 180 if (theme_pack_.get()) | 160 if (theme_supplier_.get()) |
| 181 return theme_pack_->GetDisplayProperty(id, result); | 161 return theme_supplier_->GetDisplayProperty(id, result); |
| 182 | 162 |
| 183 return Properties::GetDefaultDisplayProperty(id, result); | 163 return Properties::GetDefaultDisplayProperty(id, result); |
| 184 } | 164 } |
| 185 | 165 |
| 186 bool ThemeService::ShouldUseNativeFrame() const { | 166 bool ThemeService::ShouldUseNativeFrame() const { |
| 187 if (HasCustomImage(IDR_THEME_FRAME)) | 167 if (HasCustomImage(IDR_THEME_FRAME)) |
| 188 return false; | 168 return false; |
| 189 #if defined(OS_WIN) | 169 #if defined(OS_WIN) |
| 190 return ui::win::IsAeroGlassEnabled(); | 170 return ui::win::IsAeroGlassEnabled(); |
| 191 #else | 171 #else |
| 192 return false; | 172 return false; |
| 193 #endif | 173 #endif |
| 194 } | 174 } |
| 195 | 175 |
| 196 bool ThemeService::HasCustomImage(int id) const { | 176 bool ThemeService::HasCustomImage(int id) const { |
| 197 if (!Properties::IsThemeableImage(id)) | 177 if (!Properties::IsThemeableImage(id)) |
| 198 return false; | 178 return false; |
| 199 | 179 |
| 200 if (theme_pack_.get()) | 180 if (theme_supplier_.get()) |
| 201 return theme_pack_->HasCustomImage(id); | 181 return theme_supplier_->HasCustomImage(id); |
| 202 | |
| 203 if (IsManagedUser() && | |
| 204 (id == IDR_THEME_FRAME || id == IDR_THEME_FRAME_INACTIVE || | |
| 205 id == IDR_THEME_TAB_BACKGROUND || id == IDR_THEME_TAB_BACKGROUND_V)) | |
| 206 return true; | |
| 207 | 182 |
| 208 return false; | 183 return false; |
| 209 } | 184 } |
| 210 | 185 |
| 211 base::RefCountedMemory* ThemeService::GetRawData( | 186 base::RefCountedMemory* ThemeService::GetRawData( |
| 212 int id, | 187 int id, |
| 213 ui::ScaleFactor scale_factor) const { | 188 ui::ScaleFactor scale_factor) const { |
| 214 // Check to see whether we should substitute some images. | 189 // Check to see whether we should substitute some images. |
| 215 int ntp_alternate; | 190 int ntp_alternate; |
| 216 GetDisplayProperty(Properties::NTP_LOGO_ALTERNATE, &ntp_alternate); | 191 GetDisplayProperty(Properties::NTP_LOGO_ALTERNATE, &ntp_alternate); |
| 217 if (id == IDR_PRODUCT_LOGO && ntp_alternate != 0) | 192 if (id == IDR_PRODUCT_LOGO && ntp_alternate != 0) |
| 218 id = IDR_PRODUCT_LOGO_WHITE; | 193 id = IDR_PRODUCT_LOGO_WHITE; |
| 219 | 194 |
| 220 base::RefCountedMemory* data = NULL; | 195 base::RefCountedMemory* data = NULL; |
| 221 if (theme_pack_.get()) | 196 if (theme_supplier_.get()) |
| 222 data = theme_pack_->GetRawData(id, scale_factor); | 197 data = theme_supplier_->GetRawData(id, scale_factor); |
| 223 if (!data) | 198 if (!data) |
| 224 data = rb_.LoadDataResourceBytesForScale(id, ui::SCALE_FACTOR_100P); | 199 data = rb_.LoadDataResourceBytesForScale(id, ui::SCALE_FACTOR_100P); |
| 225 | 200 |
| 226 return data; | 201 return data; |
| 227 } | 202 } |
| 228 | 203 |
| 229 void ThemeService::Observe(int type, | 204 void ThemeService::Observe(int type, |
| 230 const content::NotificationSource& source, | 205 const content::NotificationSource& source, |
| 231 const content::NotificationDetails& details) { | 206 const content::NotificationDetails& details) { |
| 232 DCHECK(type == chrome::NOTIFICATION_EXTENSIONS_READY); | 207 DCHECK(type == chrome::NOTIFICATION_EXTENSIONS_READY); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 254 DCHECK(service->GetExtensionById(extension->id(), false)); | 229 DCHECK(service->GetExtensionById(extension->id(), false)); |
| 255 } | 230 } |
| 256 | 231 |
| 257 BuildFromExtension(extension); | 232 BuildFromExtension(extension); |
| 258 SaveThemeID(extension->id()); | 233 SaveThemeID(extension->id()); |
| 259 | 234 |
| 260 NotifyThemeChanged(); | 235 NotifyThemeChanged(); |
| 261 content::RecordAction(UserMetricsAction("Themes_Installed")); | 236 content::RecordAction(UserMetricsAction("Themes_Installed")); |
| 262 } | 237 } |
| 263 | 238 |
| 239 void ThemeService::SetCustomDefaultTheme( |
| 240 scoped_refptr<CustomThemeSupplier> theme_supplier) { |
| 241 ClearAllThemeData(); |
| 242 SwapThemeSupplier(theme_supplier); |
| 243 NotifyThemeChanged(); |
| 244 } |
| 245 |
| 246 bool ThemeService::ShouldInitWithNativeTheme() const { |
| 247 return false; |
| 248 } |
| 249 |
| 264 void ThemeService::RemoveUnusedThemes() { | 250 void ThemeService::RemoveUnusedThemes() { |
| 265 if (!profile_) | 251 // We do not want to garbage collect themes on startup (|ready_| is false). |
| 252 // Themes will get garbage collected once |
| 253 // ExtensionService::GarbageCollectExtensions() runs. |
| 254 if (!profile_ || !ready_) |
| 266 return; | 255 return; |
| 256 |
| 267 ExtensionService* service = profile_->GetExtensionService(); | 257 ExtensionService* service = profile_->GetExtensionService(); |
| 268 if (!service) | 258 if (!service) |
| 269 return; | 259 return; |
| 270 std::string current_theme = GetThemeID(); | 260 std::string current_theme = GetThemeID(); |
| 271 std::vector<std::string> remove_list; | 261 std::vector<std::string> remove_list; |
| 272 const ExtensionSet* extensions = service->extensions(); | 262 const ExtensionSet* extensions = service->extensions(); |
| 273 for (ExtensionSet::const_iterator it = extensions->begin(); | 263 for (ExtensionSet::const_iterator it = extensions->begin(); |
| 274 it != extensions->end(); ++it) { | 264 it != extensions->end(); ++it) { |
| 275 if ((*it)->is_theme() && (*it)->id() != current_theme) { | 265 if ((*it)->is_theme() && (*it)->id() != current_theme) { |
| 276 remove_list.push_back((*it)->id()); | 266 remove_list.push_back((*it)->id()); |
| 277 } | 267 } |
| 278 } | 268 } |
| 279 for (size_t i = 0; i < remove_list.size(); ++i) | 269 for (size_t i = 0; i < remove_list.size(); ++i) |
| 280 service->UninstallExtension(remove_list[i], false, NULL); | 270 service->UninstallExtension(remove_list[i], false, NULL); |
| 281 } | 271 } |
| 282 | 272 |
| 283 void ThemeService::UseDefaultTheme() { | 273 void ThemeService::UseDefaultTheme() { |
| 284 ClearAllThemeData(); | 274 if (ready_) |
| 285 NotifyThemeChanged(); | 275 content::RecordAction(UserMetricsAction("Themes_Reset")); |
| 286 content::RecordAction(UserMetricsAction("Themes_Reset")); | 276 if (IsManagedUser()) { |
| 277 SetManagedUserTheme(); |
| 278 return; |
| 279 } |
| 280 if (ready_) { |
| 281 ClearAllThemeData(); |
| 282 NotifyThemeChanged(); |
| 283 } |
| 287 } | 284 } |
| 288 | 285 |
| 289 void ThemeService::SetNativeTheme() { | 286 void ThemeService::SetNativeTheme() { |
| 290 UseDefaultTheme(); | 287 UseDefaultTheme(); |
| 291 } | 288 } |
| 292 | 289 |
| 293 bool ThemeService::UsingDefaultTheme() const { | 290 bool ThemeService::UsingDefaultTheme() const { |
| 294 std::string id = GetThemeID(); | 291 std::string id = GetThemeID(); |
| 295 return id == ThemeService::kDefaultThemeID || | 292 return id == ThemeService::kDefaultThemeID || |
| 296 id == kDefaultThemeGalleryID; | 293 (id == kDefaultThemeGalleryID && !IsManagedUser()); |
| 297 } | 294 } |
| 298 | 295 |
| 299 bool ThemeService::UsingNativeTheme() const { | 296 bool ThemeService::UsingNativeTheme() const { |
| 300 return UsingDefaultTheme(); | 297 return UsingDefaultTheme(); |
| 301 } | 298 } |
| 302 | 299 |
| 303 std::string ThemeService::GetThemeID() const { | 300 std::string ThemeService::GetThemeID() const { |
| 304 return profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); | 301 return profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); |
| 305 } | 302 } |
| 306 | 303 |
| 307 color_utils::HSL ThemeService::GetTint(int id) const { | 304 color_utils::HSL ThemeService::GetTint(int id) const { |
| 308 DCHECK(CalledOnValidThread()); | 305 DCHECK(CalledOnValidThread()); |
| 309 | 306 |
| 310 color_utils::HSL hsl; | 307 color_utils::HSL hsl; |
| 311 if (theme_pack_.get() && theme_pack_->GetTint(id, &hsl)) | 308 if (theme_supplier_.get() && theme_supplier_->GetTint(id, &hsl)) |
| 312 return hsl; | 309 return hsl; |
| 313 | 310 |
| 314 return ThemeProperties::GetDefaultTint(id); | 311 return ThemeProperties::GetDefaultTint(id); |
| 315 } | 312 } |
| 316 | 313 |
| 317 void ThemeService::ClearAllThemeData() { | 314 void ThemeService::ClearAllThemeData() { |
| 315 SwapThemeSupplier(NULL); |
| 316 |
| 318 // Clear our image cache. | 317 // Clear our image cache. |
| 319 FreePlatformCaches(); | 318 FreePlatformCaches(); |
| 320 theme_pack_ = NULL; | |
| 321 | 319 |
| 322 profile_->GetPrefs()->ClearPref(prefs::kCurrentThemePackFilename); | 320 profile_->GetPrefs()->ClearPref(prefs::kCurrentThemePackFilename); |
| 323 SaveThemeID(kDefaultThemeID); | 321 SaveThemeID(kDefaultThemeID); |
| 324 | 322 |
| 325 RemoveUnusedThemes(); | 323 RemoveUnusedThemes(); |
| 326 } | 324 } |
| 327 | 325 |
| 328 void ThemeService::LoadThemePrefs() { | 326 void ThemeService::LoadThemePrefs() { |
| 329 PrefService* prefs = profile_->GetPrefs(); | 327 PrefService* prefs = profile_->GetPrefs(); |
| 330 | 328 |
| 331 std::string current_id = GetThemeID(); | 329 std::string current_id = GetThemeID(); |
| 332 if (current_id == kDefaultThemeID) { | 330 if (current_id == kDefaultThemeID) { |
| 331 // Managed users have a different default theme. |
| 332 if (IsManagedUser()) |
| 333 SetManagedUserTheme(); |
| 334 else if (ShouldInitWithNativeTheme()) |
| 335 SetNativeTheme(); |
| 336 else |
| 337 UseDefaultTheme(); |
| 333 set_ready(); | 338 set_ready(); |
| 334 return; | 339 return; |
| 335 } | 340 } |
| 336 | 341 |
| 337 bool loaded_pack = false; | 342 bool loaded_pack = false; |
| 338 | 343 |
| 339 // If we don't have a file pack, we're updating from an old version. | 344 // If we don't have a file pack, we're updating from an old version. |
| 340 base::FilePath path = prefs->GetFilePath(prefs::kCurrentThemePackFilename); | 345 base::FilePath path = prefs->GetFilePath(prefs::kCurrentThemePackFilename); |
| 341 if (path != base::FilePath()) { | 346 if (path != base::FilePath()) { |
| 342 theme_pack_ = BrowserThemePack::BuildFromDataPack(path, current_id); | 347 SwapThemeSupplier(BrowserThemePack::BuildFromDataPack(path, current_id)); |
| 343 loaded_pack = theme_pack_.get() != NULL; | 348 loaded_pack = theme_supplier_.get() != NULL; |
| 344 } | 349 } |
| 345 | 350 |
| 346 if (loaded_pack) { | 351 if (loaded_pack) { |
| 347 content::RecordAction(UserMetricsAction("Themes.Loaded")); | 352 content::RecordAction(UserMetricsAction("Themes.Loaded")); |
| 348 set_ready(); | 353 set_ready(); |
| 349 } else { | 354 } else { |
| 350 // TODO(erg): We need to pop up a dialog informing the user that their | 355 // TODO(erg): We need to pop up a dialog informing the user that their |
| 351 // theme is being migrated. | 356 // theme is being migrated. |
| 352 ExtensionService* service = | 357 ExtensionService* service = |
| 353 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 358 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 354 if (service && service->is_ready()) { | 359 if (service && service->is_ready()) { |
| 355 MigrateTheme(); | 360 MigrateTheme(); |
| 356 set_ready(); | 361 set_ready(); |
| 357 } | 362 } |
| 358 } | 363 } |
| 359 } | 364 } |
| 360 | 365 |
| 361 void ThemeService::NotifyThemeChanged() { | 366 void ThemeService::NotifyThemeChanged() { |
| 367 if (!ready_) |
| 368 return; |
| 369 |
| 362 DVLOG(1) << "Sending BROWSER_THEME_CHANGED"; | 370 DVLOG(1) << "Sending BROWSER_THEME_CHANGED"; |
| 363 // Redraw! | 371 // Redraw! |
| 364 content::NotificationService* service = | 372 content::NotificationService* service = |
| 365 content::NotificationService::current(); | 373 content::NotificationService::current(); |
| 366 service->Notify(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 374 service->Notify(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
| 367 content::Source<ThemeService>(this), | 375 content::Source<ThemeService>(this), |
| 368 content::NotificationService::NoDetails()); | 376 content::NotificationService::NoDetails()); |
| 369 #if defined(OS_MACOSX) | 377 #if defined(OS_MACOSX) |
| 370 NotifyPlatformThemeChanged(); | 378 NotifyPlatformThemeChanged(); |
| 371 #endif // OS_MACOSX | 379 #endif // OS_MACOSX |
| 372 | 380 |
| 373 // Notify sync that theme has changed. | 381 // Notify sync that theme has changed. |
| 374 if (theme_syncable_service_.get()) { | 382 if (theme_syncable_service_.get()) { |
| 375 theme_syncable_service_->OnThemeChange(); | 383 theme_syncable_service_->OnThemeChange(); |
| 376 } | 384 } |
| 377 } | 385 } |
| 378 | 386 |
| 379 #if defined(OS_WIN) || defined(USE_AURA) | 387 #if defined(OS_WIN) || defined(USE_AURA) |
| 380 void ThemeService::FreePlatformCaches() { | 388 void ThemeService::FreePlatformCaches() { |
| 381 // Views (Skia) has no platform image cache to clear. | 389 // Views (Skia) has no platform image cache to clear. |
| 382 } | 390 } |
| 383 #endif | 391 #endif |
| 384 | 392 |
| 393 void ThemeService::SwapThemeSupplier( |
| 394 scoped_refptr<CustomThemeSupplier> theme_supplier) { |
| 395 if (theme_supplier_.get()) |
| 396 theme_supplier_->StopUsingTheme(); |
| 397 theme_supplier_ = theme_supplier; |
| 398 if (theme_supplier_.get()) |
| 399 theme_supplier_->StartUsingTheme(); |
| 400 } |
| 401 |
| 385 void ThemeService::MigrateTheme() { | 402 void ThemeService::MigrateTheme() { |
| 386 ExtensionService* service = | 403 ExtensionService* service = |
| 387 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 404 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 388 const Extension* extension = service ? | 405 const Extension* extension = service ? |
| 389 service->GetExtensionById(GetThemeID(), false) : NULL; | 406 service->GetExtensionById(GetThemeID(), false) : NULL; |
| 390 if (extension) { | 407 if (extension) { |
| 391 DLOG(ERROR) << "Migrating theme"; | 408 DLOG(ERROR) << "Migrating theme"; |
| 392 BuildFromExtension(extension); | 409 BuildFromExtension(extension); |
| 393 content::RecordAction(UserMetricsAction("Themes.Migrated")); | 410 content::RecordAction(UserMetricsAction("Themes.Migrated")); |
| 394 } else { | 411 } else { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 423 return; | 440 return; |
| 424 | 441 |
| 425 // Write the packed file to disk. | 442 // Write the packed file to disk. |
| 426 base::FilePath pack_path = | 443 base::FilePath pack_path = |
| 427 extension->path().Append(chrome::kThemePackFilename); | 444 extension->path().Append(chrome::kThemePackFilename); |
| 428 service->GetFileTaskRunner()->PostTask( | 445 service->GetFileTaskRunner()->PostTask( |
| 429 FROM_HERE, | 446 FROM_HERE, |
| 430 base::Bind(&WritePackToDiskCallback, pack, pack_path)); | 447 base::Bind(&WritePackToDiskCallback, pack, pack_path)); |
| 431 | 448 |
| 432 SavePackName(pack_path); | 449 SavePackName(pack_path); |
| 433 theme_pack_ = pack; | 450 SwapThemeSupplier(pack); |
| 434 } | 451 } |
| 435 | 452 |
| 436 bool ThemeService::IsManagedUser() const { | 453 bool ThemeService::IsManagedUser() const { |
| 437 #if defined(ENABLE_MANAGED_USERS) | 454 #if defined(ENABLE_MANAGED_USERS) |
| 438 return ManagedUserService::ProfileIsManaged(profile_); | 455 return ManagedUserService::ProfileIsManaged(profile_); |
| 439 #endif | 456 #endif |
| 440 return false; | 457 return false; |
| 441 } | 458 } |
| 442 | 459 |
| 460 void ThemeService::SetManagedUserTheme() { |
| 461 #if defined(ENABLE_MANAGED_USERS) |
| 462 SetCustomDefaultTheme(new ManagedUserTheme); |
| 463 #endif |
| 464 } |
| 465 |
| 443 void ThemeService::OnInfobarDisplayed() { | 466 void ThemeService::OnInfobarDisplayed() { |
| 444 number_of_infobars_++; | 467 number_of_infobars_++; |
| 445 } | 468 } |
| 446 | 469 |
| 447 void ThemeService::OnInfobarDestroyed() { | 470 void ThemeService::OnInfobarDestroyed() { |
| 448 number_of_infobars_--; | 471 number_of_infobars_--; |
| 449 | 472 |
| 450 if (number_of_infobars_ == 0) | 473 if (number_of_infobars_ == 0) |
| 451 RemoveUnusedThemes(); | 474 RemoveUnusedThemes(); |
| 452 } | 475 } |
| 453 | 476 |
| 454 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { | 477 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { |
| 455 return theme_syncable_service_.get(); | 478 return theme_syncable_service_.get(); |
| 456 } | 479 } |
| OLD | NEW |