blob: b631280a0bfb2beb9ad5524b4a0e40c21ff3f098 [file] [log] [blame]
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/profiles/profile_theme_update_service.h"
#include "base/notreached.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_attributes_entry.h"
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/themes/custom_theme_supplier.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/ui/signin/profile_colors_util.h"
#include "chrome/common/themes/autogenerated_theme_util.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/base/theme_provider.h"
ProfileThemeUpdateService::ProfileThemeUpdateService(
Profile* profile,
ProfileAttributesStorage* profile_attributes_storage)
: profile_(profile),
profile_attributes_storage_(profile_attributes_storage) {
observation_.Observe(ThemeServiceFactory::GetForProfile(profile));
// Kicks off an update on startup.
UpdateProfileThemeColors();
}
ProfileThemeUpdateService::~ProfileThemeUpdateService() = default;
void ProfileThemeUpdateService::UpdateProfileThemeColors() {
ProfileAttributesEntry* entry =
profile_attributes_storage_->GetProfileAttributesWithPath(
profile_->GetPath());
if (!entry)
return;
ThemeService* service = ThemeServiceFactory::GetForProfile(profile_);
if (!service->UsingAutogeneratedTheme()) {
// Only save colors for autogenerated themes.
entry->SetProfileThemeColors(absl::nullopt);
return;
}
entry->SetProfileThemeColors(
GetCurrentProfileThemeColors(*service->GetColorProvider()));
}
void ProfileThemeUpdateService::OnThemeChanged() {
UpdateProfileThemeColors();
}