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