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

Convert FakeBluetoothChooser* to new Mojo types

This CL converts FakeBluetoothChooserRequest,
FakeBluetoothChooserFactoryRequest and
FakeBluetoothChooserClient{AssociatedPtr, AssociatedPtrInfo} in
content to the new Mojo type, and uses
pending_receiver<FakeBluetoothChooser> and
pending_associated_remote<FakeBluetoothChooserClient> in
fake_bluetooth_chooser.mojom

Bug: 955171
Change-Id: I73cce0dec73868dbf3b6a0f72d3cab0acd73eade
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1788964
Commit-Queue: Miyoung Shin <myid.shin@igalia.com>
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@{#695031}
parent 7a126303
......@@ -14,10 +14,9 @@
namespace content {
FakeBluetoothChooser::FakeBluetoothChooser(
mojom::FakeBluetoothChooserRequest request,
mojom::FakeBluetoothChooserClientAssociatedPtrInfo client_ptr_info)
: binding_(this, std::move(request)),
client_ptr_(std::move(client_ptr_info)) {
mojo::PendingReceiver<mojom::FakeBluetoothChooser> receiver,
mojo::PendingAssociatedRemote<mojom::FakeBluetoothChooserClient> client)
: receiver_(this, std::move(receiver)), client_(std::move(client)) {
SetTestBluetoothScanDuration(BluetoothTestScanDurationSetting::kNeverTimeout);
}
......@@ -25,7 +24,7 @@ FakeBluetoothChooser::~FakeBluetoothChooser() {
SetTestBluetoothScanDuration(
BluetoothTestScanDurationSetting::kImmediateTimeout);
client_ptr_->OnEvent(mojom::FakeBluetoothChooserEvent::New(
client_->OnEvent(mojom::FakeBluetoothChooserEvent::New(
mojom::ChooserEventType::CHOOSER_CLOSED, /*origin=*/base::nullopt,
/*peripheral_address=*/base::nullopt));
}
......@@ -34,7 +33,7 @@ void FakeBluetoothChooser::OnRunBluetoothChooser(
const EventHandler& event_handler,
const url::Origin& origin) {
event_handler_ = event_handler;
client_ptr_->OnEvent(mojom::FakeBluetoothChooserEvent::New(
client_->OnEvent(mojom::FakeBluetoothChooserEvent::New(
mojom::ChooserEventType::CHOOSER_OPENED, origin,
/*peripheral_address=*/base::nullopt));
}
......@@ -49,7 +48,7 @@ void FakeBluetoothChooser::SelectPeripheral(
void FakeBluetoothChooser::Cancel() {
DCHECK(event_handler_);
event_handler_.Run(BluetoothChooser::Event::CANCELLED, std::string());
client_ptr_->OnEvent(mojom::FakeBluetoothChooserEvent::New(
client_->OnEvent(mojom::FakeBluetoothChooserEvent::New(
mojom::ChooserEventType::CHOOSER_CLOSED, /*origin=*/base::nullopt,
/*peripheral_address=*/base::nullopt));
}
......@@ -57,7 +56,7 @@ void FakeBluetoothChooser::Cancel() {
void FakeBluetoothChooser::Rescan() {
DCHECK(event_handler_);
event_handler_.Run(BluetoothChooser::Event::RESCAN, std::string());
client_ptr_->OnEvent(mojom::FakeBluetoothChooserEvent::New(
client_->OnEvent(mojom::FakeBluetoothChooserEvent::New(
mojom::ChooserEventType::DISCOVERING, /*origin=*/base::nullopt,
/*peripheral_address=*/base::nullopt));
}
......@@ -78,7 +77,7 @@ void FakeBluetoothChooser::SetAdapterPresence(AdapterPresence presence) {
event_ptr->type = mojom::ChooserEventType::ADAPTER_ENABLED;
break;
}
client_ptr_->OnEvent(std::move(event_ptr));
client_->OnEvent(std::move(event_ptr));
}
void FakeBluetoothChooser::ShowDiscoveryState(DiscoveryState state) {
......@@ -95,7 +94,7 @@ void FakeBluetoothChooser::ShowDiscoveryState(DiscoveryState state) {
event_ptr->type = mojom::ChooserEventType::DISCOVERY_IDLE;
break;
}
client_ptr_->OnEvent(std::move(event_ptr));
client_->OnEvent(std::move(event_ptr));
}
void FakeBluetoothChooser::AddOrUpdateDevice(const std::string& device_id,
......@@ -104,7 +103,7 @@ void FakeBluetoothChooser::AddOrUpdateDevice(const std::string& device_id,
bool is_gatt_connected,
bool is_paired,
int signal_strength_level) {
client_ptr_->OnEvent(mojom::FakeBluetoothChooserEvent::New(
client_->OnEvent(mojom::FakeBluetoothChooserEvent::New(
mojom::ChooserEventType::ADD_OR_UPDATE_DEVICE,
/*origin=*/base::nullopt, /*peripheral_address=*/device_id));
}
......
......@@ -9,8 +9,10 @@
#include "content/public/browser/bluetooth_chooser.h"
#include "content/shell/common/web_test/fake_bluetooth_chooser.mojom.h"
#include "mojo/public/cpp/bindings/associated_binding.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/pending_associated_remote.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "url/origin.h"
namespace content {
......@@ -36,8 +38,8 @@ class FakeBluetoothChooser : public mojom::FakeBluetoothChooser,
// is opened, ownership of this instance will shift to the caller of
// WebContentsDelegate::RunBluetoothChooser.
FakeBluetoothChooser(
mojom::FakeBluetoothChooserRequest request,
mojom::FakeBluetoothChooserClientAssociatedPtrInfo client_ptr_info);
mojo::PendingReceiver<mojom::FakeBluetoothChooser> receiver,
mojo::PendingAssociatedRemote<mojom::FakeBluetoothChooserClient> client);
// Resets the test scan duration to timeout immediately and sends a
// |CHOOSER_CLOSED| event to the client.
......@@ -68,11 +70,11 @@ class FakeBluetoothChooser : public mojom::FakeBluetoothChooser,
// Stores the callback function that handles chooser events.
EventHandler event_handler_;
mojo::Binding<mojom::FakeBluetoothChooser> binding_;
mojo::Receiver<mojom::FakeBluetoothChooser> receiver_;
// Stores the associated pointer to the client that will be receiving events
// from FakeBluetoothChooser.
mojom::FakeBluetoothChooserClientAssociatedPtr client_ptr_;
mojo::AssociatedRemote<mojom::FakeBluetoothChooserClient> client_;
DISALLOW_COPY_AND_ASSIGN(FakeBluetoothChooser);
};
......
......@@ -11,11 +11,11 @@ namespace content {
FakeBluetoothChooserFactory::~FakeBluetoothChooserFactory() {}
void FakeBluetoothChooserFactory::CreateFakeBluetoothChooser(
mojom::FakeBluetoothChooserRequest request,
mojom::FakeBluetoothChooserClientAssociatedPtrInfo client_ptr_info) {
mojo::PendingReceiver<mojom::FakeBluetoothChooser> receiver,
mojom::FakeBluetoothChooserClientAssociatedPtrInfo client) {
DCHECK(!next_fake_bluetooth_chooser_);
next_fake_bluetooth_chooser_ = std::make_unique<FakeBluetoothChooser>(
std::move(request), std::move(client_ptr_info));
std::move(receiver), std::move(client));
}
std::unique_ptr<FakeBluetoothChooser>
......@@ -24,7 +24,7 @@ FakeBluetoothChooserFactory::GetNextFakeBluetoothChooser() {
}
FakeBluetoothChooserFactory::FakeBluetoothChooserFactory(
mojom::FakeBluetoothChooserFactoryRequest request)
: binding_(this, std::move(request)) {}
mojo::PendingReceiver<mojom::FakeBluetoothChooserFactory> receiver)
: receiver_(this, std::move(receiver)) {}
} // namespace content
......@@ -8,7 +8,8 @@
#include <memory>
#include "content/shell/common/web_test/fake_bluetooth_chooser.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 content {
......@@ -16,8 +17,9 @@ class FakeBluetoothChooser;
// Implementation of FakeBluetoothChooserFactory in
// src/content/shell/common/web_test/fake_bluetooth_chooser.mojom to create
// FakeBluetoothChoosers with a FakeBluetoothChooserClientAssociatedPtr that
// they can use to send events to the client.
// FakeBluetoothChoosers with a
// mojo::PendingAssociatedRemote<FakeBluetoothChooserClient> that they can use
// to send events to the client.
//
// The implementation details for FakeBluetoothChooser can be found in the Web
// Bluetooth Test Scanning design document.
......@@ -29,29 +31,28 @@ class FakeBluetoothChooserFactory : public mojom::FakeBluetoothChooserFactory {
~FakeBluetoothChooserFactory() override;
// WebTestContentBrowserClient will create an instance of this class when a
// request is bound. It will maintain ownership of the instance.
// receiver is bound. It will maintain ownership of the instance.
static std::unique_ptr<FakeBluetoothChooserFactory> Create(
mojom::FakeBluetoothChooserFactoryRequest request) {
return std::unique_ptr<FakeBluetoothChooserFactory>(
new FakeBluetoothChooserFactory(std::move(request)));
mojo::PendingReceiver<mojom::FakeBluetoothChooserFactory> receiver) {
return base::WrapUnique(
new FakeBluetoothChooserFactory(std::move(receiver)));
}
// Creates an instance of FakeBluetoothChooser and stores it in
// |next_fake_bluetooth_chooser_|. This will DCHECK if
// |next_fake_bluetooth_chooser_| is not null.
void CreateFakeBluetoothChooser(
mojom::FakeBluetoothChooserRequest request,
mojom::FakeBluetoothChooserClientAssociatedPtrInfo client_ptr_info)
override;
mojo::PendingReceiver<mojom::FakeBluetoothChooser> receiver,
mojom::FakeBluetoothChooserClientAssociatedPtrInfo client) override;
// Transfers ownership of |next_fake_bluetooth_chooser_| to the caller.
std::unique_ptr<FakeBluetoothChooser> GetNextFakeBluetoothChooser();
private:
explicit FakeBluetoothChooserFactory(
mojom::FakeBluetoothChooserFactoryRequest request);
mojo::PendingReceiver<mojom::FakeBluetoothChooserFactory> receiver);
mojo::Binding<mojom::FakeBluetoothChooserFactory> binding_;
mojo::Receiver<mojom::FakeBluetoothChooserFactory> receiver_;
std::unique_ptr<FakeBluetoothChooser> next_fake_bluetooth_chooser_;
};
......
......@@ -344,10 +344,10 @@ std::unique_ptr<LoginDelegate> WebTestContentBrowserClient::CreateLoginDelegate(
// private
void WebTestContentBrowserClient::CreateFakeBluetoothChooserFactory(
mojom::FakeBluetoothChooserFactoryRequest request) {
mojo::PendingReceiver<mojom::FakeBluetoothChooserFactory> receiver) {
DCHECK(!fake_bluetooth_chooser_factory_);
fake_bluetooth_chooser_factory_ =
FakeBluetoothChooserFactory::Create(std::move(request));
FakeBluetoothChooserFactory::Create(std::move(receiver));
}
} // namespace content
......@@ -9,6 +9,7 @@
#include "content/shell/browser/shell_content_browser_client.h"
#include "content/shell/common/web_test/fake_bluetooth_chooser.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "third_party/blink/public/mojom/clipboard/clipboard.mojom.h"
namespace content {
......@@ -89,7 +90,7 @@ class WebTestContentBrowserClient : public ShellContentBrowserClient {
private:
// Creates and stores a FakeBluetoothChooserFactory instance.
void CreateFakeBluetoothChooserFactory(
mojom::FakeBluetoothChooserFactoryRequest request);
mojo::PendingReceiver<mojom::FakeBluetoothChooserFactory> receiver);
// TODO(https://crbug.com/955171): Remove this and use BindClipboardHost
// directly once it uses service_manager::BinderMap instead of
// service_manager::BinderRegistry.
......
......@@ -52,8 +52,12 @@ interface FakeBluetoothChooser {
// FakeBluetoothChooserFactory ensures that FakeBluetoothChoosers are created
// with an associated FakeBluetoothChooserClient.
// TODO(crbug.com/955171): Use |pending_associated_remote| instead of
// |associated| after supporting mojom_js_generator.py completely for
// associated interfaces.
interface FakeBluetoothChooserFactory {
CreateFakeBluetoothChooser(FakeBluetoothChooser& fake_chooser,
CreateFakeBluetoothChooser(
pending_receiver<FakeBluetoothChooser> fake_chooser,
associated FakeBluetoothChooserClient client);
};
......
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