native_theme_cache.cc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "chromeos/lacros/native_theme_cache.h"
  5. #include "chromeos/lacros/lacros_service.h"
  6. #include "ui/native_theme/native_theme_aura.h"
  7. namespace chromeos {
  8. NativeThemeCache::NativeThemeCache(const crosapi::mojom::NativeThemeInfo& info)
  9. : info_(info.Clone()) {
  10. SetNativeThemeInfo();
  11. }
  12. NativeThemeCache::~NativeThemeCache() = default;
  13. void NativeThemeCache::Start() {
  14. auto* lacros_service = chromeos::LacrosService::Get();
  15. CHECK(lacros_service->IsAvailable<crosapi::mojom::NativeThemeService>());
  16. lacros_service->GetRemote<crosapi::mojom::NativeThemeService>()
  17. ->AddNativeThemeInfoObserver(receiver_.BindNewPipeAndPassRemote());
  18. }
  19. void NativeThemeCache::OnNativeThemeInfoChanged(
  20. crosapi::mojom::NativeThemeInfoPtr info) {
  21. info_ = std::move(info);
  22. SetNativeThemeInfo();
  23. }
  24. void NativeThemeCache::SetNativeThemeInfo() {
  25. auto* native_theme = ui::NativeTheme::GetInstanceForNativeUi();
  26. native_theme->set_use_dark_colors(info_->dark_mode);
  27. native_theme->NotifyOnNativeThemeUpdated();
  28. }
  29. } // namespace chromeos