Chromium Code Reviews| Index: chrome/browser/themes/theme_service.cc |
| diff --git a/chrome/browser/themes/theme_service.cc b/chrome/browser/themes/theme_service.cc |
| index d7fe33bd290520c6da71f222a288f2fe1bd3adbf..92909d12b1ebea50897dd75748226d5dc3b69944 100644 |
| --- a/chrome/browser/themes/theme_service.cc |
| +++ b/chrome/browser/themes/theme_service.cc |
| @@ -15,6 +15,7 @@ |
| #include "chrome/browser/extensions/extension_system.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/themes/browser_theme_pack.h" |
| +#include "chrome/browser/themes/custom_theme_supplier.h" |
| #include "chrome/browser/themes/theme_properties.h" |
| #include "chrome/browser/themes/theme_syncable_service.h" |
| #include "chrome/common/chrome_constants.h" |
| @@ -34,6 +35,7 @@ |
| #if defined(ENABLE_MANAGED_USERS) |
| #include "chrome/browser/managed_mode/managed_user_service.h" |
| +#include "chrome/browser/managed_mode/managed_user_theme.h" |
| #endif |
| using content::BrowserThread; |
| @@ -104,20 +106,9 @@ void ThemeService::Init(Profile* profile) { |
| gfx::Image ThemeService::GetImageNamed(int id) const { |
| DCHECK(CalledOnValidThread()); |
| - // For a managed user, use the special frame instead of the default one. |
| - // TODO(akuegel): Remove this once we have the default managed user theme. |
| - if (IsManagedUser()) { |
| - if (id == IDR_THEME_FRAME) |
| - id = IDR_MANAGED_USER_THEME_FRAME; |
| - else if (id == IDR_THEME_FRAME_INACTIVE) |
| - id = IDR_MANAGED_USER_THEME_FRAME_INACTIVE; |
| - else if (id == IDR_THEME_TAB_BACKGROUND || id == IDR_THEME_TAB_BACKGROUND_V) |
| - id = IDR_MANAGED_USER_THEME_TAB_BACKGROUND; |
| - } |
| - |
| gfx::Image image; |
| - if (theme_pack_.get()) |
| - image = theme_pack_->GetImageNamed(id); |
| + if (theme_supplier_.get()) |
| + image = theme_supplier_->GetImageNamed(id); |
| if (image.IsEmpty()) |
| image = rb_.GetNativeImageNamed(id); |
| @@ -136,17 +127,8 @@ gfx::ImageSkia* ThemeService::GetImageSkiaNamed(int id) const { |
| SkColor ThemeService::GetColor(int id) const { |
| DCHECK(CalledOnValidThread()); |
| - |
| - // TODO(akuegel): Remove this once we have the default managed user theme. |
| - if (IsManagedUser()) { |
| - if (id == Properties::COLOR_FRAME) |
| - id = Properties::COLOR_FRAME_MANAGED_USER; |
| - else if (id == Properties::COLOR_FRAME_INACTIVE) |
| - id = Properties::COLOR_FRAME_MANAGED_USER_INACTIVE; |
| - } |
| - |
| SkColor color; |
| - if (theme_pack_.get() && theme_pack_->GetColor(id, &color)) |
| + if (theme_supplier_.get() && theme_supplier_->GetColor(id, &color)) |
| return color; |
| // For backward compat with older themes, some newer colors are generated from |
| @@ -163,22 +145,20 @@ SkColor ThemeService::GetColor(int id) const { |
| case Properties::COLOR_NTP_TEXT_LIGHT: |
| return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.40); |
| case Properties::COLOR_MANAGED_USER_LABEL: |
| - // TODO(akuegel): Use GetReadableColor() once we want to support other |
| - // themes as well. |
| - return SkColorSetRGB(231, 245, 255); |
| + return color_utils::GetReadableColor( |
| + SK_ColorWHITE, |
| + GetColor(Properties::COLOR_MANAGED_USER_LABEL_BACKGROUND)); |
| case Properties::COLOR_MANAGED_USER_LABEL_BACKGROUND: |
| - // TODO(akuegel): Replace this constant by a color calculated from the |
| - // frame color once the default managed user theme is finished and we |
| - // allow managed users to install other themes. |
| - return SkColorSetRGB(108, 167, 210); |
| + return color_utils::BlendTowardOppositeLuminance( |
| + GetColor(Properties::COLOR_FRAME), 0x80); |
| } |
| return Properties::GetDefaultColor(id); |
| } |
| bool ThemeService::GetDisplayProperty(int id, int* result) const { |
| - if (theme_pack_.get()) |
| - return theme_pack_->GetDisplayProperty(id, result); |
| + if (theme_supplier_.get()) |
| + return theme_supplier_->GetDisplayProperty(id, result); |
| return Properties::GetDefaultDisplayProperty(id, result); |
| } |
| @@ -197,13 +177,8 @@ bool ThemeService::HasCustomImage(int id) const { |
| if (!Properties::IsThemeableImage(id)) |
| return false; |
| - if (theme_pack_.get()) |
| - return theme_pack_->HasCustomImage(id); |
| - |
| - if (IsManagedUser() && |
| - (id == IDR_THEME_FRAME || id == IDR_THEME_FRAME_INACTIVE || |
| - id == IDR_THEME_TAB_BACKGROUND || id == IDR_THEME_TAB_BACKGROUND_V)) |
| - return true; |
| + if (theme_supplier_.get()) |
| + return theme_supplier_->HasCustomImage(id); |
| return false; |
| } |
| @@ -218,8 +193,8 @@ base::RefCountedMemory* ThemeService::GetRawData( |
| id = IDR_PRODUCT_LOGO_WHITE; |
| base::RefCountedMemory* data = NULL; |
| - if (theme_pack_.get()) |
| - data = theme_pack_->GetRawData(id, scale_factor); |
| + if (theme_supplier_.get()) |
| + data = theme_supplier_->GetRawData(id, scale_factor); |
| if (!data) |
| data = rb_.LoadDataResourceBytesForScale(id, ui::SCALE_FACTOR_100P); |
| @@ -261,9 +236,28 @@ void ThemeService::SetTheme(const Extension* extension) { |
| content::RecordAction(UserMetricsAction("Themes_Installed")); |
| } |
| +void ThemeService::SetCustomDefaultTheme( |
| + scoped_refptr<CustomThemeSupplier> theme_supplier) { |
| + ClearAllThemeData(); |
| + SwapThemeSupplier(theme_supplier); |
| + |
| + // When loading the theme in LoadThemePrefs(), it is not necessary to call |
| + // NotifyThemeChanged(). |
| + if (ready_) |
|
pkotwicz
2013/07/22 20:17:28
Actually, you can skip checking |ready_| here. And
Adrian Kuegel
2013/07/23 08:13:29
Done.
|
| + NotifyThemeChanged(); |
| +} |
| + |
| +bool ThemeService::ShouldInitWithNativeTheme() { |
| + return false; |
| +} |
| + |
| void ThemeService::RemoveUnusedThemes() { |
| - if (!profile_) |
| + // We do not want to garbage collect themes on startup (|ready_| is false). |
| + // Themes will get garbage collected once |
| + // ExtensionService::GarbageCollectExtensions() runs |
|
pkotwicz
2013/07/22 20:17:28
Nit '.' at the end of the sentence
Adrian Kuegel
2013/07/23 08:13:29
Done.
|
| + if (!profile_ || !ready_) |
| return; |
| + |
| ExtensionService* service = profile_->GetExtensionService(); |
| if (!service) |
| return; |
| @@ -281,9 +275,13 @@ void ThemeService::RemoveUnusedThemes() { |
| } |
| void ThemeService::UseDefaultTheme() { |
| + content::RecordAction(UserMetricsAction("Themes_Reset")); |
| + if (IsManagedUser()) { |
| + SetManagedUserTheme(); |
| + return; |
| + } |
| ClearAllThemeData(); |
| NotifyThemeChanged(); |
| - content::RecordAction(UserMetricsAction("Themes_Reset")); |
| } |
| void ThemeService::SetNativeTheme() { |
| @@ -308,16 +306,18 @@ color_utils::HSL ThemeService::GetTint(int id) const { |
| DCHECK(CalledOnValidThread()); |
| color_utils::HSL hsl; |
| - if (theme_pack_.get() && theme_pack_->GetTint(id, &hsl)) |
| + if (theme_supplier_.get() && theme_supplier_->GetTint(id, &hsl)) |
| return hsl; |
| return ThemeProperties::GetDefaultTint(id); |
| } |
| void ThemeService::ClearAllThemeData() { |
| + SwapThemeSupplier(NULL); |
| + |
| // Clear our image cache. |
| FreePlatformCaches(); |
| - theme_pack_ = NULL; |
| + theme_supplier_ = NULL; |
|
pkotwicz
2013/07/22 20:17:28
The line above should be done for us by SwapThemeS
Adrian Kuegel
2013/07/23 08:13:29
Right. I have removed this line now.
|
| profile_->GetPrefs()->ClearPref(prefs::kCurrentThemePackFilename); |
| SaveThemeID(kDefaultThemeID); |
| @@ -330,6 +330,11 @@ void ThemeService::LoadThemePrefs() { |
| std::string current_id = GetThemeID(); |
| if (current_id == kDefaultThemeID) { |
| + // Managed users should always have their own default theme. |
|
pkotwicz
2013/07/22 20:17:28
How about: "Managed users have a different default
Adrian Kuegel
2013/07/23 08:13:29
Done.
|
| + if (IsManagedUser()) |
| + SetManagedUserTheme(); |
| + else if (ShouldInitWithNativeTheme()) |
| + SetNativeTheme(); |
|
pkotwicz
2013/07/22 20:17:28
I would rather call UseDefaultTheme() in the else
Adrian Kuegel
2013/07/23 08:13:29
Done.
|
| set_ready(); |
| return; |
| } |
| @@ -339,8 +344,8 @@ void ThemeService::LoadThemePrefs() { |
| // If we don't have a file pack, we're updating from an old version. |
| base::FilePath path = prefs->GetFilePath(prefs::kCurrentThemePackFilename); |
| if (path != base::FilePath()) { |
| - theme_pack_ = BrowserThemePack::BuildFromDataPack(path, current_id); |
| - loaded_pack = theme_pack_.get() != NULL; |
| + SwapThemeSupplier(BrowserThemePack::BuildFromDataPack(path, current_id)); |
| + loaded_pack = theme_supplier_.get() != NULL; |
| } |
| if (loaded_pack) { |
| @@ -382,6 +387,15 @@ void ThemeService::FreePlatformCaches() { |
| } |
| #endif |
| +void ThemeService::SwapThemeSupplier( |
| + scoped_refptr<CustomThemeSupplier> theme_supplier) { |
| + if (theme_supplier_.get()) |
| + theme_supplier_->StopUsingTheme(); |
| + theme_supplier_ = theme_supplier; |
| + if (theme_supplier_.get()) |
| + theme_supplier_->StartUsingTheme(); |
| +} |
| + |
| void ThemeService::MigrateTheme() { |
| ExtensionService* service = |
| extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| @@ -430,7 +444,7 @@ void ThemeService::BuildFromExtension(const Extension* extension) { |
| base::Bind(&WritePackToDiskCallback, pack, pack_path)); |
| SavePackName(pack_path); |
| - theme_pack_ = pack; |
| + SwapThemeSupplier(pack); |
| } |
| bool ThemeService::IsManagedUser() const { |
| @@ -440,6 +454,12 @@ bool ThemeService::IsManagedUser() const { |
| return false; |
| } |
| +void ThemeService::SetManagedUserTheme() { |
| +#if defined(ENABLE_MANAGED_USERS) |
| + SetCustomDefaultTheme(new ManagedUserTheme); |
| +#endif |
| +} |
| + |
| void ThemeService::OnInfobarDisplayed() { |
| number_of_infobars_++; |
| } |