Commit 952be16f authored by Ahmed Mehfooz's avatar Ahmed Mehfooz Committed by Chromium LUCI CQ

Hook up basic battery updates from peripheral battery listener

Bug: 1160106
Change-Id: I51ec6cf9c745f48e389feda26515ceaded5a5e03
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2597792
Commit-Queue: Ahmed Mehfooz <amehfooz@chromium.org>
Auto-Submit: Ahmed Mehfooz <amehfooz@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#839163}
parent 43597aa3
......@@ -934,6 +934,16 @@ void Shell::Init(
accessibility_controller_ = std::make_unique<AccessibilityControllerImpl>();
toast_manager_ = std::make_unique<ToastManagerImpl>();
peripheral_battery_listener_ = std::make_unique<PeripheralBatteryListener>();
peripheral_battery_notifier_ = std::make_unique<PeripheralBatteryNotifier>(
peripheral_battery_listener_.get());
if (base::FeatureList::IsEnabled(
chromeos::features::kShowBluetoothDeviceBattery)) {
peripheral_battery_tracker_ = std::make_unique<PeripheralBatteryTracker>();
}
power_event_observer_.reset(new PowerEventObserver());
if (features::IsCaptureModeEnabled()) {
capture_mode_controller_ = std::make_unique<CaptureModeController>(
shell_delegate_->CreateCaptureModeDelegate());
......@@ -1193,16 +1203,6 @@ void Shell::Init(
cursor_manager_->HideCursor(); // Hide the mouse cursor on startup.
cursor_manager_->SetCursor(ui::mojom::CursorType::kPointer);
peripheral_battery_listener_ = std::make_unique<PeripheralBatteryListener>();
peripheral_battery_notifier_ = std::make_unique<PeripheralBatteryNotifier>(
peripheral_battery_listener_.get());
if (base::FeatureList::IsEnabled(
chromeos::features::kShowBluetoothDeviceBattery)) {
peripheral_battery_tracker_ = std::make_unique<PeripheralBatteryTracker>();
}
power_event_observer_.reset(new PowerEventObserver());
mojo::PendingRemote<device::mojom::Fingerprint> fingerprint;
shell_delegate_->BindFingerprint(
fingerprint.InitWithNewPipeAndPassReceiver());
......
......@@ -453,6 +453,9 @@ class ASH_EXPORT Shell : public SessionObserver,
PartialMagnificationController* partial_magnification_controller() {
return partial_magnification_controller_.get();
}
PeripheralBatteryListener* peripheral_battery_listener() {
return peripheral_battery_listener_.get();
}
PolicyRecommendationRestorer* policy_recommendation_restorer() {
return policy_recommendation_restorer_.get();
}
......
......@@ -21,7 +21,12 @@ constexpr int kStylusLowBatteryThreshold = 24;
constexpr int kStylusMediumBatteryThreshold = 71;
} // namespace
StylusBatteryDelegate::StylusBatteryDelegate() = default;
StylusBatteryDelegate::StylusBatteryDelegate() {
if (Shell::Get()->peripheral_battery_listener())
battery_observation_.Observe(Shell::Get()->peripheral_battery_listener());
}
StylusBatteryDelegate::~StylusBatteryDelegate() = default;
SkColor StylusBatteryDelegate::GetColorForBatteryLevel() const {
if (battery_level_ <= kStylusLowBatteryThreshold) {
......@@ -53,4 +58,17 @@ gfx::ImageSkia StylusBatteryDelegate::GetBatteryImage() const {
icon_fg_color);
}
void StylusBatteryDelegate::OnAddingBattery(
const PeripheralBatteryListener::BatteryInfo& battery) {
battery_level_ = battery.level;
}
void StylusBatteryDelegate::OnRemovingBattery(
const PeripheralBatteryListener::BatteryInfo& battery) {}
void StylusBatteryDelegate::OnUpdatedBatteryLevel(
const PeripheralBatteryListener::BatteryInfo& battery) {
battery_level_ = battery.level;
}
} // namespace ash
......@@ -6,17 +6,20 @@
#define ASH_SYSTEM_PALETTE_STYLUS_BATTERY_DELEGATE_H_
#include "ash/ash_export.h"
#include "base/scoped_observer.h"
#include "ash/system/power/peripheral_battery_listener.h"
#include "base/scoped_observation.h"
#include "base/strings/string16.h"
#include "ui/gfx/image/image_skia.h"
namespace ash {
class ASH_EXPORT StylusBatteryDelegate {
class ASH_EXPORT StylusBatteryDelegate
: public PeripheralBatteryListener::Observer {
public:
StylusBatteryDelegate();
StylusBatteryDelegate(const StylusBatteryDelegate& other) = delete;
StylusBatteryDelegate& operator=(const StylusBatteryDelegate& other) = delete;
~StylusBatteryDelegate() override;
SkColor GetColorForBatteryLevel() const;
int GetLabelIdForBatteryLevel() const;
......@@ -25,9 +28,19 @@ class ASH_EXPORT StylusBatteryDelegate {
base::Optional<uint8_t> battery_level() const { return battery_level_; }
private:
// PeripheralBatteryListener::Observer:
void OnAddingBattery(
const PeripheralBatteryListener::BatteryInfo& battery) override;
void OnRemovingBattery(
const PeripheralBatteryListener::BatteryInfo& battery) override;
void OnUpdatedBatteryLevel(
const PeripheralBatteryListener::BatteryInfo& battery) override;
base::Optional<uint8_t> battery_level_;
// Peripheral battery observer to be added here.
base::ScopedObservation<PeripheralBatteryListener,
PeripheralBatteryListener::Observer>
battery_observation_{this};
};
} // namespace ash
......
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