Commit 2df0d5b6 authored by Miyoung Shin's avatar Miyoung Shin Committed by Commit Bot

Convert Adapter, AdapterClient and DiscoverySession in adapter.mojom to new Mojo types

This CL converts AdapterPtr, AdapterClientPtr DiscoverySessionPtr
in chrome and device to the new Mojo type, and uses
pending_remote<AdapterClient> and pending_remote<DiscoverySession>
in adapter.mojom and pending_remote<bluetooth.mojom.Adapter> in
bluetooth_internals.mojom

Bug: 955171
Change-Id: I013e11c6b5b1ce16275f22e99678f22564ebd13c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1787669
Commit-Queue: Dave Tapuska <dtapuska@chromium.org>
Reviewed-by: default avatarcalamity <calamity@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#694890}
parent de4794c3
...@@ -8,5 +8,5 @@ import "device/bluetooth/public/mojom/adapter.mojom"; ...@@ -8,5 +8,5 @@ import "device/bluetooth/public/mojom/adapter.mojom";
interface BluetoothInternalsHandler { interface BluetoothInternalsHandler {
// Gets an Adapter interface. Returns null if Bluetooth is not supported. // Gets an Adapter interface. Returns null if Bluetooth is not supported.
GetAdapter() => (bluetooth.mojom.Adapter? adapter); GetAdapter() => (pending_remote<bluetooth.mojom.Adapter>? adapter);
}; };
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "device/bluetooth/adapter.h" #include "device/bluetooth/adapter.h"
#include "device/bluetooth/bluetooth_adapter_factory.h" #include "device/bluetooth/bluetooth_adapter_factory.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "url/gurl.h" #include "url/gurl.h"
BluetoothInternalsHandler::BluetoothInternalsHandler( BluetoothInternalsHandler::BluetoothInternalsHandler(
...@@ -25,15 +27,15 @@ void BluetoothInternalsHandler::GetAdapter(GetAdapterCallback callback) { ...@@ -25,15 +27,15 @@ void BluetoothInternalsHandler::GetAdapter(GetAdapterCallback callback) {
base::BindOnce(&BluetoothInternalsHandler::OnGetAdapter, base::BindOnce(&BluetoothInternalsHandler::OnGetAdapter,
weak_ptr_factory_.GetWeakPtr(), std::move(callback))); weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
} else { } else {
std::move(callback).Run(nullptr /* AdapterPtr */); std::move(callback).Run(mojo::NullRemote() /* adapter */);
} }
} }
void BluetoothInternalsHandler::OnGetAdapter( void BluetoothInternalsHandler::OnGetAdapter(
GetAdapterCallback callback, GetAdapterCallback callback,
scoped_refptr<device::BluetoothAdapter> adapter) { scoped_refptr<device::BluetoothAdapter> adapter) {
bluetooth::mojom::AdapterPtr adapter_ptr; mojo::PendingRemote<bluetooth::mojom::Adapter> pending_adapter;
mojo::MakeStrongBinding(std::make_unique<bluetooth::Adapter>(adapter), mojo::MakeSelfOwnedReceiver(std::make_unique<bluetooth::Adapter>(adapter),
mojo::MakeRequest(&adapter_ptr)); pending_adapter.InitWithNewPipeAndPassReceiver());
std::move(callback).Run(std::move(adapter_ptr)); std::move(callback).Run(std::move(pending_adapter));
} }
...@@ -12,12 +12,12 @@ ...@@ -12,12 +12,12 @@
#include "device/bluetooth/device.h" #include "device/bluetooth/device.h"
#include "device/bluetooth/discovery_session.h" #include "device/bluetooth/discovery_session.h"
#include "device/bluetooth/public/mojom/connect_result_type_converter.h" #include "device/bluetooth/public/mojom/connect_result_type_converter.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/self_owned_receiver.h"
namespace bluetooth { namespace bluetooth {
Adapter::Adapter(scoped_refptr<device::BluetoothAdapter> adapter) Adapter::Adapter(scoped_refptr<device::BluetoothAdapter> adapter)
: adapter_(std::move(adapter)), client_(nullptr) { : adapter_(std::move(adapter)) {
adapter_->AddObserver(this); adapter_->AddObserver(this);
} }
...@@ -68,8 +68,8 @@ void Adapter::GetInfo(GetInfoCallback callback) { ...@@ -68,8 +68,8 @@ void Adapter::GetInfo(GetInfoCallback callback) {
std::move(callback).Run(std::move(adapter_info)); std::move(callback).Run(std::move(adapter_info));
} }
void Adapter::SetClient(mojom::AdapterClientPtr client) { void Adapter::SetClient(mojo::PendingRemote<mojom::AdapterClient> client) {
client_ = std::move(client); client_.Bind(std::move(client));
} }
void Adapter::StartDiscoverySession(StartDiscoverySessionCallback callback) { void Adapter::StartDiscoverySession(StartDiscoverySessionCallback callback) {
...@@ -148,15 +148,15 @@ void Adapter::OnConnectError( ...@@ -148,15 +148,15 @@ void Adapter::OnConnectError(
void Adapter::OnStartDiscoverySession( void Adapter::OnStartDiscoverySession(
StartDiscoverySessionCallback callback, StartDiscoverySessionCallback callback,
std::unique_ptr<device::BluetoothDiscoverySession> session) { std::unique_ptr<device::BluetoothDiscoverySession> session) {
mojom::DiscoverySessionPtr session_ptr; mojo::PendingRemote<mojom::DiscoverySession> pending_session;
mojo::MakeStrongBinding( mojo::MakeSelfOwnedReceiver(
std::make_unique<DiscoverySession>(std::move(session)), std::make_unique<DiscoverySession>(std::move(session)),
mojo::MakeRequest(&session_ptr)); pending_session.InitWithNewPipeAndPassReceiver());
std::move(callback).Run(std::move(session_ptr)); std::move(callback).Run(std::move(pending_session));
} }
void Adapter::OnDiscoverySessionError(StartDiscoverySessionCallback callback) { void Adapter::OnDiscoverySessionError(StartDiscoverySessionCallback callback) {
std::move(callback).Run(nullptr /* session */); std::move(callback).Run(mojo::NullRemote() /* session */);
} }
} // namespace bluetooth } // namespace bluetooth
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include "device/bluetooth/bluetooth_gatt_connection.h" #include "device/bluetooth/bluetooth_gatt_connection.h"
#include "device/bluetooth/public/mojom/adapter.mojom.h" #include "device/bluetooth/public/mojom/adapter.mojom.h"
#include "device/bluetooth/public/mojom/device.mojom.h" #include "device/bluetooth/public/mojom/device.mojom.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace bluetooth { namespace bluetooth {
...@@ -32,7 +34,7 @@ class Adapter : public mojom::Adapter, ...@@ -32,7 +34,7 @@ class Adapter : public mojom::Adapter,
ConnectToDeviceCallback callback) override; ConnectToDeviceCallback callback) override;
void GetDevices(GetDevicesCallback callback) override; void GetDevices(GetDevicesCallback callback) override;
void GetInfo(GetInfoCallback callback) override; void GetInfo(GetInfoCallback callback) override;
void SetClient(mojom::AdapterClientPtr client) override; void SetClient(mojo::PendingRemote<mojom::AdapterClient> client) override;
void StartDiscoverySession(StartDiscoverySessionCallback callback) override; void StartDiscoverySession(StartDiscoverySessionCallback callback) override;
// device::BluetoothAdapter::Observer overrides: // device::BluetoothAdapter::Observer overrides:
...@@ -69,7 +71,7 @@ class Adapter : public mojom::Adapter, ...@@ -69,7 +71,7 @@ class Adapter : public mojom::Adapter,
scoped_refptr<device::BluetoothAdapter> adapter_; scoped_refptr<device::BluetoothAdapter> adapter_;
// The adapter client that listens to this service. // The adapter client that listens to this service.
mojom::AdapterClientPtr client_; mojo::Remote<mojom::AdapterClient> client_;
base::WeakPtrFactory<Adapter> weak_ptr_factory_{this}; base::WeakPtrFactory<Adapter> weak_ptr_factory_{this};
......
...@@ -66,11 +66,11 @@ interface Adapter { ...@@ -66,11 +66,11 @@ interface Adapter {
GetInfo() => (AdapterInfo info); GetInfo() => (AdapterInfo info);
// Sets the client that listens for the adapter's events. // Sets the client that listens for the adapter's events.
SetClient(AdapterClient client); SetClient(pending_remote<AdapterClient> client);
// Requests the adapter to start a new discovery session. Returns null if // Requests the adapter to start a new discovery session. Returns null if
// session not created successfully. // session not created successfully.
StartDiscoverySession() => (DiscoverySession? session); StartDiscoverySession() => (pending_remote<DiscoverySession>? session);
}; };
interface AdapterClient { interface AdapterClient {
......
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