Commit 26fa8c87 authored by Miyoung Shin's avatar Miyoung Shin Committed by Commit Bot

Convert FakeBluetooth to new Mojo types

This CL converts FakeBluetoothRequest and FakeCentralRequest in
device to the new Mojo type, and uses pending_remote<FakeCentral>
in fake_bluetooth.mojom

Bug: 955171
Change-Id: I27a8887f998056f6913b1b53fe50e21165ca1018
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1788779Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Commit-Queue: Dave Tapuska <dtapuska@chromium.org>
Cr-Commit-Position: refs/heads/master@{#694823}
parent 03f38ca8
...@@ -81,7 +81,8 @@ interface FakeBluetooth { ...@@ -81,7 +81,8 @@ interface FakeBluetooth {
SetLESupported(bool available) => (); SetLESupported(bool available) => ();
// Initializes a fake Central with |state| as the initial state. // Initializes a fake Central with |state| as the initial state.
SimulateCentral(CentralState state) => (FakeCentral fake_central); SimulateCentral(CentralState state) =>
(pending_remote<FakeCentral> fake_central);
// Evaluates whether all responses set by this API have been consumed by this // Evaluates whether all responses set by this API have been consumed by this
// central or otherwise. This includes responses set by: // central or otherwise. This includes responses set by:
......
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "device/bluetooth/bluetooth_adapter_factory.h" #include "device/bluetooth/bluetooth_adapter_factory.h"
#include "device/bluetooth/public/mojom/test/fake_bluetooth.mojom.h" #include "device/bluetooth/public/mojom/test/fake_bluetooth.mojom.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
namespace bluetooth { namespace bluetooth {
...@@ -21,9 +22,10 @@ FakeBluetooth::FakeBluetooth() ...@@ -21,9 +22,10 @@ FakeBluetooth::FakeBluetooth()
FakeBluetooth::~FakeBluetooth() = default; FakeBluetooth::~FakeBluetooth() = default;
// static // static
void FakeBluetooth::Create(mojom::FakeBluetoothRequest request) { void FakeBluetooth::Create(
mojo::MakeStrongBinding(std::make_unique<FakeBluetooth>(), mojo::PendingReceiver<mojom::FakeBluetooth> receiver) {
std::move(request)); mojo::MakeSelfOwnedReceiver(std::make_unique<FakeBluetooth>(),
std::move(receiver));
} }
void FakeBluetooth::SetLESupported(bool supported, void FakeBluetooth::SetLESupported(bool supported,
...@@ -34,11 +36,11 @@ void FakeBluetooth::SetLESupported(bool supported, ...@@ -34,11 +36,11 @@ void FakeBluetooth::SetLESupported(bool supported,
void FakeBluetooth::SimulateCentral(mojom::CentralState state, void FakeBluetooth::SimulateCentral(mojom::CentralState state,
SimulateCentralCallback callback) { SimulateCentralCallback callback) {
mojom::FakeCentralPtr fake_central_ptr; mojo::PendingRemote<mojom::FakeCentral> fake_central;
fake_central_ = base::MakeRefCounted<FakeCentral>( fake_central_ = base::MakeRefCounted<FakeCentral>(
state, mojo::MakeRequest(&fake_central_ptr)); state, fake_central.InitWithNewPipeAndPassReceiver());
device::BluetoothAdapterFactory::SetAdapterForTesting(fake_central_); device::BluetoothAdapterFactory::SetAdapterForTesting(fake_central_);
std::move(callback).Run(std::move(fake_central_ptr)); std::move(callback).Run(std::move(fake_central));
} }
void FakeBluetooth::AllResponsesConsumed( void FakeBluetooth::AllResponsesConsumed(
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "device/bluetooth/bluetooth_adapter_factory.h" #include "device/bluetooth/bluetooth_adapter_factory.h"
#include "device/bluetooth/public/mojom/test/fake_bluetooth.mojom.h" #include "device/bluetooth/public/mojom/test/fake_bluetooth.mojom.h"
#include "device/bluetooth/test/fake_central.h" #include "device/bluetooth/test/fake_central.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
namespace bluetooth { namespace bluetooth {
...@@ -24,7 +25,7 @@ class FakeBluetooth : public mojom::FakeBluetooth { ...@@ -24,7 +25,7 @@ class FakeBluetooth : public mojom::FakeBluetooth {
FakeBluetooth(); FakeBluetooth();
~FakeBluetooth() override; ~FakeBluetooth() override;
static void Create(mojom::FakeBluetoothRequest request); static void Create(mojo::PendingReceiver<mojom::FakeBluetooth> receiver);
void SetLESupported(bool available, SetLESupportedCallback callback) override; void SetLESupported(bool available, SetLESupportedCallback callback) override;
void SimulateCentral(mojom::CentralState state, void SimulateCentral(mojom::CentralState state,
......
...@@ -39,8 +39,8 @@ device::BluetoothDevice::ManufacturerDataMap ToManufacturerDataMap( ...@@ -39,8 +39,8 @@ device::BluetoothDevice::ManufacturerDataMap ToManufacturerDataMap(
} // namespace } // namespace
FakeCentral::FakeCentral(mojom::CentralState state, FakeCentral::FakeCentral(mojom::CentralState state,
mojom::FakeCentralRequest request) mojo::PendingReceiver<mojom::FakeCentral> receiver)
: state_(state), binding_(this, std::move(request)) {} : state_(state), receiver_(this, std::move(receiver)) {}
void FakeCentral::SimulatePreconnectedPeripheral( void FakeCentral::SimulatePreconnectedPeripheral(
const std::string& address, const std::string& address,
......
...@@ -11,7 +11,8 @@ ...@@ -11,7 +11,8 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "device/bluetooth/bluetooth_adapter.h" #include "device/bluetooth/bluetooth_adapter.h"
#include "device/bluetooth/public/mojom/test/fake_bluetooth.mojom.h" #include "device/bluetooth/public/mojom/test/fake_bluetooth.mojom.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
namespace bluetooth { namespace bluetooth {
...@@ -28,7 +29,8 @@ class FakeRemoteGattService; ...@@ -28,7 +29,8 @@ class FakeRemoteGattService;
// Not intended for direct use by clients. See README.md. // Not intended for direct use by clients. See README.md.
class FakeCentral : public mojom::FakeCentral, public device::BluetoothAdapter { class FakeCentral : public mojom::FakeCentral, public device::BluetoothAdapter {
public: public:
FakeCentral(mojom::CentralState state, mojom::FakeCentralRequest request); FakeCentral(mojom::CentralState state,
mojo::PendingReceiver<mojom::FakeCentral> receiver);
// FakeCentral overrides: // FakeCentral overrides:
void SimulatePreconnectedPeripheral( void SimulatePreconnectedPeripheral(
...@@ -211,7 +213,7 @@ class FakeCentral : public mojom::FakeCentral, public device::BluetoothAdapter { ...@@ -211,7 +213,7 @@ class FakeCentral : public mojom::FakeCentral, public device::BluetoothAdapter {
const std::string& descriptor_id) const; const std::string& descriptor_id) const;
mojom::CentralState state_; mojom::CentralState state_;
mojo::Binding<mojom::FakeCentral> binding_; mojo::Receiver<mojom::FakeCentral> receiver_;
}; };
} // namespace bluetooth } // namespace bluetooth
......
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