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 @@
// 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.
// Usage of `base::Unretained(this)` is safe when calling
// mojo::Remote<BluetoothSystem> methods because mojo::Remote<BluetoothSystem>
// is owned by `this` and guarantees that no callbacks will be run after its
// destruction.
namespace ash {
......@@ -38,24 +39,24 @@ void TrayBluetoothHelperExperimental::Initialize() {
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(
bluetooth_system_factory->Create(
bluetooth_system_.BindNewPipeAndPassReceiver(), std::move(client_ptr));
bluetooth_system_->GetState(
base::BindOnce(&TrayBluetoothHelperExperimental::OnStateChanged,
// See base::Unretained() note at the top.
base::Unretained(this)));
bluetooth_system_ptr_->GetScanState(
bluetooth_system_->GetScanState(
base::BindOnce(&TrayBluetoothHelperExperimental::OnScanStateChanged,
// See base::Unretained() note at the top.
base::Unretained(this)));
}
void TrayBluetoothHelperExperimental::StartBluetoothDiscovering() {
bluetooth_system_ptr_->StartScan(base::DoNothing());
bluetooth_system_->StartScan(base::DoNothing());
}
void TrayBluetoothHelperExperimental::StopBluetoothDiscovering() {
bluetooth_system_ptr_->StopScan(base::DoNothing());
bluetooth_system_->StopScan(base::DoNothing());
}
void TrayBluetoothHelperExperimental::ConnectToBluetoothDevice(
......@@ -69,7 +70,7 @@ TrayBluetoothHelperExperimental::GetBluetoothState() {
}
void TrayBluetoothHelperExperimental::SetBluetoothEnabled(bool enabled) {
bluetooth_system_ptr_->SetPowered(enabled, base::DoNothing());
bluetooth_system_->SetPowered(enabled, base::DoNothing());
}
bool TrayBluetoothHelperExperimental::HasBluetoothDiscoverySession() {
......@@ -79,7 +80,7 @@ bool TrayBluetoothHelperExperimental::HasBluetoothDiscoverySession() {
void TrayBluetoothHelperExperimental::GetBluetoothDevices(
GetBluetoothDevicesCallback callback) const {
bluetooth_system_ptr_->GetAvailableDevices(std::move(callback));
bluetooth_system_->GetAvailableDevices(std::move(callback));
}
void TrayBluetoothHelperExperimental::OnStateChanged(
......
......@@ -11,6 +11,7 @@
#include "ash/system/bluetooth/tray_bluetooth_helper.h"
#include "base/macros.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/device/public/mojom/bluetooth_system.mojom.h"
namespace service_manager {
......@@ -47,7 +48,7 @@ class TrayBluetoothHelperExperimental
private:
service_manager::Connector* connector_;
device::mojom::BluetoothSystemPtr bluetooth_system_ptr_;
mojo::Remote<device::mojom::BluetoothSystem> bluetooth_system_;
mojo::Binding<device::mojom::BluetoothSystemClient>
bluetooth_system_client_binding_{this};
......
......@@ -19,7 +19,7 @@
#include "device/bluetooth/dbus/bluetooth_adapter_client.h"
#include "device/bluetooth/dbus/bluetooth_device_client.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 {
......@@ -59,10 +59,12 @@ base::Optional<std::array<uint8_t, 6>> ParseAddress(
} // namespace
void BluetoothSystem::Create(mojom::BluetoothSystemRequest request,
mojom::BluetoothSystemClientPtr client) {
mojo::MakeStrongBinding(std::make_unique<BluetoothSystem>(std::move(client)),
std::move(request));
void BluetoothSystem::Create(
mojo::PendingReceiver<mojom::BluetoothSystem> receiver,
mojom::BluetoothSystemClientPtr client) {
mojo::MakeSelfOwnedReceiver(
std::make_unique<BluetoothSystem>(std::move(client)),
std::move(receiver));
}
BluetoothSystem::BluetoothSystem(mojom::BluetoothSystemClientPtr client) {
......
......@@ -12,6 +12,7 @@
#include "base/optional.h"
#include "dbus/object_path.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"
namespace bluez {
......@@ -24,7 +25,7 @@ namespace device {
class BluetoothSystem : public mojom::BluetoothSystem,
public bluez::BluetoothAdapterClient::Observer {
public:
static void Create(mojom::BluetoothSystemRequest request,
static void Create(mojo::PendingReceiver<mojom::BluetoothSystem> receiver,
mojom::BluetoothSystemClientPtr client);
explicit BluetoothSystem(mojom::BluetoothSystemClientPtr client);
......
......@@ -23,9 +23,9 @@ BluetoothSystemFactory::BluetoothSystemFactory() = default;
BluetoothSystemFactory::~BluetoothSystemFactory() = default;
void BluetoothSystemFactory::Create(
mojom::BluetoothSystemRequest system_request,
mojo::PendingReceiver<mojom::BluetoothSystem> system_receiver,
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
......@@ -20,7 +20,7 @@ class BluetoothSystemFactory : public mojom::BluetoothSystemFactory {
~BluetoothSystemFactory() override;
// mojom::BluetoothSystemFactory
void Create(mojom::BluetoothSystemRequest system_request,
void Create(mojo::PendingReceiver<mojom::BluetoothSystem> system_receiver,
mojom::BluetoothSystemClientPtr system_client) override;
private:
......
......@@ -72,7 +72,8 @@ struct BluetoothDeviceInfo {
// Factory to get an instance of the BluetoothSystem interface.
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:
......
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