Commit 862caf28 authored by Rune Lillesveen's avatar Rune Lillesveen Committed by Commit Bot

Move DarkModeObserver to ui/native_theme

In preparation for using the observer in WebContentsImpl, make it
available for content/.

Bug: 889087
Change-Id: Iff4dbfae5525c6bae1655662d5f29208a024da28
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1574802Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Reviewed-by: default avatarRamya Nagarajan <ramyan@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Commit-Queue: Rune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#653639}
parent e48a4ebc
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
#include "chrome/browser/themes/theme_properties.h" #include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/themes/theme_service.h" #include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h" #include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/ui/dark_mode_observer.h"
#include "chrome/browser/ui/webui/favicon_source.h" #include "chrome/browser/ui/webui/favicon_source.h"
#include "chrome/browser/ui/webui/theme_source.h" #include "chrome/browser/ui/webui/theme_source.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
...@@ -53,6 +52,7 @@ ...@@ -53,6 +52,7 @@
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/browser/url_data_source.h" #include "content/public/browser/url_data_source.h"
#include "ui/gfx/color_utils.h" #include "ui/gfx/color_utils.h"
#include "ui/native_theme/dark_mode_observer.h"
namespace { namespace {
...@@ -761,7 +761,7 @@ void InstantService::AddValidBackdropUrlForTesting(const GURL& url) const { ...@@ -761,7 +761,7 @@ void InstantService::AddValidBackdropUrlForTesting(const GURL& url) const {
} }
void InstantService::CreateDarkModeObserver(ui::NativeTheme* theme) { void InstantService::CreateDarkModeObserver(ui::NativeTheme* theme) {
dark_mode_observer_ = std::make_unique<DarkModeObserver>( dark_mode_observer_ = std::make_unique<ui::DarkModeObserver>(
theme, base::BindRepeating(&InstantService::OnDarkModeChanged, theme, base::BindRepeating(&InstantService::OnDarkModeChanged,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
dark_mode_observer_->Start(); dark_mode_observer_->Start();
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
#error "Instant is only used on desktop"; #error "Instant is only used on desktop";
#endif #endif
class DarkModeObserver;
class InstantIOContext; class InstantIOContext;
class InstantServiceObserver; class InstantServiceObserver;
class NtpBackgroundService; class NtpBackgroundService;
...@@ -44,6 +43,10 @@ namespace content { ...@@ -44,6 +43,10 @@ namespace content {
class RenderProcessHost; class RenderProcessHost;
} // namespace content } // namespace content
namespace ui {
class DarkModeObserver;
} // namespace ui
// Tracks render process host IDs that are associated with Instant, i.e. // Tracks render process host IDs that are associated with Instant, i.e.
// processes that are used to render an NTP. Also responsible for keeping // processes that are used to render an NTP. Also responsible for keeping
// necessary information (most visited tiles and theme info) updated in those // necessary information (most visited tiles and theme info) updated in those
...@@ -254,7 +257,7 @@ class InstantService : public KeyedService, ...@@ -254,7 +257,7 @@ class InstantService : public KeyedService,
PrefService* pref_service_; PrefService* pref_service_;
// Keeps track of any changes to system dark mode. // Keeps track of any changes to system dark mode.
std::unique_ptr<DarkModeObserver> dark_mode_observer_; std::unique_ptr<ui::DarkModeObserver> dark_mode_observer_;
NtpBackgroundService* background_service_; NtpBackgroundService* background_service_;
......
...@@ -108,8 +108,6 @@ jumbo_split_static_library("ui") { ...@@ -108,8 +108,6 @@ jumbo_split_static_library("ui") {
"confirm_bubble.h", "confirm_bubble.h",
"crypto_module_password_dialog.h", "crypto_module_password_dialog.h",
"cryptuiapi_shim.h", "cryptuiapi_shim.h",
"dark_mode_observer.cc",
"dark_mode_observer.h",
"enterprise_startup_dialog.h", "enterprise_startup_dialog.h",
"find_bar/find_bar.h", "find_bar/find_bar.h",
"find_bar/find_bar_state.h", "find_bar/find_bar_state.h",
......
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
#include "chrome/browser/ui/dark_mode_observer.h"
#include "content/public/browser/web_ui_message_handler.h" #include "content/public/browser/web_ui_message_handler.h"
#include "ui/native_theme/dark_mode_observer.h"
#include "ui/native_theme/native_theme.h" #include "ui/native_theme/native_theme.h"
namespace base { namespace base {
...@@ -70,7 +70,7 @@ class DarkModeHandler : public content::WebUIMessageHandler { ...@@ -70,7 +70,7 @@ class DarkModeHandler : public content::WebUIMessageHandler {
// Profile to update data sources on. Injected for testing. // Profile to update data sources on. Injected for testing.
Profile* const profile_; Profile* const profile_;
DarkModeObserver dark_mode_observer_; ui::DarkModeObserver dark_mode_observer_;
// Populated if feature is enabled. // Populated if feature is enabled.
std::string source_name_; std::string source_name_;
......
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "chrome/browser/ui/dark_mode_observer.h"
#include "components/prefs/pref_change_registrar.h" #include "components/prefs/pref_change_registrar.h"
#include "content/public/browser/url_data_source.h" #include "content/public/browser/url_data_source.h"
#include "content/public/browser/web_ui_controller.h" #include "content/public/browser/web_ui_controller.h"
#include "ui/native_theme/dark_mode_observer.h"
class GURL; class GURL;
class Profile; class Profile;
...@@ -80,7 +80,7 @@ class NewTabUI : public content::WebUIController { ...@@ -80,7 +80,7 @@ class NewTabUI : public content::WebUIController {
Profile* GetProfile() const; Profile* GetProfile() const;
DarkModeObserver dark_mode_observer_; ui::DarkModeObserver dark_mode_observer_;
PrefChangeRegistrar pref_change_registrar_; PrefChangeRegistrar pref_change_registrar_;
......
...@@ -14,6 +14,8 @@ jumbo_component("native_theme") { ...@@ -14,6 +14,8 @@ jumbo_component("native_theme") {
"caption_style_win.cc", "caption_style_win.cc",
"common_theme.cc", "common_theme.cc",
"common_theme.h", "common_theme.h",
"dark_mode_observer.cc",
"dark_mode_observer.h",
"native_theme.cc", "native_theme.cc",
"native_theme.h", "native_theme.h",
"native_theme_android.cc", "native_theme_android.cc",
......
...@@ -2,15 +2,17 @@ ...@@ -2,15 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/ui/dark_mode_observer.h" #include "ui/native_theme/dark_mode_observer.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/logging.h" #include "base/logging.h"
#include "ui/native_theme/native_theme.h" #include "ui/native_theme/native_theme.h"
#include "ui/native_theme/native_theme_observer.h" #include "ui/native_theme/native_theme_observer.h"
namespace ui {
DarkModeObserver::DarkModeObserver( DarkModeObserver::DarkModeObserver(
ui::NativeTheme* theme, NativeTheme* theme,
const base::RepeatingCallback<void(bool)>& callback) const base::RepeatingCallback<void(bool)>& callback)
: theme_(theme), : theme_(theme),
callback_(callback), callback_(callback),
...@@ -28,7 +30,7 @@ void DarkModeObserver::Stop() { ...@@ -28,7 +30,7 @@ void DarkModeObserver::Stop() {
theme_observer_.RemoveAll(); theme_observer_.RemoveAll();
} }
void DarkModeObserver::OnNativeThemeUpdated(ui::NativeTheme* observed_theme) { void DarkModeObserver::OnNativeThemeUpdated(NativeTheme* observed_theme) {
DCHECK_EQ(observed_theme, theme_); DCHECK_EQ(observed_theme, theme_);
RunCallbackIfChanged(); RunCallbackIfChanged();
} }
...@@ -40,3 +42,5 @@ void DarkModeObserver::RunCallbackIfChanged() { ...@@ -40,3 +42,5 @@ void DarkModeObserver::RunCallbackIfChanged() {
in_dark_mode_ = in_dark_mode; in_dark_mode_ = in_dark_mode;
callback_.Run(in_dark_mode_); callback_.Run(in_dark_mode_);
} }
} // namespace ui
...@@ -2,18 +2,20 @@ ...@@ -2,18 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_DARK_MODE_OBSERVER_H_ #ifndef UI_NATIVE_THEME_DARK_MODE_OBSERVER_H_
#define CHROME_BROWSER_UI_DARK_MODE_OBSERVER_H_ #define UI_NATIVE_THEME_DARK_MODE_OBSERVER_H_
#include "base/callback.h" #include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
#include "ui/native_theme/native_theme_observer.h" #include "ui/native_theme/native_theme_observer.h"
class DarkModeObserver : public ui::NativeThemeObserver { namespace ui {
class NATIVE_THEME_EXPORT DarkModeObserver : public NativeThemeObserver {
public: public:
// Observe |theme| for changes and run |callback| if detected. // Observe |theme| for changes and run |callback| if detected.
DarkModeObserver(ui::NativeTheme* theme, DarkModeObserver(NativeTheme* theme,
const base::RepeatingCallback<void(bool)>& callback); const base::RepeatingCallback<void(bool)>& callback);
~DarkModeObserver() override; ~DarkModeObserver() override;
...@@ -29,22 +31,24 @@ class DarkModeObserver : public ui::NativeThemeObserver { ...@@ -29,22 +31,24 @@ class DarkModeObserver : public ui::NativeThemeObserver {
bool InDarkMode() const { return in_dark_mode_; } bool InDarkMode() const { return in_dark_mode_; }
private: private:
// ui::NativeThemeObserver: // NativeThemeObserver:
void OnNativeThemeUpdated(ui::NativeTheme* observed_theme) override; void OnNativeThemeUpdated(NativeTheme* observed_theme) override;
// Run |callback_| if |theme_->SystemDarkModeEnabled()| != |in_dark_mode_|. // Run |callback_| if |theme_->SystemDarkModeEnabled()| != |in_dark_mode_|.
void RunCallbackIfChanged(); void RunCallbackIfChanged();
// The theme to query/watch for changes. // The theme to query/watch for changes.
ui::NativeTheme* const theme_; NativeTheme* const theme_;
base::RepeatingCallback<void(bool)> callback_; base::RepeatingCallback<void(bool)> callback_;
bool in_dark_mode_; bool in_dark_mode_;
ScopedObserver<ui::NativeTheme, DarkModeObserver> theme_observer_; ScopedObserver<NativeTheme, DarkModeObserver> theme_observer_;
DISALLOW_COPY_AND_ASSIGN(DarkModeObserver); DISALLOW_COPY_AND_ASSIGN(DarkModeObserver);
}; };
#endif // CHROME_BROWSER_UI_DARK_MODE_OBSERVER_H_ } // namespace ui
#endif // UI_NATIVE_THEME_DARK_MODE_OBSERVER_H_
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