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