Commit c87b6f34 authored by Giovanni Ortuño Urquidi's avatar Giovanni Ortuño Urquidi Committed by Commit Bot

bluetooth: Implement TrayBluetoothHelperExperimental::GetBluetoothState

Implements GetBluetoothState() by using the new BluetoothSystem mojo
interface.

Bug: 882346
Change-Id: I75f11b9de33c98e2913aeb08a1e5e085532e803d
Reviewed-on: https://chromium-review.googlesource.com/c/1272957
Commit-Queue: Giovanni Ortuño Urquidi <ortuno@chromium.org>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Reviewed-by: default avatarDan Erat <derat@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Cr-Commit-Position: refs/heads/master@{#599854}
parent ed95e624
...@@ -69,7 +69,10 @@ ...@@ -69,7 +69,10 @@
"*": [ "accessibility", "app" ], "*": [ "accessibility", "app" ],
"ash_pref_connector": [ "pref_connector" ], "ash_pref_connector": [ "pref_connector" ],
"catalog": [ "directory" ], "catalog": [ "directory" ],
"device": [ "device:fingerprint"], "device": [
"device:bluetooth_system",
"device:fingerprint"
],
"local_state": [ "pref_client" ], "local_state": [ "pref_client" ],
"multidevice_setup": [ "multidevice_setup" ], "multidevice_setup": [ "multidevice_setup" ],
"ui": [ "ui": [
......
...@@ -695,7 +695,7 @@ Shell::Shell(std::unique_ptr<ShellDelegate> shell_delegate, ...@@ -695,7 +695,7 @@ Shell::Shell(std::unique_ptr<ShellDelegate> shell_delegate,
if (base::FeatureList::IsEnabled(features::kUseBluetoothSystemInAsh)) { if (base::FeatureList::IsEnabled(features::kUseBluetoothSystemInAsh)) {
tray_bluetooth_helper_ = tray_bluetooth_helper_ =
std::make_unique<TrayBluetoothHelperExperimental>(); std::make_unique<TrayBluetoothHelperExperimental>(connector_);
} else { } else {
tray_bluetooth_helper_ = std::make_unique<TrayBluetoothHelperLegacy>(); tray_bluetooth_helper_ = std::make_unique<TrayBluetoothHelperLegacy>();
} }
......
...@@ -5,14 +5,43 @@ ...@@ -5,14 +5,43 @@
#include "ash/system/bluetooth/tray_bluetooth_helper_experimental.h" #include "ash/system/bluetooth/tray_bluetooth_helper_experimental.h"
#include <string> #include <string>
#include <utility>
#include "ash/shell.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "services/device/public/mojom/constants.mojom.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/identity.h"
// base::Unretained():
//
// Usage of `base::Unretained(this)` is safe when calling BluetoothSystemPtr
// methods because BluetoothSystemPtr is owned by `this` and guarantees that no
// callbacks will be run after its destruction.
namespace ash { namespace ash {
TrayBluetoothHelperExperimental::TrayBluetoothHelperExperimental() = default; TrayBluetoothHelperExperimental::TrayBluetoothHelperExperimental(
service_manager::Connector* connector)
: connector_(connector) {}
TrayBluetoothHelperExperimental::~TrayBluetoothHelperExperimental() = default; TrayBluetoothHelperExperimental::~TrayBluetoothHelperExperimental() = default;
void TrayBluetoothHelperExperimental::Initialize() {} void TrayBluetoothHelperExperimental::Initialize() {
device::mojom::BluetoothSystemFactoryPtr bluetooth_system_factory;
connector_->BindInterface(device::mojom::kServiceName,
&bluetooth_system_factory);
device::mojom::BluetoothSystemClientPtr client_ptr;
bluetooth_system_client_binding_.Bind(mojo::MakeRequest(&client_ptr));
bluetooth_system_factory->Create(mojo::MakeRequest(&bluetooth_system_ptr_),
std::move(client_ptr));
bluetooth_system_ptr_->GetState(
base::BindOnce(&TrayBluetoothHelperExperimental::OnStateChanged,
// See base::Unretained() note at the top.
base::Unretained(this)));
}
BluetoothDeviceList BluetoothDeviceList
TrayBluetoothHelperExperimental::GetAvailableBluetoothDevices() const { TrayBluetoothHelperExperimental::GetAvailableBluetoothDevices() const {
...@@ -35,8 +64,7 @@ void TrayBluetoothHelperExperimental::ConnectToBluetoothDevice( ...@@ -35,8 +64,7 @@ void TrayBluetoothHelperExperimental::ConnectToBluetoothDevice(
device::mojom::BluetoothSystem::State device::mojom::BluetoothSystem::State
TrayBluetoothHelperExperimental::GetBluetoothState() { TrayBluetoothHelperExperimental::GetBluetoothState() {
NOTIMPLEMENTED(); return cached_state_;
return device::mojom::BluetoothSystem::State::kUnavailable;
} }
void TrayBluetoothHelperExperimental::SetBluetoothEnabled(bool enabled) { void TrayBluetoothHelperExperimental::SetBluetoothEnabled(bool enabled) {
...@@ -48,4 +76,10 @@ bool TrayBluetoothHelperExperimental::HasBluetoothDiscoverySession() { ...@@ -48,4 +76,10 @@ bool TrayBluetoothHelperExperimental::HasBluetoothDiscoverySession() {
return false; return false;
} }
void TrayBluetoothHelperExperimental::OnStateChanged(
device::mojom::BluetoothSystem::State state) {
cached_state_ = state;
Shell::Get()->system_tray_notifier()->NotifyRefreshBluetooth();
}
} // namespace ash } // namespace ash
...@@ -10,15 +10,23 @@ ...@@ -10,15 +10,23 @@
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ash/system/bluetooth/tray_bluetooth_helper.h" #include "ash/system/bluetooth/tray_bluetooth_helper.h"
#include "base/macros.h" #include "base/macros.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "services/device/public/mojom/bluetooth_system.mojom.h" #include "services/device/public/mojom/bluetooth_system.mojom.h"
namespace service_manager {
class Connector;
} // namespace service_manager
namespace ash { namespace ash {
// Implementation of TrayBluetoothHelper on top of the BluetoothSystem Mojo // Implementation of TrayBluetoothHelper on top of the BluetoothSystem Mojo
// interface. // interface.
class TrayBluetoothHelperExperimental : public TrayBluetoothHelper { class TrayBluetoothHelperExperimental
: public TrayBluetoothHelper,
public device::mojom::BluetoothSystemClient {
public: public:
TrayBluetoothHelperExperimental(); explicit TrayBluetoothHelperExperimental(
service_manager::Connector* connector);
~TrayBluetoothHelperExperimental() override; ~TrayBluetoothHelperExperimental() override;
// TrayBluetoothHelper: // TrayBluetoothHelper:
...@@ -31,7 +39,19 @@ class TrayBluetoothHelperExperimental : public TrayBluetoothHelper { ...@@ -31,7 +39,19 @@ class TrayBluetoothHelperExperimental : public TrayBluetoothHelper {
void SetBluetoothEnabled(bool enabled) override; void SetBluetoothEnabled(bool enabled) override;
bool HasBluetoothDiscoverySession() override; bool HasBluetoothDiscoverySession() override;
// device::mojom::BluetoothSystemClient
void OnStateChanged(device::mojom::BluetoothSystem::State state) override;
private: private:
service_manager::Connector* connector_;
device::mojom::BluetoothSystemPtr bluetooth_system_ptr_;
mojo::Binding<device::mojom::BluetoothSystemClient>
bluetooth_system_client_binding_{this};
device::mojom::BluetoothSystem::State cached_state_ =
device::mojom::BluetoothSystem::State::kUnavailable;
DISALLOW_COPY_AND_ASSIGN(TrayBluetoothHelperExperimental); DISALLOW_COPY_AND_ASSIGN(TrayBluetoothHelperExperimental);
}; };
......
...@@ -105,6 +105,7 @@ ...@@ -105,6 +105,7 @@
"data_decoder": [ "image_decoder", "json_parser", "xml_parser" ], "data_decoder": [ "image_decoder", "json_parser", "xml_parser" ],
"device": [ "device": [
"device:battery_monitor", "device:battery_monitor",
"device:bluetooth_system",
"device:generic_sensor", "device:generic_sensor",
"device:geolocation", "device:geolocation",
"device:hid", "device:hid",
......
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