Commit 3ce59905 authored by Alan Cutter's avatar Alan Cutter Committed by Commit Bot

Make ThemeService::UsingDefaultTheme based on the theme_supplier instead of prefs

This CL is a data dependency refactor that makes
ThemeService::UsingDefaultTheme() based on the current
CustomThemeSupplier rather than prefs. This is in preparation to make
ThemeService::GetColor() based on any CustomThemeSupplier instead of
just the currently installed one. See follow up CL:
https://chromium-review.googlesource.com/c/chromium/src/+/1994026/15

Bug: 1020050
Change-Id: If3bd87e16f6ccf034f4c4909c7f7ca940ee2f838
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2007800Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Commit-Queue: Alan Cutter <alancutter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734275}
parent 4f756bea
......@@ -701,6 +701,7 @@ void BrowserThemePack::BuildFromExtension(
DCHECK(!pack->is_valid());
pack->InitEmptyPack();
pack->set_extension_id(extension->id());
pack->SetHeaderId(extension);
pack->SetTintsFromJSON(extensions::ThemeInfo::GetTints(extension));
pack->SetColorsFromJSON(extensions::ThemeInfo::GetColors(extension));
......@@ -733,6 +734,7 @@ scoped_refptr<BrowserThemePack> BrowserThemePack::BuildFromDataPack(
// For now data pack can only have extension type.
scoped_refptr<BrowserThemePack> pack(
new BrowserThemePack(ThemeType::EXTENSION));
pack->set_extension_id(expected_id);
// Scale factor parameter is moot as data pack has image resources for all
// supported scale factors.
pack->data_pack_.reset(
......
......@@ -43,6 +43,11 @@ class CustomThemeSupplier
return theme_type_;
}
const std::string& extension_id() const {
DCHECK_EQ(theme_type_, EXTENSION);
return extension_id_;
}
// Called when the theme starts being used.
virtual void StartUsingTheme();
......@@ -72,11 +77,17 @@ class CustomThemeSupplier
protected:
virtual ~CustomThemeSupplier();
void set_extension_id(base::StringPiece id) {
DCHECK_EQ(theme_type_, EXTENSION);
id.CopyToString(&extension_id_);
}
private:
friend class base::RefCountedDeleteOnSequence<CustomThemeSupplier>;
friend class base::DeleteHelper<CustomThemeSupplier>;
ThemeType theme_type_;
std::string extension_id_;
DISALLOW_COPY_AND_ASSIGN(CustomThemeSupplier);
};
......
......@@ -75,6 +75,17 @@ namespace {
// unpacked on the filesystem.)
const char kDefaultThemeGalleryID[] = "hkacjpbfdknhflllbcmjibkdeoafencn";
bool IsDefaultTheme(const CustomThemeSupplier* theme_supplier) {
if (!theme_supplier)
return true;
if (theme_supplier->get_theme_type() !=
CustomThemeSupplier::ThemeType::EXTENSION) {
return false;
}
const std::string& id = theme_supplier->extension_id();
return id == ThemeService::kDefaultThemeID || id == kDefaultThemeGalleryID;
}
// Wait this many seconds after startup to garbage collect unused themes.
// Removing unused themes is done after a delay because there is no
// reason to do it at startup.
......@@ -444,12 +455,16 @@ bool ThemeService::IsSystemThemeDistinctFromDefaultTheme() const {
}
bool ThemeService::UsingDefaultTheme() const {
std::string id = GetThemeID();
return id == kDefaultThemeID || id == kDefaultThemeGalleryID;
return IsDefaultTheme(get_theme_supplier());
}
bool ThemeService::UsingSystemTheme() const {
return UsingDefaultTheme();
return IsSystemTheme(get_theme_supplier());
}
bool ThemeService::IsSystemTheme(
const CustomThemeSupplier* theme_supplier) const {
return IsDefaultTheme(theme_supplier);
}
bool ThemeService::UsingExtensionTheme() const {
......
......@@ -108,14 +108,18 @@ class ThemeService : public content::NotificationObserver,
// this platform.
virtual bool IsSystemThemeDistinctFromDefaultTheme() const;
// Whether we're using the chrome default theme. Virtual so linux can check
// if we're using the GTK theme.
// Whether we're using the chrome default theme.
// Virtual for testing.
virtual bool UsingDefaultTheme() const;
// Whether we are using the system theme. On GTK, the system theme is the GTK
// theme, not the "Classic" theme.
// Whether we are using the system theme.
// Virtual for testing.
virtual bool UsingSystemTheme() const;
// Whether |theme_supplier| is the system theme. On GTK, the system theme is
// the GTK theme, not the "Classic" theme
virtual bool IsSystemTheme(const CustomThemeSupplier* theme_supplier) const;
// Whether we are using theme installed through extensions.
// |UsingExtensionTheme| and |UsingDefaultTheme| are not mutually exclusive as
// default theme can be installed through extensions.
......
......@@ -95,12 +95,8 @@ bool ThemeServiceAuraLinux::IsSystemThemeDistinctFromDefaultTheme() const {
return true;
}
bool ThemeServiceAuraLinux::UsingDefaultTheme() const {
return ThemeService::UsingDefaultTheme() && !UsingSystemTheme();
}
bool ThemeServiceAuraLinux::UsingSystemTheme() const {
const CustomThemeSupplier* theme_supplier = get_theme_supplier();
bool ThemeServiceAuraLinux::IsSystemTheme(
const CustomThemeSupplier* theme_supplier) const {
return theme_supplier &&
theme_supplier->get_theme_type() == CustomThemeSupplier::NATIVE_X11;
}
......
......@@ -21,8 +21,7 @@ class ThemeServiceAuraLinux : public ThemeService {
bool ShouldInitWithSystemTheme() const override;
void UseSystemTheme() override;
bool IsSystemThemeDistinctFromDefaultTheme() const override;
bool UsingDefaultTheme() const override;
bool UsingSystemTheme() const override;
bool IsSystemTheme(const CustomThemeSupplier* theme_supplier) const override;
void FixInconsistentPreferencesIfNeeded() override;
static bool ShouldUseSystemThemeForProfile(const Profile* profile);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment