1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
ash / components / arc / system_ui / arc_system_ui_bridge.h [blame]
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_COMPONENTS_ARC_SYSTEM_UI_ARC_SYSTEM_UI_BRIDGE_H_
#define ASH_COMPONENTS_ARC_SYSTEM_UI_ARC_SYSTEM_UI_BRIDGE_H_
#include "ash/components/arc/mojom/system_ui.mojom-shared.h"
#include "ash/components/arc/mojom/system_ui.mojom.h"
#include "ash/components/arc/session/connection_observer.h"
#include "ash/shell_observer.h"
#include "ash/style/color_palette_controller.h"
#include "base/check_is_test.h"
#include "base/gtest_prod_util.h"
#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "base/threading/thread_checker.h"
#include "components/keyed_service/core/keyed_service.h"
namespace ash {
class Shell;
}
namespace content {
class BrowserContext;
} // namespace content
namespace arc {
class ArcBridgeService;
// This class notifies the Chrome OS side dark theme state to Android.
class ArcSystemUIBridge : public KeyedService,
public ConnectionObserver<mojom::SystemUiInstance>,
public ash::ColorPaletteController::Observer,
public ash::ShellObserver {
public:
// Returns singleton instance for the given BrowserContext,
// or nullptr if the browser |context| is not allowed to use ARC.
static ArcSystemUIBridge* GetForBrowserContext(
content::BrowserContext* context);
static ArcSystemUIBridge* GetForBrowserContextForTesting(
content::BrowserContext* context);
ArcSystemUIBridge(content::BrowserContext* context,
ArcBridgeService* bridge_service);
~ArcSystemUIBridge() override;
ArcSystemUIBridge(const ArcSystemUIBridge&) = delete;
ArcSystemUIBridge& operator=(const ArcSystemUIBridge&) = delete;
// ConnectionObserver<mojom::SystemUiInstance> override:
void OnConnectionReady() override;
// ash::ColorPaletteController::Observer override:
void OnColorPaletteChanging(const ash::ColorPaletteSeed& seed) override;
// ash::ShellObserver override:
void OnShellDestroying() override;
// Sends the device overlay color and the {@link mojom::ThemeStyleType}.
bool SendOverlayColor(uint32_t source_color,
mojom::ThemeStyleType theme_style);
void SetColorPaletteControllerForTesting(
ash::ColorPaletteController* controller) {
CHECK_IS_TEST();
color_palette_controller_ = controller;
}
static void EnsureFactoryBuilt();
private:
FRIEND_TEST_ALL_PREFIXES(ArcSystemUIBridgeTest, SendOverlayColor);
// Sends the device dark theme state to Android.
bool SendDeviceDarkThemeState(bool dark_theme_status);
// Set `color_palette_controller_` from `ash::Shell` if it's not already set
// and attach the necessary observers.
void AttachColorPaletteController();
// Removes `this` as an observer of the `ColorPaletteController` and sets it
// to `nullptr`.
void DetachColorPaletteController();
THREAD_CHECKER(thread_checker_);
base::ScopedObservation<ash::Shell, ash::ShellObserver> shell_observation_{
this};
// The most recent seed sent to ARC.
std::optional<const ash::ColorPaletteSeed> previous_seed_;
raw_ptr<ash::ColorPaletteController> color_palette_controller_ =
nullptr; // Owned by Shell.
const raw_ptr<ArcBridgeService>
arc_bridge_service_; // Owned by ArcServiceManager.
};
} // namespace arc
#endif // ASH_COMPONENTS_ARC_SYSTEM_UI_ARC_SYSTEM_UI_BRIDGE_H_