Commit b7988c36 authored by Gyuyoung Kim's avatar Gyuyoung Kim Committed by Commit Bot

Reland "Migrate hid.mojom and related classes to the new Mojo types""

This reverts commit 483de1b0.

This CL changes hid.mojom-blink.h include with hid.mojom.h to
fix the build break on the linux-chromeos-rel bot.

Bug: 955171
Change-Id: I7849bc89265caf578e076451d5d853f3a5bc7105
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1767462Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Gyuyoung Kim <gyuyoung@igalia.com>
Cr-Commit-Position: refs/heads/master@{#690305}
parent eaecb5d0
......@@ -71,9 +71,10 @@ void HidService::RequestDevice(
weak_factory_.GetWeakPtr(), std::move(callback)));
}
void HidService::Connect(const std::string& device_guid,
device::mojom::HidConnectionClientPtr client,
ConnectCallback callback) {
void HidService::Connect(
const std::string& device_guid,
mojo::PendingRemote<device::mojom::HidConnectionClient> client,
ConnectCallback callback) {
GetContentClient()
->browser()
->GetHidDelegate()
......
......@@ -13,6 +13,7 @@
#include "base/memory/weak_ptr.h"
#include "content/public/browser/frame_service_base.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "services/device/public/mojom/hid.mojom.h"
#include "third_party/blink/public/mojom/hid/hid.mojom.h"
......@@ -32,7 +33,7 @@ class HidService : public content::FrameServiceBase<blink::mojom::HidService> {
void RequestDevice(std::vector<blink::mojom::HidDeviceFilterPtr> filters,
RequestDeviceCallback callback) override;
void Connect(const std::string& device_guid,
device::mojom::HidConnectionClientPtr client,
mojo::PendingRemote<device::mojom::HidConnectionClient> client,
ConnectCallback callback) override;
private:
......
......@@ -172,8 +172,9 @@ TEST_F(HidServiceTest, OpenAndCloseHidConnection) {
device_info->guid = kTestGuid;
hid_manager()->AddDevice(std::move(device_info));
device::mojom::HidConnectionClientPtr hid_connection_client;
connection_client()->Bind(mojo::MakeRequest(&hid_connection_client));
mojo::PendingRemote<device::mojom::HidConnectionClient> hid_connection_client;
connection_client()->Bind(
hid_connection_client.InitWithNewPipeAndPassReceiver());
base::RunLoop run_loop;
device::mojom::HidConnectionPtr connection;
......
......@@ -170,7 +170,7 @@ void FakeFidoHidManager::GetDevices(GetDevicesCallback callback) {
void FakeFidoHidManager::Connect(
const std::string& device_guid,
mojom::HidConnectionClientPtr connection_client,
mojo::PendingRemote<mojom::HidConnectionClient> connection_client,
ConnectCallback callback) {
auto device_it = devices_.find(device_guid);
auto connection_it = connections_.find(device_guid);
......
......@@ -107,9 +107,10 @@ class FakeFidoHidManager : public device::mojom::HidManager {
device::mojom::HidManagerClientAssociatedPtrInfo client,
GetDevicesCallback callback) override;
void GetDevices(GetDevicesCallback callback) override;
void Connect(const std::string& device_guid,
mojom::HidConnectionClientPtr connection_client,
ConnectCallback callback) override;
void Connect(
const std::string& device_guid,
mojo::PendingRemote<mojom::HidConnectionClient> connection_client,
ConnectCallback callback) override;
void AddBinding(mojo::ScopedMessagePipeHandle handle);
void AddBinding2(device::mojom::HidManagerRequest request);
void AddDevice(device::mojom::HidDeviceInfoPtr device);
......
......@@ -176,7 +176,8 @@ FidoHidDevice::PendingTransaction::~PendingTransaction() = default;
void FidoHidDevice::Connect(
device::mojom::HidManager::ConnectCallback callback) {
DCHECK(hid_manager_);
hid_manager_->Connect(device_info_->guid, /*connection_client=*/nullptr,
hid_manager_->Connect(device_info_->guid,
mojo::PendingRemote<mojom::HidConnectionClient>(),
std::move(callback));
}
......
......@@ -1134,7 +1134,8 @@ void NintendoController::UpdateRightGamepadState(Gamepad& pad,
void NintendoController::Connect(mojom::HidManager::ConnectCallback callback) {
DCHECK(!is_composite_);
DCHECK(hid_manager_);
hid_manager_->Connect(device_info_->guid, /*connection_client=*/nullptr,
hid_manager_->Connect(device_info_->guid,
mojo::PendingRemote<mojom::HidConnectionClient>(),
std::move(callback));
}
......
......@@ -24,9 +24,11 @@
#include "extensions/common/permissions/usb_device_permission.h"
#include "mojo/public/cpp/bindings/callback_helpers.h"
#include "mojo/public/cpp/bindings/interface_request.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "services/device/public/cpp/hid/hid_device_filter.h"
#include "services/device/public/cpp/hid/hid_usage_and_page.h"
#include "services/device/public/mojom/constants.mojom.h"
#include "services/device/public/mojom/hid.mojom.h"
#include "services/service_manager/public/cpp/connector.h"
namespace hid = extensions::api::hid;
......@@ -171,9 +173,10 @@ void HidDeviceManager::Connect(const std::string& device_guid,
ConnectCallback callback) {
DCHECK(initialized_);
hid_manager_->Connect(device_guid, /*connection_client=*/nullptr,
mojo::WrapCallbackWithDefaultInvokeIfNotRun(
std::move(callback), nullptr));
hid_manager_->Connect(
device_guid, mojo::PendingRemote<device::mojom::HidConnectionClient>(),
mojo::WrapCallbackWithDefaultInvokeIfNotRun(std::move(callback),
nullptr));
}
bool HidDeviceManager::HasPermission(
......
......@@ -11,11 +11,11 @@ namespace device {
HidConnectionImpl::HidConnectionImpl(
scoped_refptr<device::HidConnection> connection,
mojom::HidConnectionClientPtr connection_client)
mojo::PendingRemote<mojom::HidConnectionClient> connection_client)
: hid_connection_(std::move(connection)) {
if (connection_client) {
hid_connection_->SetClient(this);
client_ = std::move(connection_client);
client_.Bind(std::move(connection_client));
}
}
......
......@@ -6,7 +6,7 @@
#define SERVICES_DEVICE_HID_HID_CONNECTION_IMPL_H_
#include "base/memory/ref_counted.h"
#include "mojo/public/cpp/bindings/interface_ptr.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/device/hid/hid_connection.h"
#include "services/device/public/mojom/hid.mojom.h"
......@@ -18,8 +18,9 @@ namespace device {
class HidConnectionImpl : public mojom::HidConnection,
public HidConnection::Client {
public:
HidConnectionImpl(scoped_refptr<device::HidConnection> connection,
mojom::HidConnectionClientPtr connection_client);
HidConnectionImpl(
scoped_refptr<device::HidConnection> connection,
mojo::PendingRemote<mojom::HidConnectionClient> connection_client);
~HidConnectionImpl() final;
// HidConnection::Client implementation:
......@@ -50,7 +51,7 @@ class HidConnectionImpl : public mojom::HidConnection,
void OnSendFeatureReport(SendFeatureReportCallback callback, bool success);
scoped_refptr<device::HidConnection> hid_connection_;
mojo::InterfacePtr<mojom::HidConnectionClient> client_;
mojo::Remote<mojom::HidConnectionClient> client_;
base::WeakPtrFactory<HidConnectionImpl> weak_factory_{this};
......
......@@ -156,10 +156,11 @@ class HidConnectionImplTest : public DeviceServiceTestBase {
}
void CreateHidConnection(bool with_connection_client) {
mojom::HidConnectionClientPtr hid_connection_client;
mojo::PendingRemote<mojom::HidConnectionClient> hid_connection_client;
if (with_connection_client) {
connection_client_ = std::make_unique<TestHidConnectionClient>();
connection_client_->Bind(mojo::MakeRequest(&hid_connection_client));
connection_client_->Bind(
hid_connection_client.InitWithNewPipeAndPassReceiver());
}
fake_connection_ = new FakeHidConnection(CreateTestDevice());
hid_connection_impl_ = std::make_unique<HidConnectionImpl>(
......
......@@ -68,9 +68,10 @@ void HidManagerImpl::CreateDeviceList(
clients_.AddPtr(std::move(client_ptr));
}
void HidManagerImpl::Connect(const std::string& device_guid,
mojom::HidConnectionClientPtr connection_client,
ConnectCallback callback) {
void HidManagerImpl::Connect(
const std::string& device_guid,
mojo::PendingRemote<mojom::HidConnectionClient> connection_client,
ConnectCallback callback) {
hid_service_->Connect(
device_guid,
base::AdaptCallbackForRepeating(base::BindOnce(
......@@ -80,7 +81,7 @@ void HidManagerImpl::Connect(const std::string& device_guid,
void HidManagerImpl::CreateConnection(
ConnectCallback callback,
mojom::HidConnectionClientPtr connection_client,
mojo::PendingRemote<mojom::HidConnectionClient> connection_client,
scoped_refptr<HidConnection> connection) {
if (!connection) {
std::move(callback).Run(nullptr);
......
......@@ -36,18 +36,20 @@ class HidManagerImpl : public mojom::HidManager, public HidService::Observer {
void GetDevicesAndSetClient(mojom::HidManagerClientAssociatedPtrInfo client,
GetDevicesCallback callback) override;
void GetDevices(GetDevicesCallback callback) override;
void Connect(const std::string& device_guid,
mojom::HidConnectionClientPtr connection_client,
ConnectCallback callback) override;
void Connect(
const std::string& device_guid,
mojo::PendingRemote<mojom::HidConnectionClient> connection_client,
ConnectCallback callback) override;
private:
void CreateDeviceList(GetDevicesCallback callback,
mojom::HidManagerClientAssociatedPtrInfo client,
std::vector<mojom::HidDeviceInfoPtr> devices);
void CreateConnection(ConnectCallback callback,
mojom::HidConnectionClientPtr connection_client,
scoped_refptr<HidConnection> connection);
void CreateConnection(
ConnectCallback callback,
mojo::PendingRemote<mojom::HidConnectionClient> connection_client,
scoped_refptr<HidConnection> connection);
// HidService::Observer:
void OnDeviceAdded(mojom::HidDeviceInfoPtr device_info) override;
......
......@@ -245,7 +245,8 @@ TEST_F(HidManagerTest, TestHidConnectionInterface) {
{
base::RunLoop run_loop;
hid_manager_->Connect(
device0->device_guid(), /*connection_client=*/nullptr,
device0->device_guid(),
mojo::PendingRemote<mojom::HidConnectionClient>(),
base::BindOnce(&OnConnect, run_loop.QuitClosure(), client.get()));
run_loop.Run();
}
......
......@@ -117,9 +117,10 @@ void FakeHidManager::GetDevices(GetDevicesCallback callback) {
std::move(callback).Run(std::move(device_list));
}
void FakeHidManager::Connect(const std::string& device_guid,
mojom::HidConnectionClientPtr connection_client,
ConnectCallback callback) {
void FakeHidManager::Connect(
const std::string& device_guid,
mojo::PendingRemote<mojom::HidConnectionClient> connection_client,
ConnectCallback callback) {
if (!base::Contains(devices_, device_guid)) {
std::move(callback).Run(nullptr);
return;
......
......@@ -11,6 +11,7 @@
#include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/interface_ptr_set.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "services/device/public/mojom/hid.mojom.h"
namespace device {
......@@ -47,9 +48,10 @@ class FakeHidManager : public mojom::HidManager {
void GetDevicesAndSetClient(mojom::HidManagerClientAssociatedPtrInfo client,
GetDevicesCallback callback) override;
void GetDevices(GetDevicesCallback callback) override;
void Connect(const std::string& device_guid,
mojom::HidConnectionClientPtr connection_client,
ConnectCallback callback) override;
void Connect(
const std::string& device_guid,
mojo::PendingRemote<mojom::HidConnectionClient> connection_client,
ConnectCallback callback) override;
mojom::HidDeviceInfoPtr CreateAndAddDevice(uint16_t vendor_id,
uint16_t product_id,
......
......@@ -323,7 +323,8 @@ interface HidManager {
// Opens a connection to a device by given guid. The callback will be run
// with null on failure. If a connection client is provided, it will be
// notified when input reports are received.
Connect(string device_guid, HidConnectionClient? connection_client)
Connect(string device_guid,
pending_remote<HidConnectionClient>? connection_client)
=> (HidConnection? connection);
};
......
......@@ -85,6 +85,6 @@ interface HidService {
// will be notified when an input report is received from the device.
// |connection| contains the opened connection, or nullptr if the device could
// not be opened.
Connect(string device_guid, device.mojom.HidConnectionClient client)
Connect(string device_guid, pending_remote<device.mojom.HidConnectionClient> client)
=> (device.mojom.HidConnection? connection);
};
......@@ -175,9 +175,10 @@ ScriptPromise HID::requestDevice(ScriptState* script_state,
return promise;
}
void HID::Connect(const String& device_guid,
device::mojom::blink::HidConnectionClientPtr client,
device::mojom::blink::HidManager::ConnectCallback callback) {
void HID::Connect(
const String& device_guid,
mojo::PendingRemote<device::mojom::blink::HidConnectionClient> client,
device::mojom::blink::HidManager::ConnectCallback callback) {
EnsureServiceConnection();
service_->Connect(device_guid, std::move(client), std::move(callback));
}
......@@ -230,8 +231,8 @@ void HID::EnsureServiceConnection() {
auto task_runner =
GetExecutionContext()->GetTaskRunner(TaskType::kMiscPlatformAPI);
GetExecutionContext()->GetInterfaceProvider()->GetInterface(
mojo::MakeRequest(&service_, task_runner));
service_.set_connection_error_handler(
service_.BindNewPipeAndPassReceiver(task_runner));
service_.set_disconnect_handler(
WTF::Bind(&HID::OnServiceConnectionError, WrapWeakPersistent(this)));
}
......
......@@ -5,6 +5,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_HID_HID_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_HID_HID_H_
#include "mojo/public/cpp/bindings/remote.h"
#include "services/device/public/mojom/hid.mojom-blink.h"
#include "third_party/blink/public/mojom/hid/hid.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
......@@ -40,7 +41,8 @@ class HID : public EventTargetWithInlineData, public ContextLifecycleObserver {
ScriptPromise requestDevice(ScriptState*, const HIDDeviceRequestOptions*);
void Connect(const String& device_guid,
device::mojom::blink::HidConnectionClientPtr connection_client,
mojo::PendingRemote<device::mojom::blink::HidConnectionClient>
connection_client,
device::mojom::blink::HidManager::ConnectCallback callback);
void Trace(blink::Visitor*) override;
......@@ -64,7 +66,7 @@ class HID : public EventTargetWithInlineData, public ContextLifecycleObserver {
void FinishRequestDevice(ScriptPromiseResolver*,
device::mojom::blink::HidDeviceInfoPtr);
mojom::blink::HidServicePtr service_;
mojo::Remote<mojom::blink::HidService> service_;
HeapHashSet<Member<ScriptPromiseResolver>> get_devices_promises_;
HeapHashSet<Member<ScriptPromiseResolver>> request_device_promises_;
HeapHashMap<String, WeakMember<HIDDevice>> device_cache_;
......
......@@ -87,8 +87,7 @@ HIDDevice::HIDDevice(HID* parent,
ExecutionContext* context)
: ContextLifecycleObserver(context),
parent_(parent),
device_info_(std::move(info)),
binding_(this) {
device_info_(std::move(info)) {
DCHECK(device_info_);
for (const auto& collection : device_info_->collections) {
// Omit information about top-level collections with protected usages.
......@@ -150,8 +149,8 @@ ScriptPromise HIDDevice::open(ScriptState* script_state) {
return promise;
}
device::mojom::blink::HidConnectionClientPtr client;
binding_.Bind(mojo::MakeRequest(&client));
mojo::PendingRemote<device::mojom::blink::HidConnectionClient> client;
receiver_.Bind(client.InitWithNewPipeAndPassReceiver());
device_state_change_in_progress_ = true;
device_requests_.insert(resolver);
......@@ -243,8 +242,7 @@ ScriptPromise HIDDevice::receiveFeatureReport(ScriptState* script_state,
void HIDDevice::ContextDestroyed(ExecutionContext*) {
connection_.reset();
device_requests_.clear();
if (binding_)
binding_.Close();
receiver_.reset();
}
void HIDDevice::Trace(blink::Visitor* visitor) {
......@@ -259,8 +257,7 @@ void HIDDevice::Trace(blink::Visitor* visitor) {
void HIDDevice::Dispose() {
// The connection client binding holds a raw pointer to this object which must
// be released when it becomes garbage.
if (binding_)
binding_.Close();
receiver_.reset();
}
bool HIDDevice::EnsureNoDeviceChangeInProgress(
......
......@@ -5,7 +5,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_HID_HID_DEVICE_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_HID_HID_DEVICE_H_
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "services/device/public/mojom/hid.mojom-blink.h"
#include "third_party/blink/public/mojom/hid/hid.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/array_buffer_or_array_buffer_view.h"
......@@ -96,7 +96,7 @@ class MODULES_EXPORT HIDDevice
Member<HID> parent_;
device::mojom::blink::HidDeviceInfoPtr device_info_;
device::mojom::blink::HidConnectionPtr connection_;
mojo::Binding<device::mojom::blink::HidConnectionClient> binding_;
mojo::Receiver<device::mojom::blink::HidConnectionClient> receiver_{this};
HeapHashSet<Member<ScriptPromiseResolver>> device_requests_;
HeapVector<Member<HIDCollectionInfo>> collections_;
bool device_state_change_in_progress_ = false;
......
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