bluetooth_feature_pod_controller.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #ifndef ASH_SYSTEM_BLUETOOTH_BLUETOOTH_FEATURE_POD_CONTROLLER_H_
  5. #define ASH_SYSTEM_BLUETOOTH_BLUETOOTH_FEATURE_POD_CONTROLLER_H_
  6. #include <string>
  7. #include "ash/system/tray/system_tray_item_uma_type.h"
  8. #include "ash/system/unified/feature_pod_controller_base.h"
  9. #include "chromeos/services/bluetooth_config/public/mojom/cros_bluetooth_config.mojom.h"
  10. #include "mojo/public/cpp/bindings/receiver.h"
  11. #include "mojo/public/cpp/bindings/remote.h"
  12. #include "third_party/abseil-cpp/absl/types/optional.h"
  13. #include "ui/gfx/vector_icon_types.h"
  14. namespace ash {
  15. class FeaturePodButton;
  16. class UnifiedSystemTrayController;
  17. // Controller of the feature pod button that allows users to toggle whether
  18. // Bluetooth is enabled or disabled, and that allows users to navigate to a more
  19. // detailed page with a Bluetooth device list.
  20. class ASH_EXPORT BluetoothFeaturePodController
  21. : public FeaturePodControllerBase,
  22. public chromeos::bluetooth_config::mojom::SystemPropertiesObserver {
  23. public:
  24. explicit BluetoothFeaturePodController(
  25. UnifiedSystemTrayController* tray_controller);
  26. BluetoothFeaturePodController(const BluetoothFeaturePodController&) = delete;
  27. BluetoothFeaturePodController& operator=(
  28. const BluetoothFeaturePodController&) = delete;
  29. ~BluetoothFeaturePodController() override;
  30. // FeaturePodControllerBase:
  31. FeaturePodButton* CreateButton() override;
  32. void OnIconPressed() override;
  33. void OnLabelPressed() override;
  34. SystemTrayItemUmaType GetUmaType() const override;
  35. private:
  36. // Helper struct to organize the cached information of a connected device.
  37. struct BluetoothDeviceNameAndBatteryInfo {
  38. BluetoothDeviceNameAndBatteryInfo(
  39. const std::u16string& device_name,
  40. chromeos::bluetooth_config::mojom::DeviceBatteryInfoPtr battery_info);
  41. ~BluetoothDeviceNameAndBatteryInfo();
  42. const std::u16string device_name;
  43. const chromeos::bluetooth_config::mojom::DeviceBatteryInfoPtr battery_info;
  44. };
  45. bool DoesFirstConnectedDeviceHaveBatteryInfo() const;
  46. int GetFirstConnectedDeviceBatteryLevelForDisplay() const;
  47. const gfx::VectorIcon& ComputeButtonIcon() const;
  48. std::u16string ComputeButtonLabel() const;
  49. std::u16string ComputeButtonSubLabel() const;
  50. std::u16string ComputeTooltip() const;
  51. // Updates |button_| state to reflect the cached Bluetooth state.
  52. void UpdateButtonStateIfExists();
  53. // chromeos::bluetooth_config::mojom::SystemPropertiesObserver
  54. void OnPropertiesUpdated(
  55. chromeos::bluetooth_config::mojom::BluetoothSystemPropertiesPtr
  56. properties) override;
  57. mojo::Remote<chromeos::bluetooth_config::mojom::CrosBluetoothConfig>
  58. remote_cros_bluetooth_config_;
  59. mojo::Receiver<chromeos::bluetooth_config::mojom::SystemPropertiesObserver>
  60. cros_system_properties_observer_receiver_{this};
  61. size_t connected_device_count_ = 0;
  62. absl::optional<BluetoothDeviceNameAndBatteryInfo> first_connected_device_;
  63. chromeos::bluetooth_config::mojom::BluetoothModificationState
  64. modification_state_ = chromeos::bluetooth_config::mojom::
  65. BluetoothModificationState::kCannotModifyBluetooth;
  66. chromeos::bluetooth_config::mojom::BluetoothSystemState system_state_ =
  67. chromeos::bluetooth_config::mojom::BluetoothSystemState::kUnavailable;
  68. FeaturePodButton* button_ = nullptr;
  69. UnifiedSystemTrayController* tray_controller_;
  70. };
  71. } // namespace ash
  72. #endif // ASH_SYSTEM_BLUETOOTH_BLUETOOTH_FEATURE_POD_CONTROLLER_H_