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 "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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 registrar_.Add(this, | 98 registrar_.Add(this, |
| 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 | |
| 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; | 108 gfx::Image image; |
| 119 if (theme_pack_.get()) | 109 if (theme_supplier_.get()) |
| 120 image = theme_pack_->GetImageNamed(id); | 110 image = theme_supplier_->GetImageNamed(id); |
| 121 | 111 |
| 122 if (image.IsEmpty()) | 112 if (image.IsEmpty()) |
| 123 image = rb_.GetNativeImageNamed(id); | 113 image = rb_.GetNativeImageNamed(id); |
| 124 | 114 |
| 125 return image; | 115 return image; |
| 126 } | 116 } |
| 127 | 117 |
| 128 gfx::ImageSkia* ThemeService::GetImageSkiaNamed(int id) const { | 118 gfx::ImageSkia* ThemeService::GetImageSkiaNamed(int id) const { |
| 129 gfx::Image image = GetImageNamed(id); | 119 gfx::Image image = GetImageNamed(id); |
| 130 if (image.IsEmpty()) | 120 if (image.IsEmpty()) |
| 131 return NULL; | 121 return NULL; |
| 132 // TODO(pkotwicz): Remove this const cast. The gfx::Image interface returns | 122 // TODO(pkotwicz): Remove this const cast. The gfx::Image interface returns |
| 133 // its images const. GetImageSkiaNamed() also should but has many callsites. | 123 // its images const. GetImageSkiaNamed() also should but has many callsites. |
| 134 return const_cast<gfx::ImageSkia*>(image.ToImageSkia()); | 124 return const_cast<gfx::ImageSkia*>(image.ToImageSkia()); |
| 135 } | 125 } |
| 136 | 126 |
| 137 SkColor ThemeService::GetColor(int id) const { | 127 SkColor ThemeService::GetColor(int id) const { |
| 138 DCHECK(CalledOnValidThread()); | 128 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; | 129 SkColor color; |
| 149 if (theme_pack_.get() && theme_pack_->GetColor(id, &color)) | 130 if (theme_supplier_.get() && theme_supplier_->GetColor(id, &color)) |
| 150 return color; | 131 return color; |
| 151 | 132 |
| 152 // For backward compat with older themes, some newer colors are generated from | 133 // For backward compat with older themes, some newer colors are generated from |
| 153 // older ones if they are missing. | 134 // older ones if they are missing. |
| 154 switch (id) { | 135 switch (id) { |
| 155 case Properties::COLOR_NTP_SECTION_HEADER_TEXT: | 136 case Properties::COLOR_NTP_SECTION_HEADER_TEXT: |
| 156 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.30); | 137 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.30); |
| 157 case Properties::COLOR_NTP_SECTION_HEADER_TEXT_HOVER: | 138 case Properties::COLOR_NTP_SECTION_HEADER_TEXT_HOVER: |
| 158 return GetColor(Properties::COLOR_NTP_TEXT); | 139 return GetColor(Properties::COLOR_NTP_TEXT); |
| 159 case Properties::COLOR_NTP_SECTION_HEADER_RULE: | 140 case Properties::COLOR_NTP_SECTION_HEADER_RULE: |
| 160 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.70); | 141 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.70); |
| 161 case Properties::COLOR_NTP_SECTION_HEADER_RULE_LIGHT: | 142 case Properties::COLOR_NTP_SECTION_HEADER_RULE_LIGHT: |
| 162 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.86); | 143 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.86); |
| 163 case Properties::COLOR_NTP_TEXT_LIGHT: | 144 case Properties::COLOR_NTP_TEXT_LIGHT: |
| 164 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.40); | 145 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.40); |
| 165 case Properties::COLOR_MANAGED_USER_LABEL: | 146 case Properties::COLOR_MANAGED_USER_LABEL: |
| 166 // TODO(akuegel): Use GetReadableColor() once we want to support other | 147 return color_utils::GetReadableColor( |
| 167 // themes as well. | 148 SK_ColorWHITE, |
| 168 return SkColorSetRGB(231, 245, 255); | 149 GetColor(Properties::COLOR_MANAGED_USER_LABEL_BACKGROUND)); |
| 169 case Properties::COLOR_MANAGED_USER_LABEL_BACKGROUND: | 150 case Properties::COLOR_MANAGED_USER_LABEL_BACKGROUND: |
| 170 // TODO(akuegel): Replace this constant by a color calculated from the | 151 return color_utils::BlendTowardOppositeLuminance( |
| 171 // frame color once the default managed user theme is finished and we | 152 GetColor(Properties::COLOR_FRAME), 0x80); |
| 172 // allow managed users to install other themes. | |
| 173 return SkColorSetRGB(108, 167, 210); | |
| 174 } | 153 } |
| 175 | 154 |
| 176 return Properties::GetDefaultColor(id); | 155 return Properties::GetDefaultColor(id); |
| 177 } | 156 } |
| 178 | 157 |
| 179 bool ThemeService::GetDisplayProperty(int id, int* result) const { | 158 bool ThemeService::GetDisplayProperty(int id, int* result) const { |
| 180 if (theme_pack_.get()) | 159 if (theme_supplier_.get()) |
| 181 return theme_pack_->GetDisplayProperty(id, result); | 160 return theme_supplier_->GetDisplayProperty(id, result); |
| 182 | 161 |
| 183 return Properties::GetDefaultDisplayProperty(id, result); | 162 return Properties::GetDefaultDisplayProperty(id, result); |
| 184 } | 163 } |
| 185 | 164 |
| 186 bool ThemeService::ShouldUseNativeFrame() const { | 165 bool ThemeService::ShouldUseNativeFrame() const { |
| 187 if (HasCustomImage(IDR_THEME_FRAME)) | 166 if (HasCustomImage(IDR_THEME_FRAME)) |
| 188 return false; | 167 return false; |
| 189 #if defined(OS_WIN) | 168 #if defined(OS_WIN) |
| 190 return ui::win::IsAeroGlassEnabled(); | 169 return ui::win::IsAeroGlassEnabled(); |
| 191 #else | 170 #else |
| 192 return false; | 171 return false; |
| 193 #endif | 172 #endif |
| 194 } | 173 } |
| 195 | 174 |
| 196 bool ThemeService::HasCustomImage(int id) const { | 175 bool ThemeService::HasCustomImage(int id) const { |
| 197 if (!Properties::IsThemeableImage(id)) | 176 if (!Properties::IsThemeableImage(id)) |
| 198 return false; | 177 return false; |
| 199 | 178 |
| 200 if (theme_pack_.get()) | 179 if (theme_supplier_.get()) |
| 201 return theme_pack_->HasCustomImage(id); | 180 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 | 181 |
| 208 return false; | 182 return false; |
| 209 } | 183 } |
| 210 | 184 |
| 211 base::RefCountedMemory* ThemeService::GetRawData( | 185 base::RefCountedMemory* ThemeService::GetRawData( |
| 212 int id, | 186 int id, |
| 213 ui::ScaleFactor scale_factor) const { | 187 ui::ScaleFactor scale_factor) const { |
| 214 // Check to see whether we should substitute some images. | 188 // Check to see whether we should substitute some images. |
| 215 int ntp_alternate; | 189 int ntp_alternate; |
| 216 GetDisplayProperty(Properties::NTP_LOGO_ALTERNATE, &ntp_alternate); | 190 GetDisplayProperty(Properties::NTP_LOGO_ALTERNATE, &ntp_alternate); |
| 217 if (id == IDR_PRODUCT_LOGO && ntp_alternate != 0) | 191 if (id == IDR_PRODUCT_LOGO && ntp_alternate != 0) |
| 218 id = IDR_PRODUCT_LOGO_WHITE; | 192 id = IDR_PRODUCT_LOGO_WHITE; |
| 219 | 193 |
| 220 base::RefCountedMemory* data = NULL; | 194 base::RefCountedMemory* data = NULL; |
| 221 if (theme_pack_.get()) | 195 if (theme_supplier_.get()) |
| 222 data = theme_pack_->GetRawData(id, scale_factor); | 196 data = theme_supplier_->GetRawData(id, scale_factor); |
| 223 if (!data) | 197 if (!data) |
| 224 data = rb_.LoadDataResourceBytesForScale(id, ui::SCALE_FACTOR_100P); | 198 data = rb_.LoadDataResourceBytesForScale(id, ui::SCALE_FACTOR_100P); |
| 225 | 199 |
| 226 return data; | 200 return data; |
| 227 } | 201 } |
| 228 | 202 |
| 229 void ThemeService::Observe(int type, | 203 void ThemeService::Observe(int type, |
| 230 const content::NotificationSource& source, | 204 const content::NotificationSource& source, |
| 231 const content::NotificationDetails& details) { | 205 const content::NotificationDetails& details) { |
| 232 DCHECK(type == chrome::NOTIFICATION_EXTENSIONS_READY); | 206 DCHECK(type == chrome::NOTIFICATION_EXTENSIONS_READY); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 254 DCHECK(service->GetExtensionById(extension->id(), false)); | 228 DCHECK(service->GetExtensionById(extension->id(), false)); |
| 255 } | 229 } |
| 256 | 230 |
| 257 BuildFromExtension(extension); | 231 BuildFromExtension(extension); |
| 258 SaveThemeID(extension->id()); | 232 SaveThemeID(extension->id()); |
| 259 | 233 |
| 260 NotifyThemeChanged(); | 234 NotifyThemeChanged(); |
| 261 content::RecordAction(UserMetricsAction("Themes_Installed")); | 235 content::RecordAction(UserMetricsAction("Themes_Installed")); |
| 262 } | 236 } |
| 263 | 237 |
| 238 void ThemeService::SetCustomDefaultTheme( | |
| 239 scoped_refptr<CustomThemeSupplier> theme_supplier) { | |
| 240 ClearAllThemeData(); | |
| 241 SwapThemeSupplier(theme_supplier); | |
|
pkotwicz
2013/07/19 18:33:20
Nit: Comment that NotifyThemeChange() is not neces
Adrian Kuegel
2013/07/22 12:58:08
I guess it makes sense then if I also check this b
| |
| 242 NotifyThemeChanged(); | |
| 243 } | |
| 244 | |
| 245 bool ThemeService::ShouldInitWithNativeTheme() { | |
| 246 return false; | |
| 247 } | |
| 248 | |
| 264 void ThemeService::RemoveUnusedThemes() { | 249 void ThemeService::RemoveUnusedThemes() { |
| 265 if (!profile_) | 250 if (!profile_ || !ready_) |
|
pkotwicz
2013/07/19 18:33:20
Comment that we do not want to garbage collect unu
Adrian Kuegel
2013/07/22 12:58:08
Done.
| |
| 266 return; | 251 return; |
| 267 ExtensionService* service = profile_->GetExtensionService(); | 252 ExtensionService* service = profile_->GetExtensionService(); |
| 268 if (!service) | 253 if (!service) |
| 269 return; | 254 return; |
| 270 std::string current_theme = GetThemeID(); | 255 std::string current_theme = GetThemeID(); |
| 271 std::vector<std::string> remove_list; | 256 std::vector<std::string> remove_list; |
| 272 const ExtensionSet* extensions = service->extensions(); | 257 const ExtensionSet* extensions = service->extensions(); |
| 273 for (ExtensionSet::const_iterator it = extensions->begin(); | 258 for (ExtensionSet::const_iterator it = extensions->begin(); |
| 274 it != extensions->end(); ++it) { | 259 it != extensions->end(); ++it) { |
| 275 if ((*it)->is_theme() && (*it)->id() != current_theme) { | 260 if ((*it)->is_theme() && (*it)->id() != current_theme) { |
| 276 remove_list.push_back((*it)->id()); | 261 remove_list.push_back((*it)->id()); |
| 277 } | 262 } |
| 278 } | 263 } |
| 279 for (size_t i = 0; i < remove_list.size(); ++i) | 264 for (size_t i = 0; i < remove_list.size(); ++i) |
| 280 service->UninstallExtension(remove_list[i], false, NULL); | 265 service->UninstallExtension(remove_list[i], false, NULL); |
| 281 } | 266 } |
| 282 | 267 |
| 283 void ThemeService::UseDefaultTheme() { | 268 void ThemeService::UseDefaultTheme() { |
| 269 content::RecordAction(UserMetricsAction("Themes_Reset")); | |
| 270 if (IsManagedUser()) { | |
| 271 SetManagedUserTheme(); | |
| 272 return; | |
| 273 } | |
| 284 ClearAllThemeData(); | 274 ClearAllThemeData(); |
| 285 NotifyThemeChanged(); | 275 NotifyThemeChanged(); |
| 286 content::RecordAction(UserMetricsAction("Themes_Reset")); | |
| 287 } | 276 } |
| 288 | 277 |
| 289 void ThemeService::SetNativeTheme() { | 278 void ThemeService::SetNativeTheme() { |
| 290 UseDefaultTheme(); | 279 UseDefaultTheme(); |
| 291 } | 280 } |
| 292 | 281 |
| 293 bool ThemeService::UsingDefaultTheme() const { | 282 bool ThemeService::UsingDefaultTheme() const { |
| 294 std::string id = GetThemeID(); | 283 std::string id = GetThemeID(); |
| 295 return id == ThemeService::kDefaultThemeID || | 284 return id == ThemeService::kDefaultThemeID || |
| 296 id == kDefaultThemeGalleryID; | 285 id == kDefaultThemeGalleryID; |
| 297 } | 286 } |
| 298 | 287 |
| 299 bool ThemeService::UsingNativeTheme() const { | 288 bool ThemeService::UsingNativeTheme() const { |
| 300 return UsingDefaultTheme(); | 289 return UsingDefaultTheme(); |
| 301 } | 290 } |
| 302 | 291 |
| 303 std::string ThemeService::GetThemeID() const { | 292 std::string ThemeService::GetThemeID() const { |
| 304 return profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); | 293 return profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); |
| 305 } | 294 } |
| 306 | 295 |
| 307 color_utils::HSL ThemeService::GetTint(int id) const { | 296 color_utils::HSL ThemeService::GetTint(int id) const { |
| 308 DCHECK(CalledOnValidThread()); | 297 DCHECK(CalledOnValidThread()); |
| 309 | 298 |
| 310 color_utils::HSL hsl; | 299 color_utils::HSL hsl; |
| 311 if (theme_pack_.get() && theme_pack_->GetTint(id, &hsl)) | 300 if (theme_supplier_.get() && theme_supplier_->GetTint(id, &hsl)) |
| 312 return hsl; | 301 return hsl; |
| 313 | 302 |
| 314 return ThemeProperties::GetDefaultTint(id); | 303 return ThemeProperties::GetDefaultTint(id); |
| 315 } | 304 } |
| 316 | 305 |
| 317 void ThemeService::ClearAllThemeData() { | 306 void ThemeService::ClearAllThemeData() { |
| 307 if (theme_supplier_.get()) | |
| 308 theme_supplier_->StopUsingTheme(); | |
|
pkotwicz
2013/07/19 18:33:20
Optional nit: Use SwapThemeSupplier(NULL) here?
Adrian Kuegel
2013/07/22 12:58:08
Done.
| |
| 309 | |
| 318 // Clear our image cache. | 310 // Clear our image cache. |
| 319 FreePlatformCaches(); | 311 FreePlatformCaches(); |
| 320 theme_pack_ = NULL; | 312 theme_supplier_ = NULL; |
| 321 | 313 |
| 322 profile_->GetPrefs()->ClearPref(prefs::kCurrentThemePackFilename); | 314 profile_->GetPrefs()->ClearPref(prefs::kCurrentThemePackFilename); |
| 323 SaveThemeID(kDefaultThemeID); | 315 SaveThemeID(kDefaultThemeID); |
| 324 | 316 |
| 325 RemoveUnusedThemes(); | 317 RemoveUnusedThemes(); |
| 326 } | 318 } |
| 327 | 319 |
| 328 void ThemeService::LoadThemePrefs() { | 320 void ThemeService::LoadThemePrefs() { |
| 329 PrefService* prefs = profile_->GetPrefs(); | 321 PrefService* prefs = profile_->GetPrefs(); |
| 330 | 322 |
| 331 std::string current_id = GetThemeID(); | 323 std::string current_id = GetThemeID(); |
| 332 if (current_id == kDefaultThemeID) { | 324 if (current_id == kDefaultThemeID) { |
| 325 // Managed users should always have their own default theme. | |
| 326 if (IsManagedUser()) | |
| 327 SetManagedUserTheme(); | |
| 328 else if (ShouldInitWithNativeTheme()) | |
| 329 SetNativeTheme(); | |
| 333 set_ready(); | 330 set_ready(); |
| 334 return; | 331 return; |
| 335 } | 332 } |
| 336 | 333 |
| 337 bool loaded_pack = false; | 334 bool loaded_pack = false; |
| 338 | 335 |
| 339 // If we don't have a file pack, we're updating from an old version. | 336 // If we don't have a file pack, we're updating from an old version. |
| 340 base::FilePath path = prefs->GetFilePath(prefs::kCurrentThemePackFilename); | 337 base::FilePath path = prefs->GetFilePath(prefs::kCurrentThemePackFilename); |
| 341 if (path != base::FilePath()) { | 338 if (path != base::FilePath()) { |
| 342 theme_pack_ = BrowserThemePack::BuildFromDataPack(path, current_id); | 339 SwapThemeSupplier(BrowserThemePack::BuildFromDataPack(path, current_id)); |
| 343 loaded_pack = theme_pack_.get() != NULL; | 340 loaded_pack = theme_supplier_.get() != NULL; |
| 344 } | 341 } |
| 345 | 342 |
| 346 if (loaded_pack) { | 343 if (loaded_pack) { |
| 347 content::RecordAction(UserMetricsAction("Themes.Loaded")); | 344 content::RecordAction(UserMetricsAction("Themes.Loaded")); |
| 348 set_ready(); | 345 set_ready(); |
| 349 } else { | 346 } else { |
| 350 // TODO(erg): We need to pop up a dialog informing the user that their | 347 // TODO(erg): We need to pop up a dialog informing the user that their |
| 351 // theme is being migrated. | 348 // theme is being migrated. |
| 352 ExtensionService* service = | 349 ExtensionService* service = |
| 353 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 350 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 375 theme_syncable_service_->OnThemeChange(); | 372 theme_syncable_service_->OnThemeChange(); |
| 376 } | 373 } |
| 377 } | 374 } |
| 378 | 375 |
| 379 #if defined(OS_WIN) || defined(USE_AURA) | 376 #if defined(OS_WIN) || defined(USE_AURA) |
| 380 void ThemeService::FreePlatformCaches() { | 377 void ThemeService::FreePlatformCaches() { |
| 381 // Views (Skia) has no platform image cache to clear. | 378 // Views (Skia) has no platform image cache to clear. |
| 382 } | 379 } |
| 383 #endif | 380 #endif |
| 384 | 381 |
| 382 void ThemeService::SwapThemeSupplier( | |
| 383 scoped_refptr<CustomThemeSupplier> theme_supplier) { | |
| 384 if (theme_supplier_.get()) | |
| 385 theme_supplier_->StopUsingTheme(); | |
| 386 theme_supplier_ = theme_supplier; | |
| 387 if (theme_supplier_.get()) | |
| 388 theme_supplier_->StartUsingTheme(); | |
| 389 } | |
| 390 | |
| 385 void ThemeService::MigrateTheme() { | 391 void ThemeService::MigrateTheme() { |
| 386 ExtensionService* service = | 392 ExtensionService* service = |
| 387 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 393 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 388 const Extension* extension = service ? | 394 const Extension* extension = service ? |
| 389 service->GetExtensionById(GetThemeID(), false) : NULL; | 395 service->GetExtensionById(GetThemeID(), false) : NULL; |
| 390 if (extension) { | 396 if (extension) { |
| 391 DLOG(ERROR) << "Migrating theme"; | 397 DLOG(ERROR) << "Migrating theme"; |
| 392 BuildFromExtension(extension); | 398 BuildFromExtension(extension); |
| 393 content::RecordAction(UserMetricsAction("Themes.Migrated")); | 399 content::RecordAction(UserMetricsAction("Themes.Migrated")); |
| 394 } else { | 400 } else { |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 423 return; | 429 return; |
| 424 | 430 |
| 425 // Write the packed file to disk. | 431 // Write the packed file to disk. |
| 426 base::FilePath pack_path = | 432 base::FilePath pack_path = |
| 427 extension->path().Append(chrome::kThemePackFilename); | 433 extension->path().Append(chrome::kThemePackFilename); |
| 428 service->GetFileTaskRunner()->PostTask( | 434 service->GetFileTaskRunner()->PostTask( |
| 429 FROM_HERE, | 435 FROM_HERE, |
| 430 base::Bind(&WritePackToDiskCallback, pack, pack_path)); | 436 base::Bind(&WritePackToDiskCallback, pack, pack_path)); |
| 431 | 437 |
| 432 SavePackName(pack_path); | 438 SavePackName(pack_path); |
| 433 theme_pack_ = pack; | 439 SwapThemeSupplier(pack); |
| 434 } | 440 } |
| 435 | 441 |
| 436 bool ThemeService::IsManagedUser() const { | 442 bool ThemeService::IsManagedUser() const { |
| 437 #if defined(ENABLE_MANAGED_USERS) | 443 #if defined(ENABLE_MANAGED_USERS) |
| 438 return ManagedUserService::ProfileIsManaged(profile_); | 444 return ManagedUserService::ProfileIsManaged(profile_); |
| 439 #endif | 445 #endif |
| 440 return false; | 446 return false; |
| 441 } | 447 } |
| 442 | 448 |
| 449 void ThemeService::SetManagedUserTheme() { | |
| 450 #if defined(ENABLE_MANAGED_USERS) | |
| 451 SetCustomDefaultTheme(new ManagedUserTheme); | |
| 452 #endif | |
| 453 } | |
| 454 | |
| 443 void ThemeService::OnInfobarDisplayed() { | 455 void ThemeService::OnInfobarDisplayed() { |
| 444 number_of_infobars_++; | 456 number_of_infobars_++; |
| 445 } | 457 } |
| 446 | 458 |
| 447 void ThemeService::OnInfobarDestroyed() { | 459 void ThemeService::OnInfobarDestroyed() { |
| 448 number_of_infobars_--; | 460 number_of_infobars_--; |
| 449 | 461 |
| 450 if (number_of_infobars_ == 0) | 462 if (number_of_infobars_ == 0) |
| 451 RemoveUnusedThemes(); | 463 RemoveUnusedThemes(); |
| 452 } | 464 } |
| 453 | 465 |
| 454 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { | 466 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { |
| 455 return theme_syncable_service_.get(); | 467 return theme_syncable_service_.get(); |
| 456 } | 468 } |
| OLD | NEW |