Commit 3b6ffbc7 authored by Miyoung Shin's avatar Miyoung Shin Committed by Commit Bot

Convert BluetoothSystem to new Mojo types

This CL converts BluetoothSystem{Ptr, Request} in ash and services
to the new Mojo type, and uses pending_receiver<BluetoothSystem>
in bluetooth_system.mojom.

Bug: 955171
Change-Id: I764daf49604184341812fbb3b3249590b29b7d40
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1787663Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Commit-Queue: Miyoung Shin <myid.shin@igalia.com>
Cr-Commit-Position: refs/heads/master@{#695052}
parent a398fb15
...@@ -18,9 +18,10 @@ ...@@ -18,9 +18,10 @@
// base::Unretained(): // base::Unretained():
// //
// Usage of `base::Unretained(this)` is safe when calling BluetoothSystemPtr // Usage of `base::Unretained(this)` is safe when calling
// methods because BluetoothSystemPtr is owned by `this` and guarantees that no // mojo::Remote<BluetoothSystem> methods because mojo::Remote<BluetoothSystem>
// callbacks will be run after its destruction. // is owned by `this` and guarantees that no callbacks will be run after its
// destruction.
namespace ash { namespace ash {
...@@ -38,24 +39,24 @@ void TrayBluetoothHelperExperimental::Initialize() { ...@@ -38,24 +39,24 @@ void TrayBluetoothHelperExperimental::Initialize() {
device::mojom::BluetoothSystemClientPtr client_ptr; device::mojom::BluetoothSystemClientPtr client_ptr;
bluetooth_system_client_binding_.Bind(mojo::MakeRequest(&client_ptr)); bluetooth_system_client_binding_.Bind(mojo::MakeRequest(&client_ptr));
bluetooth_system_factory->Create(mojo::MakeRequest(&bluetooth_system_ptr_), bluetooth_system_factory->Create(
std::move(client_ptr)); bluetooth_system_.BindNewPipeAndPassReceiver(), std::move(client_ptr));
bluetooth_system_ptr_->GetState( bluetooth_system_->GetState(
base::BindOnce(&TrayBluetoothHelperExperimental::OnStateChanged, base::BindOnce(&TrayBluetoothHelperExperimental::OnStateChanged,
// See base::Unretained() note at the top. // See base::Unretained() note at the top.
base::Unretained(this))); base::Unretained(this)));
bluetooth_system_ptr_->GetScanState( bluetooth_system_->GetScanState(
base::BindOnce(&TrayBluetoothHelperExperimental::OnScanStateChanged, base::BindOnce(&TrayBluetoothHelperExperimental::OnScanStateChanged,
// See base::Unretained() note at the top. // See base::Unretained() note at the top.
base::Unretained(this))); base::Unretained(this)));
} }
void TrayBluetoothHelperExperimental::StartBluetoothDiscovering() { void TrayBluetoothHelperExperimental::StartBluetoothDiscovering() {
bluetooth_system_ptr_->StartScan(base::DoNothing()); bluetooth_system_->StartScan(base::DoNothing());
} }
void TrayBluetoothHelperExperimental::StopBluetoothDiscovering() { void TrayBluetoothHelperExperimental::StopBluetoothDiscovering() {
bluetooth_system_ptr_->StopScan(base::DoNothing()); bluetooth_system_->StopScan(base::DoNothing());
} }
void TrayBluetoothHelperExperimental::ConnectToBluetoothDevice( void TrayBluetoothHelperExperimental::ConnectToBluetoothDevice(
...@@ -69,7 +70,7 @@ TrayBluetoothHelperExperimental::GetBluetoothState() { ...@@ -69,7 +70,7 @@ TrayBluetoothHelperExperimental::GetBluetoothState() {
} }
void TrayBluetoothHelperExperimental::SetBluetoothEnabled(bool enabled) { void TrayBluetoothHelperExperimental::SetBluetoothEnabled(bool enabled) {
bluetooth_system_ptr_->SetPowered(enabled, base::DoNothing()); bluetooth_system_->SetPowered(enabled, base::DoNothing());
} }
bool TrayBluetoothHelperExperimental::HasBluetoothDiscoverySession() { bool TrayBluetoothHelperExperimental::HasBluetoothDiscoverySession() {
...@@ -79,7 +80,7 @@ bool TrayBluetoothHelperExperimental::HasBluetoothDiscoverySession() { ...@@ -79,7 +80,7 @@ bool TrayBluetoothHelperExperimental::HasBluetoothDiscoverySession() {
void TrayBluetoothHelperExperimental::GetBluetoothDevices( void TrayBluetoothHelperExperimental::GetBluetoothDevices(
GetBluetoothDevicesCallback callback) const { GetBluetoothDevicesCallback callback) const {
bluetooth_system_ptr_->GetAvailableDevices(std::move(callback)); bluetooth_system_->GetAvailableDevices(std::move(callback));
} }
void TrayBluetoothHelperExperimental::OnStateChanged( void TrayBluetoothHelperExperimental::OnStateChanged(
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#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 "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/device/public/mojom/bluetooth_system.mojom.h" #include "services/device/public/mojom/bluetooth_system.mojom.h"
namespace service_manager { namespace service_manager {
...@@ -47,7 +48,7 @@ class TrayBluetoothHelperExperimental ...@@ -47,7 +48,7 @@ class TrayBluetoothHelperExperimental
private: private:
service_manager::Connector* connector_; service_manager::Connector* connector_;
device::mojom::BluetoothSystemPtr bluetooth_system_ptr_; mojo::Remote<device::mojom::BluetoothSystem> bluetooth_system_;
mojo::Binding<device::mojom::BluetoothSystemClient> mojo::Binding<device::mojom::BluetoothSystemClient>
bluetooth_system_client_binding_{this}; bluetooth_system_client_binding_{this};
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include "device/bluetooth/dbus/bluetooth_adapter_client.h" #include "device/bluetooth/dbus/bluetooth_adapter_client.h"
#include "device/bluetooth/dbus/bluetooth_device_client.h" #include "device/bluetooth/dbus/bluetooth_device_client.h"
#include "device/bluetooth/dbus/bluez_dbus_manager.h" #include "device/bluetooth/dbus/bluez_dbus_manager.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/self_owned_receiver.h"
namespace device { namespace device {
...@@ -59,10 +59,12 @@ base::Optional<std::array<uint8_t, 6>> ParseAddress( ...@@ -59,10 +59,12 @@ base::Optional<std::array<uint8_t, 6>> ParseAddress(
} // namespace } // namespace
void BluetoothSystem::Create(mojom::BluetoothSystemRequest request, void BluetoothSystem::Create(
mojo::PendingReceiver<mojom::BluetoothSystem> receiver,
mojom::BluetoothSystemClientPtr client) { mojom::BluetoothSystemClientPtr client) {
mojo::MakeStrongBinding(std::make_unique<BluetoothSystem>(std::move(client)), mojo::MakeSelfOwnedReceiver(
std::move(request)); std::make_unique<BluetoothSystem>(std::move(client)),
std::move(receiver));
} }
BluetoothSystem::BluetoothSystem(mojom::BluetoothSystemClientPtr client) { BluetoothSystem::BluetoothSystem(mojom::BluetoothSystemClientPtr client) {
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/optional.h" #include "base/optional.h"
#include "dbus/object_path.h" #include "dbus/object_path.h"
#include "device/bluetooth/dbus/bluetooth_adapter_client.h" #include "device/bluetooth/dbus/bluetooth_adapter_client.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "services/device/public/mojom/bluetooth_system.mojom.h" #include "services/device/public/mojom/bluetooth_system.mojom.h"
namespace bluez { namespace bluez {
...@@ -24,7 +25,7 @@ namespace device { ...@@ -24,7 +25,7 @@ namespace device {
class BluetoothSystem : public mojom::BluetoothSystem, class BluetoothSystem : public mojom::BluetoothSystem,
public bluez::BluetoothAdapterClient::Observer { public bluez::BluetoothAdapterClient::Observer {
public: public:
static void Create(mojom::BluetoothSystemRequest request, static void Create(mojo::PendingReceiver<mojom::BluetoothSystem> receiver,
mojom::BluetoothSystemClientPtr client); mojom::BluetoothSystemClientPtr client);
explicit BluetoothSystem(mojom::BluetoothSystemClientPtr client); explicit BluetoothSystem(mojom::BluetoothSystemClientPtr client);
......
...@@ -23,9 +23,9 @@ BluetoothSystemFactory::BluetoothSystemFactory() = default; ...@@ -23,9 +23,9 @@ BluetoothSystemFactory::BluetoothSystemFactory() = default;
BluetoothSystemFactory::~BluetoothSystemFactory() = default; BluetoothSystemFactory::~BluetoothSystemFactory() = default;
void BluetoothSystemFactory::Create( void BluetoothSystemFactory::Create(
mojom::BluetoothSystemRequest system_request, mojo::PendingReceiver<mojom::BluetoothSystem> system_receiver,
mojom::BluetoothSystemClientPtr system_client) { mojom::BluetoothSystemClientPtr system_client) {
BluetoothSystem::Create(std::move(system_request), std::move(system_client)); BluetoothSystem::Create(std::move(system_receiver), std::move(system_client));
} }
} // namespace device } // namespace device
...@@ -20,7 +20,7 @@ class BluetoothSystemFactory : public mojom::BluetoothSystemFactory { ...@@ -20,7 +20,7 @@ class BluetoothSystemFactory : public mojom::BluetoothSystemFactory {
~BluetoothSystemFactory() override; ~BluetoothSystemFactory() override;
// mojom::BluetoothSystemFactory // mojom::BluetoothSystemFactory
void Create(mojom::BluetoothSystemRequest system_request, void Create(mojo::PendingReceiver<mojom::BluetoothSystem> system_receiver,
mojom::BluetoothSystemClientPtr system_client) override; mojom::BluetoothSystemClientPtr system_client) override;
private: private:
......
...@@ -72,7 +72,8 @@ struct BluetoothDeviceInfo { ...@@ -72,7 +72,8 @@ struct BluetoothDeviceInfo {
// Factory to get an instance of the BluetoothSystem interface. // Factory to get an instance of the BluetoothSystem interface.
interface BluetoothSystemFactory { interface BluetoothSystemFactory {
Create(BluetoothSystem& system, BluetoothSystemClient system_client); Create(pending_receiver<BluetoothSystem> system,
BluetoothSystemClient system_client);
}; };
// High level interface targeted towards UI level components that: // High level interface targeted towards UI level components that:
......
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