Commit ec103e51 authored by Miyoung Shin's avatar Miyoung Shin Committed by Commit Bot

Convert Device to new Mojo types

This CL converts DevicePtr and DeviceRequest in device to the new
Mojo type, and uses pending_remote<Device> in adapter.mojom.

Bug: 955171
Change-Id: I852ff06786de3fa189270fc9a6d777c67abd9d0a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1788422
Commit-Queue: Dave Tapuska <dtapuska@chromium.org>
Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695121}
parent 97d6605d
......@@ -12,6 +12,7 @@
#include "device/bluetooth/device.h"
#include "device/bluetooth/discovery_session.h"
#include "device/bluetooth/public/mojom/connect_result_type_converter.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
namespace bluetooth {
......@@ -32,7 +33,7 @@ void Adapter::ConnectToDevice(const std::string& address,
if (!device) {
std::move(callback).Run(mojom::ConnectResult::DEVICE_NO_LONGER_IN_RANGE,
nullptr /* device */);
/* device */ mojo::NullRemote());
return;
}
......@@ -132,17 +133,17 @@ void Adapter::DeviceRemoved(device::BluetoothAdapter* adapter,
void Adapter::OnGattConnected(
ConnectToDeviceCallback callback,
std::unique_ptr<device::BluetoothGattConnection> connection) {
mojom::DevicePtr device_ptr;
mojo::PendingRemote<mojom::Device> device;
Device::Create(adapter_, std::move(connection),
mojo::MakeRequest(&device_ptr));
std::move(callback).Run(mojom::ConnectResult::SUCCESS, std::move(device_ptr));
device.InitWithNewPipeAndPassReceiver());
std::move(callback).Run(mojom::ConnectResult::SUCCESS, std::move(device));
}
void Adapter::OnConnectError(
ConnectToDeviceCallback callback,
device::BluetoothDevice::ConnectErrorCode error_code) {
std::move(callback).Run(mojo::ConvertTo<mojom::ConnectResult>(error_code),
nullptr /* Device */);
/* device */ mojo::NullRemote());
}
void Adapter::OnStartDiscoverySession(
......
......@@ -10,7 +10,7 @@
#include "base/strings/utf_string_conversions.h"
#include "device/bluetooth/device.h"
#include "device/bluetooth/public/mojom/gatt_result_type_converter.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
namespace bluetooth {
Device::~Device() {
......@@ -20,12 +20,12 @@ Device::~Device() {
// static
void Device::Create(scoped_refptr<device::BluetoothAdapter> adapter,
std::unique_ptr<device::BluetoothGattConnection> connection,
mojom::DeviceRequest request) {
mojo::PendingReceiver<mojom::Device> receiver) {
auto device_impl =
base::WrapUnique(new Device(adapter, std::move(connection)));
auto* device_ptr = device_impl.get();
device_ptr->binding_ =
mojo::MakeStrongBinding(std::move(device_impl), std::move(request));
device_ptr->receiver_ =
mojo::MakeSelfOwnedReceiver(std::move(device_impl), std::move(receiver));
}
// static
......@@ -54,7 +54,7 @@ void Device::DeviceChanged(device::BluetoothAdapter* adapter,
}
if (!device->IsGattConnected()) {
binding_->Close();
receiver_->Close();
}
}
......@@ -72,7 +72,7 @@ void Device::GattServicesDiscovered(device::BluetoothAdapter* adapter,
}
void Device::Disconnect() {
binding_->Close();
receiver_->Close();
}
void Device::GetInfo(GetInfoCallback callback) {
......
......@@ -19,7 +19,7 @@
#include "device/bluetooth/bluetooth_remote_gatt_descriptor.h"
#include "device/bluetooth/bluetooth_remote_gatt_service.h"
#include "device/bluetooth/public/mojom/device.mojom.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
namespace bluetooth {
......@@ -37,7 +37,7 @@ class Device : public mojom::Device, public device::BluetoothAdapter::Observer {
static void Create(
scoped_refptr<device::BluetoothAdapter> adapter,
std::unique_ptr<device::BluetoothGattConnection> connection,
mojom::DeviceRequest request);
mojo::PendingReceiver<mojom::Device> receiver);
// Creates a mojom::DeviceInfo using info from the given |device|.
static mojom::DeviceInfoPtr ConstructDeviceInfoStruct(
......@@ -122,7 +122,7 @@ class Device : public mojom::Device, public device::BluetoothAdapter::Observer {
// The GATT connection to this device.
std::unique_ptr<device::BluetoothGattConnection> connection_;
mojo::StrongBindingPtr<mojom::Device> binding_;
mojo::SelfOwnedReceiverRef<mojom::Device> receiver_;
// The services request queue which holds callbacks that are waiting for
// services to be discovered for this device.
......
......@@ -19,6 +19,7 @@
#include "device/bluetooth/test/mock_bluetooth_gatt_characteristic.h"
#include "device/bluetooth/test/mock_bluetooth_gatt_connection.h"
#include "device/bluetooth/test/mock_bluetooth_gatt_service.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "testing/gtest/include/gtest/gtest.h"
using ::testing::Return;
......@@ -121,9 +122,10 @@ class BluetoothInterfaceDeviceTest : public testing::Test {
auto connection = std::make_unique<NiceMockBluetoothGattConnection>(
adapter_, device_.GetAddress());
Device::Create(adapter_, std::move(connection), mojo::MakeRequest(&proxy_));
Device::Create(adapter_, std::move(connection),
proxy_.BindNewPipeAndPassReceiver());
proxy_.set_connection_error_handler(
proxy_.set_disconnect_handler(
base::BindOnce(&BluetoothInterfaceDeviceTest::OnConnectionError,
weak_factory_.GetWeakPtr()));
}
......@@ -174,8 +176,7 @@ class BluetoothInterfaceDeviceTest : public testing::Test {
scoped_refptr<NiceMockBluetoothAdapter> adapter_;
NiceMockBluetoothDevice device_;
base::test::SingleThreadTaskEnvironment task_environment_;
mojom::DevicePtr proxy_;
mojo::StrongBindingPtr<mojom::Device> binding_ptr_;
mojo::Remote<mojom::Device> proxy_;
bool message_pipe_closed_ = false;
bool expect_device_service_deleted_ = false;
......
......@@ -55,7 +55,8 @@ interface Adapter {
// Creates a GATT connection to the device with |address| and returns a
// Device if the connection was succesful. The GATT connection is tied to the
// the lifetime of the Device message pipe.
ConnectToDevice(string address) => (ConnectResult result, Device? device);
ConnectToDevice(string address) =>
(ConnectResult result, pending_remote<Device>? device);
// Retrieves the list of the devices known by the adapter including Connected
// Devices, GATT Connected Devices, Paired Devices and Devices discovered
......
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