summaryrefslogtreecommitdiff
path: root/chromium/device
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-11-20 10:33:36 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-11-22 11:45:12 +0000
commitbe59a35641616a4cf23c4a13fa0632624b021c1b (patch)
tree9da183258bdf9cc413f7562079d25ace6955467f /chromium/device
parentd702e4b6a64574e97fc7df8fe3238cde70242080 (diff)
downloadqtwebengine-chromium-be59a35641616a4cf23c4a13fa0632624b021c1b.tar.gz
BASELINE: Update Chromium to 62.0.3202.101
Change-Id: I2d5eca8117600df6d331f6166ab24d943d9814ac Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/device')
-rw-r--r--chromium/device/BUILD.gn2
-rw-r--r--chromium/device/bluetooth/BUILD.gn4
-rw-r--r--chromium/device/bluetooth/adapter.cc2
-rw-r--r--chromium/device/bluetooth/adapter_factory.cc4
-rw-r--r--chromium/device/bluetooth/bluetooth_adapter.cc2
-rw-r--r--chromium/device/bluetooth/bluetooth_adapter.h5
-rw-r--r--chromium/device/bluetooth/bluetooth_adapter_android.cc5
-rw-r--r--chromium/device/bluetooth/bluetooth_adapter_android.h3
-rw-r--r--chromium/device/bluetooth/bluetooth_adapter_factory.cc20
-rw-r--r--chromium/device/bluetooth/bluetooth_adapter_factory.h2
-rw-r--r--chromium/device/bluetooth/bluetooth_adapter_mac.h26
-rw-r--r--chromium/device/bluetooth/bluetooth_adapter_mac.mm27
-rw-r--r--chromium/device/bluetooth/bluetooth_adapter_mac_metrics.h58
-rw-r--r--chromium/device/bluetooth/bluetooth_adapter_mac_metrics.mm200
-rw-r--r--chromium/device/bluetooth/bluetooth_adapter_mac_unittest.mm14
-rw-r--r--chromium/device/bluetooth/bluetooth_adapter_win_unittest.cc8
-rw-r--r--chromium/device/bluetooth/bluetooth_advertisement.h3
-rw-r--r--chromium/device/bluetooth/bluetooth_advertisement_unittest.cc8
-rw-r--r--chromium/device/bluetooth/bluetooth_device.cc2
-rw-r--r--chromium/device/bluetooth/bluetooth_device.h3
-rw-r--r--chromium/device/bluetooth/bluetooth_device_android.cc5
-rw-r--r--chromium/device/bluetooth/bluetooth_device_android.h3
-rw-r--r--chromium/device/bluetooth/bluetooth_device_win.cc4
-rw-r--r--chromium/device/bluetooth/bluetooth_device_win_unittest.cc4
-rw-r--r--chromium/device/bluetooth/bluetooth_discovery_filter.cc2
-rw-r--r--chromium/device/bluetooth/bluetooth_discovery_session.cc23
-rw-r--r--chromium/device/bluetooth/bluetooth_discovery_session.h5
-rw-r--r--chromium/device/bluetooth/bluetooth_discovery_session_outcome.h2
-rw-r--r--chromium/device/bluetooth/bluetooth_local_gatt_characteristic.cc3
-rw-r--r--chromium/device/bluetooth/bluetooth_local_gatt_descriptor.cc3
-rw-r--r--chromium/device/bluetooth/bluetooth_local_gatt_service.cc4
-rw-r--r--chromium/device/bluetooth/bluetooth_low_energy_device_mac.mm5
-rw-r--r--chromium/device/bluetooth/bluetooth_low_energy_discovery_manager_mac.mm4
-rw-r--r--chromium/device/bluetooth/bluetooth_low_energy_win.cc2
-rw-r--r--chromium/device/bluetooth/bluetooth_low_energy_win_fake.cc8
-rw-r--r--chromium/device/bluetooth/bluetooth_remote_gatt_characteristic_android.cc6
-rw-r--r--chromium/device/bluetooth/bluetooth_remote_gatt_characteristic_android.h3
-rw-r--r--chromium/device/bluetooth/bluetooth_remote_gatt_characteristic_mac.mm4
-rw-r--r--chromium/device/bluetooth/bluetooth_remote_gatt_descriptor_android.cc6
-rw-r--r--chromium/device/bluetooth/bluetooth_remote_gatt_descriptor_android.h3
-rw-r--r--chromium/device/bluetooth/bluetooth_remote_gatt_descriptor_mac.mm3
-rw-r--r--chromium/device/bluetooth/bluetooth_remote_gatt_service_android.cc6
-rw-r--r--chromium/device/bluetooth/bluetooth_remote_gatt_service_android.h3
-rw-r--r--chromium/device/bluetooth/bluetooth_service_record_win.cc4
-rw-r--r--chromium/device/bluetooth/bluetooth_task_manager_win.cc10
-rw-r--r--chromium/device/bluetooth/bluez/bluetooth_adapter_bluez.cc31
-rw-r--r--chromium/device/bluetooth/bluez/bluetooth_adapter_bluez.h4
-rw-r--r--chromium/device/bluetooth/bluez/bluetooth_adapter_profile_bluez_unittest.cc3
-rw-r--r--chromium/device/bluetooth/bluez/bluetooth_advertisement_bluez_unittest.cc12
-rw-r--r--chromium/device/bluetooth/bluez/bluetooth_bluez_unittest.cc37
-rw-r--r--chromium/device/bluetooth/bluez/bluetooth_gatt_bluez_unittest.cc4
-rw-r--r--chromium/device/bluetooth/bluez/bluetooth_service_attribute_value_bluez.cc4
-rw-r--r--chromium/device/bluetooth/bluez/bluetooth_service_attribute_value_bluez_unittest.cc20
-rw-r--r--chromium/device/bluetooth/bluez/bluetooth_service_record_bluez_unittest.cc2
-rw-r--r--chromium/device/bluetooth/bluez/bluetooth_socket_bluez_unittest.cc6
-rw-r--r--chromium/device/bluetooth/dbus/bluetooth_device_client.cc18
-rw-r--r--chromium/device/bluetooth/dbus/bluetooth_gatt_application_service_provider.cc6
-rw-r--r--chromium/device/bluetooth/dbus/bluetooth_gatt_application_service_provider_unittest.cc6
-rw-r--r--chromium/device/bluetooth/dbus/bluetooth_le_advertisement_service_provider.cc4
-rw-r--r--chromium/device/bluetooth/dbus/fake_bluetooth_device_client.cc12
-rw-r--r--chromium/device/bluetooth/dbus/fake_bluetooth_input_client.cc2
-rw-r--r--chromium/device/bluetooth/dbus/fake_bluetooth_media_transport_client.cc2
-rw-r--r--chromium/device/bluetooth/device_unittest.cc12
-rw-r--r--chromium/device/bluetooth/public/interfaces/test/fake_bluetooth.mojom19
-rw-r--r--chromium/device/gamepad/BUILD.gn2
-rw-r--r--chromium/device/gamepad/gamepad_monitor.cc2
-rw-r--r--chromium/device/gamepad/gamepad_monitor.h5
-rw-r--r--chromium/device/gamepad/gamepad_platform_data_fetcher_android.cc5
-rw-r--r--chromium/device/gamepad/gamepad_platform_data_fetcher_android.h3
-rw-r--r--chromium/device/gamepad/gamepad_standard_mappings_linux.cc59
-rw-r--r--chromium/device/gamepad/gamepad_standard_mappings_mac.mm27
-rw-r--r--chromium/device/gamepad/public/interfaces/gamepad_struct_traits.cc33
-rw-r--r--chromium/device/gamepad/public/interfaces/gamepad_struct_traits.h16
-rw-r--r--chromium/device/geolocation/BUILD.gn2
-rw-r--r--chromium/device/geolocation/geolocation_config.cc2
-rw-r--r--chromium/device/geolocation/geolocation_config.h2
-rw-r--r--chromium/device/geolocation/geolocation_impl.cc5
-rw-r--r--chromium/device/geolocation/geolocation_impl.h6
-rw-r--r--chromium/device/geolocation/geolocation_provider_impl.cc2
-rw-r--r--chromium/device/geolocation/geolocation_provider_impl.h2
-rw-r--r--chromium/device/geolocation/geolocation_provider_impl_unittest.cc2
-rw-r--r--chromium/device/geolocation/location_api_adapter_android.cc5
-rw-r--r--chromium/device/geolocation/location_api_adapter_android.h3
-rw-r--r--chromium/device/geolocation/location_arbitrator.cc5
-rw-r--r--chromium/device/geolocation/network_location_provider_unittest.cc1
-rw-r--r--chromium/device/geolocation/network_location_request.cc6
-rw-r--r--chromium/device/geolocation/public/interfaces/geolocation.mojom17
-rw-r--r--chromium/device/geolocation/wifi_data_provider_chromeos_unittest.cc11
-rw-r--r--chromium/device/geolocation/wifi_data_provider_linux.cc2
-rw-r--r--chromium/device/geolocation/wifi_data_provider_mac.mm4
-rw-r--r--chromium/device/geolocation/wifi_data_provider_win.cc4
-rw-r--r--chromium/device/hid/BUILD.gn6
-rw-r--r--chromium/device/hid/hid_connection.cc41
-rw-r--r--chromium/device/hid/hid_connection.h26
-rw-r--r--chromium/device/hid/hid_connection_linux.cc84
-rw-r--r--chromium/device/hid/hid_connection_linux.h8
-rw-r--r--chromium/device/hid/hid_connection_mac.cc69
-rw-r--r--chromium/device/hid/hid_connection_mac.h14
-rw-r--r--chromium/device/hid/hid_connection_unittest.cc60
-rw-r--r--chromium/device/hid/hid_connection_win.cc57
-rw-r--r--chromium/device/hid/hid_connection_win.h14
-rw-r--r--chromium/device/hid/hid_device_filter.cc13
-rw-r--r--chromium/device/hid/hid_device_filter.h7
-rw-r--r--chromium/device/hid/hid_device_filter_unittest.cc29
-rw-r--r--chromium/device/hid/hid_device_info.cc69
-rw-r--r--chromium/device/hid/hid_device_info.h76
-rw-r--r--chromium/device/hid/hid_device_info_linux.cc30
-rw-r--r--chromium/device/hid/hid_device_info_linux.h35
-rw-r--r--chromium/device/hid/hid_service.cc100
-rw-r--r--chromium/device/hid/hid_service.h39
-rw-r--r--chromium/device/hid/hid_service_linux.cc33
-rw-r--r--chromium/device/hid/hid_service_linux.h3
-rw-r--r--chromium/device/hid/hid_service_mac.cc18
-rw-r--r--chromium/device/hid/hid_service_mac.h3
-rw-r--r--chromium/device/hid/hid_service_unittest.cc3
-rw-r--r--chromium/device/hid/hid_service_win.cc16
-rw-r--r--chromium/device/hid/hid_service_win.h3
-rw-r--r--chromium/device/hid/hid_usage_and_page.h1
-rw-r--r--chromium/device/hid/mock_hid_service.cc13
-rw-r--r--chromium/device/hid/mock_hid_service.h11
-rw-r--r--chromium/device/hid/public/interfaces/BUILD.gn11
-rw-r--r--chromium/device/hid/public/interfaces/OWNERS8
-rw-r--r--chromium/device/hid/public/interfaces/hid.mojom72
-rw-r--r--chromium/device/hid/public/interfaces/hid.typemap22
-rw-r--r--chromium/device/hid/public/interfaces/hid_struct_traits.cc226
-rw-r--r--chromium/device/hid/public/interfaces/hid_struct_traits.h55
-rw-r--r--chromium/device/hid/public/interfaces/typemaps.gni5
-rw-r--r--chromium/device/sensors/BUILD.gn8
-rw-r--r--chromium/device/sensors/data_fetcher_shared_memory_fuchsia.cc29
-rw-r--r--chromium/device/sensors/device_sensor_host.h2
-rw-r--r--chromium/device/sensors/sensor_manager_android.cc4
-rw-r--r--chromium/device/sensors/sensor_manager_android.h2
-rw-r--r--chromium/device/sensors/sensor_manager_android_unittest.cc5
-rw-r--r--chromium/device/serial/BUILD.gn133
-rw-r--r--chromium/device/serial/DEPS1
-rw-r--r--chromium/device/serial/buffer.cc30
-rw-r--r--chromium/device/serial/buffer.h27
-rw-r--r--chromium/device/serial/serial.mojom85
-rw-r--r--chromium/device/serial/serial_device_enumerator.h4
-rw-r--r--chromium/device/serial/serial_device_enumerator_linux.cc7
-rw-r--r--chromium/device/serial/serial_device_enumerator_linux.h2
-rw-r--r--chromium/device/serial/serial_device_enumerator_mac.cc21
-rw-r--r--chromium/device/serial/serial_device_enumerator_mac.h2
-rw-r--r--chromium/device/serial/serial_device_enumerator_win.cc19
-rw-r--r--chromium/device/serial/serial_device_enumerator_win.h2
-rw-r--r--chromium/device/serial/serial_io_handler.cc82
-rw-r--r--chromium/device/serial/serial_io_handler.h46
-rw-r--r--chromium/device/serial/serial_io_handler_posix.cc70
-rw-r--r--chromium/device/serial/serial_io_handler_posix.h8
-rw-r--r--chromium/device/serial/serial_io_handler_win.cc102
-rw-r--r--chromium/device/serial/serial_io_handler_win.h6
-rw-r--r--chromium/device/serial/test_serial_io_handler.cc46
-rw-r--r--chromium/device/serial/test_serial_io_handler.h31
-rw-r--r--chromium/device/u2f/mock_u2f_device.cc8
-rw-r--r--chromium/device/u2f/u2f_apdu_command.cc10
-rw-r--r--chromium/device/u2f/u2f_apdu_response.cc2
-rw-r--r--chromium/device/u2f/u2f_apdu_unittest.cc4
-rw-r--r--chromium/device/u2f/u2f_hid_device.cc11
-rw-r--r--chromium/device/u2f/u2f_hid_device.h6
-rw-r--r--chromium/device/u2f/u2f_hid_device_unittest.cc36
-rw-r--r--chromium/device/u2f/u2f_message.cc8
-rw-r--r--chromium/device/u2f/u2f_message_unittest.cc8
-rw-r--r--chromium/device/u2f/u2f_packet.cc4
-rw-r--r--chromium/device/u2f/u2f_register.cc2
-rw-r--r--chromium/device/u2f/u2f_request.cc29
-rw-r--r--chromium/device/u2f/u2f_request.h8
-rw-r--r--chromium/device/u2f/u2f_request_unittest.cc56
-rw-r--r--chromium/device/u2f/u2f_sign.cc2
-rw-r--r--chromium/device/usb/BUILD.gn2
-rw-r--r--chromium/device/usb/fake_usb_device_handle.cc28
-rw-r--r--chromium/device/usb/fake_usb_device_handle.h38
-rw-r--r--chromium/device/usb/mock_usb_device.h3
-rw-r--r--chromium/device/usb/mock_usb_device_handle.h110
-rw-r--r--chromium/device/usb/mojo/device_impl.cc157
-rw-r--r--chromium/device/usb/mojo/device_impl.h48
-rw-r--r--chromium/device/usb/mojo/device_impl_unittest.cc158
-rw-r--r--chromium/device/usb/mojo/device_manager_impl.cc12
-rw-r--r--chromium/device/usb/mojo/device_manager_impl.h4
-rw-r--r--chromium/device/usb/public/interfaces/BUILD.gn3
-rw-r--r--chromium/device/usb/usb_descriptors.cc83
-rw-r--r--chromium/device/usb/usb_descriptors.h6
-rw-r--r--chromium/device/usb/usb_descriptors_unittest.cc60
-rw-r--r--chromium/device/usb/usb_device.cc8
-rw-r--r--chromium/device/usb/usb_device.h10
-rw-r--r--chromium/device/usb/usb_device_android.cc14
-rw-r--r--chromium/device/usb/usb_device_android.h4
-rw-r--r--chromium/device/usb/usb_device_handle.h28
-rw-r--r--chromium/device/usb/usb_device_handle_impl.cc301
-rw-r--r--chromium/device/usb/usb_device_handle_impl.h70
-rw-r--r--chromium/device/usb/usb_device_handle_unittest.cc9
-rw-r--r--chromium/device/usb/usb_device_handle_usbfs.cc223
-rw-r--r--chromium/device/usb/usb_device_handle_usbfs.h49
-rw-r--r--chromium/device/usb/usb_device_handle_win.cc79
-rw-r--r--chromium/device/usb/usb_device_handle_win.h42
-rw-r--r--chromium/device/usb/usb_device_impl.cc20
-rw-r--r--chromium/device/usb/usb_device_impl.h6
-rw-r--r--chromium/device/usb/usb_device_linux.cc42
-rw-r--r--chromium/device/usb/usb_device_linux.h12
-rw-r--r--chromium/device/usb/usb_device_win.cc31
-rw-r--r--chromium/device/usb/usb_device_win.h10
-rw-r--r--chromium/device/usb/usb_service_android.cc5
-rw-r--r--chromium/device/usb/usb_service_android.h3
-rw-r--r--chromium/device/usb/usb_service_linux.cc2
-rw-r--r--chromium/device/usb/usb_service_win.cc2
-rw-r--r--chromium/device/usb/webusb_descriptors_unittest.cc18
-rw-r--r--chromium/device/vr/android/gvr/cardboard_gamepad_data_fetcher.cc2
-rw-r--r--chromium/device/vr/android/gvr/cardboard_gamepad_data_provider.h1
-rw-r--r--chromium/device/vr/android/gvr/gvr_delegate.cc1
-rw-r--r--chromium/device/vr/android/gvr/gvr_delegate.h14
-rw-r--r--chromium/device/vr/android/gvr/gvr_delegate_provider.h8
-rw-r--r--chromium/device/vr/android/gvr/gvr_device.cc45
-rw-r--r--chromium/device/vr/android/gvr/gvr_device.h13
-rw-r--r--chromium/device/vr/android/gvr/gvr_device_provider.cc26
-rw-r--r--chromium/device/vr/android/gvr/gvr_device_provider.h7
-rw-r--r--chromium/device/vr/android/gvr/gvr_gamepad_data_fetcher.cc4
-rw-r--r--chromium/device/vr/android/gvr/gvr_gamepad_data_provider.h6
-rw-r--r--chromium/device/vr/openvr/openvr_device.cc6
-rw-r--r--chromium/device/vr/openvr/openvr_device.h1
-rw-r--r--chromium/device/vr/openvr/openvr_gamepad_data_fetcher.cc2
-rw-r--r--chromium/device/vr/vr_device.h2
-rw-r--r--chromium/device/vr/vr_device_manager.cc9
-rw-r--r--chromium/device/vr/vr_device_manager.h15
-rw-r--r--chromium/device/vr/vr_display_impl.cc16
-rw-r--r--chromium/device/vr/vr_display_impl.h4
-rw-r--r--chromium/device/vr/vr_display_impl_unittest.cc2
-rw-r--r--chromium/device/vr/vr_service.mojom9
-rw-r--r--chromium/device/vr/vr_service_impl.cc4
227 files changed, 2935 insertions, 2170 deletions
diff --git a/chromium/device/BUILD.gn b/chromium/device/BUILD.gn
index eb4f649400b..995b4a32f9e 100644
--- a/chromium/device/BUILD.gn
+++ b/chromium/device/BUILD.gn
@@ -239,7 +239,7 @@ test("device_unittests") {
]
}
- if (enable_vr) {
+ if (enable_vr && is_android) {
sources += [
"vr/vr_device_manager_unittest.cc",
"vr/vr_display_impl_unittest.cc",
diff --git a/chromium/device/bluetooth/BUILD.gn b/chromium/device/bluetooth/BUILD.gn
index 304ac674352..e0d141b2df2 100644
--- a/chromium/device/bluetooth/BUILD.gn
+++ b/chromium/device/bluetooth/BUILD.gn
@@ -68,8 +68,6 @@ source_set("fake_bluetooth") {
component("bluetooth") {
sources = [
- "android/bluetooth_jni_registrar.cc",
- "android/bluetooth_jni_registrar.h",
"android/wrappers.cc",
"android/wrappers.h",
"bluetooth_adapter.cc",
@@ -82,6 +80,8 @@ component("bluetooth") {
"bluetooth_adapter_factory_wrapper.h",
"bluetooth_adapter_mac.h",
"bluetooth_adapter_mac.mm",
+ "bluetooth_adapter_mac_metrics.h",
+ "bluetooth_adapter_mac_metrics.mm",
"bluetooth_adapter_win.cc",
"bluetooth_adapter_win.h",
"bluetooth_advertisement.cc",
diff --git a/chromium/device/bluetooth/adapter.cc b/chromium/device/bluetooth/adapter.cc
index fb1f99988a1..bd8883d9fbd 100644
--- a/chromium/device/bluetooth/adapter.cc
+++ b/chromium/device/bluetooth/adapter.cc
@@ -149,7 +149,7 @@ void Adapter::OnStartDiscoverySession(
std::unique_ptr<device::BluetoothDiscoverySession> session) {
mojom::DiscoverySessionPtr session_ptr;
mojo::MakeStrongBinding(
- base::MakeUnique<DiscoverySession>(std::move(session)),
+ std::make_unique<DiscoverySession>(std::move(session)),
mojo::MakeRequest(&session_ptr));
std::move(callback).Run(std::move(session_ptr));
}
diff --git a/chromium/device/bluetooth/adapter_factory.cc b/chromium/device/bluetooth/adapter_factory.cc
index f334779b7ad..81536500220 100644
--- a/chromium/device/bluetooth/adapter_factory.cc
+++ b/chromium/device/bluetooth/adapter_factory.cc
@@ -17,7 +17,7 @@ AdapterFactory::~AdapterFactory() {}
// static
void AdapterFactory::Create(mojom::AdapterFactoryRequest request) {
- mojo::MakeStrongBinding(base::MakeUnique<AdapterFactory>(),
+ mojo::MakeStrongBinding(std::make_unique<AdapterFactory>(),
std::move(request));
}
@@ -35,7 +35,7 @@ void AdapterFactory::OnGetAdapter(
GetAdapterCallback callback,
scoped_refptr<device::BluetoothAdapter> adapter) {
mojom::AdapterPtr adapter_ptr;
- mojo::MakeStrongBinding(base::MakeUnique<Adapter>(adapter),
+ mojo::MakeStrongBinding(std::make_unique<Adapter>(adapter),
mojo::MakeRequest(&adapter_ptr));
std::move(callback).Run(std::move(adapter_ptr));
}
diff --git a/chromium/device/bluetooth/bluetooth_adapter.cc b/chromium/device/bluetooth/bluetooth_adapter.cc
index 9153dc58aac..49cab45baf4 100644
--- a/chromium/device/bluetooth/bluetooth_adapter.cc
+++ b/chromium/device/bluetooth/bluetooth_adapter.cc
@@ -38,7 +38,7 @@ base::WeakPtr<BluetoothAdapter> BluetoothAdapter::GetWeakPtrForTesting() {
return weak_ptr_factory_.GetWeakPtr();
}
-#if defined(OS_CHROMEOS) || defined(OS_LINUX)
+#if defined(OS_LINUX)
void BluetoothAdapter::Shutdown() {
NOTIMPLEMENTED();
}
diff --git a/chromium/device/bluetooth/bluetooth_adapter.h b/chromium/device/bluetooth/bluetooth_adapter.h
index bdefc09ba3b..ac3e19b1fcd 100644
--- a/chromium/device/bluetooth/bluetooth_adapter.h
+++ b/chromium/device/bluetooth/bluetooth_adapter.h
@@ -117,6 +117,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapter
BluetoothDevice* device,
const std::string& old_address) {}
+// TODO(crbug.com/732991): Update comment and fix redundant #ifs throughout.
#if defined(OS_CHROMEOS) || defined(OS_LINUX)
// This function is implemented for ChromeOS only, and the support for
// Android, MaxOS and Windows should be added on demand in the future.
@@ -262,7 +263,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapter
// Returns a weak pointer to an existing adapter for testing purposes only.
base::WeakPtr<BluetoothAdapter> GetWeakPtrForTesting();
-#if defined(OS_CHROMEOS) || defined(OS_LINUX)
+#if defined(OS_LINUX)
// Shutdown the adapter: tear down and clean up all objects owned by
// BluetoothAdapter. After this call, the BluetoothAdapter will behave as if
// no Bluetooth controller exists in the local system. |IsPresent| will return
@@ -444,7 +445,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapter
const CreateAdvertisementCallback& callback,
const AdvertisementErrorCallback& error_callback) = 0;
-#if defined(OS_CHROMEOS) || defined(OS_LINUX)
+#if defined(OS_LINUX)
// Sets the interval between two consecutive advertisements. Valid ranges
// for the interval are from 20ms to 10.24 seconds, with min <= max.
// Note: This is a best effort. The actual interval may vary non-trivially
diff --git a/chromium/device/bluetooth/bluetooth_adapter_android.cc b/chromium/device/bluetooth/bluetooth_adapter_android.cc
index 191abadf88c..e3aa67f61ad 100644
--- a/chromium/device/bluetooth/bluetooth_adapter_android.cc
+++ b/chromium/device/bluetooth/bluetooth_adapter_android.cc
@@ -61,11 +61,6 @@ base::WeakPtr<BluetoothAdapterAndroid> BluetoothAdapterAndroid::Create(
return adapter->weak_ptr_factory_.GetWeakPtr();
}
-// static
-bool BluetoothAdapterAndroid::RegisterJNI(JNIEnv* env) {
- return RegisterNativesImpl(env); // Generated in BluetoothAdapter_jni.h
-}
-
std::string BluetoothAdapterAndroid::GetAddress() const {
return ConvertJavaStringToUTF8(Java_ChromeBluetoothAdapter_getAddress(
AttachCurrentThread(), j_adapter_));
diff --git a/chromium/device/bluetooth/bluetooth_adapter_android.h b/chromium/device/bluetooth/bluetooth_adapter_android.h
index 7ebb5055a87..d6c2ba3b070 100644
--- a/chromium/device/bluetooth/bluetooth_adapter_android.h
+++ b/chromium/device/bluetooth/bluetooth_adapter_android.h
@@ -47,9 +47,6 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterAndroid final
const base::android::JavaRef<jobject>&
bluetooth_adapter_wrapper); // Java Type: bluetoothAdapterWrapper
- // Register C++ methods exposed to Java using JNI.
- static bool RegisterJNI(JNIEnv* env);
-
// BluetoothAdapter:
std::string GetAddress() const override;
std::string GetName() const override;
diff --git a/chromium/device/bluetooth/bluetooth_adapter_factory.cc b/chromium/device/bluetooth/bluetooth_adapter_factory.cc
index cee5e1dce10..bde11f01f6e 100644
--- a/chromium/device/bluetooth/bluetooth_adapter_factory.cc
+++ b/chromium/device/bluetooth/bluetooth_adapter_factory.cc
@@ -38,7 +38,7 @@ static base::LazyInstance<BluetoothAdapterFactory>::Leaky g_singleton =
base::LazyInstance<base::WeakPtr<BluetoothAdapter>>::Leaky default_adapter =
LAZY_INSTANCE_INITIALIZER;
-#if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_CHROMEOS)
+#if defined(OS_WIN) || defined(OS_LINUX)
typedef std::vector<BluetoothAdapterFactory::AdapterCallback>
AdapterCallbackList;
@@ -59,7 +59,7 @@ void RunAdapterCallbacks() {
}
adapter_callbacks.Get().clear();
}
-#endif // defined(OS_WIN) || defined(OS_LINUX) || defined(OS_CHROMEOS)
+#endif // defined(OS_WIN) || defined(OS_LINUX)
} // namespace
@@ -76,8 +76,8 @@ bool BluetoothAdapterFactory::IsBluetoothSupported() {
// instance even on platforms that would otherwise not support it.
if (default_adapter.Get())
return true;
-#if defined(OS_ANDROID) || defined(OS_CHROMEOS) || defined(OS_WIN) || \
- defined(OS_LINUX) || defined(OS_MACOSX)
+#if defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_LINUX) || \
+ defined(OS_MACOSX)
return true;
#else
return false;
@@ -99,7 +99,7 @@ bool BluetoothAdapterFactory::IsLowEnergySupported() {
return base::win::GetVersion() >= base::win::VERSION_WIN10;
#elif defined(OS_MACOSX)
return base::mac::IsAtLeastOS10_10();
-#elif defined(OS_LINUX) || defined(OS_CHROMEOS)
+#elif defined(OS_LINUX)
return true;
#else
return false;
@@ -110,7 +110,7 @@ bool BluetoothAdapterFactory::IsLowEnergySupported() {
void BluetoothAdapterFactory::GetAdapter(const AdapterCallback& callback) {
DCHECK(IsBluetoothSupported());
-#if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_CHROMEOS)
+#if defined(OS_WIN) || defined(OS_LINUX)
if (!default_adapter.Get()) {
default_adapter.Get() =
BluetoothAdapter::CreateAdapter(base::Bind(&RunAdapterCallbacks));
@@ -119,20 +119,20 @@ void BluetoothAdapterFactory::GetAdapter(const AdapterCallback& callback) {
if (!default_adapter.Get()->IsInitialized())
adapter_callbacks.Get().push_back(callback);
-#else // !defined(OS_WIN) && !defined(OS_LINUX) && !defined(OS_CHROMEOS)
+#else // !defined(OS_WIN) && !defined(OS_LINUX)
if (!default_adapter.Get()) {
default_adapter.Get() =
BluetoothAdapter::CreateAdapter(BluetoothAdapter::InitCallback());
}
DCHECK(default_adapter.Get()->IsInitialized());
-#endif // defined(OS_WIN) || defined(OS_LINUX) || defined(OS_CHROMEOS)
+#endif // defined(OS_WIN) || defined(OS_LINUX)
if (default_adapter.Get()->IsInitialized())
callback.Run(scoped_refptr<BluetoothAdapter>(default_adapter.Get().get()));
}
-#if defined(OS_CHROMEOS) || defined(OS_LINUX)
+#if defined(OS_LINUX)
// static
void BluetoothAdapterFactory::Shutdown() {
if (default_adapter.Get())
@@ -163,7 +163,7 @@ BluetoothAdapterFactory::GlobalValuesForTesting::GetWeakPtr() {
std::unique_ptr<BluetoothAdapterFactory::GlobalValuesForTesting>
BluetoothAdapterFactory::InitGlobalValuesForTesting() {
- auto v = base::MakeUnique<BluetoothAdapterFactory::GlobalValuesForTesting>();
+ auto v = std::make_unique<BluetoothAdapterFactory::GlobalValuesForTesting>();
values_for_testing_ = v->GetWeakPtr();
return v;
}
diff --git a/chromium/device/bluetooth/bluetooth_adapter_factory.h b/chromium/device/bluetooth/bluetooth_adapter_factory.h
index 16f845703af..7217c2f7578 100644
--- a/chromium/device/bluetooth/bluetooth_adapter_factory.h
+++ b/chromium/device/bluetooth/bluetooth_adapter_factory.h
@@ -52,7 +52,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterFactory {
// use.
static void GetAdapter(const AdapterCallback& callback);
-#if defined(OS_CHROMEOS) || defined(OS_LINUX)
+#if defined(OS_LINUX)
// Calls |BluetoothAdapter::Shutdown| on the adapter if
// present.
static void Shutdown();
diff --git a/chromium/device/bluetooth/bluetooth_adapter_mac.h b/chromium/device/bluetooth/bluetooth_adapter_mac.h
index 52b1634a364..fae1f0188bc 100644
--- a/chromium/device/bluetooth/bluetooth_adapter_mac.h
+++ b/chromium/device/bluetooth/bluetooth_adapter_mac.h
@@ -29,25 +29,6 @@
@class NSArray;
@class NSDate;
-#if !defined(MAC_OS_X_VERSION_10_13)
-
-// The 10.13 SDK deprecates the CBCentralManagerState enum. When building
-// against older SDKs, define the new enum in terms of the deprecated one.
-using CBManagerState = CBCentralManagerState;
-constexpr CBManagerState CBManagerStateUnknown = CBCentralManagerStateUnknown;
-constexpr CBManagerState CBManagerStateResetting =
- CBCentralManagerStateResetting;
-constexpr CBManagerState CBManagerStateUnsupported =
- CBCentralManagerStateUnsupported;
-constexpr CBManagerState CBManagerStateUnauthorized =
- CBCentralManagerStateUnauthorized;
-constexpr CBManagerState CBManagerStatePoweredOff =
- CBCentralManagerStatePoweredOff;
-constexpr CBManagerState CBManagerStatePoweredOn =
- CBCentralManagerStatePoweredOn;
-
-#endif // MAC_OS_X_VERSION_10_13
-
namespace base {
class SequencedTaskRunner;
@@ -58,6 +39,13 @@ class SequencedTaskRunner;
namespace device {
+// The 10.13 SDK deprecates the CBCentralManagerState enum, but marks the
+// replacement enum with limited availability, making it unusable. API methods
+// now return the new enum, so to compare enum values the new enum must be cast.
+// Wrap this in a function to obtain the state via a call to [manager state] to
+// avoid code that would use the replacement enum and trigger warnings.
+CBCentralManagerState GetCBManagerState(CBCentralManager* manager);
+
class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterMac
: public BluetoothAdapter,
public BluetoothDiscoveryManagerMac::Observer,
diff --git a/chromium/device/bluetooth/bluetooth_adapter_mac.mm b/chromium/device/bluetooth/bluetooth_adapter_mac.mm
index c73ab4e2364..e163647adad 100644
--- a/chromium/device/bluetooth/bluetooth_adapter_mac.mm
+++ b/chromium/device/bluetooth/bluetooth_adapter_mac.mm
@@ -24,6 +24,7 @@
#include "base/strings/sys_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
+#include "device/bluetooth/bluetooth_adapter_mac_metrics.h"
#include "device/bluetooth/bluetooth_classic_device_mac.h"
#include "device/bluetooth/bluetooth_common.h"
#include "device/bluetooth/bluetooth_discovery_session.h"
@@ -40,6 +41,14 @@ const int kPollIntervalMs = 500;
namespace device {
+CBCentralManagerState GetCBManagerState(CBCentralManager* manager) {
+#if defined(MAC_OS_X_VERSION_10_13)
+ return static_cast<CBCentralManagerState>([manager state]);
+#else
+ return [manager state];
+#endif
+}
+
// static
base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter(
const InitCallback& init_callback) {
@@ -158,8 +167,9 @@ bool BluetoothAdapterMac::IsInitialized() const {
bool BluetoothAdapterMac::IsPresent() const {
bool is_present = !address_.empty();
if (IsLowEnergyAvailable()) {
- is_present = is_present || ([low_energy_central_manager_ state] !=
- CBManagerStateUnsupported);
+ is_present =
+ is_present || (GetCBManagerState(low_energy_central_manager_) !=
+ CBCentralManagerStateUnsupported);
}
return is_present;
}
@@ -167,8 +177,9 @@ bool BluetoothAdapterMac::IsPresent() const {
bool BluetoothAdapterMac::IsPowered() const {
bool is_powered = classic_powered_;
if (IsLowEnergyAvailable()) {
- is_powered = is_powered || ([low_energy_central_manager_ state] ==
- CBManagerStatePoweredOn);
+ is_powered =
+ is_powered || (GetCBManagerState(low_energy_central_manager_) ==
+ CBCentralManagerStatePoweredOn);
}
return is_powered;
}
@@ -592,17 +603,18 @@ void BluetoothAdapterMac::LowEnergyDeviceUpdated(
}
}
-// TODO(crbug.com/511025): Handle state < CBManagerStatePoweredOff.
+// TODO(crbug.com/511025): Handle state < CBCentralManagerStatePoweredOff.
void BluetoothAdapterMac::LowEnergyCentralManagerUpdatedState() {
VLOG(1) << "Central manager state updated: "
<< [low_energy_central_manager_ state];
- // A state with a value lower than CBManagerStatePoweredOn implies that
+ // A state with a value lower than CBCentralManagerStatePoweredOn implies that
// scanning has stopped and that any connected peripherals have been
// disconnected. Call DidDisconnectPeripheral manually to update the devices'
// states since macOS doesn't call it.
// See
// https://developer.apple.com/reference/corebluetooth/cbcentralmanagerdelegate/1518888-centralmanagerdidupdatestate?language=objc
- if ([low_energy_central_manager_ state] < CBManagerStatePoweredOn) {
+ if (GetCBManagerState(low_energy_central_manager_) <
+ CBCentralManagerStatePoweredOn) {
VLOG(1)
<< "Central no longer powered on. Notifying of device disconnection.";
for (BluetoothDevice* device : GetDevices()) {
@@ -703,6 +715,7 @@ void BluetoothAdapterMac::DidFailToConnectPeripheral(CBPeripheral* peripheral,
[low_energy_central_manager_ cancelPeripheralConnection:peripheral];
return;
}
+ RecordDidFailToConnectPeripheralResult(error);
BluetoothDevice::ConnectErrorCode error_code =
BluetoothDevice::ConnectErrorCode::ERROR_UNKNOWN;
if (error) {
diff --git a/chromium/device/bluetooth/bluetooth_adapter_mac_metrics.h b/chromium/device/bluetooth/bluetooth_adapter_mac_metrics.h
new file mode 100644
index 00000000000..d4ac2fe139e
--- /dev/null
+++ b/chromium/device/bluetooth/bluetooth_adapter_mac_metrics.h
@@ -0,0 +1,58 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_METRICS_H_
+#define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_METRICS_H_
+
+@class NSError;
+
+enum class MacOSBluetoothOperationsResult : int {
+ UNKNOWN_ERROR_DOMAIN = -2,
+ NO_ERROR = -1,
+ CBATT_ERROR_SUCCESS = 0,
+ CBATT_ERROR_INVALID_HANDLE = 1,
+ CBATT_ERROR_READ_NOT_PERMITTED = 2,
+ CBATT_ERROR_WRITE_NOT_PERMITTED = 3,
+ CBATT_ERROR_INVALID_PDU = 4,
+ CBATT_ERROR_INSUFFICIENT_AUTHENTICATION = 5,
+ CBATT_ERROR_REQUEST_NOT_SUPPORTED = 6,
+ CBATT_ERROR_INVALID_OFFSET = 7,
+ CBATT_ERROR_INSUFFICIENT_AUTHORIZATION = 8,
+ CBATT_ERROR_PREPARE_QUEUE_FULL = 9,
+ CBATT_ERROR_ATTRIBUTE_NOT_FOUND = 10,
+ CBATT_ERROR_ATTRIBUTE_NOT_LONG = 11,
+ CBATT_ERROR_INSUFFICIENT_ENCRYPTION_KEY_SIZE = 12,
+ CBATT_ERROR_INVALID_ATTRIBUTE_VALUE_LENGTH = 13,
+ CBATT_ERROR_UNLIKELY_ERROR = 14,
+ CBATT_ERROR_INSUFFICIENT_ENCRYPTION = 15,
+ CBATT_ERROR_UNSUPPORTED_GROUP_TYPE = 16,
+ CBATT_ERROR_INSUFFICIENT_RESOURCES = 17,
+ CBATT_ERROR_UNKNOWN_ERROR_CODE = 999,
+ CBERROR_UNKNOWN = 1000,
+ CBERROR_INVALID_PARAMETERS = 1001,
+ CBERROR_INVALID_HANDLE = 1002,
+ CBERROR_NOT_CONNECTED = 1003,
+ CBERROR_OUT_OF_SPACE = 1004,
+ CBERROR_OPERATION_CANCELLED = 1005,
+ CBERROR_CONNECTION_TIMEOUT = 1006,
+ CBERROR_PERIPHERAL_DISCONNECTED = 1007,
+ CBERROR_UUID_NOT_ALLOWED = 1008,
+ CBERROR_ALREADY_ADVERTISING = 1009,
+ CBERROR_MAX_CONNECTION = 1010,
+ CBERROR_UNKNOWN_ERROR_CODE = 1999,
+ MAX,
+};
+
+void RecordDidFailToConnectPeripheralResult(NSError* error);
+void RecordDidDisconnectPeripheralResult(NSError* error);
+void RecordDidDiscoverPrimaryServicesResult(NSError* error);
+void RecordDidDiscoverCharacteristicsResult(NSError* error);
+void RecordDidUpdateValueResult(NSError* error);
+void RecordDidWriteValueResult(NSError* error);
+void RecordDidUpdateNotificationStateResult(NSError* error);
+void RecordDidDiscoverDescriptorsResult(NSError* error);
+void RecordDidUpdateValueForDescriptorResult(NSError* error);
+void RecordDidWriteValueForDescriptorResult(NSError* error);
+
+#endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_METRICS_H_
diff --git a/chromium/device/bluetooth/bluetooth_adapter_mac_metrics.mm b/chromium/device/bluetooth/bluetooth_adapter_mac_metrics.mm
new file mode 100644
index 00000000000..dd63b84a60e
--- /dev/null
+++ b/chromium/device/bluetooth/bluetooth_adapter_mac_metrics.mm
@@ -0,0 +1,200 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "device/bluetooth/bluetooth_adapter_mac_metrics.h"
+
+#import <CoreBluetooth/CoreBluetooth.h>
+#import <Foundation/Foundation.h>
+
+#include "base/metrics/histogram_macros.h"
+
+namespace {
+
+#if !defined(MAC_OS_X_VERSION_10_11) || \
+ MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_11
+const NSInteger CBErrorMaxConnection = 10;
+#endif // MAC_OS_X_VERSION_10_11
+
+MacOSBluetoothOperationsResult GetMacOSOperationResultFromNSError(
+ NSError* error) {
+ if (!error)
+ return MacOSBluetoothOperationsResult::NO_ERROR;
+ NSString* error_domain = [error domain];
+ NSInteger error_code = [error code];
+ if ([error_domain isEqualToString:CBErrorDomain]) {
+ CBError cb_error_code = static_cast<CBError>(error_code);
+ switch (cb_error_code) {
+ case CBErrorUnknown:
+ return MacOSBluetoothOperationsResult::CBERROR_UNKNOWN;
+ case CBErrorInvalidParameters:
+ return MacOSBluetoothOperationsResult::CBERROR_INVALID_PARAMETERS;
+ case CBErrorInvalidHandle:
+ return MacOSBluetoothOperationsResult::CBERROR_INVALID_HANDLE;
+ case CBErrorNotConnected:
+ return MacOSBluetoothOperationsResult::CBERROR_NOT_CONNECTED;
+ case CBErrorOutOfSpace:
+ return MacOSBluetoothOperationsResult::CBERROR_OUT_OF_SPACE;
+ case CBErrorOperationCancelled:
+ return MacOSBluetoothOperationsResult::CBERROR_OPERATION_CANCELLED;
+ case CBErrorConnectionTimeout:
+ return MacOSBluetoothOperationsResult::CBERROR_CONNECTION_TIMEOUT;
+ case CBErrorPeripheralDisconnected:
+ return MacOSBluetoothOperationsResult::CBERROR_PERIPHERAL_DISCONNECTED;
+ case CBErrorUUIDNotAllowed:
+ return MacOSBluetoothOperationsResult::CBERROR_UUID_NOT_ALLOWED;
+ case CBErrorAlreadyAdvertising:
+ return MacOSBluetoothOperationsResult::CBERROR_ALREADY_ADVERTISING;
+ default:
+ if (@available(macOS 10.11, *)) {
+ if (CBErrorMaxConnection == cb_error_code)
+ return MacOSBluetoothOperationsResult::CBERROR_MAX_CONNECTION;
+ }
+ NOTREACHED();
+ }
+ return MacOSBluetoothOperationsResult::CBATT_ERROR_UNKNOWN_ERROR_CODE;
+ } else if ([error_domain isEqualToString:CBATTErrorDomain]) {
+ switch (static_cast<CBATTError>(error_code)) {
+ case CBATTErrorSuccess:
+ return MacOSBluetoothOperationsResult::CBATT_ERROR_SUCCESS;
+ case CBATTErrorInvalidHandle:
+ return MacOSBluetoothOperationsResult::CBATT_ERROR_INVALID_HANDLE;
+ case CBATTErrorReadNotPermitted:
+ return MacOSBluetoothOperationsResult::CBATT_ERROR_READ_NOT_PERMITTED;
+ case CBATTErrorWriteNotPermitted:
+ return MacOSBluetoothOperationsResult::CBATT_ERROR_WRITE_NOT_PERMITTED;
+ case CBATTErrorInvalidPdu:
+ return MacOSBluetoothOperationsResult::CBATT_ERROR_INVALID_PDU;
+ case CBATTErrorInsufficientAuthentication:
+ return MacOSBluetoothOperationsResult::
+ CBATT_ERROR_INSUFFICIENT_AUTHENTICATION;
+ case CBATTErrorRequestNotSupported:
+ return MacOSBluetoothOperationsResult::
+ CBATT_ERROR_REQUEST_NOT_SUPPORTED;
+ case CBATTErrorInvalidOffset:
+ return MacOSBluetoothOperationsResult::CBATT_ERROR_INVALID_OFFSET;
+ case CBATTErrorInsufficientAuthorization:
+ return MacOSBluetoothOperationsResult::
+ CBATT_ERROR_INSUFFICIENT_AUTHORIZATION;
+ case CBATTErrorPrepareQueueFull:
+ return MacOSBluetoothOperationsResult::CBATT_ERROR_PREPARE_QUEUE_FULL;
+ case CBATTErrorAttributeNotFound:
+ return MacOSBluetoothOperationsResult::CBATT_ERROR_ATTRIBUTE_NOT_FOUND;
+ case CBATTErrorAttributeNotLong:
+ return MacOSBluetoothOperationsResult::CBATT_ERROR_ATTRIBUTE_NOT_LONG;
+ case CBATTErrorInsufficientEncryptionKeySize:
+ return MacOSBluetoothOperationsResult::
+ CBATT_ERROR_INSUFFICIENT_ENCRYPTION_KEY_SIZE;
+ case CBATTErrorInvalidAttributeValueLength:
+ return MacOSBluetoothOperationsResult::
+ CBATT_ERROR_INVALID_ATTRIBUTE_VALUE_LENGTH;
+ case CBATTErrorUnlikelyError:
+ return MacOSBluetoothOperationsResult::CBATT_ERROR_UNLIKELY_ERROR;
+ case CBATTErrorInsufficientEncryption:
+ return MacOSBluetoothOperationsResult::
+ CBATT_ERROR_INSUFFICIENT_ENCRYPTION;
+ case CBATTErrorUnsupportedGroupType:
+ return MacOSBluetoothOperationsResult::
+ CBATT_ERROR_UNSUPPORTED_GROUP_TYPE;
+ case CBATTErrorInsufficientResources:
+ return MacOSBluetoothOperationsResult::
+ CBATT_ERROR_INSUFFICIENT_RESOURCES;
+ }
+ return MacOSBluetoothOperationsResult::CBERROR_UNKNOWN_ERROR_CODE;
+ }
+ // TODO(crbug.com/755667): Needs to create an histogram to record unknown
+ // error domains.
+ return MacOSBluetoothOperationsResult::UNKNOWN_ERROR_DOMAIN;
+}
+
+} // namespace
+
+void RecordDidFailToConnectPeripheralResult(NSError* error) {
+ MacOSBluetoothOperationsResult histogram_macos_error =
+ GetMacOSOperationResultFromNSError(error);
+ UMA_HISTOGRAM_ENUMERATION(
+ "Bluetooth.MacOS.Errors.DidFailToConnectToPeripheral",
+ static_cast<int>(histogram_macos_error),
+ static_cast<int>(MacOSBluetoothOperationsResult::MAX));
+}
+
+void RecordDidDisconnectPeripheralResult(NSError* error) {
+ MacOSBluetoothOperationsResult histogram_macos_error =
+ GetMacOSOperationResultFromNSError(error);
+ UMA_HISTOGRAM_ENUMERATION(
+ "Bluetooth.MacOS.Errors.DidDisconnectPeripheral",
+ static_cast<int>(histogram_macos_error),
+ static_cast<int>(MacOSBluetoothOperationsResult::MAX));
+}
+
+void RecordDidDiscoverPrimaryServicesResult(NSError* error) {
+ MacOSBluetoothOperationsResult histogram_macos_error =
+ GetMacOSOperationResultFromNSError(error);
+ UMA_HISTOGRAM_ENUMERATION(
+ "Bluetooth.MacOS.Errors.DidDiscoverPrimaryServices",
+ static_cast<int>(histogram_macos_error),
+ static_cast<int>(MacOSBluetoothOperationsResult::MAX));
+}
+
+void RecordDidDiscoverCharacteristicsResult(NSError* error) {
+ MacOSBluetoothOperationsResult histogram_macos_error =
+ GetMacOSOperationResultFromNSError(error);
+ UMA_HISTOGRAM_ENUMERATION(
+ "Bluetooth.MacOS.Errors.DidDiscoverCharacteristics",
+ static_cast<int>(histogram_macos_error),
+ static_cast<int>(MacOSBluetoothOperationsResult::MAX));
+}
+
+void RecordDidUpdateValueResult(NSError* error) {
+ MacOSBluetoothOperationsResult histogram_macos_error =
+ GetMacOSOperationResultFromNSError(error);
+ UMA_HISTOGRAM_ENUMERATION(
+ "Bluetooth.MacOS.Errors.DidUpdateValue",
+ static_cast<int>(histogram_macos_error),
+ static_cast<int>(MacOSBluetoothOperationsResult::MAX));
+}
+
+void RecordDidWriteValueResult(NSError* error) {
+ MacOSBluetoothOperationsResult histogram_macos_error =
+ GetMacOSOperationResultFromNSError(error);
+ UMA_HISTOGRAM_ENUMERATION(
+ "Bluetooth.MacOS.Errors.DidWriteValue",
+ static_cast<int>(histogram_macos_error),
+ static_cast<int>(MacOSBluetoothOperationsResult::MAX));
+}
+
+void RecordDidUpdateNotificationStateResult(NSError* error) {
+ MacOSBluetoothOperationsResult histogram_macos_error =
+ GetMacOSOperationResultFromNSError(error);
+ UMA_HISTOGRAM_ENUMERATION(
+ "Bluetooth.MacOS.Errors.DidUpdateNotificationState",
+ static_cast<int>(histogram_macos_error),
+ static_cast<int>(MacOSBluetoothOperationsResult::MAX));
+}
+
+void RecordDidDiscoverDescriptorsResult(NSError* error) {
+ MacOSBluetoothOperationsResult histogram_macos_error =
+ GetMacOSOperationResultFromNSError(error);
+ UMA_HISTOGRAM_ENUMERATION(
+ "Bluetooth.MacOS.Errors.DidDiscoverDescriptors",
+ static_cast<int>(histogram_macos_error),
+ static_cast<int>(MacOSBluetoothOperationsResult::MAX));
+}
+
+void RecordDidUpdateValueForDescriptorResult(NSError* error) {
+ MacOSBluetoothOperationsResult histogram_macos_error =
+ GetMacOSOperationResultFromNSError(error);
+ UMA_HISTOGRAM_ENUMERATION(
+ "Bluetooth.MacOS.Errors.DidUpdateValueForDescriptor",
+ static_cast<int>(histogram_macos_error),
+ static_cast<int>(MacOSBluetoothOperationsResult::MAX));
+}
+
+void RecordDidWriteValueForDescriptorResult(NSError* error) {
+ MacOSBluetoothOperationsResult histogram_macos_error =
+ GetMacOSOperationResultFromNSError(error);
+ UMA_HISTOGRAM_ENUMERATION(
+ "Bluetooth.MacOS.Errors.DidWriteValueForDescriptor",
+ static_cast<int>(histogram_macos_error),
+ static_cast<int>(MacOSBluetoothOperationsResult::MAX));
+}
diff --git a/chromium/device/bluetooth/bluetooth_adapter_mac_unittest.mm b/chromium/device/bluetooth/bluetooth_adapter_mac_unittest.mm
index 47ca54a1451..753ed2aaf3c 100644
--- a/chromium/device/bluetooth/bluetooth_adapter_mac_unittest.mm
+++ b/chromium/device/bluetooth/bluetooth_adapter_mac_unittest.mm
@@ -92,7 +92,7 @@ class BluetoothAdapterMacTest : public testing::Test {
return (device != NULL);
}
- bool SetMockCentralManager(CBManagerState desired_state) {
+ bool SetMockCentralManager(CBCentralManagerState desired_state) {
if (!BluetoothAdapterMac::IsLowEnergyAvailable()) {
LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
return false;
@@ -148,7 +148,7 @@ TEST_F(BluetoothAdapterMacTest, Poll) {
}
TEST_F(BluetoothAdapterMacTest, AddDiscoverySessionWithLowEnergyFilter) {
- if (!SetMockCentralManager(CBManagerStatePoweredOn))
+ if (!SetMockCentralManager(CBCentralManagerStatePoweredOn))
return;
EXPECT_EQ(0, [mock_central_manager_ scanForPeripheralsCallCount]);
EXPECT_EQ(0, NumDiscoverySessions());
@@ -168,7 +168,7 @@ TEST_F(BluetoothAdapterMacTest, AddDiscoverySessionWithLowEnergyFilter) {
// TODO(krstnmnlsn): Test changing the filter when adding the second discovery
// session (once we have that ability).
TEST_F(BluetoothAdapterMacTest, AddSecondDiscoverySessionWithLowEnergyFilter) {
- if (!SetMockCentralManager(CBManagerStatePoweredOn))
+ if (!SetMockCentralManager(CBCentralManagerStatePoweredOn))
return;
std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(
new BluetoothDiscoveryFilter(BLUETOOTH_TRANSPORT_LE));
@@ -189,7 +189,7 @@ TEST_F(BluetoothAdapterMacTest, AddSecondDiscoverySessionWithLowEnergyFilter) {
}
TEST_F(BluetoothAdapterMacTest, RemoveDiscoverySessionWithLowEnergyFilter) {
- if (!SetMockCentralManager(CBManagerStatePoweredOn))
+ if (!SetMockCentralManager(CBCentralManagerStatePoweredOn))
return;
EXPECT_EQ(0, [mock_central_manager_ scanForPeripheralsCallCount]);
@@ -212,7 +212,7 @@ TEST_F(BluetoothAdapterMacTest, RemoveDiscoverySessionWithLowEnergyFilter) {
}
TEST_F(BluetoothAdapterMacTest, RemoveDiscoverySessionWithLowEnergyFilterFail) {
- if (!SetMockCentralManager(CBManagerStatePoweredOn))
+ if (!SetMockCentralManager(CBCentralManagerStatePoweredOn))
return;
EXPECT_EQ(0, [mock_central_manager_ scanForPeripheralsCallCount]);
EXPECT_EQ(0, [mock_central_manager_ stopScanCallCount]);
@@ -230,7 +230,7 @@ TEST_F(BluetoothAdapterMacTest, RemoveDiscoverySessionWithLowEnergyFilterFail) {
}
TEST_F(BluetoothAdapterMacTest, CheckGetPeripheralHashAddress) {
- if (!SetMockCentralManager(CBManagerStatePoweredOn))
+ if (!SetMockCentralManager(CBCentralManagerStatePoweredOn))
return;
base::scoped_nsobject<CBPeripheral> mock_peripheral(
CreateMockPeripheral(kTestNSUUID));
@@ -240,7 +240,7 @@ TEST_F(BluetoothAdapterMacTest, CheckGetPeripheralHashAddress) {
}
TEST_F(BluetoothAdapterMacTest, LowEnergyDeviceUpdatedNewDevice) {
- if (!SetMockCentralManager(CBManagerStatePoweredOn))
+ if (!SetMockCentralManager(CBCentralManagerStatePoweredOn))
return;
base::scoped_nsobject<CBPeripheral> mock_peripheral(
CreateMockPeripheral(kTestNSUUID));
diff --git a/chromium/device/bluetooth/bluetooth_adapter_win_unittest.cc b/chromium/device/bluetooth/bluetooth_adapter_win_unittest.cc
index fa481ffdc0f..0537efb078a 100644
--- a/chromium/device/bluetooth/bluetooth_adapter_win_unittest.cc
+++ b/chromium/device/bluetooth/bluetooth_adapter_win_unittest.cc
@@ -438,9 +438,9 @@ TEST_F(BluetoothAdapterWinTest, StopDiscoveryBeforeDiscoveryStartedAndFailed) {
TEST_F(BluetoothAdapterWinTest, DevicesPolled) {
std::vector<std::unique_ptr<BluetoothTaskManagerWin::DeviceState>> devices;
- devices.push_back(base::MakeUnique<BluetoothTaskManagerWin::DeviceState>());
- devices.push_back(base::MakeUnique<BluetoothTaskManagerWin::DeviceState>());
- devices.push_back(base::MakeUnique<BluetoothTaskManagerWin::DeviceState>());
+ devices.push_back(std::make_unique<BluetoothTaskManagerWin::DeviceState>());
+ devices.push_back(std::make_unique<BluetoothTaskManagerWin::DeviceState>());
+ devices.push_back(std::make_unique<BluetoothTaskManagerWin::DeviceState>());
BluetoothTaskManagerWin::DeviceState* android_phone_state = devices[0].get();
BluetoothTaskManagerWin::DeviceState* laptop_state = devices[1].get();
@@ -482,7 +482,7 @@ TEST_F(BluetoothAdapterWinTest, DevicesPolled) {
// Add a service
laptop_state->service_record_states.push_back(
- base::MakeUnique<BluetoothTaskManagerWin::ServiceRecordState>());
+ std::make_unique<BluetoothTaskManagerWin::ServiceRecordState>());
BluetoothTaskManagerWin::ServiceRecordState* audio_state =
laptop_state->service_record_states.back().get();
audio_state->name = kTestAudioSdpName;
diff --git a/chromium/device/bluetooth/bluetooth_advertisement.h b/chromium/device/bluetooth/bluetooth_advertisement.h
index 70659f37fed..d379f72453a 100644
--- a/chromium/device/bluetooth/bluetooth_advertisement.h
+++ b/chromium/device/bluetooth/bluetooth_advertisement.h
@@ -17,6 +17,7 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/observer_list.h"
+#include "build/build_config.h"
#include "device/bluetooth/bluetooth_export.h"
namespace device {
@@ -37,7 +38,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdvertisement
// is not registered.
ERROR_ADVERTISEMENT_INVALID_LENGTH, // Advertisement is not of a valid
// length.
-#if defined(OS_CHROMEOS) || defined(OS_LINUX)
+#if defined(OS_LINUX)
ERROR_INVALID_ADVERTISEMENT_INTERVAL, // Advertisement interval specified
// is out of valid range.
ERROR_RESET_ADVERTISING, // Error while resetting advertising.
diff --git a/chromium/device/bluetooth/bluetooth_advertisement_unittest.cc b/chromium/device/bluetooth/bluetooth_advertisement_unittest.cc
index a0ef62c7ba5..83287dafed1 100644
--- a/chromium/device/bluetooth/bluetooth_advertisement_unittest.cc
+++ b/chromium/device/bluetooth/bluetooth_advertisement_unittest.cc
@@ -34,7 +34,7 @@ TEST(BluetoothAdvertisementTest, DataMembersAreAssignedCorrectly) {
ASSERT_FALSE(data.service_uuids().get());
// Assign Service UUID.
data.set_service_uuids(
- base::MakeUnique<BluetoothAdvertisement::UUIDList>(uuids));
+ std::make_unique<BluetoothAdvertisement::UUIDList>(uuids));
// Retrieve Service UUID.
ASSERT_EQ(*data.service_uuids(), uuids);
// Retrieve again.
@@ -44,7 +44,7 @@ TEST(BluetoothAdvertisementTest, DataMembersAreAssignedCorrectly) {
ASSERT_FALSE(data.manufacturer_data().get());
// Assign Manufacturer Data.
data.set_manufacturer_data(
- base::MakeUnique<BluetoothAdvertisement::ManufacturerData>(
+ std::make_unique<BluetoothAdvertisement::ManufacturerData>(
manufacturer_data));
// Retrieve Manufacturer Data.
ASSERT_EQ(*data.manufacturer_data(), manufacturer_data);
@@ -55,7 +55,7 @@ TEST(BluetoothAdvertisementTest, DataMembersAreAssignedCorrectly) {
ASSERT_FALSE(data.solicit_uuids().get());
// Assign Solicit UUIDs.
data.set_solicit_uuids(
- base::MakeUnique<BluetoothAdvertisement::UUIDList>(uuids));
+ std::make_unique<BluetoothAdvertisement::UUIDList>(uuids));
// Retrieve Solicit UUIDs.
ASSERT_EQ(*data.solicit_uuids(), uuids);
// Retieve again.
@@ -65,7 +65,7 @@ TEST(BluetoothAdvertisementTest, DataMembersAreAssignedCorrectly) {
ASSERT_FALSE(data.service_data().get());
// Assign Service Data.
data.set_service_data(
- base::MakeUnique<BluetoothAdvertisement::ServiceData>(service_data));
+ std::make_unique<BluetoothAdvertisement::ServiceData>(service_data));
// Retrieve Service Data.
ASSERT_EQ(*data.service_data(), service_data);
// Retrieve again.
diff --git a/chromium/device/bluetooth/bluetooth_device.cc b/chromium/device/bluetooth/bluetooth_device.cc
index 49cf01b08a2..02374c9f608 100644
--- a/chromium/device/bluetooth/bluetooth_device.cc
+++ b/chromium/device/bluetooth/bluetooth_device.cc
@@ -467,7 +467,7 @@ BluetoothDevice::GetPrimaryServicesByUUID(const BluetoothUUID& service_uuid) {
void BluetoothDevice::DidConnectGatt() {
for (const auto& callback : create_gatt_connection_success_callbacks_) {
callback.Run(
- base::MakeUnique<BluetoothGattConnection>(adapter_, GetAddress()));
+ std::make_unique<BluetoothGattConnection>(adapter_, GetAddress()));
}
create_gatt_connection_success_callbacks_.clear();
create_gatt_connection_error_callbacks_.clear();
diff --git a/chromium/device/bluetooth/bluetooth_device.h b/chromium/device/bluetooth/bluetooth_device.h
index ac9dc0ea7f7..913346971b8 100644
--- a/chromium/device/bluetooth/bluetooth_device.h
+++ b/chromium/device/bluetooth/bluetooth_device.h
@@ -22,6 +22,7 @@
#include "base/optional.h"
#include "base/strings/string16.h"
#include "base/time/time.h"
+#include "build/build_config.h"
#include "device/bluetooth/bluetooth_common.h"
#include "device/bluetooth/bluetooth_export.h"
#include "device/bluetooth/bluetooth_remote_gatt_service.h"
@@ -203,7 +204,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDevice {
// and metrics logging,
virtual uint32_t GetBluetoothClass() const = 0;
-#if defined(OS_CHROMEOS) || defined(OS_LINUX)
+#if defined(OS_LINUX)
// Returns the transport type of the device. Some devices only support one
// of BR/EDR or LE, and some support both.
virtual BluetoothTransport GetType() const = 0;
diff --git a/chromium/device/bluetooth/bluetooth_device_android.cc b/chromium/device/bluetooth/bluetooth_device_android.cc
index 9c930a98219..9961798e2bb 100644
--- a/chromium/device/bluetooth/bluetooth_device_android.cc
+++ b/chromium/device/bluetooth/bluetooth_device_android.cc
@@ -52,11 +52,6 @@ BluetoothDeviceAndroid::~BluetoothDeviceAndroid() {
AttachCurrentThread(), j_device_);
}
-// static
-bool BluetoothDeviceAndroid::RegisterJNI(JNIEnv* env) {
- return RegisterNativesImpl(env); // Generated in ChromeBluetoothDevice_jni.h
-}
-
base::android::ScopedJavaLocalRef<jobject>
BluetoothDeviceAndroid::GetJavaObject() {
return base::android::ScopedJavaLocalRef<jobject>(j_device_);
diff --git a/chromium/device/bluetooth/bluetooth_device_android.h b/chromium/device/bluetooth/bluetooth_device_android.h
index 485be65d3d8..96e6d2805f5 100644
--- a/chromium/device/bluetooth/bluetooth_device_android.h
+++ b/chromium/device/bluetooth/bluetooth_device_android.h
@@ -36,9 +36,6 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDeviceAndroid final
~BluetoothDeviceAndroid() override;
- // Register C++ methods exposed to Java using JNI.
- static bool RegisterJNI(JNIEnv* env);
-
// Returns the associated ChromeBluetoothDevice Java object.
base::android::ScopedJavaLocalRef<jobject> GetJavaObject();
diff --git a/chromium/device/bluetooth/bluetooth_device_win.cc b/chromium/device/bluetooth/bluetooth_device_win.cc
index 88bd521b6e1..35ceee76405 100644
--- a/chromium/device/bluetooth/bluetooth_device_win.cc
+++ b/chromium/device/bluetooth/bluetooth_device_win.cc
@@ -243,7 +243,7 @@ bool BluetoothDeviceWin::IsEqual(
new_service_records;
for (auto iter = device_state.service_record_states.begin();
iter != device_state.service_record_states.end(); ++iter) {
- auto service_record = base::MakeUnique<BluetoothServiceRecordWin>(
+ auto service_record = std::make_unique<BluetoothServiceRecordWin>(
address_, (*iter)->name, (*iter)->sdp_bytes, (*iter)->gatt_uuid);
new_services.insert(service_record->uuid());
new_service_records[service_record->uuid().canonical_value()] =
@@ -299,7 +299,7 @@ void BluetoothDeviceWin::UpdateServices(
service_record_list_.clear();
for (const auto& record_state : device_state.service_record_states) {
- auto service_record = base::MakeUnique<BluetoothServiceRecordWin>(
+ auto service_record = std::make_unique<BluetoothServiceRecordWin>(
device_state.address, record_state->name, record_state->sdp_bytes,
record_state->gatt_uuid);
uuids_.insert(service_record->uuid());
diff --git a/chromium/device/bluetooth/bluetooth_device_win_unittest.cc b/chromium/device/bluetooth/bluetooth_device_win_unittest.cc
index b75d5385f79..daefa6b151e 100644
--- a/chromium/device/bluetooth/bluetooth_device_win_unittest.cc
+++ b/chromium/device/bluetooth/bluetooth_device_win_unittest.cc
@@ -55,13 +55,13 @@ class BluetoothDeviceWinTest : public testing::Test {
device_state_->address = kDeviceAddress;
auto audio_state =
- base::MakeUnique<BluetoothTaskManagerWin::ServiceRecordState>();
+ std::make_unique<BluetoothTaskManagerWin::ServiceRecordState>();
audio_state->name = kTestAudioSdpName;
base::HexStringToBytes(kTestAudioSdpBytes, &audio_state->sdp_bytes);
device_state_->service_record_states.push_back(std::move(audio_state));
auto video_state =
- base::MakeUnique<BluetoothTaskManagerWin::ServiceRecordState>();
+ std::make_unique<BluetoothTaskManagerWin::ServiceRecordState>();
video_state->name = kTestVideoSdpName;
base::HexStringToBytes(kTestVideoSdpBytes, &video_state->sdp_bytes);
device_state_->service_record_states.push_back(std::move(video_state));
diff --git a/chromium/device/bluetooth/bluetooth_discovery_filter.cc b/chromium/device/bluetooth/bluetooth_discovery_filter.cc
index 8fe0eb7c90d..16609126b0b 100644
--- a/chromium/device/bluetooth/bluetooth_discovery_filter.cc
+++ b/chromium/device/bluetooth/bluetooth_discovery_filter.cc
@@ -76,7 +76,7 @@ void BluetoothDiscoveryFilter::AddUUID(const device::BluetoothUUID& uuid) {
return;
}
- uuids_.push_back(base::MakeUnique<device::BluetoothUUID>(uuid));
+ uuids_.push_back(std::make_unique<device::BluetoothUUID>(uuid));
}
void BluetoothDiscoveryFilter::CopyFrom(
diff --git a/chromium/device/bluetooth/bluetooth_discovery_session.cc b/chromium/device/bluetooth/bluetooth_discovery_session.cc
index faf158cd152..2876fc7f9cc 100644
--- a/chromium/device/bluetooth/bluetooth_discovery_session.cc
+++ b/chromium/device/bluetooth/bluetooth_discovery_session.cc
@@ -16,6 +16,7 @@ BluetoothDiscoverySession::BluetoothDiscoverySession(
scoped_refptr<BluetoothAdapter> adapter,
std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter)
: active_(true),
+ is_stop_in_progress_(false),
adapter_(adapter),
discovery_filter_(discovery_filter.release()),
weak_ptr_factory_(this) {
@@ -42,6 +43,17 @@ void BluetoothDiscoverySession::Stop(const base::Closure& success_callback,
error_callback.Run();
return;
}
+
+ if (is_stop_in_progress_) {
+ LOG(WARNING) << "Discovery session Stop in progress.";
+ BluetoothAdapter::RecordBluetoothDiscoverySessionStopOutcome(
+ UMABluetoothDiscoverySessionOutcome::STOP_IN_PROGRESS);
+ error_callback.Run();
+ return;
+ }
+
+ is_stop_in_progress_ = true;
+
VLOG(1) << "Stopping device discovery session.";
base::Closure deactive_discovery_session =
base::Bind(&BluetoothDiscoverySession::DeactivateDiscoverySession,
@@ -52,28 +64,35 @@ void BluetoothDiscoverySession::Stop(const base::Closure& success_callback,
// exists, but always runs success_callback.
base::Closure discovery_session_removed_callback =
base::Bind(&BluetoothDiscoverySession::OnDiscoverySessionRemoved,
- deactive_discovery_session, success_callback);
+ weak_ptr_factory_.GetWeakPtr(), deactive_discovery_session,
+ success_callback);
adapter_->RemoveDiscoverySession(
discovery_filter_.get(), discovery_session_removed_callback,
base::Bind(&BluetoothDiscoverySession::OnDiscoverySessionRemovalFailed,
- error_callback));
+ weak_ptr_factory_.GetWeakPtr(), error_callback));
}
// static
void BluetoothDiscoverySession::OnDiscoverySessionRemoved(
+ base::WeakPtr<BluetoothDiscoverySession> session,
const base::Closure& deactivate_discovery_session,
const base::Closure& success_callback) {
BluetoothAdapter::RecordBluetoothDiscoverySessionStopOutcome(
UMABluetoothDiscoverySessionOutcome::SUCCESS);
+ if (session)
+ session->is_stop_in_progress_ = false;
deactivate_discovery_session.Run();
success_callback.Run();
}
// static
void BluetoothDiscoverySession::OnDiscoverySessionRemovalFailed(
+ base::WeakPtr<BluetoothDiscoverySession> session,
const base::Closure& error_callback,
UMABluetoothDiscoverySessionOutcome outcome) {
BluetoothAdapter::RecordBluetoothDiscoverySessionStopOutcome(outcome);
+ if (session)
+ session->is_stop_in_progress_ = false;
error_callback.Run();
}
diff --git a/chromium/device/bluetooth/bluetooth_discovery_session.h b/chromium/device/bluetooth/bluetooth_discovery_session.h
index 05798b695c9..5d2ddc9dfc9 100644
--- a/chromium/device/bluetooth/bluetooth_discovery_session.h
+++ b/chromium/device/bluetooth/bluetooth_discovery_session.h
@@ -82,10 +82,12 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDiscoverySession {
// |deactivate_discovery_session| if the session object still
// exists when this callback executes. Always invokes |success_callback|.
static void OnDiscoverySessionRemoved(
+ base::WeakPtr<BluetoothDiscoverySession> session,
const base::Closure& deactivate_discovery_session,
const base::Closure& success_callback);
static void OnDiscoverySessionRemovalFailed(
+ base::WeakPtr<BluetoothDiscoverySession> session,
const base::Closure& error_callback,
UMABluetoothDiscoverySessionOutcome outcome);
@@ -101,6 +103,9 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDiscoverySession {
// Whether or not this instance represents an active discovery session.
bool active_;
+ // Whether a Stop() operation is in progress for this session.
+ bool is_stop_in_progress_;
+
// The adapter that created this instance.
scoped_refptr<BluetoothAdapter> adapter_;
diff --git a/chromium/device/bluetooth/bluetooth_discovery_session_outcome.h b/chromium/device/bluetooth/bluetooth_discovery_session_outcome.h
index 41a85ed625e..a4667ed7030 100644
--- a/chromium/device/bluetooth/bluetooth_discovery_session_outcome.h
+++ b/chromium/device/bluetooth/bluetooth_discovery_session_outcome.h
@@ -30,6 +30,8 @@ enum class UMABluetoothDiscoverySessionOutcome {
BLUEZ_DBUS_NOT_READY = 12,
BLUEZ_DBUS_FAILED_MAYBE_UNSUPPORTED_TRANSPORT = 13,
BLUEZ_DBUS_UNSUPPORTED_DEVICE = 14,
+
+ STOP_IN_PROGRESS = 15,
// NOTE: Add new outcomes immediately above this line. Make sure to update the
// enum list in tools/metrics/histograms/histograms.xml accordingly.
COUNT
diff --git a/chromium/device/bluetooth/bluetooth_local_gatt_characteristic.cc b/chromium/device/bluetooth/bluetooth_local_gatt_characteristic.cc
index e4350c09aea..70ab35620fe 100644
--- a/chromium/device/bluetooth/bluetooth_local_gatt_characteristic.cc
+++ b/chromium/device/bluetooth/bluetooth_local_gatt_characteristic.cc
@@ -5,11 +5,12 @@
#include "device/bluetooth/bluetooth_local_gatt_characteristic.h"
#include "base/logging.h"
+#include "build/build_config.h"
#include "device/bluetooth/bluetooth_local_gatt_service.h"
namespace device {
-#if !defined(OS_CHROMEOS) && !defined(OS_LINUX)
+#if !defined(OS_LINUX)
// static
base::WeakPtr<BluetoothLocalGattCharacteristic>
BluetoothLocalGattCharacteristic::Create(const BluetoothUUID& uuid,
diff --git a/chromium/device/bluetooth/bluetooth_local_gatt_descriptor.cc b/chromium/device/bluetooth/bluetooth_local_gatt_descriptor.cc
index 2ffa9793ced..0ab463bbcbe 100644
--- a/chromium/device/bluetooth/bluetooth_local_gatt_descriptor.cc
+++ b/chromium/device/bluetooth/bluetooth_local_gatt_descriptor.cc
@@ -5,10 +5,11 @@
#include "device/bluetooth/bluetooth_local_gatt_descriptor.h"
#include "base/logging.h"
+#include "build/build_config.h"
namespace device {
-#if !defined(OS_CHROMEOS) && !defined(OS_LINUX)
+#if !defined(OS_LINUX)
// static
base::WeakPtr<BluetoothLocalGattDescriptor>
BluetoothLocalGattDescriptor::Create(
diff --git a/chromium/device/bluetooth/bluetooth_local_gatt_service.cc b/chromium/device/bluetooth/bluetooth_local_gatt_service.cc
index 000d6abf1ad..86da8c9b09f 100644
--- a/chromium/device/bluetooth/bluetooth_local_gatt_service.cc
+++ b/chromium/device/bluetooth/bluetooth_local_gatt_service.cc
@@ -4,9 +4,11 @@
#include "device/bluetooth/bluetooth_local_gatt_service.h"
+#include "build/build_config.h"
+
namespace device {
-#if !defined(OS_CHROMEOS) && !defined(OS_LINUX)
+#if !defined(OS_LINUX)
// static
base::WeakPtr<BluetoothLocalGattService> BluetoothLocalGattService::Create(
BluetoothAdapter* adapter,
diff --git a/chromium/device/bluetooth/bluetooth_low_energy_device_mac.mm b/chromium/device/bluetooth/bluetooth_low_energy_device_mac.mm
index 41dcd06bdf9..187f3c91c07 100644
--- a/chromium/device/bluetooth/bluetooth_low_energy_device_mac.mm
+++ b/chromium/device/bluetooth/bluetooth_low_energy_device_mac.mm
@@ -14,6 +14,7 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/sys_string_conversions.h"
#include "device/bluetooth/bluetooth_adapter_mac.h"
+#include "device/bluetooth/bluetooth_adapter_mac_metrics.h"
#include "device/bluetooth/bluetooth_device.h"
#include "device/bluetooth/bluetooth_low_energy_peripheral_delegate.h"
#include "device/bluetooth/bluetooth_remote_gatt_characteristic_mac.h"
@@ -222,6 +223,7 @@ void BluetoothLowEnergyDeviceMac::DidDiscoverPrimaryServices(NSError* error) {
discovery_pending_count_ = 0;
return;
}
+ RecordDidDiscoverPrimaryServicesResult(error);
if (error) {
// TODO(http://crbug.com/609320): Need to pass the error.
// TODO(http://crbug.com/609844): Decide what to do if discover failed
@@ -268,6 +270,7 @@ void BluetoothLowEnergyDeviceMac::DidDiscoverPrimaryServices(NSError* error) {
void BluetoothLowEnergyDeviceMac::DidDiscoverCharacteristics(
CBService* cb_service,
NSError* error) {
+ RecordDidDiscoverCharacteristicsResult(error);
if (error) {
// TODO(http://crbug.com/609320): Need to pass the error.
// TODO(http://crbug.com/609844): Decide what to do if discover failed
@@ -347,6 +350,7 @@ void BluetoothLowEnergyDeviceMac::DidUpdateNotificationState(
void BluetoothLowEnergyDeviceMac::DidDiscoverDescriptors(
CBCharacteristic* cb_characteristic,
NSError* error) {
+ RecordDidDiscoverDescriptorsResult(error);
if (error) {
// TODO(http://crbug.com/609320): Need to pass the error.
// TODO(http://crbug.com/609844): Decide what to do if discover failed
@@ -502,6 +506,7 @@ BluetoothLowEnergyDeviceMac::GetBluetoothRemoteGattDescriptorMac(
void BluetoothLowEnergyDeviceMac::DidDisconnectPeripheral(NSError* error) {
connected_ = false;
VLOG(1) << *this << ": Disconnected from peripheral.";
+ RecordDidDisconnectPeripheralResult(error);
if (error) {
VLOG(1) << *this
<< ": Bluetooth error: " << BluetoothAdapterMac::String(error);
diff --git a/chromium/device/bluetooth/bluetooth_low_energy_discovery_manager_mac.mm b/chromium/device/bluetooth/bluetooth_low_energy_discovery_manager_mac.mm
index 7cb766f863e..650982b2c48 100644
--- a/chromium/device/bluetooth/bluetooth_low_energy_discovery_manager_mac.mm
+++ b/chromium/device/bluetooth/bluetooth_low_energy_discovery_manager_mac.mm
@@ -46,8 +46,8 @@ void BluetoothLowEnergyDiscoveryManagerMac::TryStartDiscovery() {
return;
}
- if ([central_manager_ state] != CBManagerStatePoweredOn) {
- VLOG(1) << "TryStartDiscovery != CBManagerStatePoweredOn";
+ if (GetCBManagerState(central_manager_) != CBCentralManagerStatePoweredOn) {
+ VLOG(1) << "TryStartDiscovery != CBCentralManagerStatePoweredOn";
return;
}
diff --git a/chromium/device/bluetooth/bluetooth_low_energy_win.cc b/chromium/device/bluetooth/bluetooth_low_energy_win.cc
index 53c5a39f9b1..e07326ab886 100644
--- a/chromium/device/bluetooth/bluetooth_low_energy_win.cc
+++ b/chromium/device/bluetooth/bluetooth_low_energy_win.cc
@@ -408,7 +408,7 @@ bool CollectBluetoothLowEnergyDeviceServices(
for (USHORT i = 0; i < actual_length; ++i) {
BTH_LE_GATT_SERVICE& gatt_service(gatt_services.get()[i]);
- auto service_info = base::MakeUnique<BluetoothLowEnergyServiceInfo>();
+ auto service_info = std::make_unique<BluetoothLowEnergyServiceInfo>();
service_info->uuid = gatt_service.ServiceUuid;
service_info->attribute_handle = gatt_service.AttributeHandle;
services->push_back(std::move(service_info));
diff --git a/chromium/device/bluetooth/bluetooth_low_energy_win_fake.cc b/chromium/device/bluetooth/bluetooth_low_energy_win_fake.cc
index bfbc1b2a82c..553cbb2a16a 100644
--- a/chromium/device/bluetooth/bluetooth_low_energy_win_fake.cc
+++ b/chromium/device/bluetooth/bluetooth_low_energy_win_fake.cc
@@ -52,7 +52,7 @@ bool BluetoothLowEnergyWrapperFake::EnumerateKnownBluetoothLowEnergyDevices(
for (auto& device : simulated_devices_) {
if (device.second->marked_as_deleted)
continue;
- auto device_info = base::MakeUnique<BluetoothLowEnergyDeviceInfo>();
+ auto device_info = std::make_unique<BluetoothLowEnergyDeviceInfo>();
*device_info = *(device.second->device_info);
devices->push_back(std::move(device_info));
}
@@ -70,7 +70,7 @@ bool BluetoothLowEnergyWrapperFake::
for (auto& device : simulated_devices_) {
for (auto& service : device.second->primary_services) {
- auto device_info = base::MakeUnique<BluetoothLowEnergyDeviceInfo>();
+ auto device_info = std::make_unique<BluetoothLowEnergyDeviceInfo>();
*device_info = *(device.second->device_info);
base::string16 path = GenerateGattServiceDevicePath(
device.second->device_info->path.value(),
@@ -105,7 +105,7 @@ bool BluetoothLowEnergyWrapperFake::EnumerateKnownBluetoothLowEnergyServices(
if (service_attribute_handles.empty()) {
// Return all primary services for BLE device.
for (auto& primary_service : it_d->second->primary_services) {
- auto service_info = base::MakeUnique<BluetoothLowEnergyServiceInfo>();
+ auto service_info = std::make_unique<BluetoothLowEnergyServiceInfo>();
service_info->uuid = primary_service.second->service_info->ServiceUuid;
service_info->attribute_handle =
primary_service.second->service_info->AttributeHandle;
@@ -115,7 +115,7 @@ bool BluetoothLowEnergyWrapperFake::EnumerateKnownBluetoothLowEnergyServices(
// Return corresponding GATT service for BLE GATT service device.
GattService* target_service =
GetSimulatedGattService(it_d->second.get(), service_attribute_handles);
- auto service_info = base::MakeUnique<BluetoothLowEnergyServiceInfo>();
+ auto service_info = std::make_unique<BluetoothLowEnergyServiceInfo>();
service_info->uuid = target_service->service_info->ServiceUuid;
service_info->attribute_handle =
target_service->service_info->AttributeHandle;
diff --git a/chromium/device/bluetooth/bluetooth_remote_gatt_characteristic_android.cc b/chromium/device/bluetooth/bluetooth_remote_gatt_characteristic_android.cc
index 49af8d2c680..787307a8bfb 100644
--- a/chromium/device/bluetooth/bluetooth_remote_gatt_characteristic_android.cc
+++ b/chromium/device/bluetooth/bluetooth_remote_gatt_characteristic_android.cc
@@ -66,12 +66,6 @@ BluetoothRemoteGattCharacteristicAndroid::
}
}
-// static
-bool BluetoothRemoteGattCharacteristicAndroid::RegisterJNI(JNIEnv* env) {
- return RegisterNativesImpl(
- env); // Generated in ChromeBluetoothRemoteGattCharacteristic_jni.h
-}
-
base::android::ScopedJavaLocalRef<jobject>
BluetoothRemoteGattCharacteristicAndroid::GetJavaObject() {
return base::android::ScopedJavaLocalRef<jobject>(j_characteristic_);
diff --git a/chromium/device/bluetooth/bluetooth_remote_gatt_characteristic_android.h b/chromium/device/bluetooth/bluetooth_remote_gatt_characteristic_android.h
index 06967e96b0c..a51ffd65934 100644
--- a/chromium/device/bluetooth/bluetooth_remote_gatt_characteristic_android.h
+++ b/chromium/device/bluetooth/bluetooth_remote_gatt_characteristic_android.h
@@ -48,9 +48,6 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattCharacteristicAndroid
~BluetoothRemoteGattCharacteristicAndroid() override;
- // Register C++ methods exposed to Java using JNI.
- static bool RegisterJNI(JNIEnv* env);
-
// Returns the associated ChromeBluetoothRemoteGattCharacteristic Java object.
base::android::ScopedJavaLocalRef<jobject> GetJavaObject();
diff --git a/chromium/device/bluetooth/bluetooth_remote_gatt_characteristic_mac.mm b/chromium/device/bluetooth/bluetooth_remote_gatt_characteristic_mac.mm
index 900f3f6613f..1131a84a144 100644
--- a/chromium/device/bluetooth/bluetooth_remote_gatt_characteristic_mac.mm
+++ b/chromium/device/bluetooth/bluetooth_remote_gatt_characteristic_mac.mm
@@ -9,6 +9,7 @@
#include "base/strings/sys_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "device/bluetooth/bluetooth_adapter_mac.h"
+#include "device/bluetooth/bluetooth_adapter_mac_metrics.h"
#include "device/bluetooth/bluetooth_device_mac.h"
#include "device/bluetooth/bluetooth_gatt_notify_session.h"
#include "device/bluetooth/bluetooth_remote_gatt_descriptor_mac.h"
@@ -251,6 +252,7 @@ void BluetoothRemoteGattCharacteristicMac::DidUpdateValue(NSError* error) {
CHECK_EQ(GetCBPeripheral().state, CBPeripheralStateConnected);
// This method is called when the characteristic is read and when a
// notification is received.
+ RecordDidUpdateValueResult(error);
if (HasPendingRead()) {
std::pair<ValueCallback, ErrorCallback> callbacks;
callbacks.swap(read_characteristic_value_callbacks_);
@@ -289,6 +291,7 @@ void BluetoothRemoteGattCharacteristicMac::UpdateValue() {
}
void BluetoothRemoteGattCharacteristicMac::DidWriteValue(NSError* error) {
+ RecordDidWriteValueResult(error);
// We could have called cancelPeripheralConnection, which causes
// [CBPeripheral state] to be CBPeripheralStateDisconnected, before or during
// a write without response callback so we flush all pending writes.
@@ -340,6 +343,7 @@ void BluetoothRemoteGattCharacteristicMac::DidUpdateNotificationState(
VLOG(1) << *this << ": No pending notification update for characteristic.";
return;
}
+ RecordDidUpdateNotificationStateResult(error);
if (error) {
BluetoothGattService::GattErrorCode error_code =
BluetoothDeviceMac::GetGattErrorCodeFromNSError(error);
diff --git a/chromium/device/bluetooth/bluetooth_remote_gatt_descriptor_android.cc b/chromium/device/bluetooth/bluetooth_remote_gatt_descriptor_android.cc
index b0ee1b3e024..773342f0dc5 100644
--- a/chromium/device/bluetooth/bluetooth_remote_gatt_descriptor_android.cc
+++ b/chromium/device/bluetooth/bluetooth_remote_gatt_descriptor_android.cc
@@ -47,12 +47,6 @@ BluetoothRemoteGattDescriptorAndroid::~BluetoothRemoteGattDescriptorAndroid() {
AttachCurrentThread(), j_descriptor_);
}
-// static
-bool BluetoothRemoteGattDescriptorAndroid::RegisterJNI(JNIEnv* env) {
- return RegisterNativesImpl(
- env); // Generated in ChromeBluetoothRemoteGattDescriptor_jni.h
-}
-
base::android::ScopedJavaLocalRef<jobject>
BluetoothRemoteGattDescriptorAndroid::GetJavaObject() {
return base::android::ScopedJavaLocalRef<jobject>(j_descriptor_);
diff --git a/chromium/device/bluetooth/bluetooth_remote_gatt_descriptor_android.h b/chromium/device/bluetooth/bluetooth_remote_gatt_descriptor_android.h
index fa4a4158123..f8fb862041e 100644
--- a/chromium/device/bluetooth/bluetooth_remote_gatt_descriptor_android.h
+++ b/chromium/device/bluetooth/bluetooth_remote_gatt_descriptor_android.h
@@ -37,9 +37,6 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattDescriptorAndroid
~BluetoothRemoteGattDescriptorAndroid() override;
- // Register C++ methods exposed to Java using JNI.
- static bool RegisterJNI(JNIEnv* env);
-
// Returns the associated ChromeBluetoothRemoteGattDescriptor Java object.
base::android::ScopedJavaLocalRef<jobject> GetJavaObject();
diff --git a/chromium/device/bluetooth/bluetooth_remote_gatt_descriptor_mac.mm b/chromium/device/bluetooth/bluetooth_remote_gatt_descriptor_mac.mm
index 173adcdf789..84eaeb71a4b 100644
--- a/chromium/device/bluetooth/bluetooth_remote_gatt_descriptor_mac.mm
+++ b/chromium/device/bluetooth/bluetooth_remote_gatt_descriptor_mac.mm
@@ -9,6 +9,7 @@
#include "base/strings/sys_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
#import "device/bluetooth/bluetooth_adapter_mac.h"
+#include "device/bluetooth/bluetooth_adapter_mac_metrics.h"
#import "device/bluetooth/bluetooth_remote_gatt_characteristic_mac.h"
using base::mac::ObjCCast;
@@ -139,6 +140,7 @@ void BluetoothRemoteGattDescriptorMac::DidUpdateValueForDescriptor(
std::pair<ValueCallback, ErrorCallback> callbacks;
callbacks.swap(read_value_callbacks_);
value_read_or_write_in_progress_ = false;
+ RecordDidUpdateValueForDescriptorResult(error);
if (error) {
BluetoothGattService::GattErrorCode error_code =
BluetoothDeviceMac::GetGattErrorCodeFromNSError(error);
@@ -162,6 +164,7 @@ void BluetoothRemoteGattDescriptorMac::DidWriteValueForDescriptor(
std::pair<base::Closure, ErrorCallback> callbacks;
callbacks.swap(write_value_callbacks_);
value_read_or_write_in_progress_ = false;
+ RecordDidWriteValueForDescriptorResult(error);
if (error) {
BluetoothGattService::GattErrorCode error_code =
BluetoothDeviceMac::GetGattErrorCodeFromNSError(error);
diff --git a/chromium/device/bluetooth/bluetooth_remote_gatt_service_android.cc b/chromium/device/bluetooth/bluetooth_remote_gatt_service_android.cc
index 3864070230b..5a29d75316f 100644
--- a/chromium/device/bluetooth/bluetooth_remote_gatt_service_android.cc
+++ b/chromium/device/bluetooth/bluetooth_remote_gatt_service_android.cc
@@ -47,12 +47,6 @@ BluetoothRemoteGattServiceAndroid::~BluetoothRemoteGattServiceAndroid() {
AttachCurrentThread(), j_service_);
}
-// static
-bool BluetoothRemoteGattServiceAndroid::RegisterJNI(JNIEnv* env) {
- return RegisterNativesImpl(
- env); // Generated in ChromeBluetoothRemoteGattService_jni.h
-}
-
base::android::ScopedJavaLocalRef<jobject>
BluetoothRemoteGattServiceAndroid::GetJavaObject() {
return base::android::ScopedJavaLocalRef<jobject>(j_service_);
diff --git a/chromium/device/bluetooth/bluetooth_remote_gatt_service_android.h b/chromium/device/bluetooth/bluetooth_remote_gatt_service_android.h
index 38827024c5f..8c33a31d06f 100644
--- a/chromium/device/bluetooth/bluetooth_remote_gatt_service_android.h
+++ b/chromium/device/bluetooth/bluetooth_remote_gatt_service_android.h
@@ -46,9 +46,6 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattServiceAndroid
~BluetoothRemoteGattServiceAndroid() override;
- // Register C++ methods exposed to Java using JNI.
- static bool RegisterJNI(JNIEnv* env);
-
// Returns the associated ChromeBluetoothRemoteGattService Java object.
base::android::ScopedJavaLocalRef<jobject> GetJavaObject();
diff --git a/chromium/device/bluetooth/bluetooth_service_record_win.cc b/chromium/device/bluetooth/bluetooth_service_record_win.cc
index 1b91e7d8bff..463a56136b2 100644
--- a/chromium/device/bluetooth/bluetooth_service_record_win.cc
+++ b/chromium/device/bluetooth/bluetooth_service_record_win.cc
@@ -74,11 +74,11 @@ void ExtractUuid(const SDP_ELEMENT_DATA& uuid_data,
*uuid = device::BluetoothUUID(uuid_hex);
} else if (inner_uuid_data.specificType == SDP_ST_UUID32) {
std::string uuid_hex =
- base::StringPrintf("%08x", inner_uuid_data.data.uuid32);
+ base::StringPrintf("%08lx", inner_uuid_data.data.uuid32);
*uuid = device::BluetoothUUID(uuid_hex);
} else if (inner_uuid_data.specificType == SDP_ST_UUID128) {
*uuid = device::BluetoothUUID(base::StringPrintf(
- "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
+ "%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
inner_uuid_data.data.uuid128.Data1,
inner_uuid_data.data.uuid128.Data2,
inner_uuid_data.data.uuid128.Data3,
diff --git a/chromium/device/bluetooth/bluetooth_task_manager_win.cc b/chromium/device/bluetooth/bluetooth_task_manager_win.cc
index ed2c651bd67..55716ff50e2 100644
--- a/chromium/device/bluetooth/bluetooth_task_manager_win.cc
+++ b/chromium/device/bluetooth/bluetooth_task_manager_win.cc
@@ -228,7 +228,7 @@ BluetoothUUID BluetoothTaskManagerWin::BluetoothLowEnergyUuidToBluetoothUuid(
return BluetoothUUID(uuid_hex);
} else {
return BluetoothUUID(base::StringPrintf(
- "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
+ "%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
bth_le_uuid.Value.LongUuid.Data1, bth_le_uuid.Value.LongUuid.Data2,
bth_le_uuid.Value.LongUuid.Data3, bth_le_uuid.Value.LongUuid.Data4[0],
bth_le_uuid.Value.LongUuid.Data4[1],
@@ -529,7 +529,7 @@ bool BluetoothTaskManagerWin::SearchClassicDevices(
}
while (true) {
- auto device_state = base::MakeUnique<DeviceState>();
+ auto device_state = std::make_unique<DeviceState>();
GetDeviceState(device_info, device_state.get());
device_list->push_back(std::move(device_state));
@@ -574,7 +574,7 @@ bool BluetoothTaskManagerWin::SearchLowEnergyDevices(
}
for (const auto& device_info : btle_devices) {
- auto device_state = base::MakeUnique<DeviceState>();
+ auto device_state = std::make_unique<DeviceState>();
device_state->name = device_info->friendly_name;
device_state->address =
BluetoothAddressToCanonicalString(device_info->address);
@@ -694,7 +694,7 @@ int BluetoothTaskManagerWin::DiscoverClassicDeviceServicesWorker(
WSALookupServiceEnd(sdp_handle);
return last_error;
}
- auto service_record_state = base::MakeUnique<ServiceRecordState>();
+ auto service_record_state = std::make_unique<ServiceRecordState>();
service_record_state->name =
base::SysWideToUTF8(sdp_result_data->lpszServiceInstanceName);
for (uint64_t i = 0; i < sdp_result_data->lpBlob->cbSize; i++) {
@@ -731,7 +731,7 @@ bool BluetoothTaskManagerWin::DiscoverLowEnergyDeviceServices(
}
for (const auto& service : services) {
- auto service_state = base::MakeUnique<ServiceRecordState>();
+ auto service_state = std::make_unique<ServiceRecordState>();
service_state->gatt_uuid =
BluetoothLowEnergyUuidToBluetoothUuid(service->uuid);
service_state->attribute_handle = service->attribute_handle;
diff --git a/chromium/device/bluetooth/bluez/bluetooth_adapter_bluez.cc b/chromium/device/bluetooth/bluez/bluetooth_adapter_bluez.cc
index a84aaf4c75b..083db962131 100644
--- a/chromium/device/bluetooth/bluez/bluetooth_adapter_bluez.cc
+++ b/chromium/device/bluetooth/bluez/bluetooth_adapter_bluez.cc
@@ -240,6 +240,7 @@ BluetoothAdapterBlueZ::BluetoothAdapterBlueZ(const InitCallback& init_callback)
dbus_is_shutdown_(false),
num_discovery_sessions_(0),
discovery_request_pending_(false),
+ force_deactivate_discovery_(false),
weak_ptr_factory_(this) {
ui_task_runner_ = base::ThreadTaskRunnerHandle::Get();
socket_thread_ = device::BluetoothSocketThread::Get();
@@ -1090,11 +1091,21 @@ void BluetoothAdapterBlueZ::DiscoveringChanged(bool discovering) {
// If the adapter stopped discovery due to a reason other than a request by
// us, reset the count to 0.
BLUETOOTH_LOG(EVENT) << "Discovering changed: " << discovering;
- if (!discovering && !discovery_request_pending_ &&
- num_discovery_sessions_ > 0) {
- BLUETOOTH_LOG(DEBUG) << "Marking sessions as inactive.";
- num_discovery_sessions_ = 0;
- MarkDiscoverySessionsAsInactive();
+ if (!discovering && num_discovery_sessions_ > 0) {
+ if (discovery_request_pending_) {
+ // If there is discovery request pending, this is guaranteed to be a
+ // Stop() of the last discovery session (num_discovery_sessions_ == 1).
+ // That last Stop() may fail due to adapter not being present, in which
+ // case there will be dangling discovery count. So we are setting a flag
+ // so that the failing Stop() assumes that there is no more discovery
+ // session.
+ BLUETOOTH_LOG(DEBUG) << "Forcing to deactivate discovery.";
+ force_deactivate_discovery_ = true;
+ } else {
+ BLUETOOTH_LOG(DEBUG) << "Marking sessions as inactive.";
+ num_discovery_sessions_ = 0;
+ MarkDiscoverySessionsAsInactive();
+ }
}
for (auto& observer : observers_)
observer.AdapterDiscoveringChanged(this, discovering);
@@ -1580,6 +1591,8 @@ void BluetoothAdapterBlueZ::OnStopDiscovery(const base::Closure& callback) {
num_discovery_sessions_--;
callback.Run();
+ force_deactivate_discovery_ = false;
+
current_filter_.reset();
// Try to add a new discovery session for each queued request.
@@ -1598,6 +1611,14 @@ void BluetoothAdapterBlueZ::OnStopDiscoveryError(
DCHECK(discovery_request_pending_);
DCHECK_EQ(num_discovery_sessions_, 1);
discovery_request_pending_ = false;
+
+ if (force_deactivate_discovery_) {
+ BLUETOOTH_LOG(DEBUG) << "Forced to mark sessions as inactive";
+ force_deactivate_discovery_ = false;
+ num_discovery_sessions_ = 0;
+ MarkDiscoverySessionsAsInactive();
+ }
+
error_callback.Run(TranslateDiscoveryErrorToUMA(error_name));
// Try to add a new discovery session for each queued request.
diff --git a/chromium/device/bluetooth/bluez/bluetooth_adapter_bluez.h b/chromium/device/bluetooth/bluez/bluetooth_adapter_bluez.h
index 8e0c2aeea1b..2ecd2a4466d 100644
--- a/chromium/device/bluetooth/bluez/bluetooth_adapter_bluez.h
+++ b/chromium/device/bluetooth/bluez/bluetooth_adapter_bluez.h
@@ -448,6 +448,10 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterBlueZ
// True, if there is a pending request to start or stop discovery.
bool discovery_request_pending_;
+ // If true that means the last pending stop discovery operation should assume
+ // that the discovery sessions have been deactivated even though it failed.
+ bool force_deactivate_discovery_;
+
// List of queued requests to add new discovery sessions. While there is a
// pending request to BlueZ to start or stop discovery, many requests from
// within Chrome to start or stop discovery sessions may occur. We only
diff --git a/chromium/device/bluetooth/bluez/bluetooth_adapter_profile_bluez_unittest.cc b/chromium/device/bluetooth/bluez/bluetooth_adapter_profile_bluez_unittest.cc
index a969fb07eed..4067bb3a6b0 100644
--- a/chromium/device/bluetooth/bluez/bluetooth_adapter_profile_bluez_unittest.cc
+++ b/chromium/device/bluetooth/bluez/bluetooth_adapter_profile_bluez_unittest.cc
@@ -7,7 +7,6 @@
#include <memory>
#include "base/bind.h"
-#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/test/scoped_task_environment.h"
#include "device/bluetooth/bluetooth_adapter.h"
@@ -80,7 +79,7 @@ class BluetoothAdapterProfileBlueZTest : public testing::Test {
void AdapterCallback(scoped_refptr<BluetoothAdapter> adapter) {
adapter_ = adapter;
if (base::RunLoop::IsRunningOnCurrentThread())
- base::MessageLoop::current()->QuitWhenIdle();
+ base::RunLoop::QuitCurrentWhenIdleDeprecated();
}
class FakeDelegate : public bluez::BluetoothProfileServiceProvider::Delegate {
diff --git a/chromium/device/bluetooth/bluez/bluetooth_advertisement_bluez_unittest.cc b/chromium/device/bluetooth/bluez/bluetooth_advertisement_bluez_unittest.cc
index 170c8063679..81518ba6020 100644
--- a/chromium/device/bluetooth/bluez/bluetooth_advertisement_bluez_unittest.cc
+++ b/chromium/device/bluetooth/bluez/bluetooth_advertisement_bluez_unittest.cc
@@ -94,21 +94,21 @@ class BluetoothAdvertisementBlueZTest : public testing::Test {
ASSERT_NE(adapter_.get(), nullptr);
ASSERT_TRUE(adapter_->IsInitialized());
if (base::RunLoop::IsRunningOnCurrentThread())
- base::MessageLoop::current()->QuitWhenIdle();
+ base::RunLoop::QuitCurrentWhenIdleDeprecated();
}
std::unique_ptr<BluetoothAdvertisement::Data> CreateAdvertisementData() {
std::unique_ptr<BluetoothAdvertisement::Data> data =
- base::MakeUnique<BluetoothAdvertisement::Data>(
+ std::make_unique<BluetoothAdvertisement::Data>(
BluetoothAdvertisement::ADVERTISEMENT_TYPE_BROADCAST);
data->set_service_uuids(
- base::MakeUnique<BluetoothAdvertisement::UUIDList>());
+ std::make_unique<BluetoothAdvertisement::UUIDList>());
data->set_manufacturer_data(
- base::MakeUnique<BluetoothAdvertisement::ManufacturerData>());
+ std::make_unique<BluetoothAdvertisement::ManufacturerData>());
data->set_solicit_uuids(
- base::MakeUnique<BluetoothAdvertisement::UUIDList>());
+ std::make_unique<BluetoothAdvertisement::UUIDList>());
data->set_service_data(
- base::MakeUnique<BluetoothAdvertisement::ServiceData>());
+ std::make_unique<BluetoothAdvertisement::ServiceData>());
return data;
}
diff --git a/chromium/device/bluetooth/bluez/bluetooth_bluez_unittest.cc b/chromium/device/bluetooth/bluez/bluetooth_bluez_unittest.cc
index ef58f0aa670..9e86fee5f75 100644
--- a/chromium/device/bluetooth/bluez/bluetooth_bluez_unittest.cc
+++ b/chromium/device/bluetooth/bluez/bluetooth_bluez_unittest.cc
@@ -166,7 +166,7 @@ class TestPairingDelegate : public BluetoothDevice::PairingDelegate {
// break out of those loops.
void QuitMessageLoop() {
if (base::RunLoop::IsRunningOnCurrentThread())
- base::MessageLoop::current()->QuitWhenIdle();
+ base::RunLoop::QuitCurrentWhenIdleDeprecated();
}
};
@@ -362,7 +362,7 @@ class BluetoothBlueZTest : public testing::Test {
// break out of those loops.
void QuitMessageLoop() {
if (base::RunLoop::IsRunningOnCurrentThread())
- base::MessageLoop::current()->QuitWhenIdle();
+ base::RunLoop::QuitCurrentWhenIdleDeprecated();
}
};
const char BluetoothBlueZTest::kGapUuid[] =
@@ -758,6 +758,39 @@ TEST_F(BluetoothBlueZTest, StopDiscovery) {
EXPECT_EQ(0, error_callback_count_);
}
+TEST_F(BluetoothBlueZTest, StopDiscoveryInProgress) {
+ GetAdapter();
+
+ adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
+
+ callback_count_ = 0;
+ adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
+ adapter_->StartDiscoverySession(
+ base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
+ base::Unretained(this)),
+ GetErrorCallback());
+ base::RunLoop().Run();
+ EXPECT_EQ(2, callback_count_);
+ EXPECT_EQ(0, error_callback_count_);
+ callback_count_ = 0;
+ ASSERT_TRUE(adapter_->IsPowered());
+ ASSERT_TRUE(adapter_->IsDiscovering());
+ ASSERT_EQ((size_t)1, discovery_sessions_.size());
+ ASSERT_TRUE(discovery_sessions_[0]->IsActive());
+
+ // First call to Stop() should succeed.
+ discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback());
+ // Second call to Stop() while the first is in progress should fail.
+ discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback());
+
+ base::RunLoop().Run();
+ EXPECT_EQ(1, callback_count_);
+ EXPECT_EQ(1, error_callback_count_);
+ discovery_sessions_.clear();
+ callback_count_ = 0;
+ error_callback_count_ = 0;
+}
+
TEST_F(BluetoothBlueZTest, Discovery) {
// Test a simulated discovery session.
fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
diff --git a/chromium/device/bluetooth/bluez/bluetooth_gatt_bluez_unittest.cc b/chromium/device/bluetooth/bluez/bluetooth_gatt_bluez_unittest.cc
index fb0a052b07a..083ac37caf2 100644
--- a/chromium/device/bluetooth/bluez/bluetooth_gatt_bluez_unittest.cc
+++ b/chromium/device/bluetooth/bluez/bluetooth_gatt_bluez_unittest.cc
@@ -239,7 +239,7 @@ class BluetoothGattBlueZTest : public testing::Test {
void AdapterCallback(scoped_refptr<BluetoothAdapter> adapter) {
adapter_ = adapter;
if (base::RunLoop::IsRunningOnCurrentThread())
- base::MessageLoop::current()->QuitWhenIdle();
+ base::RunLoop::QuitCurrentWhenIdleDeprecated();
}
void SuccessCallback() { ++success_callback_count_; }
@@ -280,7 +280,7 @@ class BluetoothGattBlueZTest : public testing::Test {
protected:
void QuitMessageLoop() {
if (base::RunLoop::IsRunningOnCurrentThread())
- base::MessageLoop::current()->QuitWhenIdle();
+ base::RunLoop::QuitCurrentWhenIdleDeprecated();
}
base::MessageLoop message_loop_;
diff --git a/chromium/device/bluetooth/bluez/bluetooth_service_attribute_value_bluez.cc b/chromium/device/bluetooth/bluez/bluetooth_service_attribute_value_bluez.cc
index 2c484c1d367..2a145185e07 100644
--- a/chromium/device/bluetooth/bluez/bluetooth_service_attribute_value_bluez.cc
+++ b/chromium/device/bluetooth/bluez/bluetooth_service_attribute_value_bluez.cc
@@ -12,7 +12,7 @@
namespace bluez {
BluetoothServiceAttributeValueBlueZ::BluetoothServiceAttributeValueBlueZ()
- : type_(NULLTYPE), size_(0), value_(base::MakeUnique<base::Value>()) {}
+ : type_(NULLTYPE), size_(0), value_(std::make_unique<base::Value>()) {}
BluetoothServiceAttributeValueBlueZ::BluetoothServiceAttributeValueBlueZ(
Type type,
@@ -40,7 +40,7 @@ operator=(const BluetoothServiceAttributeValueBlueZ& attribute) {
size_ = attribute.size_;
if (attribute.type_ == SEQUENCE) {
value_ = nullptr;
- sequence_ = base::MakeUnique<Sequence>(*attribute.sequence_);
+ sequence_ = std::make_unique<Sequence>(*attribute.sequence_);
} else {
value_ = attribute.value_->CreateDeepCopy();
sequence_ = nullptr;
diff --git a/chromium/device/bluetooth/bluez/bluetooth_service_attribute_value_bluez_unittest.cc b/chromium/device/bluetooth/bluez/bluetooth_service_attribute_value_bluez_unittest.cc
index ba66a4b29ae..377c16359c4 100644
--- a/chromium/device/bluetooth/bluez/bluetooth_service_attribute_value_bluez_unittest.cc
+++ b/chromium/device/bluetooth/bluez/bluetooth_service_attribute_value_bluez_unittest.cc
@@ -41,14 +41,14 @@ void CheckIntValue(const BluetoothServiceAttributeValueBlueZ& value,
// in the call. This function helps us avoid all that ugly syntax.
std::unique_ptr<Sequence> MakeSequence(
const std::initializer_list<BluetoothServiceAttributeValueBlueZ> list) {
- return base::MakeUnique<Sequence>(list);
+ return std::make_unique<Sequence>(list);
}
} // namespace
TEST(BluetoothServiceAttributeBlueZTest, BasicValue) {
BluetoothServiceAttributeValueBlueZ value1(
- Type::UUID, 16, base::MakeUnique<base::Value>(kServiceUuid));
+ Type::UUID, 16, std::make_unique<base::Value>(kServiceUuid));
BluetoothServiceAttributeValueBlueZ value2 = value1;
CheckUuidValue(value2, kServiceUuid);
@@ -56,11 +56,11 @@ TEST(BluetoothServiceAttributeBlueZTest, BasicValue) {
TEST(BluetoothServiceAttributeBlueZTest, Sequence) {
BluetoothServiceAttributeValueBlueZ value1(
- Type::UUID, 16, base::MakeUnique<base::Value>(kServiceUuid));
+ Type::UUID, 16, std::make_unique<base::Value>(kServiceUuid));
BluetoothServiceAttributeValueBlueZ value2(
- Type::INT, 4, base::MakeUnique<base::Value>(0x1337));
+ Type::INT, 4, std::make_unique<base::Value>(0x1337));
BluetoothServiceAttributeValueBlueZ value3(
- Type::INT, 4, base::MakeUnique<base::Value>(0x7331));
+ Type::INT, 4, std::make_unique<base::Value>(0x7331));
BluetoothServiceAttributeValueBlueZ* value4 =
new BluetoothServiceAttributeValueBlueZ(
@@ -80,9 +80,9 @@ TEST(BluetoothServiceAttributeBlueZTest, Sequence) {
TEST(BluetoothServiceAttributeBlueZTest, NestedValue) {
BluetoothServiceAttributeValueBlueZ value1(
- Type::UUID, 16, base::MakeUnique<base::Value>(kServiceUuid));
+ Type::UUID, 16, std::make_unique<base::Value>(kServiceUuid));
BluetoothServiceAttributeValueBlueZ value2(
- Type::INT, 4, base::MakeUnique<base::Value>(0x1337));
+ Type::INT, 4, std::make_unique<base::Value>(0x1337));
BluetoothServiceAttributeValueBlueZ value3(MakeSequence({value1, value2}));
BluetoothServiceAttributeValueBlueZ value4(MakeSequence({value3}));
@@ -124,11 +124,11 @@ TEST(BluetoothServiceAttributeBlueZTest, NestedValue) {
TEST(BluetoothServiceAttributeBlueZTest, CopyAssignment) {
BluetoothServiceAttributeValueBlueZ value1(
- Type::UUID, 16, base::MakeUnique<base::Value>(kServiceUuid));
+ Type::UUID, 16, std::make_unique<base::Value>(kServiceUuid));
BluetoothServiceAttributeValueBlueZ value2(
- Type::INT, 4, base::MakeUnique<base::Value>(0x1337));
+ Type::INT, 4, std::make_unique<base::Value>(0x1337));
BluetoothServiceAttributeValueBlueZ value3(
- Type::INT, 4, base::MakeUnique<base::Value>(0x7331));
+ Type::INT, 4, std::make_unique<base::Value>(0x7331));
std::unique_ptr<BluetoothServiceAttributeValueBlueZ> value4(
new BluetoothServiceAttributeValueBlueZ(
MakeSequence({value1, value2, value3})));
diff --git a/chromium/device/bluetooth/bluez/bluetooth_service_record_bluez_unittest.cc b/chromium/device/bluetooth/bluez/bluetooth_service_record_bluez_unittest.cc
index 0c2433ce009..af35997b09e 100644
--- a/chromium/device/bluetooth/bluez/bluetooth_service_record_bluez_unittest.cc
+++ b/chromium/device/bluetooth/bluez/bluetooth_service_record_bluez_unittest.cc
@@ -130,7 +130,7 @@ class BluetoothServiceRecordBlueZTest : public device::BluetoothTestBlueZ {
record.AddRecordEntry(kServiceUuidAttributeId,
BluetoothServiceAttributeValueBlueZ(
BluetoothServiceAttributeValueBlueZ::UUID, 16,
- base::MakeUnique<base::Value>(uuid)));
+ std::make_unique<base::Value>(uuid)));
return record;
}
diff --git a/chromium/device/bluetooth/bluez/bluetooth_socket_bluez_unittest.cc b/chromium/device/bluetooth/bluez/bluetooth_socket_bluez_unittest.cc
index d536eb08901..9df63a98a19 100644
--- a/chromium/device/bluetooth/bluez/bluetooth_socket_bluez_unittest.cc
+++ b/chromium/device/bluetooth/bluez/bluetooth_socket_bluez_unittest.cc
@@ -8,9 +8,8 @@
#include "base/bind.h"
#include "base/memory/ref_counted.h"
-#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
-#include "base/test/scoped_async_task_scheduler.h"
+#include "base/test/scoped_task_environment.h"
#include "device/bluetooth/bluetooth_adapter.h"
#include "device/bluetooth/bluetooth_adapter_factory.h"
#include "device/bluetooth/bluetooth_device.h"
@@ -173,8 +172,7 @@ class BluetoothSocketBlueZTest : public testing::Test {
void ImmediateSuccessCallback() { ++success_callback_count_; }
protected:
- base::MessageLoop message_loop_;
- base::test::ScopedAsyncTaskScheduler scoped_async_task_scheduler_;
+ base::test::ScopedTaskEnvironment scoped_task_environment_;
scoped_refptr<BluetoothAdapter> adapter_;
diff --git a/chromium/device/bluetooth/dbus/bluetooth_device_client.cc b/chromium/device/bluetooth/dbus/bluetooth_device_client.cc
index c79cba40f64..38a4c462788 100644
--- a/chromium/device/bluetooth/dbus/bluetooth_device_client.cc
+++ b/chromium/device/bluetooth/dbus/bluetooth_device_client.cc
@@ -54,19 +54,19 @@ std::unique_ptr<BluetoothServiceAttributeValueBlueZ> ReadAttributeValue(
uint8_t byte;
if (!struct_reader->PopVariantOfByte(&byte))
return nullptr;
- value = base::MakeUnique<base::Value>(byte);
+ value = std::make_unique<base::Value>(byte);
break;
case 2:
uint16_t short_val;
if (!struct_reader->PopVariantOfUint16(&short_val))
return nullptr;
- value = base::MakeUnique<base::Value>(short_val);
+ value = std::make_unique<base::Value>(short_val);
break;
case 4:
uint32_t val;
if (!struct_reader->PopVariantOfUint32(&val))
return nullptr;
- value = base::MakeUnique<base::Value>(static_cast<int32_t>(val));
+ value = std::make_unique<base::Value>(static_cast<int32_t>(val));
break;
case 8:
// Fall through.
@@ -87,14 +87,14 @@ std::unique_ptr<BluetoothServiceAttributeValueBlueZ> ReadAttributeValue(
std::string str;
if (!struct_reader->PopVariantOfString(&str))
return nullptr;
- value = base::MakeUnique<base::Value>(str);
+ value = std::make_unique<base::Value>(str);
break;
}
case bluez::BluetoothServiceAttributeValueBlueZ::BOOL: {
bool b;
if (!struct_reader->PopVariantOfBool(&b))
return nullptr;
- value = base::MakeUnique<base::Value>(b);
+ value = std::make_unique<base::Value>(b);
break;
}
case bluez::BluetoothServiceAttributeValueBlueZ::SEQUENCE: {
@@ -105,7 +105,7 @@ std::unique_ptr<BluetoothServiceAttributeValueBlueZ> ReadAttributeValue(
if (!variant_reader.PopArray(&array_reader))
return nullptr;
std::unique_ptr<BluetoothServiceAttributeValueBlueZ::Sequence> sequence =
- base::MakeUnique<BluetoothServiceAttributeValueBlueZ::Sequence>();
+ std::make_unique<BluetoothServiceAttributeValueBlueZ::Sequence>();
while (array_reader.HasMoreData()) {
dbus::MessageReader sequence_element_struct_reader(nullptr);
if (!array_reader.PopStruct(&sequence_element_struct_reader))
@@ -116,18 +116,18 @@ std::unique_ptr<BluetoothServiceAttributeValueBlueZ> ReadAttributeValue(
return nullptr;
sequence->emplace_back(*attribute_value);
}
- return base::MakeUnique<BluetoothServiceAttributeValueBlueZ>(
+ return std::make_unique<BluetoothServiceAttributeValueBlueZ>(
std::move(sequence));
}
}
- return base::MakeUnique<BluetoothServiceAttributeValueBlueZ>(
+ return std::make_unique<BluetoothServiceAttributeValueBlueZ>(
type, size, std::move(value));
}
std::unique_ptr<BluetoothServiceRecordBlueZ> ReadRecord(
dbus::MessageReader* array_reader) {
std::unique_ptr<BluetoothServiceRecordBlueZ> record =
- base::MakeUnique<BluetoothServiceRecordBlueZ>();
+ std::make_unique<BluetoothServiceRecordBlueZ>();
while (array_reader->HasMoreData()) {
dbus::MessageReader dict_entry_reader(nullptr);
if (!array_reader->PopDictEntry(&dict_entry_reader))
diff --git a/chromium/device/bluetooth/dbus/bluetooth_gatt_application_service_provider.cc b/chromium/device/bluetooth/dbus/bluetooth_gatt_application_service_provider.cc
index 5d436b844aa..92f1100005b 100644
--- a/chromium/device/bluetooth/dbus/bluetooth_gatt_application_service_provider.cc
+++ b/chromium/device/bluetooth/dbus/bluetooth_gatt_application_service_provider.cc
@@ -116,7 +116,7 @@ void BluetoothGattApplicationServiceProvider::CreateAttributeServiceProviders(
characteristic_providers_.push_back(
base::WrapUnique(BluetoothGattCharacteristicServiceProvider::Create(
bus, characteristic.second->object_path(),
- base::MakeUnique<BluetoothGattCharacteristicDelegateWrapper>(
+ std::make_unique<BluetoothGattCharacteristicDelegateWrapper>(
service.second, characteristic.second.get()),
characteristic.second->GetUUID().value(),
FlagsFromProperties(characteristic.second->GetProperties()),
@@ -125,7 +125,7 @@ void BluetoothGattApplicationServiceProvider::CreateAttributeServiceProviders(
descriptor_providers_.push_back(
base::WrapUnique(BluetoothGattDescriptorServiceProvider::Create(
bus, descriptor->object_path(),
- base::MakeUnique<BluetoothGattDescriptorDelegateWrapper>(
+ std::make_unique<BluetoothGattDescriptorDelegateWrapper>(
service.second, descriptor.get()),
descriptor->GetUUID().value(),
FlagsFromPermissions(descriptor->GetPermissions()),
@@ -161,7 +161,7 @@ BluetoothGattApplicationServiceProvider::Create(
return base::WrapUnique(new BluetoothGattApplicationServiceProviderImpl(
bus, object_path, services));
}
- return base::MakeUnique<FakeBluetoothGattApplicationServiceProvider>(
+ return std::make_unique<FakeBluetoothGattApplicationServiceProvider>(
object_path, services);
}
diff --git a/chromium/device/bluetooth/dbus/bluetooth_gatt_application_service_provider_unittest.cc b/chromium/device/bluetooth/dbus/bluetooth_gatt_application_service_provider_unittest.cc
index da236c3fa16..35725baf083 100644
--- a/chromium/device/bluetooth/dbus/bluetooth_gatt_application_service_provider_unittest.cc
+++ b/chromium/device/bluetooth/dbus/bluetooth_gatt_application_service_provider_unittest.cc
@@ -293,7 +293,7 @@ class BluetoothGattApplicationServiceProviderTest : public testing::Test {
const std::string& full_service_path =
std::string(kAppObjectPath) + "/" + service_path;
app_provider->service_providers_.push_back(
- base::MakeUnique<BluetoothGattServiceServiceProviderImpl>(
+ std::make_unique<BluetoothGattServiceServiceProviderImpl>(
nullptr, dbus::ObjectPath(full_service_path), kFakeServiceUuid,
true, std::vector<dbus::ObjectPath>()));
return full_service_path;
@@ -350,7 +350,7 @@ class BluetoothGattApplicationServiceProviderTest : public testing::Test {
TEST_F(BluetoothGattApplicationServiceProviderTest, GetManagedObjects) {
std::unique_ptr<BluetoothGattApplicationServiceProviderImpl> app_provider =
- base::MakeUnique<BluetoothGattApplicationServiceProviderImpl>(
+ std::make_unique<BluetoothGattApplicationServiceProviderImpl>(
nullptr, dbus::ObjectPath(kAppObjectPath),
std::map<dbus::ObjectPath, BluetoothLocalGattServiceBlueZ*>());
CreateFakeAttributes(app_provider.get());
@@ -364,7 +364,7 @@ TEST_F(BluetoothGattApplicationServiceProviderTest, GetManagedObjects) {
TEST_F(BluetoothGattApplicationServiceProviderTest, SendValueChanged) {
std::unique_ptr<BluetoothGattApplicationServiceProviderImpl> app_provider =
- base::MakeUnique<BluetoothGattApplicationServiceProviderImpl>(
+ std::make_unique<BluetoothGattApplicationServiceProviderImpl>(
nullptr, dbus::ObjectPath(kAppObjectPath),
std::map<dbus::ObjectPath, BluetoothLocalGattServiceBlueZ*>());
const std::string& kServicePath =
diff --git a/chromium/device/bluetooth/dbus/bluetooth_le_advertisement_service_provider.cc b/chromium/device/bluetooth/dbus/bluetooth_le_advertisement_service_provider.cc
index 51494bb51b5..9b5cbff3d1a 100644
--- a/chromium/device/bluetooth/dbus/bluetooth_le_advertisement_service_provider.cc
+++ b/chromium/device/bluetooth/dbus/bluetooth_le_advertisement_service_provider.cc
@@ -422,12 +422,12 @@ BluetoothLEAdvertisementServiceProvider::Create(
std::unique_ptr<UUIDList> solicit_uuids,
std::unique_ptr<ServiceData> service_data) {
if (!bluez::BluezDBusManager::Get()->IsUsingFakes()) {
- return base::MakeUnique<BluetoothAdvertisementServiceProviderImpl>(
+ return std::make_unique<BluetoothAdvertisementServiceProviderImpl>(
bus, object_path, delegate, type, std::move(service_uuids),
std::move(manufacturer_data), std::move(solicit_uuids),
std::move(service_data));
}
- return base::MakeUnique<FakeBluetoothLEAdvertisementServiceProvider>(
+ return std::make_unique<FakeBluetoothLEAdvertisementServiceProvider>(
object_path, delegate);
}
diff --git a/chromium/device/bluetooth/dbus/fake_bluetooth_device_client.cc b/chromium/device/bluetooth/dbus/fake_bluetooth_device_client.cc
index ae73a84fd29..26710672e3a 100644
--- a/chromium/device/bluetooth/dbus/fake_bluetooth_device_client.cc
+++ b/chromium/device/bluetooth/dbus/fake_bluetooth_device_client.cc
@@ -104,29 +104,29 @@ BluetoothDeviceClient::ServiceRecordList CreateFakeServiceRecords() {
BluetoothDeviceClient::ServiceRecordList records;
std::unique_ptr<BluetoothServiceRecordBlueZ> record1 =
- base::MakeUnique<BluetoothServiceRecordBlueZ>();
+ std::make_unique<BluetoothServiceRecordBlueZ>();
// ID 0 = handle.
record1->AddRecordEntry(
0x0, BluetoothServiceAttributeValueBlueZ(
BluetoothServiceAttributeValueBlueZ::UINT, 4,
- base::MakeUnique<base::Value>(static_cast<int32_t>(0x1337))));
+ std::make_unique<base::Value>(static_cast<int32_t>(0x1337))));
// ID 1 = service class id list.
std::unique_ptr<BluetoothServiceAttributeValueBlueZ::Sequence> class_id_list =
- base::MakeUnique<BluetoothServiceAttributeValueBlueZ::Sequence>();
+ std::make_unique<BluetoothServiceAttributeValueBlueZ::Sequence>();
class_id_list->emplace_back(BluetoothServiceAttributeValueBlueZ::UUID, 4,
- base::MakeUnique<base::Value>("1802"));
+ std::make_unique<base::Value>("1802"));
record1->AddRecordEntry(
0x1, BluetoothServiceAttributeValueBlueZ(std::move(class_id_list)));
records.emplace_back(*record1);
std::unique_ptr<BluetoothServiceRecordBlueZ> record2 =
- base::MakeUnique<BluetoothServiceRecordBlueZ>();
+ std::make_unique<BluetoothServiceRecordBlueZ>();
// ID 0 = handle.
record2->AddRecordEntry(
0x0,
BluetoothServiceAttributeValueBlueZ(
BluetoothServiceAttributeValueBlueZ::UINT, 4,
- base::MakeUnique<base::Value>(static_cast<int32_t>(0xffffffff))));
+ std::make_unique<base::Value>(static_cast<int32_t>(0xffffffff))));
records.emplace_back(*record2);
return records;
diff --git a/chromium/device/bluetooth/dbus/fake_bluetooth_input_client.cc b/chromium/device/bluetooth/dbus/fake_bluetooth_input_client.cc
index f7f7baa893e..699e4170272 100644
--- a/chromium/device/bluetooth/dbus/fake_bluetooth_input_client.cc
+++ b/chromium/device/bluetooth/dbus/fake_bluetooth_input_client.cc
@@ -71,7 +71,7 @@ void FakeBluetoothInputClient::AddInputDevice(
if (properties_map_.find(object_path) != properties_map_.end())
return;
- std::unique_ptr<Properties> properties = base::MakeUnique<Properties>(
+ std::unique_ptr<Properties> properties = std::make_unique<Properties>(
base::Bind(&FakeBluetoothInputClient::OnPropertyChanged,
base::Unretained(this), object_path));
diff --git a/chromium/device/bluetooth/dbus/fake_bluetooth_media_transport_client.cc b/chromium/device/bluetooth/dbus/fake_bluetooth_media_transport_client.cc
index ae6754e0262..3c5b82550d9 100644
--- a/chromium/device/bluetooth/dbus/fake_bluetooth_media_transport_client.cc
+++ b/chromium/device/bluetooth/dbus/fake_bluetooth_media_transport_client.cc
@@ -178,7 +178,7 @@ void FakeBluetoothMediaTransportClient::SetValid(
properties->volume.ReplaceValue(kTransportVolume);
endpoint_to_transport_map_[endpoint_path] =
- base::MakeUnique<Transport>(transport_path, std::move(properties));
+ std::make_unique<Transport>(transport_path, std::move(properties));
transport_to_endpoint_map_[transport_path] = endpoint_path;
return;
}
diff --git a/chromium/device/bluetooth/device_unittest.cc b/chromium/device/bluetooth/device_unittest.cc
index 9a07564f333..12928821629 100644
--- a/chromium/device/bluetooth/device_unittest.cc
+++ b/chromium/device/bluetooth/device_unittest.cc
@@ -76,18 +76,18 @@ class BluetoothInterfaceDeviceTest : public testing::Test {
ON_CALL(*adapter_, GetDevice(kTestLeDeviceAddress0))
.WillByDefault(Return(&device_));
- auto service1 = base::MakeUnique<NiceMockBluetoothGattService>(
+ auto service1 = std::make_unique<NiceMockBluetoothGattService>(
&device_, kTestServiceId0, device::BluetoothUUID(kTestServiceUuid0),
true /* is_primary */, false /* is_local */);
auto characteristic1 =
- base::MakeUnique<NiceMockBluetoothGattCharacteristic>(
+ std::make_unique<NiceMockBluetoothGattCharacteristic>(
service1.get(), kTestCharacteristicId0,
device::BluetoothUUID(kTestCharacteristicUuid0),
false /* is_local */, kReadWriteProperties, 0 /* permissions */);
auto characteristic2 =
- base::MakeUnique<NiceMockBluetoothGattCharacteristic>(
+ std::make_unique<NiceMockBluetoothGattCharacteristic>(
service1.get(), kTestCharacteristicId1,
device::BluetoothUUID(kTestCharacteristicUuid1),
false /* is_local */, kReadWriteProperties, 0 /* permissions */);
@@ -95,12 +95,12 @@ class BluetoothInterfaceDeviceTest : public testing::Test {
service1->AddMockCharacteristic(std::move(characteristic1));
service1->AddMockCharacteristic(std::move(characteristic2));
- auto service2 = base::MakeUnique<NiceMockBluetoothGattService>(
+ auto service2 = std::make_unique<NiceMockBluetoothGattService>(
&device_, kTestServiceId1, device::BluetoothUUID(kTestServiceUuid1),
true /* is_primary */, false /* is_local */);
auto characteristic3 =
- base::MakeUnique<NiceMockBluetoothGattCharacteristic>(
+ std::make_unique<NiceMockBluetoothGattCharacteristic>(
service2.get(), kTestCharacteristicId2,
device::BluetoothUUID(kTestCharacteristicUuid2),
false /* is_local */, kAllProperties, 0 /* permissions */);
@@ -128,7 +128,7 @@ class BluetoothInterfaceDeviceTest : public testing::Test {
.WillRepeatedly(
Invoke(&device_, &device::MockBluetoothDevice::GetMockService));
- auto connection = base::MakeUnique<NiceMockBluetoothGattConnection>(
+ auto connection = std::make_unique<NiceMockBluetoothGattConnection>(
adapter_, device_.GetAddress());
Device::Create(adapter_, std::move(connection), mojo::MakeRequest(&proxy_));
diff --git a/chromium/device/bluetooth/public/interfaces/test/fake_bluetooth.mojom b/chromium/device/bluetooth/public/interfaces/test/fake_bluetooth.mojom
index aea942f8731..b1d2faa9652 100644
--- a/chromium/device/bluetooth/public/interfaces/test/fake_bluetooth.mojom
+++ b/chromium/device/bluetooth/public/interfaces/test/fake_bluetooth.mojom
@@ -105,6 +105,18 @@ interface FakeCentral {
// have completed or if there was an error during any of them.
SetNextGATTDiscoveryResponse(string address, uint16 code) => (bool success);
+ // Simulates an Indication from the peripheral's GATT `Service Changed`
+ // Characteristic from BT 4.2 Vol 3 Part G 7.1. This Indication is signaled
+ // when services, characteristics, or descriptors are changed, added, or
+ // removed.
+ //
+ // The value for `Service Changed` is a range of attribute handles that have
+ // changed. However, this testing specification works at an abstracted
+ // level and does not expose setting attribute handles when adding
+ // attributes. Consequently, this simulate method should include the full
+ // range of all the peripheral's attribute handle values.
+ SimulateGATTServicesChanged(string address) => (bool success);
+
// Adds a fake GATT Service with |service_uuid| to |peripheral_address|
// peripheral. The service will be found found when discovering the
// peripheral's GATT Attributes. Runs its callback with the fake service's Id.
@@ -123,6 +135,13 @@ interface FakeCentral {
string service_id,
string peripheral_address) => (string? characteristic_id);
+ // Removes a fake GATT Characteristic with |identifier| to the fake service
+ // with |service_id| in |peripheral_address| peripheral.
+ RemoveFakeCharacteristic(
+ string identifier,
+ string service_id,
+ string peripheral_address) => (bool success);
+
// Adds a fake GATT Descriptor with |descriptor_uuid| to the fake service with
// |service_id| in |peripheral_address| peripheral. The descriptor will be
// found when discovering the peripheral's GATT Attributes. Runs its callback
diff --git a/chromium/device/gamepad/BUILD.gn b/chromium/device/gamepad/BUILD.gn
index 5ab5ee818d0..e39da45fb27 100644
--- a/chromium/device/gamepad/BUILD.gn
+++ b/chromium/device/gamepad/BUILD.gn
@@ -13,8 +13,6 @@ component("gamepad") {
output_name = "device_gamepad"
sources = [
- "android/gamepad_jni_registrar.cc",
- "android/gamepad_jni_registrar.h",
"game_controller_data_fetcher_mac.h",
"game_controller_data_fetcher_mac.mm",
"gamepad_consumer.cc",
diff --git a/chromium/device/gamepad/gamepad_monitor.cc b/chromium/device/gamepad/gamepad_monitor.cc
index 8e3144e4e37..f15ee2080bb 100644
--- a/chromium/device/gamepad/gamepad_monitor.cc
+++ b/chromium/device/gamepad/gamepad_monitor.cc
@@ -23,7 +23,7 @@ GamepadMonitor::~GamepadMonitor() {
// static
void GamepadMonitor::Create(mojom::GamepadMonitorRequest request) {
- mojo::MakeStrongBinding(base::MakeUnique<GamepadMonitor>(),
+ mojo::MakeStrongBinding(std::make_unique<GamepadMonitor>(),
std::move(request));
}
diff --git a/chromium/device/gamepad/gamepad_monitor.h b/chromium/device/gamepad/gamepad_monitor.h
index eab2fa08881..b043474a484 100644
--- a/chromium/device/gamepad/gamepad_monitor.h
+++ b/chromium/device/gamepad/gamepad_monitor.h
@@ -13,9 +13,8 @@
namespace device {
-class DEVICE_GAMEPAD_EXPORT GamepadMonitor
- : public GamepadConsumer,
- NON_EXPORTED_BASE(public mojom::GamepadMonitor) {
+class DEVICE_GAMEPAD_EXPORT GamepadMonitor : public GamepadConsumer,
+ public mojom::GamepadMonitor {
public:
GamepadMonitor();
~GamepadMonitor() override;
diff --git a/chromium/device/gamepad/gamepad_platform_data_fetcher_android.cc b/chromium/device/gamepad/gamepad_platform_data_fetcher_android.cc
index f925b07291b..5273d211f20 100644
--- a/chromium/device/gamepad/gamepad_platform_data_fetcher_android.cc
+++ b/chromium/device/gamepad/gamepad_platform_data_fetcher_android.cc
@@ -25,11 +25,6 @@ using base::android::ScopedJavaLocalRef;
namespace device {
-bool GamepadPlatformDataFetcherAndroid::
- RegisterGamepadPlatformDataFetcherAndroid(JNIEnv* env) {
- return RegisterNativesImpl(env);
-}
-
GamepadPlatformDataFetcherAndroid::GamepadPlatformDataFetcherAndroid() {
}
diff --git a/chromium/device/gamepad/gamepad_platform_data_fetcher_android.h b/chromium/device/gamepad/gamepad_platform_data_fetcher_android.h
index 158b5ccf043..614ae7b257e 100644
--- a/chromium/device/gamepad/gamepad_platform_data_fetcher_android.h
+++ b/chromium/device/gamepad/gamepad_platform_data_fetcher_android.h
@@ -34,9 +34,6 @@ class GamepadPlatformDataFetcherAndroid : public GamepadDataFetcher {
void GetGamepadData(bool devices_changed_hint) override;
- // Registers the JNI methods for GamepadsReader.
- static bool RegisterGamepadPlatformDataFetcherAndroid(JNIEnv* env);
-
private:
void OnAddedToProvider() override;
diff --git a/chromium/device/gamepad/gamepad_standard_mappings_linux.cc b/chromium/device/gamepad/gamepad_standard_mappings_linux.cc
index 17b8afc2430..ea41db972d8 100644
--- a/chromium/device/gamepad/gamepad_standard_mappings_linux.cc
+++ b/chromium/device/gamepad/gamepad_standard_mappings_linux.cc
@@ -31,7 +31,32 @@ void MapperXInputStyleGamepad(const Gamepad& input, Gamepad* mapped) {
mapped->axes_length = AXIS_INDEX_COUNT;
}
-void MapperXboxOneHidGamepad(const Gamepad& input, Gamepad* mapped) {
+void MapperXboxOneS2016Firmware(const Gamepad& input, Gamepad* mapped) {
+ *mapped = input;
+ mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[0];
+ mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1];
+ mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[2];
+ mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[3];
+ mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[4];
+ mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[5];
+ mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[2]);
+ mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[5]);
+ mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[6];
+ mapped->buttons[BUTTON_INDEX_START] = input.buttons[7];
+ mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[8];
+ mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[9];
+ mapped->buttons[BUTTON_INDEX_DPAD_UP] = AxisNegativeAsButton(input.axes[7]);
+ mapped->buttons[BUTTON_INDEX_DPAD_DOWN] = AxisPositiveAsButton(input.axes[7]);
+ mapped->buttons[BUTTON_INDEX_DPAD_LEFT] = AxisNegativeAsButton(input.axes[6]);
+ mapped->buttons[BUTTON_INDEX_DPAD_RIGHT] =
+ AxisPositiveAsButton(input.axes[6]);
+ mapped->axes[AXIS_INDEX_RIGHT_STICK_X] = input.axes[3];
+ mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[4];
+ mapped->buttons_length = BUTTON_INDEX_COUNT - 1; /* no meta */
+ mapped->axes_length = AXIS_INDEX_COUNT;
+}
+
+void MapperXboxOneS(const Gamepad& input, Gamepad* mapped) {
*mapped = input;
mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[0];
@@ -291,7 +316,7 @@ void MapperRazerServal(const Gamepad& input, Gamepad* mapped) {
mapped->axes_length = AXIS_INDEX_COUNT;
}
-void MapperMogaPro(const Gamepad& input, Gamepad* mapped) {
+void MapperMoga(const Gamepad& input, Gamepad* mapped) {
*mapped = input;
mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[5]);
mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[4]);
@@ -340,6 +365,28 @@ void MapperSamsung_EI_GP20(const Gamepad& input, Gamepad* mapped) {
mapped->axes_length = AXIS_INDEX_COUNT;
}
+void MapperSteelSeries(const Gamepad& input, Gamepad* mapped) {
+ *mapped = input;
+ mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
+ mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[4];
+ mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6];
+ mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7];
+ mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = NullButton();
+ mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = NullButton();
+ mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[12];
+ mapped->buttons[BUTTON_INDEX_START] = input.buttons[11];
+ mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = NullButton();
+ mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = NullButton();
+ mapped->buttons[BUTTON_INDEX_DPAD_UP] = AxisNegativeAsButton(input.axes[5]);
+ mapped->buttons[BUTTON_INDEX_DPAD_DOWN] = AxisPositiveAsButton(input.axes[5]);
+ mapped->buttons[BUTTON_INDEX_DPAD_LEFT] = AxisNegativeAsButton(input.axes[4]);
+ mapped->buttons[BUTTON_INDEX_DPAD_RIGHT] =
+ AxisPositiveAsButton(input.axes[4]);
+ mapped->buttons[BUTTON_INDEX_META] = NullButton();
+ mapped->buttons_length = BUTTON_INDEX_META;
+ mapped->axes_length = AXIS_INDEX_COUNT;
+}
+
struct MappingData {
const char* const vendor_id;
const char* const product_id;
@@ -350,11 +397,13 @@ struct MappingData {
{"045e", "028e", MapperXInputStyleGamepad}, // Xbox 360 Wired
{"045e", "028f", MapperXInputStyleGamepad}, // Xbox 360 Wireless
{"045e", "02a1", MapperXInputStyleGamepad}, // Xbox 360 Wireless
+ {"045e", "0291", MapperXInputStyleGamepad}, // Xbox 360 Wireless
{"045e", "02d1", MapperXInputStyleGamepad}, // Xbox One Wired
{"045e", "02dd", MapperXInputStyleGamepad}, // Xbox One Wired (2015 FW)
+ {"045e", "02e0", MapperXboxOneS2016Firmware}, // Xbox One S (Bluetooth)
{"045e", "02e3", MapperXInputStyleGamepad}, // Xbox One Elite Wired
{"045e", "02ea", MapperXInputStyleGamepad}, // Xbox One S (USB)
- {"045e", "02fd", MapperXboxOneHidGamepad}, // Xbox One S (Bluetooth)
+ {"045e", "02fd", MapperXboxOneS}, // Xbox One S (Bluetooth)
{"045e", "0719", MapperXInputStyleGamepad}, // Xbox 360 Wireless
{"046d", "c21d", MapperXInputStyleGamepad}, // Logitech F310
{"046d", "c21e", MapperXInputStyleGamepad}, // Logitech F510
@@ -369,9 +418,11 @@ struct MappingData {
{"0955", "7210", MapperNvShield}, // Nvidia Shield gamepad
{"0b05", "4500", MapperADT1}, // Nexus Player Controller
{"0e8f", "0003", MapperXGEAR}, // XFXforce XGEAR PS2 Controller
+ {"1038", "1412", MapperSteelSeries}, // Zeemote: SteelSeries FREE
{"1532", "0900", MapperRazerServal}, // Razer Serval Controller
{"18d1", "2c40", MapperADT1}, // ADT-1 Controller
- {"20d6", "6271", MapperMogaPro}, // Moga Pro Controller (HID mode)
+ {"20d6", "6271", MapperMoga}, // Moga Pro Controller (HID mode)
+ {"20d6", "89e5", MapperMoga}, // Moga 2 HID
{"2378", "1008", MapperOnLiveWireless}, // OnLive Controller (Bluetooth)
{"2378", "100a", MapperOnLiveWireless}, // OnLive Controller (Wired)
{"2836", "0001", MapperOUYA}, // OUYA Controller
diff --git a/chromium/device/gamepad/gamepad_standard_mappings_mac.mm b/chromium/device/gamepad/gamepad_standard_mappings_mac.mm
index 27e12ce6898..8d358dfc095 100644
--- a/chromium/device/gamepad/gamepad_standard_mappings_mac.mm
+++ b/chromium/device/gamepad/gamepad_standard_mappings_mac.mm
@@ -30,7 +30,29 @@ void MapperXbox360Gamepad(const Gamepad& input, Gamepad* mapped) {
mapped->axes_length = AXIS_INDEX_COUNT;
}
-void MapperXboxOneHidGamepad(const Gamepad& input, Gamepad* mapped) {
+void MapperXboxOneS2016Firmware(const Gamepad& input, Gamepad* mapped) {
+ *mapped = input;
+ mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[0];
+ mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1];
+ mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[2];
+ mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[3];
+ mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[4];
+ mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[5];
+ mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[2]);
+ mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[5]);
+ mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[6];
+ mapped->buttons[BUTTON_INDEX_START] = input.buttons[7];
+ mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[8];
+ mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[9];
+ mapped->axes[AXIS_INDEX_RIGHT_STICK_X] = input.axes[3];
+ mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[4];
+ DpadFromAxis(mapped, input.axes[9]);
+
+ mapped->buttons_length = BUTTON_INDEX_COUNT - 1; /* no meta */
+ mapped->axes_length = AXIS_INDEX_COUNT;
+}
+
+void MapperXboxOneS(const Gamepad& input, Gamepad* mapped) {
*mapped = input;
mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[0];
@@ -374,9 +396,10 @@ struct MappingData {
{"045e", "028f", MapperXbox360Gamepad}, // Xbox 360 Wireless
{"045e", "02d1", MapperXbox360Gamepad}, // Xbox One Wired
{"045e", "02dd", MapperXbox360Gamepad}, // Xbox One Wired (2015 FW)
+ {"045e", "02e0", MapperXboxOneS2016Firmware}, // Xbox One S (Bluetooth)
{"045e", "02e3", MapperXbox360Gamepad}, // Xbox One Elite Wired
{"045e", "02ea", MapperXbox360Gamepad}, // Xbox One S (USB)
- {"045e", "02fd", MapperXboxOneHidGamepad}, // Xbox One S (Bluetooth)
+ {"045e", "02fd", MapperXboxOneS}, // Xbox One S (Bluetooth)
{"045e", "0719", MapperXbox360Gamepad}, // Xbox 360 Wireless
{"046d", "c216", MapperDirectInputStyle}, // Logitech F310, D mode
{"046d", "c218", MapperDirectInputStyle}, // Logitech F510, D mode
diff --git a/chromium/device/gamepad/public/interfaces/gamepad_struct_traits.cc b/chromium/device/gamepad/public/interfaces/gamepad_struct_traits.cc
index 2a97cea2d95..56e77b71720 100644
--- a/chromium/device/gamepad/public/interfaces/gamepad_struct_traits.cc
+++ b/chromium/device/gamepad/public/interfaces/gamepad_struct_traits.cc
@@ -4,6 +4,8 @@
#include "device/gamepad/public/interfaces/gamepad_struct_traits.h"
+#include "base/containers/span.h"
+
namespace mojo {
// static
@@ -130,18 +132,18 @@ bool EnumTraits<device::mojom::GamepadHand, device::GamepadHand>::FromMojom(
}
// static
-ConstCArray<uint16_t>
+base::span<const uint16_t>
StructTraits<device::mojom::GamepadDataView, device::Gamepad>::id(
const device::Gamepad& r) {
size_t id_length = 0;
while (id_length < device::Gamepad::kIdLengthCap && r.id[id_length] != 0) {
id_length++;
}
- return {id_length, reinterpret_cast<const uint16_t*>(&r.id[0])};
+ return base::make_span(reinterpret_cast<const uint16_t*>(r.id), id_length);
}
// static
-ConstCArray<uint16_t>
+base::span<const uint16_t>
StructTraits<device::mojom::GamepadDataView, device::Gamepad>::mapping(
const device::Gamepad& r) {
size_t mapping_length = 0;
@@ -149,7 +151,8 @@ StructTraits<device::mojom::GamepadDataView, device::Gamepad>::mapping(
r.mapping[mapping_length] != 0) {
mapping_length++;
}
- return {mapping_length, reinterpret_cast<const uint16_t*>(&r.mapping[0])};
+ return base::make_span(reinterpret_cast<const uint16_t*>(r.mapping),
+ mapping_length);
}
// static
@@ -158,34 +161,32 @@ bool StructTraits<device::mojom::GamepadDataView, device::Gamepad>::Read(
device::Gamepad* out) {
out->connected = data.connected();
- memset(&out->id[0], 0, device::Gamepad::kIdLengthCap * sizeof(device::UChar));
- CArray<uint16_t> id = {0, device::Gamepad::kIdLengthCap,
- reinterpret_cast<uint16_t*>(&out->id[0])};
+ memset(out->id, 0, sizeof(out->id));
+ base::span<uint16_t> id(reinterpret_cast<uint16_t*>(out->id),
+ device::Gamepad::kIdLengthCap);
if (!data.ReadId(&id)) {
return false;
}
out->timestamp = data.timestamp();
- CArray<double> axes = {0, device::Gamepad::kAxesLengthCap, &out->axes[0]};
+ base::span<double> axes(out->axes);
if (!data.ReadAxes(&axes)) {
return false;
}
// static_cast is safe when "data.ReadAxes(&axes)" above returns true.
- out->axes_length = static_cast<unsigned>(axes.size);
+ out->axes_length = static_cast<unsigned>(axes.size());
- CArray<device::GamepadButton> buttons = {
- 0, device::Gamepad::kButtonsLengthCap, &out->buttons[0]};
+ base::span<device::GamepadButton> buttons(out->buttons);
if (!data.ReadButtons(&buttons)) {
return false;
}
// static_cast is safe when "data.ReadButtons(&buttons)" above returns true.
- out->buttons_length = static_cast<unsigned>(buttons.size);
+ out->buttons_length = static_cast<unsigned>(buttons.size());
- memset(&out->mapping[0], 0,
- device::Gamepad::kMappingLengthCap * sizeof(device::UChar));
- CArray<uint16_t> mapping = {0, device::Gamepad::kMappingLengthCap,
- reinterpret_cast<uint16_t*>(&out->mapping[0])};
+ memset(out->mapping, 0, sizeof(out->mapping));
+ base::span<uint16_t> mapping(reinterpret_cast<uint16_t*>(out->mapping),
+ device::Gamepad::kMappingLengthCap);
if (!data.ReadMapping(&mapping)) {
return false;
}
diff --git a/chromium/device/gamepad/public/interfaces/gamepad_struct_traits.h b/chromium/device/gamepad/public/interfaces/gamepad_struct_traits.h
index 9d02f52f197..e175270be17 100644
--- a/chromium/device/gamepad/public/interfaces/gamepad_struct_traits.h
+++ b/chromium/device/gamepad/public/interfaces/gamepad_struct_traits.h
@@ -7,9 +7,10 @@
#include <stddef.h>
+#include "base/containers/span.h"
#include "device/gamepad/public/cpp/gamepad.h"
#include "device/gamepad/public/interfaces/gamepad.mojom.h"
-#include "mojo/public/cpp/bindings/array_traits_carray.h"
+#include "mojo/public/cpp/bindings/array_traits_span.h"
#include "mojo/public/cpp/bindings/struct_traits.h"
namespace mojo {
@@ -91,11 +92,12 @@ template <>
struct StructTraits<device::mojom::GamepadDataView, device::Gamepad> {
static bool connected(const device::Gamepad& r) { return r.connected; }
static uint64_t timestamp(const device::Gamepad& r) { return r.timestamp; }
- static ConstCArray<double> axes(const device::Gamepad& r) {
- return {r.axes_length, &r.axes[0]};
+ static base::span<const double> axes(const device::Gamepad& r) {
+ return base::make_span(r.axes, r.axes_length);
}
- static ConstCArray<device::GamepadButton> buttons(const device::Gamepad& r) {
- return {r.buttons_length, &r.buttons[0]};
+ static base::span<const device::GamepadButton> buttons(
+ const device::Gamepad& r) {
+ return base::make_span(r.buttons, r.buttons_length);
}
static const device::GamepadPose& pose(const device::Gamepad& r) {
return r.pose;
@@ -105,8 +107,8 @@ struct StructTraits<device::mojom::GamepadDataView, device::Gamepad> {
}
static uint32_t display_id(const device::Gamepad& r) { return r.display_id; }
- static ConstCArray<uint16_t> id(const device::Gamepad& r);
- static ConstCArray<uint16_t> mapping(const device::Gamepad& r);
+ static base::span<const uint16_t> id(const device::Gamepad& r);
+ static base::span<const uint16_t> mapping(const device::Gamepad& r);
static bool Read(device::mojom::GamepadDataView data, device::Gamepad* out);
};
diff --git a/chromium/device/geolocation/BUILD.gn b/chromium/device/geolocation/BUILD.gn
index 27069c5f970..4539c83a6ce 100644
--- a/chromium/device/geolocation/BUILD.gn
+++ b/chromium/device/geolocation/BUILD.gn
@@ -14,8 +14,6 @@ component("geolocation") {
sources = [
"access_token_store.h",
- "android/geolocation_jni_registrar.cc",
- "android/geolocation_jni_registrar.h",
"empty_wifi_data_provider.cc",
"empty_wifi_data_provider.h",
"geolocation_config.cc",
diff --git a/chromium/device/geolocation/geolocation_config.cc b/chromium/device/geolocation/geolocation_config.cc
index b8e3b40caec..b7dd98c91ed 100644
--- a/chromium/device/geolocation/geolocation_config.cc
+++ b/chromium/device/geolocation/geolocation_config.cc
@@ -17,7 +17,7 @@ GeolocationConfig::~GeolocationConfig() {}
void GeolocationConfig::Create(
mojom::GeolocationConfigRequest request,
const service_manager::BindSourceInfo& source_info) {
- mojo::MakeStrongBinding(base::MakeUnique<GeolocationConfig>(),
+ mojo::MakeStrongBinding(std::make_unique<GeolocationConfig>(),
std::move(request));
}
diff --git a/chromium/device/geolocation/geolocation_config.h b/chromium/device/geolocation/geolocation_config.h
index 586ce461365..5c00ee7a592 100644
--- a/chromium/device/geolocation/geolocation_config.h
+++ b/chromium/device/geolocation/geolocation_config.h
@@ -19,7 +19,7 @@ namespace device {
// Implements the GeolocationConfig Mojo interface.
class DEVICE_GEOLOCATION_EXPORT GeolocationConfig
- : public NON_EXPORTED_BASE(mojom::GeolocationConfig) {
+ : public mojom::GeolocationConfig {
public:
GeolocationConfig();
~GeolocationConfig() override;
diff --git a/chromium/device/geolocation/geolocation_impl.cc b/chromium/device/geolocation/geolocation_impl.cc
index 16e376ab8d0..f4b2d8aeade 100644
--- a/chromium/device/geolocation/geolocation_impl.cc
+++ b/chromium/device/geolocation/geolocation_impl.cc
@@ -130,10 +130,11 @@ void GeolocationImpl::QueryNextPosition(QueryNextPositionCallback callback) {
}
void GeolocationImpl::SetOverride(const Geoposition& position) {
+ if (!position_callback_.is_null())
+ ReportCurrentPosition();
position_override_ = position;
- if (!position_override_.Validate()) {
+ if (!position_override_.Validate())
ResumeUpdates();
- }
geolocation_subscription_.reset();
diff --git a/chromium/device/geolocation/geolocation_impl.h b/chromium/device/geolocation/geolocation_impl.h
index 187393a67f5..067162bc4a8 100644
--- a/chromium/device/geolocation/geolocation_impl.h
+++ b/chromium/device/geolocation/geolocation_impl.h
@@ -20,9 +20,7 @@ class GeolocationContext;
// Implements the Geolocation Mojo interface.
class GeolocationImpl : public mojom::Geolocation {
public:
- // |context| must outlive this object. |update_callback| will be called when
- // location updates are sent, allowing the client to know when the service
- // is being used.
+ // |context| must outlive this object.
GeolocationImpl(mojo::InterfaceRequest<mojom::Geolocation> request,
GeolocationContext* context);
~GeolocationImpl() override;
@@ -53,6 +51,8 @@ class GeolocationImpl : public mojom::Geolocation {
// Owns this object.
GeolocationContext* context_;
+
+ // Token that unsubscribes from GeolocationProvider updates when destroyed.
std::unique_ptr<GeolocationProvider::Subscription> geolocation_subscription_;
// The callback passed to QueryNextPosition.
diff --git a/chromium/device/geolocation/geolocation_provider_impl.cc b/chromium/device/geolocation/geolocation_provider_impl.cc
index 9cba76927c8..3ea97c9c519 100644
--- a/chromium/device/geolocation/geolocation_provider_impl.cc
+++ b/chromium/device/geolocation/geolocation_provider_impl.cc
@@ -194,7 +194,7 @@ void GeolocationProviderImpl::Init() {
if (!g_delegate.Get())
g_delegate.Get().reset(new GeolocationDelegate);
- arbitrator_ = base::MakeUnique<LocationArbitrator>(
+ arbitrator_ = std::make_unique<LocationArbitrator>(
base::WrapUnique(g_delegate.Get().get()));
arbitrator_->SetUpdateCallback(callback);
}
diff --git a/chromium/device/geolocation/geolocation_provider_impl.h b/chromium/device/geolocation/geolocation_provider_impl.h
index 4f9c4da327c..2d1bf5632cf 100644
--- a/chromium/device/geolocation/geolocation_provider_impl.h
+++ b/chromium/device/geolocation/geolocation_provider_impl.h
@@ -27,7 +27,7 @@ class SingleThreadTaskRunner;
namespace device {
class DEVICE_GEOLOCATION_EXPORT GeolocationProviderImpl
- : public NON_EXPORTED_BASE(GeolocationProvider),
+ : public GeolocationProvider,
public base::Thread {
public:
// GeolocationProvider implementation:
diff --git a/chromium/device/geolocation/geolocation_provider_impl_unittest.cc b/chromium/device/geolocation/geolocation_provider_impl_unittest.cc
index 190c34859e3..d981db7e1ce 100644
--- a/chromium/device/geolocation/geolocation_provider_impl_unittest.cc
+++ b/chromium/device/geolocation/geolocation_provider_impl_unittest.cc
@@ -48,7 +48,7 @@ class AsyncMockGeolocationObserver : public MockGeolocationObserver {
public:
void OnLocationUpdate(const Geoposition& position) override {
MockGeolocationObserver::OnLocationUpdate(position);
- base::MessageLoop::current()->QuitWhenIdle();
+ base::RunLoop::QuitCurrentWhenIdleDeprecated();
}
};
diff --git a/chromium/device/geolocation/location_api_adapter_android.cc b/chromium/device/geolocation/location_api_adapter_android.cc
index fd77631dcb3..0cbd285ffe5 100644
--- a/chromium/device/geolocation/location_api_adapter_android.cc
+++ b/chromium/device/geolocation/location_api_adapter_android.cc
@@ -79,11 +79,6 @@ void LocationApiAdapterAndroid::Stop() {
}
// static
-bool LocationApiAdapterAndroid::RegisterGeolocationService(JNIEnv* env) {
- return RegisterNativesImpl(env);
-}
-
-// static
void LocationApiAdapterAndroid::OnNewLocationAvailable(double latitude,
double longitude,
double time_stamp,
diff --git a/chromium/device/geolocation/location_api_adapter_android.h b/chromium/device/geolocation/location_api_adapter_android.h
index de36f4dcb5d..48122322b20 100644
--- a/chromium/device/geolocation/location_api_adapter_android.h
+++ b/chromium/device/geolocation/location_api_adapter_android.h
@@ -41,9 +41,6 @@ class LocationApiAdapterAndroid {
// Stops the underlying location provider. Called on |task_runner_|.
void Stop();
- // Called when initializing chrome_view to obtain a pointer to the java class.
- static bool RegisterGeolocationService(JNIEnv* env);
-
// Called by JNI on its thread looper.
static void OnNewLocationAvailable(double latitude,
double longitude,
diff --git a/chromium/device/geolocation/location_arbitrator.cc b/chromium/device/geolocation/location_arbitrator.cc
index 444262686f0..6267e5a54d5 100644
--- a/chromium/device/geolocation/location_arbitrator.cc
+++ b/chromium/device/geolocation/location_arbitrator.cc
@@ -175,14 +175,15 @@ LocationArbitrator::NewNetworkLocationProvider(
// Android uses its own SystemLocationProvider.
return nullptr;
#else
- return base::MakeUnique<NetworkLocationProvider>(access_token_store, context,
+ return std::make_unique<NetworkLocationProvider>(access_token_store, context,
url, access_token);
#endif
}
std::unique_ptr<LocationProvider>
LocationArbitrator::NewSystemLocationProvider() {
-#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)
+#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || \
+ defined(OS_FUCHSIA)
return nullptr;
#else
return device::NewSystemLocationProvider();
diff --git a/chromium/device/geolocation/network_location_provider_unittest.cc b/chromium/device/geolocation/network_location_provider_unittest.cc
index 0129625bde3..5eb58916a93 100644
--- a/chromium/device/geolocation/network_location_provider_unittest.cc
+++ b/chromium/device/geolocation/network_location_provider_unittest.cc
@@ -51,7 +51,6 @@ class MessageLoopQuitListener {
const Geoposition& position) {
EXPECT_EQ(client_message_loop_, base::MessageLoop::current());
updated_provider_ = provider;
- client_message_loop_->QuitWhenIdle();
}
base::MessageLoop* client_message_loop_;
diff --git a/chromium/device/geolocation/network_location_request.cc b/chromium/device/geolocation/network_location_request.cc
index 08c157415f4..9cd3ad2234f 100644
--- a/chromium/device/geolocation/network_location_request.cc
+++ b/chromium/device/geolocation/network_location_request.cc
@@ -140,7 +140,7 @@ bool NetworkLocationRequest::MakeRequest(const base::string16& access_token,
destination: GOOGLE_OWNED_SERVICE
}
policy {
- cookies_allowed: false
+ cookies_allowed: NO
setting:
"Users can control this feature via the Location setting under "
"'Privacy', 'Content Settings...'."
@@ -276,9 +276,9 @@ void AddWifiData(const WifiData& wifi_data,
for (const auto& ap_data : wifi_data.access_point_data)
access_points_by_signal_strength.insert(&ap_data);
- auto wifi_access_point_list = base::MakeUnique<base::ListValue>();
+ auto wifi_access_point_list = std::make_unique<base::ListValue>();
for (auto* ap_data : access_points_by_signal_strength) {
- auto wifi_dict = base::MakeUnique<base::DictionaryValue>();
+ auto wifi_dict = std::make_unique<base::DictionaryValue>();
AddString("macAddress", base::UTF16ToUTF8(ap_data->mac_address),
wifi_dict.get());
AddInteger("signalStrength", ap_data->radio_signal_strength,
diff --git a/chromium/device/geolocation/public/interfaces/geolocation.mojom b/chromium/device/geolocation/public/interfaces/geolocation.mojom
index 7bbc4bb3a22..56e689ceebc 100644
--- a/chromium/device/geolocation/public/interfaces/geolocation.mojom
+++ b/chromium/device/geolocation/public/interfaces/geolocation.mojom
@@ -6,9 +6,9 @@ module device.mojom;
import "device/geolocation/public/interfaces/geoposition.mojom";
-// The Geolocation service provides updates on the device's location. By
-// default, it provides updates with low accuracy, but |SetHighAccuracy()| may
-// be called to change this.
+// Geolocation provides updates on the device's location. By default, it
+// provides updates with low accuracy, but |SetHighAccuracy()| may be called
+// to change this.
interface Geolocation {
SetHighAccuracy(bool high_accuracy);
@@ -18,3 +18,14 @@ interface Geolocation {
// this method are prohibited and will be treated as a connection error.
QueryNextPosition() => (Geoposition geoposition);
};
+
+// GeolocationService provides a Geolocation. It exists in order to examine the
+// environment (permissions, etc.) before creating a Geolocation.
+// There should only be one GeolocationService instance that creates many
+// Geolocation instances. There is one GeolocationService per RenderFrameHost.
+interface GeolocationService {
+ // Creates a Geolocation.
+ // This may not be called a second time until the Geolocation instance has
+ // been created.
+ CreateGeolocation(Geolocation& request, bool user_gesture);
+};
diff --git a/chromium/device/geolocation/wifi_data_provider_chromeos_unittest.cc b/chromium/device/geolocation/wifi_data_provider_chromeos_unittest.cc
index 66d750ec1eb..e499ff8d591 100644
--- a/chromium/device/geolocation/wifi_data_provider_chromeos_unittest.cc
+++ b/chromium/device/geolocation/wifi_data_provider_chromeos_unittest.cc
@@ -48,12 +48,11 @@ class GeolocationChromeOsWifiDataProviderTest : public testing::Test {
"%02X:%02X:%02X:%02X:%02X:%02X", i, j, 3, 4, 5, 6);
std::string channel = base::IntToString(i * 10 + j);
std::string strength = base::IntToString(i * 100 + j);
- properties.SetStringWithoutPathExpansion(shill::kGeoMacAddressProperty,
- mac_address);
- properties.SetStringWithoutPathExpansion(shill::kGeoChannelProperty,
- channel);
- properties.SetStringWithoutPathExpansion(
- shill::kGeoSignalStrengthProperty, strength);
+ properties.SetKey(shill::kGeoMacAddressProperty,
+ base::Value(mac_address));
+ properties.SetKey(shill::kGeoChannelProperty, base::Value(channel));
+ properties.SetKey(shill::kGeoSignalStrengthProperty,
+ base::Value(strength));
manager_test_->AddGeoNetwork(shill::kGeoWifiAccessPointsProperty,
properties);
}
diff --git a/chromium/device/geolocation/wifi_data_provider_linux.cc b/chromium/device/geolocation/wifi_data_provider_linux.cc
index 832672c5f47..4c41dc53f4e 100644
--- a/chromium/device/geolocation/wifi_data_provider_linux.cc
+++ b/chromium/device/geolocation/wifi_data_provider_linux.cc
@@ -354,7 +354,7 @@ WifiDataProviderLinux::CreateWlanApi() {
std::unique_ptr<WifiPollingPolicy>
WifiDataProviderLinux::CreatePollingPolicy() {
- return base::MakeUnique<GenericWifiPollingPolicy<
+ return std::make_unique<GenericWifiPollingPolicy<
kDefaultPollingIntervalMilliseconds, kNoChangePollingIntervalMilliseconds,
kTwoNoChangePollingIntervalMilliseconds,
kNoWifiPollingIntervalMilliseconds>>();
diff --git a/chromium/device/geolocation/wifi_data_provider_mac.mm b/chromium/device/geolocation/wifi_data_provider_mac.mm
index 6edf1793bc4..dd5492dd72f 100644
--- a/chromium/device/geolocation/wifi_data_provider_mac.mm
+++ b/chromium/device/geolocation/wifi_data_provider_mac.mm
@@ -125,11 +125,11 @@ WifiDataProviderMac::~WifiDataProviderMac() {}
std::unique_ptr<WifiDataProviderMac::WlanApiInterface>
WifiDataProviderMac::CreateWlanApi() {
- return base::MakeUnique<CoreWlanApi>();
+ return std::make_unique<CoreWlanApi>();
}
std::unique_ptr<WifiPollingPolicy> WifiDataProviderMac::CreatePollingPolicy() {
- return base::MakeUnique<GenericWifiPollingPolicy<
+ return std::make_unique<GenericWifiPollingPolicy<
kDefaultPollingInterval, kNoChangePollingInterval,
kTwoNoChangePollingInterval, kNoWifiPollingIntervalMilliseconds>>();
}
diff --git a/chromium/device/geolocation/wifi_data_provider_win.cc b/chromium/device/geolocation/wifi_data_provider_win.cc
index 908d06c4f54..c3c2821b7c5 100644
--- a/chromium/device/geolocation/wifi_data_provider_win.cc
+++ b/chromium/device/geolocation/wifi_data_provider_win.cc
@@ -117,7 +117,7 @@ std::unique_ptr<WindowsWlanApi> WindowsWlanApi::Create() {
HINSTANCE library = LoadLibraryEx(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
if (!library)
return nullptr;
- return base::MakeUnique<WindowsWlanApi>(library);
+ return std::make_unique<WindowsWlanApi>(library);
}
WindowsWlanApi::WindowsWlanApi(HINSTANCE library) : library_(library) {
@@ -248,7 +248,7 @@ WifiDataProviderWin::CreateWlanApi() {
}
std::unique_ptr<WifiPollingPolicy> WifiDataProviderWin::CreatePollingPolicy() {
- return base::MakeUnique<GenericWifiPollingPolicy<
+ return std::make_unique<GenericWifiPollingPolicy<
kDefaultPollingIntervalMs, kNoChangePollingIntervalMs,
kTwoNoChangePollingIntervalMs, kNoWifiPollingIntervalMs>>();
}
diff --git a/chromium/device/hid/BUILD.gn b/chromium/device/hid/BUILD.gn
index 6a95817206c..ae135754d61 100644
--- a/chromium/device/hid/BUILD.gn
+++ b/chromium/device/hid/BUILD.gn
@@ -21,8 +21,6 @@ source_set("hid") {
"hid_device_filter.h",
"hid_device_info.cc",
"hid_device_info.h",
- "hid_device_info_linux.cc",
- "hid_device_info_linux.h",
"hid_report_descriptor.cc",
"hid_report_descriptor.h",
"hid_report_descriptor_item.cc",
@@ -44,6 +42,10 @@ source_set("hid") {
"//net",
]
+ public_deps = [
+ "//device/hid/public/interfaces",
+ ]
+
if (is_linux && use_udev) {
sources += [
"fake_input_service_linux.cc",
diff --git a/chromium/device/hid/hid_connection.cc b/chromium/device/hid/hid_connection.cc
index eb72b6167b0..c85a756861c 100644
--- a/chromium/device/hid/hid_connection.cc
+++ b/chromium/device/hid/hid_connection.cc
@@ -80,93 +80,92 @@ void HidConnection::Close() {
closed_ = true;
}
-void HidConnection::Read(const ReadCallback& callback) {
+void HidConnection::Read(ReadCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
if (device_info_->max_input_report_size() == 0) {
HID_LOG(USER) << "This device does not support input reports.";
- callback.Run(false, NULL, 0);
+ std::move(callback).Run(false, NULL, 0);
return;
}
- PlatformRead(callback);
+ PlatformRead(std::move(callback));
}
void HidConnection::Write(scoped_refptr<net::IOBuffer> buffer,
size_t size,
- const WriteCallback& callback) {
+ WriteCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
if (device_info_->max_output_report_size() == 0) {
HID_LOG(USER) << "This device does not support output reports.";
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
if (size > device_info_->max_output_report_size() + 1) {
HID_LOG(USER) << "Output report buffer too long (" << size << " > "
<< (device_info_->max_output_report_size() + 1) << ").";
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
DCHECK_GE(size, 1u);
uint8_t report_id = buffer->data()[0];
if (device_info_->has_report_id() != (report_id != 0)) {
HID_LOG(USER) << "Invalid output report ID.";
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
if (IsReportIdProtected(report_id)) {
HID_LOG(USER) << "Attempt to set a protected output report.";
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
- PlatformWrite(buffer, size, callback);
+ PlatformWrite(buffer, size, std::move(callback));
}
-void HidConnection::GetFeatureReport(uint8_t report_id,
- const ReadCallback& callback) {
+void HidConnection::GetFeatureReport(uint8_t report_id, ReadCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
if (device_info_->max_feature_report_size() == 0) {
HID_LOG(USER) << "This device does not support feature reports.";
- callback.Run(false, NULL, 0);
+ std::move(callback).Run(false, NULL, 0);
return;
}
if (device_info_->has_report_id() != (report_id != 0)) {
HID_LOG(USER) << "Invalid feature report ID.";
- callback.Run(false, NULL, 0);
+ std::move(callback).Run(false, NULL, 0);
return;
}
if (IsReportIdProtected(report_id)) {
HID_LOG(USER) << "Attempt to get a protected feature report.";
- callback.Run(false, NULL, 0);
+ std::move(callback).Run(false, NULL, 0);
return;
}
- PlatformGetFeatureReport(report_id, callback);
+ PlatformGetFeatureReport(report_id, std::move(callback));
}
void HidConnection::SendFeatureReport(scoped_refptr<net::IOBuffer> buffer,
size_t size,
- const WriteCallback& callback) {
+ WriteCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
if (device_info_->max_feature_report_size() == 0) {
HID_LOG(USER) << "This device does not support feature reports.";
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
DCHECK_GE(size, 1u);
uint8_t report_id = buffer->data()[0];
if (device_info_->has_report_id() != (report_id != 0)) {
HID_LOG(USER) << "Invalid feature report ID.";
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
if (IsReportIdProtected(report_id)) {
HID_LOG(USER) << "Attempt to set a protected feature report.";
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
- PlatformSendFeatureReport(buffer, size, callback);
+ PlatformSendFeatureReport(buffer, size, std::move(callback));
}
bool HidConnection::IsReportIdProtected(uint8_t report_id) {
@@ -187,7 +186,7 @@ PendingHidReport::~PendingHidReport() {}
PendingHidRead::PendingHidRead() {}
-PendingHidRead::PendingHidRead(const PendingHidRead& other) = default;
+PendingHidRead::PendingHidRead(PendingHidRead&& other) = default;
PendingHidRead::~PendingHidRead() {}
diff --git a/chromium/device/hid/hid_connection.h b/chromium/device/hid/hid_connection.h
index dbff1caf093..a8a0d1c4e1e 100644
--- a/chromium/device/hid/hid_connection.h
+++ b/chromium/device/hid/hid_connection.h
@@ -24,10 +24,10 @@ class HidConnection : public base::RefCountedThreadSafe<HidConnection> {
kAnyReportId = 0xFF,
};
- typedef base::Callback<
- void(bool success, scoped_refptr<net::IOBuffer> buffer, size_t size)>
- ReadCallback;
- typedef base::Callback<void(bool success)> WriteCallback;
+ using ReadCallback = base::OnceCallback<
+ void(bool success, scoped_refptr<net::IOBuffer> buffer, size_t size)>;
+
+ using WriteCallback = base::OnceCallback<void(bool success)>;
scoped_refptr<HidDeviceInfo> device_info() const { return device_info_; }
bool has_protected_collection() const { return has_protected_collection_; }
@@ -39,24 +39,24 @@ class HidConnection : public base::RefCountedThreadSafe<HidConnection> {
// The report ID (or 0 if report IDs are not supported by the device) is
// always returned in the first byte of the buffer.
- void Read(const ReadCallback& callback);
+ void Read(ReadCallback callback);
// The report ID (or 0 if report IDs are not supported by the device) is
// always expected in the first byte of the buffer.
void Write(scoped_refptr<net::IOBuffer> buffer,
size_t size,
- const WriteCallback& callback);
+ WriteCallback callback);
// The buffer will contain whatever report data was received from the device.
// This may include the report ID. The report ID is not stripped because a
// device may respond with other data in place of the report ID.
- void GetFeatureReport(uint8_t report_id, const ReadCallback& callback);
+ void GetFeatureReport(uint8_t report_id, ReadCallback callback);
// The report ID (or 0 if report IDs are not supported by the device) is
// always expected in the first byte of the buffer.
void SendFeatureReport(scoped_refptr<net::IOBuffer> buffer,
size_t size,
- const WriteCallback& callback);
+ WriteCallback callback);
protected:
friend class base::RefCountedThreadSafe<HidConnection>;
@@ -65,15 +65,15 @@ class HidConnection : public base::RefCountedThreadSafe<HidConnection> {
virtual ~HidConnection();
virtual void PlatformClose() = 0;
- virtual void PlatformRead(const ReadCallback& callback) = 0;
+ virtual void PlatformRead(ReadCallback callback) = 0;
virtual void PlatformWrite(scoped_refptr<net::IOBuffer> buffer,
size_t size,
- const WriteCallback& callback) = 0;
+ WriteCallback callback) = 0;
virtual void PlatformGetFeatureReport(uint8_t report_id,
- const ReadCallback& callback) = 0;
+ ReadCallback callback) = 0;
virtual void PlatformSendFeatureReport(scoped_refptr<net::IOBuffer> buffer,
size_t size,
- const WriteCallback& callback) = 0;
+ WriteCallback callback) = 0;
bool IsReportIdProtected(uint8_t report_id);
@@ -97,7 +97,7 @@ struct PendingHidReport {
struct PendingHidRead {
PendingHidRead();
- PendingHidRead(const PendingHidRead& other);
+ PendingHidRead(PendingHidRead&& other);
~PendingHidRead();
HidConnection::ReadCallback callback;
diff --git a/chromium/device/hid/hid_connection_linux.cc b/chromium/device/hid/hid_connection_linux.cc
index fd5fc01ee40..8824fce9dc9 100644
--- a/chromium/device/hid/hid_connection_linux.cc
+++ b/chromium/device/hid/hid_connection_linux.cc
@@ -61,56 +61,61 @@ class HidConnectionLinux::BlockingTaskHelper {
void Write(scoped_refptr<net::IOBuffer> buffer,
size_t size,
- const WriteCallback& callback) {
+ WriteCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
ssize_t result = HANDLE_EINTR(write(fd_.get(), buffer->data(), size));
if (result < 0) {
HID_PLOG(EVENT) << "Write failed";
- origin_task_runner_->PostTask(FROM_HERE, base::Bind(callback, false));
+ origin_task_runner_->PostTask(FROM_HERE,
+ base::BindOnce(std::move(callback), false));
} else {
if (static_cast<size_t>(result) != size)
HID_LOG(EVENT) << "Incomplete HID write: " << result << " != " << size;
- origin_task_runner_->PostTask(FROM_HERE, base::Bind(callback, true));
+ origin_task_runner_->PostTask(FROM_HERE,
+ base::BindOnce(std::move(callback), true));
}
}
void GetFeatureReport(uint8_t report_id,
scoped_refptr<net::IOBufferWithSize> buffer,
- const ReadCallback& callback) {
+ ReadCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
int result = HANDLE_EINTR(
ioctl(fd_.get(), HIDIOCGFEATURE(buffer->size()), buffer->data()));
if (result < 0) {
HID_PLOG(EVENT) << "Failed to get feature report";
- origin_task_runner_->PostTask(FROM_HERE,
- base::Bind(callback, false, nullptr, 0));
+ origin_task_runner_->PostTask(
+ FROM_HERE, base::BindOnce(std::move(callback), false, nullptr, 0));
} else if (result == 0) {
HID_LOG(EVENT) << "Get feature result too short.";
- origin_task_runner_->PostTask(FROM_HERE,
- base::Bind(callback, false, nullptr, 0));
+ origin_task_runner_->PostTask(
+ FROM_HERE, base::BindOnce(std::move(callback), false, nullptr, 0));
} else if (report_id == 0) {
// Linux adds a 0 to the beginning of the data received from the device.
scoped_refptr<net::IOBuffer> copied_buffer(new net::IOBuffer(result - 1));
memcpy(copied_buffer->data(), buffer->data() + 1, result - 1);
origin_task_runner_->PostTask(
- FROM_HERE, base::Bind(callback, true, copied_buffer, result - 1));
+ FROM_HERE,
+ base::BindOnce(std::move(callback), true, copied_buffer, result - 1));
} else {
- origin_task_runner_->PostTask(FROM_HERE,
- base::Bind(callback, true, buffer, result));
+ origin_task_runner_->PostTask(
+ FROM_HERE, base::BindOnce(std::move(callback), true, buffer, result));
}
}
void SendFeatureReport(scoped_refptr<net::IOBuffer> buffer,
size_t size,
- const WriteCallback& callback) {
+ WriteCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
int result =
HANDLE_EINTR(ioctl(fd_.get(), HIDIOCSFEATURE(size), buffer->data()));
if (result < 0) {
HID_PLOG(EVENT) << "Failed to send feature report";
- origin_task_runner_->PostTask(FROM_HERE, base::Bind(callback, false));
+ origin_task_runner_->PostTask(FROM_HERE,
+ base::BindOnce(std::move(callback), false));
} else {
- origin_task_runner_->PostTask(FROM_HERE, base::Bind(callback, true));
+ origin_task_runner_->PostTask(FROM_HERE,
+ base::BindOnce(std::move(callback), true));
}
}
@@ -147,8 +152,8 @@ class HidConnectionLinux::BlockingTaskHelper {
}
origin_task_runner_->PostTask(
- FROM_HERE, base::Bind(&HidConnectionLinux::ProcessInputReport,
- connection_, buffer, bytes_read));
+ FROM_HERE, base::BindOnce(&HidConnectionLinux::ProcessInputReport,
+ connection_, buffer, bytes_read));
}
SEQUENCE_CHECKER(sequence_checker_);
@@ -169,11 +174,11 @@ HidConnectionLinux::HidConnectionLinux(
: HidConnection(device_info),
blocking_task_runner_(std::move(blocking_task_runner)),
weak_factory_(this) {
- helper_ = base::MakeUnique<BlockingTaskHelper>(std::move(fd), device_info,
+ helper_ = std::make_unique<BlockingTaskHelper>(std::move(fd), device_info,
weak_factory_.GetWeakPtr());
blocking_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&BlockingTaskHelper::Start, base::Unretained(helper_.get())));
+ FROM_HERE, base::BindOnce(&BlockingTaskHelper::Start,
+ base::Unretained(helper_.get())));
}
HidConnectionLinux::~HidConnectionLinux() {
@@ -188,32 +193,31 @@ void HidConnectionLinux::PlatformClose() {
blocking_task_runner_->DeleteSoon(FROM_HERE, helper_.release());
while (!pending_reads_.empty()) {
- pending_reads_.front().callback.Run(false, NULL, 0);
+ std::move(pending_reads_.front().callback).Run(false, NULL, 0);
pending_reads_.pop();
}
}
-void HidConnectionLinux::PlatformRead(const ReadCallback& callback) {
+void HidConnectionLinux::PlatformRead(ReadCallback callback) {
PendingHidRead pending_read;
- pending_read.callback = callback;
- pending_reads_.push(pending_read);
+ pending_read.callback = std::move(callback);
+ pending_reads_.push(std::move(pending_read));
ProcessReadQueue();
}
void HidConnectionLinux::PlatformWrite(scoped_refptr<net::IOBuffer> buffer,
size_t size,
- const WriteCallback& callback) {
+ WriteCallback callback) {
// Linux expects the first byte of the buffer to always be a report ID so the
// buffer can be used directly.
blocking_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&BlockingTaskHelper::Write, base::Unretained(helper_.get()),
- buffer, size, callback));
+ FROM_HERE, base::BindOnce(&BlockingTaskHelper::Write,
+ base::Unretained(helper_.get()), buffer, size,
+ std::move(callback)));
}
-void HidConnectionLinux::PlatformGetFeatureReport(
- uint8_t report_id,
- const ReadCallback& callback) {
+void HidConnectionLinux::PlatformGetFeatureReport(uint8_t report_id,
+ ReadCallback callback) {
// The first byte of the destination buffer is the report ID being requested
// and is overwritten by the feature report.
DCHECK_GT(device_info()->max_feature_report_size(), 0u);
@@ -222,21 +226,21 @@ void HidConnectionLinux::PlatformGetFeatureReport(
buffer->data()[0] = report_id;
blocking_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&BlockingTaskHelper::GetFeatureReport,
- base::Unretained(helper_.get()), report_id, buffer, callback));
+ FROM_HERE, base::BindOnce(&BlockingTaskHelper::GetFeatureReport,
+ base::Unretained(helper_.get()), report_id,
+ buffer, std::move(callback)));
}
void HidConnectionLinux::PlatformSendFeatureReport(
scoped_refptr<net::IOBuffer> buffer,
size_t size,
- const WriteCallback& callback) {
+ WriteCallback callback) {
// Linux expects the first byte of the buffer to always be a report ID so the
// buffer can be used directly.
blocking_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&BlockingTaskHelper::SendFeatureReport,
- base::Unretained(helper_.get()), buffer, size, callback));
+ FROM_HERE, base::BindOnce(&BlockingTaskHelper::SendFeatureReport,
+ base::Unretained(helper_.get()), buffer, size,
+ std::move(callback)));
}
void HidConnectionLinux::ProcessInputReport(scoped_refptr<net::IOBuffer> buffer,
@@ -262,12 +266,12 @@ void HidConnectionLinux::ProcessReadQueue() {
// during the loop.
scoped_refptr<HidConnectionLinux> self(this);
while (pending_reads_.size() && pending_reports_.size()) {
- PendingHidRead read = pending_reads_.front();
- PendingHidReport report = pending_reports_.front();
+ PendingHidRead read = std::move(pending_reads_.front());
+ PendingHidReport report = std::move(pending_reports_.front());
pending_reads_.pop();
pending_reports_.pop();
- read.callback.Run(true, report.buffer, report.size);
+ std::move(read.callback).Run(true, std::move(report.buffer), report.size);
}
}
diff --git a/chromium/device/hid/hid_connection_linux.h b/chromium/device/hid/hid_connection_linux.h
index 1231d58a988..d04c733fc16 100644
--- a/chromium/device/hid/hid_connection_linux.h
+++ b/chromium/device/hid/hid_connection_linux.h
@@ -37,15 +37,15 @@ class HidConnectionLinux : public HidConnection {
// HidConnection implementation.
void PlatformClose() override;
- void PlatformRead(const ReadCallback& callback) override;
+ void PlatformRead(ReadCallback callback) override;
void PlatformWrite(scoped_refptr<net::IOBuffer> buffer,
size_t size,
- const WriteCallback& callback) override;
+ WriteCallback callback) override;
void PlatformGetFeatureReport(uint8_t report_id,
- const ReadCallback& callback) override;
+ ReadCallback callback) override;
void PlatformSendFeatureReport(scoped_refptr<net::IOBuffer> buffer,
size_t size,
- const WriteCallback& callback) override;
+ WriteCallback callback) override;
void ProcessInputReport(scoped_refptr<net::IOBuffer> buffer, size_t size);
void ProcessReadQueue();
diff --git a/chromium/device/hid/hid_connection_mac.cc b/chromium/device/hid/hid_connection_mac.cc
index 69b3c6f5626..34bb067fb33 100644
--- a/chromium/device/hid/hid_connection_mac.cc
+++ b/chromium/device/hid/hid_connection_mac.cc
@@ -70,41 +70,43 @@ void HidConnectionMac::PlatformClose() {
}
while (!pending_reads_.empty()) {
- pending_reads_.front().callback.Run(false, NULL, 0);
+ std::move(pending_reads_.front().callback).Run(false, NULL, 0);
pending_reads_.pop();
}
}
-void HidConnectionMac::PlatformRead(const ReadCallback& callback) {
+void HidConnectionMac::PlatformRead(ReadCallback callback) {
DCHECK(thread_checker().CalledOnValidThread());
PendingHidRead pending_read;
- pending_read.callback = callback;
- pending_reads_.push(pending_read);
+ pending_read.callback = std::move(callback);
+ pending_reads_.push(std::move(pending_read));
ProcessReadQueue();
}
void HidConnectionMac::PlatformWrite(scoped_refptr<net::IOBuffer> buffer,
size_t size,
- const WriteCallback& callback) {
+ WriteCallback callback) {
blocking_task_runner_->PostTask(
- FROM_HERE, base::Bind(&HidConnectionMac::SetReportAsync, this,
- kIOHIDReportTypeOutput, buffer, size, callback));
+ FROM_HERE, base::BindOnce(&HidConnectionMac::SetReportAsync, this,
+ kIOHIDReportTypeOutput, buffer, size,
+ std::move(callback)));
}
void HidConnectionMac::PlatformGetFeatureReport(uint8_t report_id,
- const ReadCallback& callback) {
+ ReadCallback callback) {
blocking_task_runner_->PostTask(
- FROM_HERE, base::Bind(&HidConnectionMac::GetFeatureReportAsync, this,
- report_id, callback));
+ FROM_HERE, base::BindOnce(&HidConnectionMac::GetFeatureReportAsync, this,
+ report_id, std::move(callback)));
}
void HidConnectionMac::PlatformSendFeatureReport(
scoped_refptr<net::IOBuffer> buffer,
size_t size,
- const WriteCallback& callback) {
+ WriteCallback callback) {
blocking_task_runner_->PostTask(
- FROM_HERE, base::Bind(&HidConnectionMac::SetReportAsync, this,
- kIOHIDReportTypeFeature, buffer, size, callback));
+ FROM_HERE, base::BindOnce(&HidConnectionMac::SetReportAsync, this,
+ kIOHIDReportTypeFeature, buffer, size,
+ std::move(callback)));
}
// static
@@ -160,17 +162,17 @@ void HidConnectionMac::ProcessReadQueue() {
// during the loop.
scoped_refptr<HidConnectionMac> self(this);
while (pending_reads_.size() && pending_reports_.size()) {
- PendingHidRead read = pending_reads_.front();
+ PendingHidRead read = std::move(pending_reads_.front());
PendingHidReport report = pending_reports_.front();
pending_reads_.pop();
pending_reports_.pop();
- read.callback.Run(true, report.buffer, report.size);
+ std::move(read.callback).Run(true, report.buffer, report.size);
}
}
void HidConnectionMac::GetFeatureReportAsync(uint8_t report_id,
- const ReadCallback& callback) {
+ ReadCallback callback) {
scoped_refptr<net::IOBufferWithSize> buffer(
new net::IOBufferWithSize(device_info()->max_feature_report_size() + 1));
CFIndex report_size = buffer->size();
@@ -188,23 +190,22 @@ void HidConnectionMac::GetFeatureReportAsync(uint8_t report_id,
&report_size);
if (result == kIOReturnSuccess) {
task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&HidConnectionMac::ReturnAsyncResult,
- this,
- base::Bind(callback, true, buffer, report_size)));
+ FROM_HERE, base::BindOnce(&HidConnectionMac::ReturnAsyncResult, this,
+ base::BindOnce(std::move(callback), true,
+ buffer, report_size)));
} else {
HID_LOG(EVENT) << "Failed to get feature report: " << HexErrorCode(result);
- task_runner_->PostTask(FROM_HERE,
- base::Bind(&HidConnectionMac::ReturnAsyncResult,
- this,
- base::Bind(callback, false, nullptr, 0)));
+ task_runner_->PostTask(
+ FROM_HERE,
+ base::BindOnce(&HidConnectionMac::ReturnAsyncResult, this,
+ base::BindOnce(std::move(callback), false, nullptr, 0)));
}
}
void HidConnectionMac::SetReportAsync(IOHIDReportType report_type,
scoped_refptr<net::IOBuffer> buffer,
size_t size,
- const WriteCallback& callback) {
+ WriteCallback callback) {
uint8_t* data = reinterpret_cast<uint8_t*>(buffer->data());
DCHECK_GE(size, 1u);
uint8_t report_id = data[0];
@@ -223,23 +224,21 @@ void HidConnectionMac::SetReportAsync(IOHIDReportType report_type,
IOReturn result =
IOHIDDeviceSetReport(device_.get(), report_type, report_id, data, size);
if (result == kIOReturnSuccess) {
- task_runner_->PostTask(FROM_HERE,
- base::Bind(&HidConnectionMac::ReturnAsyncResult,
- this,
- base::Bind(callback, true)));
+ task_runner_->PostTask(
+ FROM_HERE, base::BindOnce(&HidConnectionMac::ReturnAsyncResult, this,
+ base::BindOnce(std::move(callback), true)));
} else {
HID_LOG(EVENT) << "Failed to set report: " << HexErrorCode(result);
- task_runner_->PostTask(FROM_HERE,
- base::Bind(&HidConnectionMac::ReturnAsyncResult,
- this,
- base::Bind(callback, false)));
+ task_runner_->PostTask(
+ FROM_HERE, base::BindOnce(&HidConnectionMac::ReturnAsyncResult, this,
+ base::BindOnce(std::move(callback), false)));
}
}
-void HidConnectionMac::ReturnAsyncResult(const base::Closure& callback) {
+void HidConnectionMac::ReturnAsyncResult(base::OnceClosure callback) {
// This function is used so that the last reference to |this| can be released
// on the thread where it was created.
- callback.Run();
+ std::move(callback).Run();
}
} // namespace device
diff --git a/chromium/device/hid/hid_connection_mac.h b/chromium/device/hid/hid_connection_mac.h
index 914d5101195..5ee53ac0275 100644
--- a/chromium/device/hid/hid_connection_mac.h
+++ b/chromium/device/hid/hid_connection_mac.h
@@ -36,15 +36,15 @@ class HidConnectionMac : public HidConnection {
// HidConnection implementation.
void PlatformClose() override;
- void PlatformRead(const ReadCallback& callback) override;
+ void PlatformRead(ReadCallback callback) override;
void PlatformWrite(scoped_refptr<net::IOBuffer> buffer,
size_t size,
- const WriteCallback& callback) override;
+ WriteCallback callback) override;
void PlatformGetFeatureReport(uint8_t report_id,
- const ReadCallback& callback) override;
+ ReadCallback callback) override;
void PlatformSendFeatureReport(scoped_refptr<net::IOBuffer> buffer,
size_t size,
- const WriteCallback& callback) override;
+ WriteCallback callback) override;
static void InputReportCallback(void* context,
IOReturn result,
@@ -55,12 +55,12 @@ class HidConnectionMac : public HidConnection {
CFIndex report_length);
void ProcessInputReport(scoped_refptr<net::IOBufferWithSize> buffer);
void ProcessReadQueue();
- void GetFeatureReportAsync(uint8_t report_id, const ReadCallback& callback);
+ void GetFeatureReportAsync(uint8_t report_id, ReadCallback callback);
void SetReportAsync(IOHIDReportType report_type,
scoped_refptr<net::IOBuffer> buffer,
size_t size,
- const WriteCallback& callback);
- void ReturnAsyncResult(const base::Closure& callback);
+ WriteCallback callback);
+ void ReturnAsyncResult(base::OnceClosure callback);
base::ScopedCFTypeRef<IOHIDDeviceRef> device_;
const scoped_refptr<base::SequencedTaskRunner> task_runner_;
diff --git a/chromium/device/hid/hid_connection_unittest.cc b/chromium/device/hid/hid_connection_unittest.cc
index 590c27281f2..806ccc7b159 100644
--- a/chromium/device/hid/hid_connection_unittest.cc
+++ b/chromium/device/hid/hid_connection_unittest.cc
@@ -18,6 +18,7 @@
#include "base/test/scoped_task_environment.h"
#include "base/test/test_io_thread.h"
#include "device/hid/hid_service.h"
+#include "device/hid/public/interfaces/hid.mojom.h"
#include "device/test/test_device_client.h"
#include "device/test/usb_test_gadget.h"
#include "device/usb/usb_device.h"
@@ -34,39 +35,40 @@ using net::IOBufferWithSize;
// serial number is available. Example usage:
//
// DeviceCatcher device_catcher("ABC123");
-// HidDeviceId device_id = device_catcher.WaitForDevice();
-// /* Call HidService::Connect(device_id) to open the device. */
+// std::string device_guid = device_catcher.WaitForDevice();
+// /* Call HidService::Connect(device_guid) to open the device. */
//
class DeviceCatcher : HidService::Observer {
public:
DeviceCatcher(HidService* hid_service, const base::string16& serial_number)
: serial_number_(base::UTF16ToUTF8(serial_number)), observer_(this) {
- observer_.Add(hid_service);
hid_service->GetDevices(base::Bind(&DeviceCatcher::OnEnumerationComplete,
- base::Unretained(this)));
+ base::Unretained(this), hid_service));
}
- const HidDeviceId& WaitForDevice() {
+ const std::string& WaitForDevice() {
run_loop_.Run();
observer_.RemoveAll();
- return device_id_;
+ return device_guid_;
}
private:
void OnEnumerationComplete(
- const std::vector<scoped_refptr<HidDeviceInfo>>& devices) {
- for (const scoped_refptr<HidDeviceInfo>& device_info : devices) {
- if (device_info->serial_number() == serial_number_) {
- device_id_ = device_info->device_id();
+ HidService* hid_service,
+ std::vector<device::mojom::HidDeviceInfoPtr> devices) {
+ for (auto& device_info : devices) {
+ if (device_info->serial_number == serial_number_) {
+ device_guid_ = device_info->guid;
run_loop_.Quit();
break;
}
}
+ observer_.Add(hid_service);
}
- void OnDeviceAdded(scoped_refptr<HidDeviceInfo> device_info) override {
- if (device_info->serial_number() == serial_number_) {
- device_id_ = device_info->device_id();
+ void OnDeviceAdded(device::mojom::HidDeviceInfoPtr device_info) override {
+ if (device_info->serial_number == serial_number_) {
+ device_guid_ = device_info->guid;
run_loop_.Quit();
}
}
@@ -74,7 +76,7 @@ class DeviceCatcher : HidService::Observer {
std::string serial_number_;
ScopedObserver<device::HidService, device::HidService::Observer> observer_;
base::RunLoop run_loop_;
- HidDeviceId device_id_;
+ std::string device_guid_;
};
class TestConnectCallback {
@@ -104,11 +106,7 @@ class TestConnectCallback {
class TestIoCallback {
public:
- TestIoCallback()
- : read_callback_(
- base::Bind(&TestIoCallback::SetReadResult, base::Unretained(this))),
- write_callback_(base::Bind(&TestIoCallback::SetWriteResult,
- base::Unretained(this))) {}
+ TestIoCallback() {}
~TestIoCallback() {}
void SetReadResult(bool success,
@@ -130,9 +128,13 @@ class TestIoCallback {
return result_;
}
- const HidConnection::ReadCallback& read_callback() { return read_callback_; }
- const HidConnection::WriteCallback write_callback() {
- return write_callback_;
+ HidConnection::ReadCallback GetReadCallback() {
+ return base::BindOnce(&TestIoCallback::SetReadResult,
+ base::Unretained(this));
+ }
+ HidConnection::WriteCallback GetWriteCallback() {
+ return base::BindOnce(&TestIoCallback::SetWriteResult,
+ base::Unretained(this));
}
scoped_refptr<net::IOBuffer> buffer() const { return buffer_; }
size_t size() const { return size_; }
@@ -142,8 +144,6 @@ class TestIoCallback {
bool result_;
size_t size_;
scoped_refptr<net::IOBuffer> buffer_;
- HidConnection::ReadCallback read_callback_;
- HidConnection::WriteCallback write_callback_;
};
} // namespace
@@ -168,8 +168,8 @@ class HidConnectionTest : public testing::Test {
DeviceCatcher device_catcher(service_,
test_gadget_->GetDevice()->serial_number());
- device_id_ = device_catcher.WaitForDevice();
- ASSERT_NE(device_id_, kInvalidHidDeviceId);
+ device_guid_ = device_catcher.WaitForDevice();
+ ASSERT_FALSE(device_guid_.empty());
}
base::test::ScopedTaskEnvironment scoped_task_environment_;
@@ -177,14 +177,14 @@ class HidConnectionTest : public testing::Test {
TestDeviceClient device_client_;
HidService* service_;
std::unique_ptr<UsbTestGadget> test_gadget_;
- HidDeviceId device_id_;
+ std::string device_guid_;
};
TEST_F(HidConnectionTest, ReadWrite) {
if (!UsbTestGadget::IsTestEnabled()) return;
TestConnectCallback connect_callback;
- service_->Connect(device_id_, connect_callback.callback());
+ service_->Connect(device_guid_, connect_callback.callback());
scoped_refptr<HidConnection> conn = connect_callback.WaitForConnection();
ASSERT_TRUE(conn.get());
@@ -197,11 +197,11 @@ TEST_F(HidConnectionTest, ReadWrite) {
}
TestIoCallback write_callback;
- conn->Write(buffer, buffer->size(), write_callback.write_callback());
+ conn->Write(buffer, buffer->size(), write_callback.GetWriteCallback());
ASSERT_TRUE(write_callback.WaitForResult());
TestIoCallback read_callback;
- conn->Read(read_callback.read_callback());
+ conn->Read(read_callback.GetReadCallback());
ASSERT_TRUE(read_callback.WaitForResult());
ASSERT_EQ(9UL, read_callback.size());
ASSERT_EQ(0, read_callback.buffer()->data()[0]);
diff --git a/chromium/device/hid/hid_connection_win.cc b/chromium/device/hid/hid_connection_win.cc
index ad4ca2a26f8..3b3b983b652 100644
--- a/chromium/device/hid/hid_connection_win.cc
+++ b/chromium/device/hid/hid_connection_win.cc
@@ -99,15 +99,14 @@ void HidConnectionWin::PlatformClose() {
transfers_.clear();
}
-void HidConnectionWin::PlatformRead(
- const HidConnection::ReadCallback& callback) {
+void HidConnectionWin::PlatformRead(HidConnection::ReadCallback callback) {
// Windows will always include the report ID (including zero if report IDs
// are not in use) in the buffer.
scoped_refptr<net::IOBufferWithSize> buffer = new net::IOBufferWithSize(
base::checked_cast<int>(device_info()->max_input_report_size() + 1));
- transfers_.push_back(base::MakeUnique<PendingHidTransfer>(
+ transfers_.push_back(std::make_unique<PendingHidTransfer>(
buffer, base::BindOnce(&HidConnectionWin::OnReadComplete, this, buffer,
- callback)));
+ std::move(callback))));
transfers_.back()->TakeResultFromWindowsAPI(
ReadFile(file_.Get(), buffer->data(), static_cast<DWORD>(buffer->size()),
NULL, transfers_.back()->GetOverlapped()));
@@ -115,7 +114,7 @@ void HidConnectionWin::PlatformRead(
void HidConnectionWin::PlatformWrite(scoped_refptr<net::IOBuffer> buffer,
size_t size,
- const WriteCallback& callback) {
+ WriteCallback callback) {
size_t expected_size = device_info()->max_output_report_size() + 1;
DCHECK(size <= expected_size);
// The Windows API always wants either a report ID (if supported) or zero at
@@ -129,24 +128,24 @@ void HidConnectionWin::PlatformWrite(scoped_refptr<net::IOBuffer> buffer,
buffer = tmp_buffer;
size = expected_size;
}
- transfers_.push_back(base::MakeUnique<PendingHidTransfer>(
- buffer,
- base::BindOnce(&HidConnectionWin::OnWriteComplete, this, callback)));
+ transfers_.push_back(std::make_unique<PendingHidTransfer>(
+ buffer, base::BindOnce(&HidConnectionWin::OnWriteComplete, this,
+ std::move(callback))));
transfers_.back()->TakeResultFromWindowsAPI(
WriteFile(file_.Get(), buffer->data(), static_cast<DWORD>(size), NULL,
transfers_.back()->GetOverlapped()));
}
void HidConnectionWin::PlatformGetFeatureReport(uint8_t report_id,
- const ReadCallback& callback) {
+ ReadCallback callback) {
// The first byte of the destination buffer is the report ID being requested.
scoped_refptr<net::IOBufferWithSize> buffer = new net::IOBufferWithSize(
base::checked_cast<int>(device_info()->max_feature_report_size() + 1));
buffer->data()[0] = report_id;
- transfers_.push_back(base::MakeUnique<PendingHidTransfer>(
+ transfers_.push_back(std::make_unique<PendingHidTransfer>(
buffer, base::BindOnce(&HidConnectionWin::OnReadFeatureComplete, this,
- buffer, callback)));
+ buffer, std::move(callback))));
transfers_.back()->TakeResultFromWindowsAPI(
DeviceIoControl(file_.Get(), IOCTL_HID_GET_FEATURE, NULL, 0,
buffer->data(), static_cast<DWORD>(buffer->size()), NULL,
@@ -156,12 +155,12 @@ void HidConnectionWin::PlatformGetFeatureReport(uint8_t report_id,
void HidConnectionWin::PlatformSendFeatureReport(
scoped_refptr<net::IOBuffer> buffer,
size_t size,
- const WriteCallback& callback) {
+ WriteCallback callback) {
// The Windows API always wants either a report ID (if supported) or
// zero at the front of every output report.
- transfers_.push_back(base::MakeUnique<PendingHidTransfer>(
- buffer,
- base::BindOnce(&HidConnectionWin::OnWriteComplete, this, callback)));
+ transfers_.push_back(std::make_unique<PendingHidTransfer>(
+ buffer, base::BindOnce(&HidConnectionWin::OnWriteComplete, this,
+ std::move(callback))));
transfers_.back()->TakeResultFromWindowsAPI(
DeviceIoControl(file_.Get(), IOCTL_HID_SET_FEATURE, buffer->data(),
static_cast<DWORD>(size), NULL, 0, NULL,
@@ -169,11 +168,11 @@ void HidConnectionWin::PlatformSendFeatureReport(
}
void HidConnectionWin::OnReadComplete(scoped_refptr<net::IOBuffer> buffer,
- const ReadCallback& callback,
+ ReadCallback callback,
PendingHidTransfer* transfer_raw,
bool signaled) {
if (!file_.IsValid()) {
- callback.Run(false, nullptr, 0);
+ std::move(callback).Run(false, nullptr, 0);
return;
}
@@ -182,32 +181,32 @@ void HidConnectionWin::OnReadComplete(scoped_refptr<net::IOBuffer> buffer,
if (!signaled || !GetOverlappedResult(file_.Get(), transfer->GetOverlapped(),
&bytes_transferred, FALSE)) {
HID_PLOG(EVENT) << "HID read failed";
- callback.Run(false, nullptr, 0);
+ std::move(callback).Run(false, nullptr, 0);
return;
}
if (bytes_transferred < 1) {
HID_LOG(EVENT) << "HID read too short.";
- callback.Run(false, nullptr, 0);
+ std::move(callback).Run(false, nullptr, 0);
return;
}
uint8_t report_id = buffer->data()[0];
if (IsReportIdProtected(report_id)) {
- PlatformRead(callback);
+ PlatformRead(std::move(callback));
return;
}
- callback.Run(true, buffer, bytes_transferred);
+ std::move(callback).Run(true, buffer, bytes_transferred);
}
void HidConnectionWin::OnReadFeatureComplete(
scoped_refptr<net::IOBuffer> buffer,
- const ReadCallback& callback,
+ ReadCallback callback,
PendingHidTransfer* transfer_raw,
bool signaled) {
if (!file_.IsValid()) {
- callback.Run(false, nullptr, 0);
+ std::move(callback).Run(false, nullptr, 0);
return;
}
@@ -215,18 +214,18 @@ void HidConnectionWin::OnReadFeatureComplete(
DWORD bytes_transferred;
if (signaled && GetOverlappedResult(file_.Get(), transfer->GetOverlapped(),
&bytes_transferred, FALSE)) {
- callback.Run(true, buffer, bytes_transferred);
+ std::move(callback).Run(true, buffer, bytes_transferred);
} else {
HID_PLOG(EVENT) << "HID read failed";
- callback.Run(false, nullptr, 0);
+ std::move(callback).Run(false, nullptr, 0);
}
}
-void HidConnectionWin::OnWriteComplete(const WriteCallback& callback,
+void HidConnectionWin::OnWriteComplete(WriteCallback callback,
PendingHidTransfer* transfer_raw,
bool signaled) {
if (!file_.IsValid()) {
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
@@ -234,10 +233,10 @@ void HidConnectionWin::OnWriteComplete(const WriteCallback& callback,
DWORD bytes_transferred;
if (signaled && GetOverlappedResult(file_.Get(), transfer->GetOverlapped(),
&bytes_transferred, FALSE)) {
- callback.Run(true);
+ std::move(callback).Run(true);
} else {
HID_PLOG(EVENT) << "HID write failed";
- callback.Run(false);
+ std::move(callback).Run(false);
}
}
diff --git a/chromium/device/hid/hid_connection_win.h b/chromium/device/hid/hid_connection_win.h
index a131f5ce08d..99d4b6240f4 100644
--- a/chromium/device/hid/hid_connection_win.h
+++ b/chromium/device/hid/hid_connection_win.h
@@ -32,25 +32,25 @@ class HidConnectionWin : public HidConnection {
// HidConnection implementation.
void PlatformClose() override;
- void PlatformRead(const ReadCallback& callback) override;
+ void PlatformRead(ReadCallback callback) override;
void PlatformWrite(scoped_refptr<net::IOBuffer> buffer,
size_t size,
- const WriteCallback& callback) override;
+ WriteCallback callback) override;
void PlatformGetFeatureReport(uint8_t report_id,
- const ReadCallback& callback) override;
+ ReadCallback callback) override;
void PlatformSendFeatureReport(scoped_refptr<net::IOBuffer> buffer,
size_t size,
- const WriteCallback& callback) override;
+ WriteCallback callback) override;
void OnReadComplete(scoped_refptr<net::IOBuffer> buffer,
- const ReadCallback& callback,
+ ReadCallback callback,
PendingHidTransfer* transfer,
bool signaled);
void OnReadFeatureComplete(scoped_refptr<net::IOBuffer> buffer,
- const ReadCallback& callback,
+ ReadCallback callback,
PendingHidTransfer* transfer,
bool signaled);
- void OnWriteComplete(const WriteCallback& callback,
+ void OnWriteComplete(WriteCallback callback,
PendingHidTransfer* transfer,
bool signaled);
diff --git a/chromium/device/hid/hid_device_filter.cc b/chromium/device/hid/hid_device_filter.cc
index 3be57ab69fc..9917fd5362d 100644
--- a/chromium/device/hid/hid_device_filter.cc
+++ b/chromium/device/hid/hid_device_filter.cc
@@ -39,20 +39,20 @@ void HidDeviceFilter::SetUsage(uint16_t usage) {
}
bool HidDeviceFilter::Matches(
- scoped_refptr<const HidDeviceInfo> device_info) const {
+ const device::mojom::HidDeviceInfo& device_info) const {
if (vendor_id_set_) {
- if (device_info->vendor_id() != vendor_id_) {
+ if (device_info.vendor_id != vendor_id_) {
return false;
}
- if (product_id_set_ && device_info->product_id() != product_id_) {
+ if (product_id_set_ && device_info.product_id != product_id_) {
return false;
}
}
if (usage_page_set_) {
bool found_matching_collection = false;
- for (const HidCollectionInfo& collection : device_info->collections()) {
+ for (const HidCollectionInfo& collection : device_info.collections) {
if (collection.usage.usage_page != usage_page_) {
continue;
}
@@ -70,8 +70,9 @@ bool HidDeviceFilter::Matches(
}
// static
-bool HidDeviceFilter::MatchesAny(scoped_refptr<const HidDeviceInfo> device_info,
- const std::vector<HidDeviceFilter>& filters) {
+bool HidDeviceFilter::MatchesAny(
+ const device::mojom::HidDeviceInfo& device_info,
+ const std::vector<HidDeviceFilter>& filters) {
for (const HidDeviceFilter& filter : filters) {
if (filter.Matches(device_info)) {
return true;
diff --git a/chromium/device/hid/hid_device_filter.h b/chromium/device/hid/hid_device_filter.h
index fbffd2bfdba..98ae6fc4d5e 100644
--- a/chromium/device/hid/hid_device_filter.h
+++ b/chromium/device/hid/hid_device_filter.h
@@ -9,11 +9,10 @@
#include <vector>
#include "base/memory/ref_counted.h"
+#include "device/hid/public/interfaces/hid.mojom.h"
namespace device {
-class HidDeviceInfo;
-
class HidDeviceFilter {
public:
HidDeviceFilter();
@@ -24,9 +23,9 @@ class HidDeviceFilter {
void SetUsagePage(uint16_t usage_page);
void SetUsage(uint16_t usage);
- bool Matches(scoped_refptr<const HidDeviceInfo> device_info) const;
+ bool Matches(const device::mojom::HidDeviceInfo& device_info) const;
- static bool MatchesAny(scoped_refptr<const HidDeviceInfo> device_info,
+ static bool MatchesAny(const device::mojom::HidDeviceInfo& device_info,
const std::vector<HidDeviceFilter>& filters);
private:
diff --git a/chromium/device/hid/hid_device_filter_unittest.cc b/chromium/device/hid/hid_device_filter_unittest.cc
index c19a7346573..3a8eff3f6ef 100644
--- a/chromium/device/hid/hid_device_filter_unittest.cc
+++ b/chromium/device/hid/hid_device_filter_unittest.cc
@@ -7,6 +7,7 @@
#include "build/build_config.h"
#include "device/hid/hid_device_filter.h"
#include "device/hid/hid_device_info.h"
+#include "device/hid/public/interfaces/hid.mojom.h"
#include "device/hid/test_report_descriptors.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -27,7 +28,7 @@ class HidFilterTest : public testing::Test {
void SetUp() override {
device_info_ = new HidDeviceInfo(
kTestDeviceId, 0x046d, 0xc31c, "Test Keyboard", "123ABC",
- kHIDBusTypeUSB,
+ device::mojom::HidBusType::kHIDBusTypeUSB,
std::vector<uint8_t>(kKeyboard, kKeyboard + kKeyboardSize));
}
@@ -37,71 +38,71 @@ class HidFilterTest : public testing::Test {
TEST_F(HidFilterTest, MatchAny) {
HidDeviceFilter filter;
- ASSERT_TRUE(filter.Matches(device_info_));
+ ASSERT_TRUE(filter.Matches(*device_info_->device()));
}
TEST_F(HidFilterTest, MatchVendorId) {
HidDeviceFilter filter;
filter.SetVendorId(0x046d);
- ASSERT_TRUE(filter.Matches(device_info_));
+ ASSERT_TRUE(filter.Matches(*device_info_->device()));
}
TEST_F(HidFilterTest, MatchVendorIdNegative) {
HidDeviceFilter filter;
filter.SetVendorId(0x18d1);
- ASSERT_FALSE(filter.Matches(device_info_));
+ ASSERT_FALSE(filter.Matches(*device_info_->device()));
}
TEST_F(HidFilterTest, MatchProductId) {
HidDeviceFilter filter;
filter.SetVendorId(0x046d);
filter.SetProductId(0xc31c);
- ASSERT_TRUE(filter.Matches(device_info_));
+ ASSERT_TRUE(filter.Matches(*device_info_->device()));
}
TEST_F(HidFilterTest, MatchProductIdNegative) {
HidDeviceFilter filter;
filter.SetVendorId(0x046d);
filter.SetProductId(0x0801);
- ASSERT_FALSE(filter.Matches(device_info_));
+ ASSERT_FALSE(filter.Matches(*device_info_->device()));
}
TEST_F(HidFilterTest, MatchUsagePage) {
HidDeviceFilter filter;
filter.SetUsagePage(HidUsageAndPage::kPageGenericDesktop);
- ASSERT_TRUE(filter.Matches(device_info_));
+ ASSERT_TRUE(filter.Matches(*device_info_->device()));
}
TEST_F(HidFilterTest, MatchUsagePageNegative) {
HidDeviceFilter filter;
filter.SetUsagePage(HidUsageAndPage::kPageLed);
- ASSERT_FALSE(filter.Matches(device_info_));
+ ASSERT_FALSE(filter.Matches(*device_info_->device()));
}
TEST_F(HidFilterTest, MatchVendorAndUsagePage) {
HidDeviceFilter filter;
filter.SetVendorId(0x046d);
filter.SetUsagePage(HidUsageAndPage::kPageGenericDesktop);
- ASSERT_TRUE(filter.Matches(device_info_));
+ ASSERT_TRUE(filter.Matches(*device_info_->device()));
}
TEST_F(HidFilterTest, MatchUsageAndPage) {
HidDeviceFilter filter;
filter.SetUsagePage(HidUsageAndPage::kPageGenericDesktop);
filter.SetUsage(HidUsageAndPage::kGenericDesktopKeyboard);
- ASSERT_TRUE(filter.Matches(device_info_));
+ ASSERT_TRUE(filter.Matches(*device_info_->device()));
}
TEST_F(HidFilterTest, MatchUsageAndPageNegative) {
HidDeviceFilter filter;
filter.SetUsagePage(HidUsageAndPage::kPageGenericDesktop);
filter.SetUsage(0x02);
- ASSERT_FALSE(filter.Matches(device_info_));
+ ASSERT_FALSE(filter.Matches(*device_info_->device()));
}
TEST_F(HidFilterTest, MatchEmptyFilterListNegative) {
std::vector<HidDeviceFilter> filters;
- ASSERT_FALSE(HidDeviceFilter::MatchesAny(device_info_, filters));
+ ASSERT_FALSE(HidDeviceFilter::MatchesAny(*device_info_->device(), filters));
}
TEST_F(HidFilterTest, MatchFilterList) {
@@ -109,7 +110,7 @@ TEST_F(HidFilterTest, MatchFilterList) {
HidDeviceFilter filter;
filter.SetUsagePage(HidUsageAndPage::kPageGenericDesktop);
filters.push_back(filter);
- ASSERT_TRUE(HidDeviceFilter::MatchesAny(device_info_, filters));
+ ASSERT_TRUE(HidDeviceFilter::MatchesAny(*device_info_->device(), filters));
}
TEST_F(HidFilterTest, MatchFilterListNegative) {
@@ -117,7 +118,7 @@ TEST_F(HidFilterTest, MatchFilterListNegative) {
HidDeviceFilter filter;
filter.SetUsagePage(HidUsageAndPage::kPageLed);
filters.push_back(filter);
- ASSERT_FALSE(HidDeviceFilter::MatchesAny(device_info_, filters));
+ ASSERT_FALSE(HidDeviceFilter::MatchesAny(*device_info_->device(), filters));
}
} // namespace device
diff --git a/chromium/device/hid/hid_device_info.cc b/chromium/device/hid/hid_device_info.cc
index 1e8a4f12882..fd787ecf6ce 100644
--- a/chromium/device/hid/hid_device_info.cc
+++ b/chromium/device/hid/hid_device_info.cc
@@ -2,57 +2,62 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "build/build_config.h"
#include "device/hid/hid_device_info.h"
+
+#include "base/guid.h"
+#include "build/build_config.h"
#include "device/hid/hid_report_descriptor.h"
namespace device {
-#if !defined(OS_MACOSX)
-const char kInvalidHidDeviceId[] = "";
-#endif
-
-HidDeviceInfo::HidDeviceInfo(const HidDeviceId& device_id,
+HidDeviceInfo::HidDeviceInfo(const HidPlatformDeviceId& platform_device_id,
uint16_t vendor_id,
uint16_t product_id,
const std::string& product_name,
const std::string& serial_number,
- HidBusType bus_type,
- const std::vector<uint8_t> report_descriptor)
- : device_id_(device_id),
- vendor_id_(vendor_id),
- product_id_(product_id),
- product_name_(product_name),
- serial_number_(serial_number),
- bus_type_(bus_type),
- report_descriptor_(report_descriptor) {
- HidReportDescriptor descriptor_parser(report_descriptor_);
- descriptor_parser.GetDetails(
- &collections_, &has_report_id_, &max_input_report_size_,
- &max_output_report_size_, &max_feature_report_size_);
+ device::mojom::HidBusType bus_type,
+ const std::vector<uint8_t> report_descriptor,
+ std::string device_node)
+ : platform_device_id_(platform_device_id) {
+ std::vector<HidCollectionInfo> collections;
+ bool has_report_id;
+ size_t max_input_report_size;
+ size_t max_output_report_size;
+ size_t max_feature_report_size;
+
+ HidReportDescriptor descriptor_parser(report_descriptor);
+ descriptor_parser.GetDetails(&collections, &has_report_id,
+ &max_input_report_size, &max_output_report_size,
+ &max_feature_report_size);
+
+ device_ = device::mojom::HidDeviceInfo::New(
+ base::GenerateGUID(), vendor_id, product_id, product_name, serial_number,
+ bus_type, report_descriptor, collections, has_report_id,
+ max_input_report_size, max_output_report_size, max_feature_report_size,
+ device_node);
}
-HidDeviceInfo::HidDeviceInfo(const HidDeviceId& device_id,
+HidDeviceInfo::HidDeviceInfo(const HidPlatformDeviceId& platform_device_id,
uint16_t vendor_id,
uint16_t product_id,
const std::string& product_name,
const std::string& serial_number,
- HidBusType bus_type,
+ device::mojom::HidBusType bus_type,
const HidCollectionInfo& collection,
size_t max_input_report_size,
size_t max_output_report_size,
size_t max_feature_report_size)
- : device_id_(device_id),
- vendor_id_(vendor_id),
- product_id_(product_id),
- product_name_(product_name),
- serial_number_(serial_number),
- bus_type_(bus_type),
- max_input_report_size_(max_input_report_size),
- max_output_report_size_(max_output_report_size),
- max_feature_report_size_(max_feature_report_size) {
- collections_.push_back(collection);
- has_report_id_ = !collection.report_ids.empty();
+ : platform_device_id_(platform_device_id) {
+ std::vector<HidCollectionInfo> collections;
+ collections.push_back(collection);
+ bool has_report_id = !collection.report_ids.empty();
+
+ std::vector<uint8_t> report_descriptor;
+ device_ = device::mojom::HidDeviceInfo::New(
+ base::GenerateGUID(), vendor_id, product_id, product_name, serial_number,
+ bus_type, report_descriptor, collections, has_report_id,
+ max_input_report_size, max_output_report_size, max_feature_report_size,
+ "");
}
HidDeviceInfo::~HidDeviceInfo() {}
diff --git a/chromium/device/hid/hid_device_info.h b/chromium/device/hid/hid_device_info.h
index 15a957dd82d..632bbebb930 100644
--- a/chromium/device/hid/hid_device_info.h
+++ b/chromium/device/hid/hid_device_info.h
@@ -15,64 +15,71 @@
#include "base/memory/ref_counted.h"
#include "build/build_config.h"
#include "device/hid/hid_collection_info.h"
+#include "device/hid/public/interfaces/hid.mojom.h"
namespace device {
-enum HidBusType {
- kHIDBusTypeUSB = 0,
- kHIDBusTypeBluetooth = 1,
-};
-
#if defined(OS_MACOSX)
-typedef uint64_t HidDeviceId;
-const uint64_t kInvalidHidDeviceId = -1;
+typedef uint64_t HidPlatformDeviceId;
#else
-typedef std::string HidDeviceId;
-extern const char kInvalidHidDeviceId[];
+typedef std::string HidPlatformDeviceId;
#endif
class HidDeviceInfo : public base::RefCountedThreadSafe<HidDeviceInfo> {
public:
- HidDeviceInfo(const HidDeviceId& device_id,
+ HidDeviceInfo(const HidPlatformDeviceId& platform_device_id,
uint16_t vendor_id,
uint16_t product_id,
const std::string& product_name,
const std::string& serial_number,
- HidBusType bus_type,
- const std::vector<uint8_t> report_descriptor);
+ device::mojom::HidBusType bus_type,
+ const std::vector<uint8_t> report_descriptor,
+ std::string device_node = "");
- HidDeviceInfo(const HidDeviceId& device_id,
+ HidDeviceInfo(const HidPlatformDeviceId& platform_device_id,
uint16_t vendor_id,
uint16_t product_id,
const std::string& product_name,
const std::string& serial_number,
- HidBusType bus_type,
+ device::mojom::HidBusType bus_type,
const HidCollectionInfo& collection,
size_t max_input_report_size,
size_t max_output_report_size,
size_t max_feature_report_size);
+ const device::mojom::HidDeviceInfoPtr& device() { return device_; }
+
// Device identification.
- const HidDeviceId& device_id() const { return device_id_; }
- uint16_t vendor_id() const { return vendor_id_; }
- uint16_t product_id() const { return product_id_; }
- const std::string& product_name() const { return product_name_; }
- const std::string& serial_number() const { return serial_number_; }
- HidBusType bus_type() const { return bus_type_; }
+ const std::string& device_guid() const { return device_->guid; }
+ const HidPlatformDeviceId& platform_device_id() const {
+ return platform_device_id_;
+ }
+ uint16_t vendor_id() const { return device_->vendor_id; }
+ uint16_t product_id() const { return device_->product_id; }
+ const std::string& product_name() const { return device_->product_name; }
+ const std::string& serial_number() const { return device_->serial_number; }
+ device::mojom::HidBusType bus_type() const { return device_->bus_type; }
// Top-Level Collections information.
const std::vector<HidCollectionInfo>& collections() const {
- return collections_;
+ return device_->collections;
+ }
+ bool has_report_id() const { return device_->has_report_id; };
+ size_t max_input_report_size() const {
+ return device_->max_input_report_size;
+ }
+ size_t max_output_report_size() const {
+ return device_->max_output_report_size;
+ }
+ size_t max_feature_report_size() const {
+ return device_->max_feature_report_size;
}
- bool has_report_id() const { return has_report_id_; };
- size_t max_input_report_size() const { return max_input_report_size_; }
- size_t max_output_report_size() const { return max_output_report_size_; }
- size_t max_feature_report_size() const { return max_feature_report_size_; }
// The raw HID report descriptor is not available on Windows.
const std::vector<uint8_t>& report_descriptor() const {
- return report_descriptor_;
+ return device_->report_descriptor;
}
+ const std::string& device_node() const { return device_->device_node; }
protected:
virtual ~HidDeviceInfo();
@@ -80,21 +87,8 @@ class HidDeviceInfo : public base::RefCountedThreadSafe<HidDeviceInfo> {
private:
friend class base::RefCountedThreadSafe<HidDeviceInfo>;
- // Device identification.
- HidDeviceId device_id_;
- uint16_t vendor_id_;
- uint16_t product_id_;
- std::string product_name_;
- std::string serial_number_;
- HidBusType bus_type_;
- std::vector<uint8_t> report_descriptor_;
-
- // Top-Level Collections information.
- std::vector<HidCollectionInfo> collections_;
- bool has_report_id_;
- size_t max_input_report_size_;
- size_t max_output_report_size_;
- size_t max_feature_report_size_;
+ HidPlatformDeviceId platform_device_id_;
+ device::mojom::HidDeviceInfoPtr device_;
DISALLOW_COPY_AND_ASSIGN(HidDeviceInfo);
};
diff --git a/chromium/device/hid/hid_device_info_linux.cc b/chromium/device/hid/hid_device_info_linux.cc
deleted file mode 100644
index b8d95a3b34c..00000000000
--- a/chromium/device/hid/hid_device_info_linux.cc
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "hid_device_info_linux.h"
-
-namespace device {
-
-HidDeviceInfoLinux::HidDeviceInfoLinux(
- const HidDeviceId& device_id,
- const std::string& device_node,
- uint16_t vendor_id,
- uint16_t product_id,
- const std::string& product_name,
- const std::string& serial_number,
- HidBusType bus_type,
- const std::vector<uint8_t> report_descriptor)
- : HidDeviceInfo(device_id,
- vendor_id,
- product_id,
- product_name,
- serial_number,
- bus_type,
- report_descriptor),
- device_node_(device_node) {}
-
-HidDeviceInfoLinux::~HidDeviceInfoLinux() {
-}
-
-} // namespace device
diff --git a/chromium/device/hid/hid_device_info_linux.h b/chromium/device/hid/hid_device_info_linux.h
deleted file mode 100644
index 6546c8ad199..00000000000
--- a/chromium/device/hid/hid_device_info_linux.h
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef DEVICE_HID_HID_DEVICE_INFO_LINUX_H_
-#define DEVICE_HID_HID_DEVICE_INFO_LINUX_H_
-
-#include <stdint.h>
-
-#include "device/hid/hid_device_info.h"
-
-namespace device {
-
-class HidDeviceInfoLinux : public HidDeviceInfo {
- public:
- HidDeviceInfoLinux(const HidDeviceId& device_id,
- const std::string& device_node,
- uint16_t vendor_id,
- uint16_t product_id,
- const std::string& product_name,
- const std::string& serial_number,
- HidBusType bus_type,
- const std::vector<uint8_t> report_descriptor);
-
- const std::string& device_node() const { return device_node_; }
-
- private:
- ~HidDeviceInfoLinux() override;
-
- std::string device_node_;
-};
-
-} // namespace device
-
-#endif // DEVICE_HID_HID_DEVICE_INFO_LINUX_H_
diff --git a/chromium/device/hid/hid_service.cc b/chromium/device/hid/hid_service.cc
index f129a9776fd..8f3b40a7df1 100644
--- a/chromium/device/hid/hid_service.cc
+++ b/chromium/device/hid/hid_service.cc
@@ -25,16 +25,10 @@
namespace device {
void HidService::Observer::OnDeviceAdded(
- scoped_refptr<HidDeviceInfo> device_info) {
-}
+ device::mojom::HidDeviceInfoPtr device_info) {}
void HidService::Observer::OnDeviceRemoved(
- scoped_refptr<HidDeviceInfo> device_info) {
-}
-
-void HidService::Observer::OnDeviceRemovedCleanup(
- scoped_refptr<HidDeviceInfo> device_info) {
-}
+ device::mojom::HidDeviceInfoPtr device_info) {}
// static
constexpr base::TaskTraits HidService::kBlockingTaskTraits;
@@ -53,15 +47,13 @@ std::unique_ptr<HidService> HidService::Create() {
void HidService::GetDevices(const GetDevicesCallback& callback) {
DCHECK(thread_checker_.CalledOnValidThread());
- if (enumeration_ready_) {
- std::vector<scoped_refptr<HidDeviceInfo>> devices;
- for (const auto& map_entry : devices_) {
- devices.push_back(map_entry.second);
- }
+
+ bool was_empty = pending_enumerations_.empty();
+ pending_enumerations_.push_back(callback);
+ if (enumeration_ready_ && was_empty) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(callback, devices));
- } else {
- pending_enumerations_.push_back(callback);
+ FROM_HERE,
+ base::Bind(&HidService::RunPendingEnumerations, GetWeakPtr()));
}
}
@@ -73,17 +65,6 @@ void HidService::RemoveObserver(HidService::Observer* observer) {
observer_list_.RemoveObserver(observer);
}
-// Fills in the device info struct of the given device_id.
-scoped_refptr<HidDeviceInfo> HidService::GetDeviceInfo(
- const HidDeviceId& device_id) const {
- DCHECK(thread_checker_.CalledOnValidThread());
- DeviceMap::const_iterator it = devices_.find(device_id);
- if (it == devices_.end()) {
- return nullptr;
- }
- return it->second;
-}
-
HidService::HidService() = default;
HidService::~HidService() {
@@ -92,8 +73,11 @@ HidService::~HidService() {
void HidService::AddDevice(scoped_refptr<HidDeviceInfo> device_info) {
DCHECK(thread_checker_.CalledOnValidThread());
- if (!base::ContainsKey(devices_, device_info->device_id())) {
- devices_[device_info->device_id()] = device_info;
+
+ std::string device_guid =
+ FindDeviceIdByPlatformDeviceId(device_info->platform_device_id());
+ if (device_guid.empty()) {
+ devices_[device_info->device_guid()] = device_info;
HID_LOG(USER) << "HID device "
<< (enumeration_ready_ ? "added" : "detected")
@@ -101,48 +85,64 @@ void HidService::AddDevice(scoped_refptr<HidDeviceInfo> device_info) {
<< ", productId=" << device_info->product_id() << ", name='"
<< device_info->product_name() << "', serial='"
<< device_info->serial_number() << "', deviceId='"
- << device_info->device_id() << "'";
+ << device_info->platform_device_id() << "'";
if (enumeration_ready_) {
for (auto& observer : observer_list_)
- observer.OnDeviceAdded(device_info);
+ observer.OnDeviceAdded(device_info->device()->Clone());
}
}
}
-void HidService::RemoveDevice(const HidDeviceId& device_id) {
+void HidService::RemoveDevice(const HidPlatformDeviceId& platform_device_id) {
DCHECK(thread_checker_.CalledOnValidThread());
- DeviceMap::iterator it = devices_.find(device_id);
- if (it != devices_.end()) {
- HID_LOG(USER) << "HID device removed: deviceId='" << device_id << "'";
- scoped_refptr<HidDeviceInfo> device = it->second;
- if (enumeration_ready_) {
- for (auto& observer : observer_list_)
- observer.OnDeviceRemoved(device);
- }
- devices_.erase(it);
+ std::string device_guid = FindDeviceIdByPlatformDeviceId(platform_device_id);
+ if (!device_guid.empty()) {
+ HID_LOG(USER) << "HID device removed: deviceId='" << platform_device_id
+ << "'";
+ DCHECK(base::ContainsKey(devices_, device_guid));
+
+ scoped_refptr<HidDeviceInfo> device_info = devices_[device_guid];
if (enumeration_ready_) {
for (auto& observer : observer_list_)
- observer.OnDeviceRemovedCleanup(device);
+ observer.OnDeviceRemoved(device_info->device()->Clone());
}
+ devices_.erase(device_guid);
+ }
+}
+
+void HidService::RunPendingEnumerations() {
+ DCHECK(enumeration_ready_);
+ DCHECK(!pending_enumerations_.empty());
+
+ std::vector<GetDevicesCallback> callbacks;
+ callbacks.swap(pending_enumerations_);
+
+ // Clone and pass device::mojom::HidDeviceInfoPtr vector for each clients.
+ for (const auto& callback : callbacks) {
+ std::vector<device::mojom::HidDeviceInfoPtr> devices;
+ for (const auto& map_entry : devices_)
+ devices.push_back(map_entry.second->device()->Clone());
+ callback.Run(std::move(devices));
}
}
void HidService::FirstEnumerationComplete() {
enumeration_ready_ = true;
-
if (!pending_enumerations_.empty()) {
- std::vector<scoped_refptr<HidDeviceInfo>> devices;
- for (const auto& map_entry : devices_) {
- devices.push_back(map_entry.second);
- }
+ RunPendingEnumerations();
+ }
+}
- for (const GetDevicesCallback& callback : pending_enumerations_) {
- callback.Run(devices);
+std::string HidService::FindDeviceIdByPlatformDeviceId(
+ const HidPlatformDeviceId& platform_device_id) {
+ for (const auto& map_entry : devices_) {
+ if (map_entry.second->platform_device_id() == platform_device_id) {
+ return map_entry.first;
}
- pending_enumerations_.clear();
}
+ return std::string();
}
} // namespace device
diff --git a/chromium/device/hid/hid_service.h b/chromium/device/hid/hid_service.h
index 1144837fdc4..906db275cd4 100644
--- a/chromium/device/hid/hid_service.h
+++ b/chromium/device/hid/hid_service.h
@@ -14,11 +14,13 @@
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/single_thread_task_runner.h"
#include "base/task_scheduler/task_traits.h"
#include "base/threading/thread_checker.h"
#include "device/hid/hid_device_info.h"
+#include "device/hid/public/interfaces/hid.mojom.h"
namespace device {
@@ -28,22 +30,24 @@ class HidConnection;
// system. Call HidService::GetInstance to get the singleton instance.
class HidService {
public:
+ // Clients of HidService should add themselves as observer in their
+ // GetDevicesCallback. Earlier might cause OnDeviceAdded() and
+ // OnDeviceRemoved() to be called before the GetDevicesCallback, while later
+ // might cause missing OnDeviceAdded() and OnDeviceRemoved() notifications.
+ // TODO(ke.he@intel.com): In the mojofication of HidService, clients should
+ // pass an mojom::ObserverPtr in the GetDevices() interface, HidService adds
+ // the observer immediately after calling the GetDevicesCallback.
class Observer {
public:
- virtual void OnDeviceAdded(scoped_refptr<HidDeviceInfo> info);
+ virtual void OnDeviceAdded(device::mojom::HidDeviceInfoPtr info);
// Notifies all observers that a device is being removed, called before
// removing the device from HidService. Observers should not depend on the
// order in which they are notified of the OnDeviceRemove event.
- virtual void OnDeviceRemoved(scoped_refptr<HidDeviceInfo> info);
- // Notifies all observers again, after having first notified all observers
- // with OnDeviceRemoved and removed the device from internal structures.
- // Each observer must not depend on any other observers' awareness of the
- // device as they could be cleaned up in any order.
- virtual void OnDeviceRemovedCleanup(scoped_refptr<HidDeviceInfo> info);
+ virtual void OnDeviceRemoved(device::mojom::HidDeviceInfoPtr info);
};
using GetDevicesCallback =
- base::Callback<void(const std::vector<scoped_refptr<HidDeviceInfo>>&)>;
+ base::Callback<void(std::vector<device::mojom::HidDeviceInfoPtr>)>;
using ConnectCallback =
base::Callback<void(scoped_refptr<HidConnection> connection)>;
@@ -58,30 +62,26 @@ class HidService {
// Enumerates available devices. The provided callback will always be posted
// to the calling thread's task runner.
- virtual void GetDevices(const GetDevicesCallback& callback);
+ void GetDevices(const GetDevicesCallback& callback);
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
- // Fills in a DeviceInfo struct with info for the given device_id.
- // Returns |nullptr| if |device_id| is invalid.
- scoped_refptr<HidDeviceInfo> GetDeviceInfo(
- const HidDeviceId& device_id) const;
-
// Opens a connection to a device. The callback will be run with null on
// failure.
- virtual void Connect(const HidDeviceId& device_id,
+ virtual void Connect(const std::string& device_guid,
const ConnectCallback& callback) = 0;
protected:
friend class HidConnectionTest;
- typedef std::map<HidDeviceId, scoped_refptr<HidDeviceInfo>> DeviceMap;
+ typedef std::map<std::string, scoped_refptr<HidDeviceInfo>> DeviceMap;
HidService();
+ virtual base::WeakPtr<HidService> GetWeakPtr() = 0;
void AddDevice(scoped_refptr<HidDeviceInfo> info);
- void RemoveDevice(const HidDeviceId& device_id);
+ void RemoveDevice(const HidPlatformDeviceId& platform_device_id);
void FirstEnumerationComplete();
const DeviceMap& devices() const { return devices_; }
@@ -89,7 +89,12 @@ class HidService {
base::ThreadChecker thread_checker_;
private:
+ void RunPendingEnumerations();
+ std::string FindDeviceIdByPlatformDeviceId(
+ const HidPlatformDeviceId& platform_device_id);
+
DeviceMap devices_;
+
bool enumeration_ready_ = false;
std::vector<GetDevicesCallback> pending_enumerations_;
base::ObserverList<Observer, true> observer_list_;
diff --git a/chromium/device/hid/hid_service_linux.cc b/chromium/device/hid/hid_service_linux.cc
index 506fb07f726..1e264935379 100644
--- a/chromium/device/hid/hid_service_linux.cc
+++ b/chromium/device/hid/hid_service_linux.cc
@@ -30,7 +30,6 @@
#include "build/build_config.h"
#include "components/device_event_log/device_event_log.h"
#include "device/hid/hid_connection_linux.h"
-#include "device/hid/hid_device_info_linux.h"
#include "device/udev_linux/scoped_udev.h"
#include "device/udev_linux/udev_watcher.h"
@@ -53,7 +52,7 @@ const char kSysfsReportDescriptorKey[] = "report_descriptor";
} // namespace
struct HidServiceLinux::ConnectParams {
- ConnectParams(scoped_refptr<HidDeviceInfoLinux> device_info,
+ ConnectParams(scoped_refptr<HidDeviceInfo> device_info,
const ConnectCallback& callback)
: device_info(std::move(device_info)),
callback(callback),
@@ -62,7 +61,7 @@ struct HidServiceLinux::ConnectParams {
base::CreateSequencedTaskRunnerWithTraits(kBlockingTaskTraits)) {}
~ConnectParams() {}
- scoped_refptr<HidDeviceInfoLinux> device_info;
+ scoped_refptr<HidDeviceInfo> device_info;
ConnectCallback callback;
scoped_refptr<base::SequencedTaskRunner> task_runner;
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner;
@@ -99,7 +98,7 @@ class HidServiceLinux::BlockingTaskHelper : public UdevWatcher::Observer {
const char* device_path = udev_device_get_syspath(device.get());
if (!device_path)
return;
- HidDeviceId device_id = device_path;
+ HidPlatformDeviceId platform_device_id = device_path;
const char* subsystem = udev_device_get_subsystem(device.get());
if (!subsystem || strcmp(subsystem, kHidrawSubsystem) != 0)
@@ -155,12 +154,13 @@ class HidServiceLinux::BlockingTaskHelper : public UdevWatcher::Observer {
if (!base::ReadFileToString(report_descriptor_path, &report_descriptor_str))
return;
- scoped_refptr<HidDeviceInfo> device_info(new HidDeviceInfoLinux(
- device_id, device_node, vendor_id, product_id, product_name,
- serial_number,
- kHIDBusTypeUSB, // TODO(reillyg): Detect Bluetooth. crbug.com/443335
+ scoped_refptr<HidDeviceInfo> device_info(new HidDeviceInfo(
+ platform_device_id, vendor_id, product_id, product_name, serial_number,
+ // TODO(reillyg): Detect Bluetooth. crbug.com/443335
+ device::mojom::HidBusType::kHIDBusTypeUSB,
std::vector<uint8_t>(report_descriptor_str.begin(),
- report_descriptor_str.end())));
+ report_descriptor_str.end()),
+ device_node));
task_runner_->PostTask(FROM_HERE, base::Bind(&HidServiceLinux::AddDevice,
service_, device_info));
@@ -190,7 +190,7 @@ HidServiceLinux::HidServiceLinux()
: blocking_task_runner_(
base::CreateSequencedTaskRunnerWithTraits(kBlockingTaskTraits)),
weak_factory_(this) {
- helper_ = base::MakeUnique<BlockingTaskHelper>(weak_factory_.GetWeakPtr());
+ helper_ = std::make_unique<BlockingTaskHelper>(weak_factory_.GetWeakPtr());
blocking_task_runner_->PostTask(
FROM_HERE,
base::Bind(&BlockingTaskHelper::Start, base::Unretained(helper_.get())));
@@ -200,20 +200,23 @@ HidServiceLinux::~HidServiceLinux() {
blocking_task_runner_->DeleteSoon(FROM_HERE, helper_.release());
}
-void HidServiceLinux::Connect(const HidDeviceId& device_id,
+base::WeakPtr<HidService> HidServiceLinux::GetWeakPtr() {
+ return weak_factory_.GetWeakPtr();
+}
+
+void HidServiceLinux::Connect(const std::string& device_guid,
const ConnectCallback& callback) {
DCHECK(thread_checker_.CalledOnValidThread());
- const auto& map_entry = devices().find(device_id);
+ const auto& map_entry = devices().find(device_guid);
if (map_entry == devices().end()) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(callback, nullptr));
return;
}
- scoped_refptr<HidDeviceInfoLinux> device_info =
- static_cast<HidDeviceInfoLinux*>(map_entry->second.get());
+ scoped_refptr<HidDeviceInfo> device_info = map_entry->second;
- auto params = base::MakeUnique<ConnectParams>(device_info, callback);
+ auto params = std::make_unique<ConnectParams>(device_info, callback);
#if defined(OS_CHROMEOS)
chromeos::PermissionBrokerClient* client =
diff --git a/chromium/device/hid/hid_service_linux.h b/chromium/device/hid/hid_service_linux.h
index 037945e6736..35aad42fb84 100644
--- a/chromium/device/hid/hid_service_linux.h
+++ b/chromium/device/hid/hid_service_linux.h
@@ -23,8 +23,9 @@ class HidServiceLinux : public HidService {
~HidServiceLinux() override;
// HidService:
- void Connect(const HidDeviceId& device_id,
+ void Connect(const std::string& device_id,
const ConnectCallback& callback) override;
+ base::WeakPtr<HidService> GetWeakPtr() override;
private:
struct ConnectParams;
diff --git a/chromium/device/hid/hid_service_mac.cc b/chromium/device/hid/hid_service_mac.cc
index 056050342e7..7ecedb71dce 100644
--- a/chromium/device/hid/hid_service_mac.cc
+++ b/chromium/device/hid/hid_service_mac.cc
@@ -85,8 +85,8 @@ scoped_refptr<HidDeviceInfo> CreateDeviceInfo(
GetIntProperty(service, CFSTR(kIOHIDProductIDKey)),
GetStringProperty(service, CFSTR(kIOHIDProductKey)),
GetStringProperty(service, CFSTR(kIOHIDSerialNumberKey)),
- kHIDBusTypeUSB, // TODO(reillyg): Detect Bluetooth. crbug.com/443335
- report_descriptor);
+ // TODO(reillyg): Detect Bluetooth. crbug.com/443335
+ device::mojom::HidBusType::kHIDBusTypeUSB, report_descriptor);
}
} // namespace
@@ -127,11 +127,11 @@ HidServiceMac::HidServiceMac() : weak_factory_(this) {
HidServiceMac::~HidServiceMac() {}
-void HidServiceMac::Connect(const HidDeviceId& device_id,
+void HidServiceMac::Connect(const std::string& device_guid,
const ConnectCallback& callback) {
DCHECK(thread_checker_.CalledOnValidThread());
- const auto& map_entry = devices().find(device_id);
+ const auto& map_entry = devices().find(device_guid);
if (map_entry == devices().end()) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(callback, nullptr));
@@ -145,14 +145,18 @@ void HidServiceMac::Connect(const HidDeviceId& device_id,
map_entry->second, callback));
}
+base::WeakPtr<HidService> HidServiceMac::GetWeakPtr() {
+ return weak_factory_.GetWeakPtr();
+}
+
// static
base::ScopedCFTypeRef<IOHIDDeviceRef> HidServiceMac::OpenOnBlockingThread(
scoped_refptr<HidDeviceInfo> device_info) {
base::ScopedCFTypeRef<CFDictionaryRef> matching_dict(
- IORegistryEntryIDMatching(device_info->device_id()));
+ IORegistryEntryIDMatching(device_info->platform_device_id()));
if (!matching_dict.get()) {
HID_LOG(EVENT) << "Failed to create matching dictionary for ID: "
- << device_info->device_id();
+ << device_info->platform_device_id();
return base::ScopedCFTypeRef<IOHIDDeviceRef>();
}
@@ -162,7 +166,7 @@ base::ScopedCFTypeRef<IOHIDDeviceRef> HidServiceMac::OpenOnBlockingThread(
kIOMasterPortDefault, matching_dict.release()));
if (!service.get()) {
HID_LOG(EVENT) << "IOService not found for ID: "
- << device_info->device_id();
+ << device_info->platform_device_id();
return base::ScopedCFTypeRef<IOHIDDeviceRef>();
}
diff --git a/chromium/device/hid/hid_service_mac.h b/chromium/device/hid/hid_service_mac.h
index 7e238f3fb96..99e8596c5d1 100644
--- a/chromium/device/hid/hid_service_mac.h
+++ b/chromium/device/hid/hid_service_mac.h
@@ -26,8 +26,9 @@ class HidServiceMac : public HidService {
HidServiceMac();
~HidServiceMac() override;
- void Connect(const HidDeviceId& device_id,
+ void Connect(const std::string& device_id,
const ConnectCallback& connect) override;
+ base::WeakPtr<HidService> GetWeakPtr() override;
private:
static base::ScopedCFTypeRef<IOHIDDeviceRef> OpenOnBlockingThread(
diff --git a/chromium/device/hid/hid_service_unittest.cc b/chromium/device/hid/hid_service_unittest.cc
index 4da84d480cf..17ac871fe27 100644
--- a/chromium/device/hid/hid_service_unittest.cc
+++ b/chromium/device/hid/hid_service_unittest.cc
@@ -6,6 +6,7 @@
#include "base/bind.h"
#include "base/run_loop.h"
#include "base/test/scoped_task_environment.h"
+#include "device/hid/public/interfaces/hid.mojom.h"
#include "device/test/test_device_client.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -25,7 +26,7 @@ class HidServiceTest : public ::testing::Test {
};
void OnGetDevices(const base::Closure& quit_closure,
- const std::vector<scoped_refptr<HidDeviceInfo>>& devices) {
+ std::vector<device::mojom::HidDeviceInfoPtr> devices) {
// Since there's no guarantee that any devices are connected at the moment
// this test doesn't assume anything about the result but it at least verifies
// that devices can be enumerated without the application crashing.
diff --git a/chromium/device/hid/hid_service_win.cc b/chromium/device/hid/hid_service_win.cc
index 0fc0c06ccd5..0357ea717e3 100644
--- a/chromium/device/hid/hid_service_win.cc
+++ b/chromium/device/hid/hid_service_win.cc
@@ -49,17 +49,17 @@ HidServiceWin::HidServiceWin()
HidServiceWin::~HidServiceWin() {}
-void HidServiceWin::Connect(const HidDeviceId& device_id,
+void HidServiceWin::Connect(const std::string& device_guid,
const ConnectCallback& callback) {
DCHECK(thread_checker_.CalledOnValidThread());
- const auto& map_entry = devices().find(device_id);
+ const auto& map_entry = devices().find(device_guid);
if (map_entry == devices().end()) {
task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr));
return;
}
scoped_refptr<HidDeviceInfo> device_info = map_entry->second;
- base::win::ScopedHandle file(OpenDevice(device_info->device_id()));
+ base::win::ScopedHandle file(OpenDevice(device_info->platform_device_id()));
if (!file.IsValid()) {
HID_PLOG(EVENT) << "Failed to open device";
task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr));
@@ -71,6 +71,10 @@ void HidServiceWin::Connect(const HidDeviceId& device_id,
device_info, std::move(file))));
}
+base::WeakPtr<HidService> HidServiceWin::GetWeakPtr() {
+ return weak_factory_.GetWeakPtr();
+}
+
// static
void HidServiceWin::EnumerateBlocking(
base::WeakPtr<HidServiceWin> service,
@@ -256,9 +260,9 @@ void HidServiceWin::AddDeviceBlocking(
scoped_refptr<HidDeviceInfo> device_info(new HidDeviceInfo(
device_path, attrib.VendorID, attrib.ProductID, product_name,
serial_number,
- kHIDBusTypeUSB, // TODO(reillyg): Detect Bluetooth. crbug.com/443335
- collection_info, max_input_report_size, max_output_report_size,
- max_feature_report_size));
+ // TODO(reillyg): Detect Bluetooth. crbug.com/443335
+ device::mojom::HidBusType::kHIDBusTypeUSB, collection_info,
+ max_input_report_size, max_output_report_size, max_feature_report_size));
HidD_FreePreparsedData(preparsed_data);
task_runner->PostTask(
diff --git a/chromium/device/hid/hid_service_win.h b/chromium/device/hid/hid_service_win.h
index d544862d0e6..80305da6565 100644
--- a/chromium/device/hid/hid_service_win.h
+++ b/chromium/device/hid/hid_service_win.h
@@ -34,8 +34,9 @@ class HidServiceWin : public HidService, public DeviceMonitorWin::Observer {
HidServiceWin();
~HidServiceWin() override;
- void Connect(const HidDeviceId& device_id,
+ void Connect(const std::string& device_id,
const ConnectCallback& callback) override;
+ base::WeakPtr<HidService> GetWeakPtr() override;
private:
static void EnumerateBlocking(
diff --git a/chromium/device/hid/hid_usage_and_page.h b/chromium/device/hid/hid_usage_and_page.h
index 1015854e9c4..2ed911369b6 100644
--- a/chromium/device/hid/hid_usage_and_page.h
+++ b/chromium/device/hid/hid_usage_and_page.h
@@ -119,6 +119,7 @@ struct HidUsageAndPage {
kGenericDesktopSystemDisplaySwap = 0xb6,
};
+ HidUsageAndPage() {}
HidUsageAndPage(uint16_t usage, Page usage_page)
: usage(usage), usage_page(usage_page) {}
~HidUsageAndPage() {}
diff --git a/chromium/device/hid/mock_hid_service.cc b/chromium/device/hid/mock_hid_service.cc
index 238e4165f1a..ea2ccb8f055 100644
--- a/chromium/device/hid/mock_hid_service.cc
+++ b/chromium/device/hid/mock_hid_service.cc
@@ -6,23 +6,28 @@
namespace device {
-MockHidService::MockHidService() = default;
+MockHidService::MockHidService() : weak_factory_(this) {}
MockHidService::~MockHidService() = default;
+base::WeakPtr<HidService> MockHidService::GetWeakPtr() {
+ return weak_factory_.GetWeakPtr();
+}
+
void MockHidService::AddDevice(scoped_refptr<HidDeviceInfo> info) {
HidService::AddDevice(info);
}
-void MockHidService::RemoveDevice(const HidDeviceId& device_id) {
- HidService::RemoveDevice(device_id);
+void MockHidService::RemoveDevice(
+ const HidPlatformDeviceId& platform_device_id) {
+ HidService::RemoveDevice(platform_device_id);
}
void MockHidService::FirstEnumerationComplete() {
HidService::FirstEnumerationComplete();
}
-const std::map<HidDeviceId, scoped_refptr<HidDeviceInfo>>&
+const std::map<std::string, scoped_refptr<HidDeviceInfo>>&
MockHidService::devices() const {
return HidService::devices();
}
diff --git a/chromium/device/hid/mock_hid_service.h b/chromium/device/hid/mock_hid_service.h
index f5f6c82df11..fde4b322f2b 100644
--- a/chromium/device/hid/mock_hid_service.h
+++ b/chromium/device/hid/mock_hid_service.h
@@ -19,13 +19,18 @@ class MockHidService : public HidService {
// Public wrappers around protected functions needed for tests.
void AddDevice(scoped_refptr<HidDeviceInfo> info);
- void RemoveDevice(const HidDeviceId& device_id);
+ void RemoveDevice(const HidPlatformDeviceId& platform_device_id);
void FirstEnumerationComplete();
- const std::map<HidDeviceId, scoped_refptr<HidDeviceInfo>>& devices() const;
+ const std::map<std::string, scoped_refptr<HidDeviceInfo>>& devices() const;
MOCK_METHOD2(Connect,
- void(const HidDeviceId& device_id,
+ void(const std::string& device_guid,
const ConnectCallback& callback));
+
+ private:
+ base::WeakPtr<HidService> GetWeakPtr() override;
+
+ base::WeakPtrFactory<MockHidService> weak_factory_;
};
} // namespace device
diff --git a/chromium/device/hid/public/interfaces/BUILD.gn b/chromium/device/hid/public/interfaces/BUILD.gn
new file mode 100644
index 00000000000..3791874a5bc
--- /dev/null
+++ b/chromium/device/hid/public/interfaces/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2017 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("//mojo/public/tools/bindings/mojom.gni")
+
+mojom("interfaces") {
+ sources = [
+ "hid.mojom",
+ ]
+}
diff --git a/chromium/device/hid/public/interfaces/OWNERS b/chromium/device/hid/public/interfaces/OWNERS
new file mode 100644
index 00000000000..51ec2e6f1da
--- /dev/null
+++ b/chromium/device/hid/public/interfaces/OWNERS
@@ -0,0 +1,8 @@
+# Changes to Mojo interfaces require a security review to avoid
+# introducing new sandbox escapes.
+per-file *.mojom=set noparent
+per-file *.mojom=file://ipc/SECURITY_OWNERS
+per-file *_struct_traits*.*=set noparent
+per-file *_struct_traits*.*=file://ipc/SECURITY_OWNERS
+per-file *.typemap=set noparent
+per-file *.typemap=file://ipc/SECURITY_OWNERS
diff --git a/chromium/device/hid/public/interfaces/hid.mojom b/chromium/device/hid/public/interfaces/hid.mojom
new file mode 100644
index 00000000000..25cf4cdbfb4
--- /dev/null
+++ b/chromium/device/hid/public/interfaces/hid.mojom
@@ -0,0 +1,72 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+module device.mojom;
+
+enum HidBusType {
+ kHIDBusTypeUSB = 0,
+ kHIDBusTypeBluetooth = 1,
+};
+
+enum HidPage {
+ PageUndefined = 0x00,
+ PageGenericDesktop = 0x01,
+ PageSimulation = 0x02,
+ PageVirtualReality = 0x03,
+ PageSport = 0x04,
+ PageGame = 0x05,
+ PageKeyboard = 0x07,
+ PageLed = 0x08,
+ PageButton = 0x09,
+ PageOrdinal = 0x0A,
+ PageTelephony = 0x0B,
+ PageConsumer = 0x0C,
+ PageDigitizer = 0x0D,
+ PagePidPage = 0x0F,
+ PageUnicode = 0x10,
+ PageAlphanumericDisplay = 0x14,
+ PageMedicalInstruments = 0x40,
+ PageMonitor0 = 0x80,
+ PageMonitor1 = 0x81,
+ PageMonitor2 = 0x82,
+ PageMonitor3 = 0x83,
+ PagePower0 = 0x84,
+ PagePower1 = 0x85,
+ PagePower2 = 0x86,
+ PagePower3 = 0x87,
+ PageBarCodeScanner = 0x8C,
+ PageScale = 0x8D,
+ PageMagneticStripeReader = 0x8E,
+ PageReservedPointOfSale = 0x8F,
+ PageCameraControl = 0x90,
+ PageArcade = 0x91,
+ PageVendor = 0xFF00,
+ PageMediaCenter = 0xFFBC
+};
+
+struct HidUsageAndPage {
+ uint16 usage;
+ HidPage usage_page;
+};
+
+struct HidCollectionInfo {
+ HidUsageAndPage usage;
+ array<int32> report_ids;
+};
+
+struct HidDeviceInfo {
+ string guid;
+ uint16 vendor_id;
+ uint16 product_id;
+ string product_name;
+ string serial_number;
+ HidBusType bus_type;
+ array<uint8> report_descriptor;
+ array<HidCollectionInfo> collections;
+ bool has_report_id;
+ uint64 max_input_report_size;
+ uint64 max_output_report_size;
+ uint64 max_feature_report_size;
+ string device_node;
+};
diff --git a/chromium/device/hid/public/interfaces/hid.typemap b/chromium/device/hid/public/interfaces/hid.typemap
new file mode 100644
index 00000000000..4ef18a054c0
--- /dev/null
+++ b/chromium/device/hid/public/interfaces/hid.typemap
@@ -0,0 +1,22 @@
+# Copyright 2017 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+mojom = "//device/hid/public/interfaces/hid.mojom"
+public_headers = [
+ "//device/hid/hid_collection_info.h",
+ "//device/hid/hid_usage_and_page.h",
+]
+traits_headers = [ "//device/hid/public/interfaces/hid_struct_traits.h" ]
+sources = [
+ "//device/hid/public/interfaces/hid_struct_traits.cc",
+]
+deps = [
+ "//mojo/public/cpp/bindings",
+]
+
+type_mappings = [
+ "device.mojom.HidPage=device::HidUsageAndPage::Page",
+ "device.mojom.HidUsageAndPage=device::HidUsageAndPage",
+ "device.mojom.HidCollectionInfo=device::HidCollectionInfo",
+]
diff --git a/chromium/device/hid/public/interfaces/hid_struct_traits.cc b/chromium/device/hid/public/interfaces/hid_struct_traits.cc
new file mode 100644
index 00000000000..6c56ca8f78c
--- /dev/null
+++ b/chromium/device/hid/public/interfaces/hid_struct_traits.cc
@@ -0,0 +1,226 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "device/hid/public/interfaces/hid_struct_traits.h"
+
+namespace mojo {
+
+// static
+device::mojom::HidPage
+EnumTraits<device::mojom::HidPage, device::HidUsageAndPage::Page>::ToMojom(
+ device::HidUsageAndPage::Page input) {
+ switch (input) {
+ case device::HidUsageAndPage::Page::kPageUndefined:
+ return device::mojom::HidPage::PageUndefined;
+ case device::HidUsageAndPage::Page::kPageGenericDesktop:
+ return device::mojom::HidPage::PageGenericDesktop;
+ case device::HidUsageAndPage::Page::kPageSimulation:
+ return device::mojom::HidPage::PageSimulation;
+ case device::HidUsageAndPage::Page::kPageVirtualReality:
+ return device::mojom::HidPage::PageVirtualReality;
+ case device::HidUsageAndPage::Page::kPageSport:
+ return device::mojom::HidPage::PageSport;
+ case device::HidUsageAndPage::Page::kPageGame:
+ return device::mojom::HidPage::PageGame;
+ case device::HidUsageAndPage::Page::kPageKeyboard:
+ return device::mojom::HidPage::PageKeyboard;
+ case device::HidUsageAndPage::Page::kPageLed:
+ return device::mojom::HidPage::PageLed;
+ case device::HidUsageAndPage::Page::kPageButton:
+ return device::mojom::HidPage::PageButton;
+ case device::HidUsageAndPage::Page::kPageOrdinal:
+ return device::mojom::HidPage::PageOrdinal;
+ case device::HidUsageAndPage::Page::kPageTelephony:
+ return device::mojom::HidPage::PageTelephony;
+ case device::HidUsageAndPage::Page::kPageConsumer:
+ return device::mojom::HidPage::PageConsumer;
+ case device::HidUsageAndPage::Page::kPageDigitizer:
+ return device::mojom::HidPage::PageDigitizer;
+ case device::HidUsageAndPage::Page::kPagePidPage:
+ return device::mojom::HidPage::PagePidPage;
+ case device::HidUsageAndPage::Page::kPageUnicode:
+ return device::mojom::HidPage::PageUnicode;
+ case device::HidUsageAndPage::Page::kPageAlphanumericDisplay:
+ return device::mojom::HidPage::PageAlphanumericDisplay;
+ case device::HidUsageAndPage::Page::kPageMedicalInstruments:
+ return device::mojom::HidPage::PageMedicalInstruments;
+ case device::HidUsageAndPage::Page::kPageMonitor0:
+ return device::mojom::HidPage::PageMonitor0;
+ case device::HidUsageAndPage::Page::kPageMonitor1:
+ return device::mojom::HidPage::PageMonitor1;
+ case device::HidUsageAndPage::Page::kPageMonitor2:
+ return device::mojom::HidPage::PageMonitor2;
+ case device::HidUsageAndPage::Page::kPageMonitor3:
+ return device::mojom::HidPage::PageMonitor3;
+ case device::HidUsageAndPage::Page::kPagePower0:
+ return device::mojom::HidPage::PagePower0;
+ case device::HidUsageAndPage::Page::kPagePower1:
+ return device::mojom::HidPage::PagePower1;
+ case device::HidUsageAndPage::Page::kPagePower2:
+ return device::mojom::HidPage::PagePower2;
+ case device::HidUsageAndPage::Page::kPagePower3:
+ return device::mojom::HidPage::PagePower3;
+ case device::HidUsageAndPage::Page::kPageBarCodeScanner:
+ return device::mojom::HidPage::PageBarCodeScanner;
+ case device::HidUsageAndPage::Page::kPageScale:
+ return device::mojom::HidPage::PageScale;
+ case device::HidUsageAndPage::Page::kPageMagneticStripeReader:
+ return device::mojom::HidPage::PageMagneticStripeReader;
+ case device::HidUsageAndPage::Page::kPageReservedPointOfSale:
+ return device::mojom::HidPage::PageReservedPointOfSale;
+ case device::HidUsageAndPage::Page::kPageCameraControl:
+ return device::mojom::HidPage::PageCameraControl;
+ case device::HidUsageAndPage::Page::kPageArcade:
+ return device::mojom::HidPage::PageArcade;
+ case device::HidUsageAndPage::Page::kPageVendor:
+ return device::mojom::HidPage::PageVendor;
+ case device::HidUsageAndPage::Page::kPageMediaCenter:
+ return device::mojom::HidPage::PageMediaCenter;
+ }
+
+ NOTREACHED();
+ return device::mojom::HidPage::PageUndefined;
+}
+
+// static
+bool EnumTraits<device::mojom::HidPage, device::HidUsageAndPage::Page>::
+ FromMojom(device::mojom::HidPage input,
+ device::HidUsageAndPage::Page* output) {
+ switch (input) {
+ case device::mojom::HidPage::PageUndefined:
+ *output = device::HidUsageAndPage::Page::kPageUndefined;
+ return true;
+ case device::mojom::HidPage::PageGenericDesktop:
+ *output = device::HidUsageAndPage::Page::kPageGenericDesktop;
+ return true;
+ case device::mojom::HidPage::PageSimulation:
+ *output = device::HidUsageAndPage::Page::kPageSimulation;
+ return true;
+ case device::mojom::HidPage::PageVirtualReality:
+ *output = device::HidUsageAndPage::Page::kPageVirtualReality;
+ return true;
+ case device::mojom::HidPage::PageSport:
+ *output = device::HidUsageAndPage::Page::kPageSport;
+ return true;
+ case device::mojom::HidPage::PageGame:
+ *output = device::HidUsageAndPage::Page::kPageGame;
+ return true;
+ case device::mojom::HidPage::PageKeyboard:
+ *output = device::HidUsageAndPage::Page::kPageKeyboard;
+ return true;
+ case device::mojom::HidPage::PageLed:
+ *output = device::HidUsageAndPage::Page::kPageLed;
+ return true;
+ case device::mojom::HidPage::PageButton:
+ *output = device::HidUsageAndPage::Page::kPageButton;
+ return true;
+ case device::mojom::HidPage::PageOrdinal:
+ *output = device::HidUsageAndPage::Page::kPageOrdinal;
+ return true;
+ case device::mojom::HidPage::PageTelephony:
+ *output = device::HidUsageAndPage::Page::kPageTelephony;
+ return true;
+ case device::mojom::HidPage::PageConsumer:
+ *output = device::HidUsageAndPage::Page::kPageConsumer;
+ return true;
+ case device::mojom::HidPage::PageDigitizer:
+ *output = device::HidUsageAndPage::Page::kPageDigitizer;
+ return true;
+ case device::mojom::HidPage::PagePidPage:
+ *output = device::HidUsageAndPage::Page::kPagePidPage;
+ return true;
+ case device::mojom::HidPage::PageUnicode:
+ *output = device::HidUsageAndPage::Page::kPageUnicode;
+ return true;
+ case device::mojom::HidPage::PageAlphanumericDisplay:
+ *output = device::HidUsageAndPage::Page::kPageAlphanumericDisplay;
+ return true;
+ case device::mojom::HidPage::PageMedicalInstruments:
+ *output = device::HidUsageAndPage::Page::kPageMedicalInstruments;
+ return true;
+ case device::mojom::HidPage::PageMonitor0:
+ *output = device::HidUsageAndPage::Page::kPageMonitor0;
+ return true;
+ case device::mojom::HidPage::PageMonitor1:
+ *output = device::HidUsageAndPage::Page::kPageMonitor1;
+ return true;
+ case device::mojom::HidPage::PageMonitor2:
+ *output = device::HidUsageAndPage::Page::kPageMonitor2;
+ return true;
+ case device::mojom::HidPage::PageMonitor3:
+ *output = device::HidUsageAndPage::Page::kPageMonitor3;
+ return true;
+ case device::mojom::HidPage::PagePower0:
+ *output = device::HidUsageAndPage::Page::kPagePower0;
+ return true;
+ case device::mojom::HidPage::PagePower1:
+ *output = device::HidUsageAndPage::Page::kPagePower1;
+ return true;
+ case device::mojom::HidPage::PagePower2:
+ *output = device::HidUsageAndPage::Page::kPagePower2;
+ return true;
+ case device::mojom::HidPage::PagePower3:
+ *output = device::HidUsageAndPage::Page::kPagePower3;
+ return true;
+ case device::mojom::HidPage::PageBarCodeScanner:
+ *output = device::HidUsageAndPage::Page::kPageBarCodeScanner;
+ return true;
+ case device::mojom::HidPage::PageScale:
+ *output = device::HidUsageAndPage::Page::kPageScale;
+ return true;
+ case device::mojom::HidPage::PageMagneticStripeReader:
+ *output = device::HidUsageAndPage::Page::kPageMagneticStripeReader;
+ return true;
+ case device::mojom::HidPage::PageReservedPointOfSale:
+ *output = device::HidUsageAndPage::Page::kPageReservedPointOfSale;
+ return true;
+ case device::mojom::HidPage::PageCameraControl:
+ *output = device::HidUsageAndPage::Page::kPageCameraControl;
+ return true;
+ case device::mojom::HidPage::PageArcade:
+ *output = device::HidUsageAndPage::Page::kPageArcade;
+ return true;
+ case device::mojom::HidPage::PageVendor:
+ *output = device::HidUsageAndPage::Page::kPageVendor;
+ return true;
+ case device::mojom::HidPage::PageMediaCenter:
+ *output = device::HidUsageAndPage::Page::kPageMediaCenter;
+ return true;
+ }
+
+ NOTREACHED();
+ return false;
+}
+
+// static
+bool StructTraits<
+ device::mojom::HidUsageAndPageDataView,
+ device::HidUsageAndPage>::Read(device::mojom::HidUsageAndPageDataView data,
+ device::HidUsageAndPage* out) {
+ out->usage = data.usage();
+
+ if (!data.ReadUsagePage(&out->usage_page))
+ return false;
+
+ return true;
+}
+
+// static
+bool StructTraits<device::mojom::HidCollectionInfoDataView,
+ device::HidCollectionInfo>::
+ Read(device::mojom::HidCollectionInfoDataView data,
+ device::HidCollectionInfo* out) {
+ if (!data.ReadUsage(&out->usage))
+ return false;
+
+ std::vector<int> vec;
+ if (!data.ReadReportIds(&vec))
+ return false;
+
+ out->report_ids.clear();
+ out->report_ids.insert(vec.begin(), vec.end());
+ return true;
+}
+
+} // namespace mojo
diff --git a/chromium/device/hid/public/interfaces/hid_struct_traits.h b/chromium/device/hid/public/interfaces/hid_struct_traits.h
new file mode 100644
index 00000000000..ff46a4f4414
--- /dev/null
+++ b/chromium/device/hid/public/interfaces/hid_struct_traits.h
@@ -0,0 +1,55 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef DEVICE_HID_PUBLIC_INTERFACES_HID_STRUCT_TRAITS_H_
+#define DEVICE_HID_PUBLIC_INTERFACES_HID_STRUCT_TRAITS_H_
+
+#include <stddef.h>
+
+#include "device/hid/hid_collection_info.h"
+#include "device/hid/hid_usage_and_page.h"
+#include "device/hid/public/interfaces/hid.mojom.h"
+#include "mojo/public/cpp/bindings/array_traits_stl.h"
+#include "mojo/public/cpp/bindings/struct_traits.h"
+
+namespace mojo {
+
+template <>
+struct EnumTraits<device::mojom::HidPage, device::HidUsageAndPage::Page> {
+ static device::mojom::HidPage ToMojom(device::HidUsageAndPage::Page input);
+ static bool FromMojom(device::mojom::HidPage input,
+ device::HidUsageAndPage::Page* output);
+};
+
+template <>
+struct StructTraits<device::mojom::HidUsageAndPageDataView,
+ device::HidUsageAndPage> {
+ static uint16_t usage(const device::HidUsageAndPage& r) { return r.usage; }
+ static const device::HidUsageAndPage::Page& usage_page(
+ const device::HidUsageAndPage& r) {
+ return r.usage_page;
+ }
+ static bool Read(device::mojom::HidUsageAndPageDataView data,
+ device::HidUsageAndPage* out);
+};
+
+template <>
+struct StructTraits<device::mojom::HidCollectionInfoDataView,
+ device::HidCollectionInfo> {
+ static const device::HidUsageAndPage& usage(
+ const device::HidCollectionInfo& r) {
+ return r.usage;
+ }
+
+ static const std::set<int>& report_ids(const device::HidCollectionInfo& r) {
+ return r.report_ids;
+ }
+
+ static bool Read(device::mojom::HidCollectionInfoDataView data,
+ device::HidCollectionInfo* out);
+};
+
+} // namespace mojo
+
+#endif // DEVICE_HID_PUBLIC_INTERFACES_HID_STRUCT_TRAITS_H_
diff --git a/chromium/device/hid/public/interfaces/typemaps.gni b/chromium/device/hid/public/interfaces/typemaps.gni
new file mode 100644
index 00000000000..0a40a67ca3b
--- /dev/null
+++ b/chromium/device/hid/public/interfaces/typemaps.gni
@@ -0,0 +1,5 @@
+# Copyright 2017 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+typemaps = [ "//device/hid/public/interfaces/hid.typemap" ]
diff --git a/chromium/device/sensors/BUILD.gn b/chromium/device/sensors/BUILD.gn
index 4a217b68fc7..8583e6c87dc 100644
--- a/chromium/device/sensors/BUILD.gn
+++ b/chromium/device/sensors/BUILD.gn
@@ -10,8 +10,6 @@ if (is_android) {
component("sensors") {
sources = [
- "android/device_sensor_jni_registrar.cc",
- "android/device_sensor_jni_registrar.h",
"data_fetcher_shared_memory.h",
"data_fetcher_shared_memory_android.cc",
"data_fetcher_shared_memory_base.cc",
@@ -70,6 +68,10 @@ component("sensors") {
"//ui/gfx",
]
}
+ if (is_fuchsia) {
+ sources += [ "data_fetcher_shared_memory_fuchsia.cc" ]
+ sources -= [ "data_fetcher_shared_memory_default.cc" ]
+ }
}
if (is_android) {
@@ -95,7 +97,9 @@ if (is_android) {
java_files = [ "android/javatests/src/org/chromium/device/sensors/DeviceSensorsTest.java" ]
deps = [
":java",
+ "//base:base_java_test_support",
"//third_party/android_support_test_runner:runner_java",
+ "//third_party/junit",
]
}
diff --git a/chromium/device/sensors/data_fetcher_shared_memory_fuchsia.cc b/chromium/device/sensors/data_fetcher_shared_memory_fuchsia.cc
new file mode 100644
index 00000000000..ce1aee90d53
--- /dev/null
+++ b/chromium/device/sensors/data_fetcher_shared_memory_fuchsia.cc
@@ -0,0 +1,29 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "device/sensors/data_fetcher_shared_memory.h"
+
+#include "base/logging.h"
+
+namespace device {
+
+DataFetcherSharedMemory::DataFetcherSharedMemory() {}
+
+DataFetcherSharedMemory::~DataFetcherSharedMemory() {}
+
+bool DataFetcherSharedMemory::Start(ConsumerType consumer_type, void* buffer) {
+ // TODO(fuchsia): Implement support for sensor consumer buffers.
+ // (crbug.com/750934)
+ NOTIMPLEMENTED();
+ return false;
+}
+
+bool DataFetcherSharedMemory::Stop(ConsumerType consumer_type) {
+ // TODO(fuchsia): Implement support for sensor consumer buffers.
+ // (crbug.com/750934)
+ NOTIMPLEMENTED();
+ return false;
+}
+
+} // namespace device
diff --git a/chromium/device/sensors/device_sensor_host.h b/chromium/device/sensors/device_sensor_host.h
index d6d54933e4a..fd4fe3ac366 100644
--- a/chromium/device/sensors/device_sensor_host.h
+++ b/chromium/device/sensors/device_sensor_host.h
@@ -17,7 +17,7 @@ namespace device {
// A base class for device sensor related mojo interface implementations.
template <typename MojoInterface, ConsumerType consumer_type>
-class DeviceSensorHost : NON_EXPORTED_BASE(public MojoInterface) {
+class DeviceSensorHost : public MojoInterface {
public:
static void Create(mojo::InterfaceRequest<MojoInterface> request);
diff --git a/chromium/device/sensors/sensor_manager_android.cc b/chromium/device/sensors/sensor_manager_android.cc
index 47aeb1d0424..6a5b4e1f888 100644
--- a/chromium/device/sensors/sensor_manager_android.cc
+++ b/chromium/device/sensors/sensor_manager_android.cc
@@ -66,10 +66,6 @@ SensorManagerAndroid::SensorManagerAndroid()
SensorManagerAndroid::~SensorManagerAndroid() {}
-bool SensorManagerAndroid::Register(JNIEnv* env) {
- return RegisterNativesImpl(env);
-}
-
SensorManagerAndroid* SensorManagerAndroid::GetInstance() {
DCHECK(base::MessageLoopForUI::IsCurrent());
return base::Singleton<
diff --git a/chromium/device/sensors/sensor_manager_android.h b/chromium/device/sensors/sensor_manager_android.h
index bf285ebfbee..25d30a3c230 100644
--- a/chromium/device/sensors/sensor_manager_android.h
+++ b/chromium/device/sensors/sensor_manager_android.h
@@ -30,8 +30,6 @@ namespace device {
// memory buffer, which is read by the renderer processes.
class DEVICE_SENSOR_EXPORT SensorManagerAndroid {
public:
- // Must be called at startup, before GetInstance().
- static bool Register(JNIEnv* env);
// Should be called only on the UI thread.
static SensorManagerAndroid* GetInstance();
diff --git a/chromium/device/sensors/sensor_manager_android_unittest.cc b/chromium/device/sensors/sensor_manager_android_unittest.cc
index 620c6f9faa2..9807d4c46a2 100644
--- a/chromium/device/sensors/sensor_manager_android_unittest.cc
+++ b/chromium/device/sensors/sensor_manager_android_unittest.cc
@@ -70,7 +70,6 @@ class AndroidSensorManagerTest : public testing::Test {
};
TEST_F(AndroidSensorManagerTest, ThreeDeviceMotionSensorsActive) {
- FakeSensorManagerAndroid::Register(base::android::AttachCurrentThread());
FakeSensorManagerAndroid sensorManager;
sensorManager.SetNumberActiveDeviceMotionSensors(3);
@@ -111,7 +110,6 @@ TEST_F(AndroidSensorManagerTest, ThreeDeviceMotionSensorsActive) {
}
TEST_F(AndroidSensorManagerTest, TwoDeviceMotionSensorsActive) {
- FakeSensorManagerAndroid::Register(base::android::AttachCurrentThread());
FakeSensorManagerAndroid sensorManager;
sensorManager.SetNumberActiveDeviceMotionSensors(2);
@@ -131,7 +129,6 @@ TEST_F(AndroidSensorManagerTest, TwoDeviceMotionSensorsActive) {
}
TEST_F(AndroidSensorManagerTest, ZeroDeviceMotionSensorsActive) {
- FakeSensorManagerAndroid::Register(base::android::AttachCurrentThread());
FakeSensorManagerAndroid sensorManager;
sensorManager.SetNumberActiveDeviceMotionSensors(0);
@@ -145,7 +142,6 @@ TEST_F(AndroidSensorManagerTest, ZeroDeviceMotionSensorsActive) {
}
TEST_F(AndroidSensorManagerTest, DeviceOrientationSensorsActive) {
- FakeSensorManagerAndroid::Register(base::android::AttachCurrentThread());
FakeSensorManagerAndroid sensorManager;
sensorManager.StartFetchingDeviceOrientationData(orientation_buffer_.get());
@@ -159,7 +155,6 @@ TEST_F(AndroidSensorManagerTest, DeviceOrientationSensorsActive) {
}
TEST_F(AndroidSensorManagerTest, DeviceOrientationAbsoluteSensorsActive) {
- FakeSensorManagerAndroid::Register(base::android::AttachCurrentThread());
FakeSensorManagerAndroid sensorManager;
sensorManager.StartFetchingDeviceOrientationAbsoluteData(
diff --git a/chromium/device/serial/BUILD.gn b/chromium/device/serial/BUILD.gn
index 2881619c677..b467ac6df78 100644
--- a/chromium/device/serial/BUILD.gn
+++ b/chromium/device/serial/BUILD.gn
@@ -6,87 +6,76 @@ import("//build/config/features.gni")
import("//mojo/public/tools/bindings/mojom.gni")
# Library works only on desktop platforms.
-assert(is_win || is_linux || is_mac)
-
-config("platform_support") {
- visibility = [ ":serial" ]
- if (is_win) {
- libs = [ "setupapi.lib" ]
- ldflags = [ "/DELAYLOAD:setupapi.dll" ]
+if (is_win || is_linux || is_mac) {
+ config("platform_support") {
+ visibility = [ ":serial" ]
+ if (is_win) {
+ libs = [ "setupapi.lib" ]
+ ldflags = [ "/DELAYLOAD:setupapi.dll" ]
+ }
}
-}
-static_library("serial") {
- output_name = "device_serial"
+ static_library("serial") {
+ output_name = "device_serial"
- sources = [
- "buffer.cc",
- "buffer.h",
- "serial_device_enumerator.cc",
- "serial_device_enumerator.h",
- "serial_device_enumerator_linux.cc",
- "serial_device_enumerator_linux.h",
- "serial_device_enumerator_mac.cc",
- "serial_device_enumerator_mac.h",
- "serial_device_enumerator_win.cc",
- "serial_device_enumerator_win.h",
- "serial_io_handler.cc",
- "serial_io_handler.h",
- "serial_io_handler_posix.cc",
- "serial_io_handler_posix.h",
- "serial_io_handler_win.cc",
- "serial_io_handler_win.h",
- ]
+ sources = [
+ "buffer.cc",
+ "buffer.h",
+ "serial_device_enumerator.cc",
+ "serial_device_enumerator.h",
+ "serial_device_enumerator_linux.cc",
+ "serial_device_enumerator_linux.h",
+ "serial_device_enumerator_mac.cc",
+ "serial_device_enumerator_mac.h",
+ "serial_device_enumerator_win.cc",
+ "serial_device_enumerator_win.h",
+ "serial_io_handler.cc",
+ "serial_io_handler.h",
+ "serial_io_handler_posix.cc",
+ "serial_io_handler_posix.h",
+ "serial_io_handler_win.cc",
+ "serial_io_handler_win.h",
+ ]
- public_configs = [ ":platform_support" ]
+ public_configs = [ ":platform_support" ]
- public_deps = [
- ":serial_mojo",
- "//base",
- "//device/base",
- ]
+ public_deps = [
+ "//base",
+ "//device/base",
+ "//services/device/public/interfaces",
+ ]
- deps = [
- "//mojo/public/cpp/system",
- "//net",
- "//third_party/re2",
- ]
+ deps = [
+ "//mojo/public/cpp/system",
+ "//net",
+ "//third_party/re2",
+ ]
- if (use_udev) {
- deps += [ "//device/udev_linux" ]
+ if (use_udev) {
+ deps += [ "//device/udev_linux" ]
+ }
+ if (is_chromeos) {
+ deps += [
+ "//chromeos",
+ "//dbus",
+ ]
+ }
+ if (is_mac) {
+ libs = [
+ "Foundation.framework",
+ "IOKit.framework",
+ ]
+ }
}
- if (is_chromeos) {
- deps += [
- "//chromeos",
- "//dbus",
+
+ static_library("test_support") {
+ sources = [
+ "test_serial_io_handler.cc",
+ "test_serial_io_handler.h",
]
- }
- if (is_mac) {
- libs = [
- "Foundation.framework",
- "IOKit.framework",
+
+ public_deps = [
+ ":serial",
]
}
}
-
-static_library("test_support") {
- sources = [
- "test_serial_io_handler.cc",
- "test_serial_io_handler.h",
- ]
-
- public_deps = [
- ":serial",
- ]
-}
-
-mojom("serial_mojo") {
- visibility = [
- ":serial",
- "//extensions:extensions_renderer_resources_grit",
- ]
-
- sources = [
- "serial.mojom",
- ]
-}
diff --git a/chromium/device/serial/DEPS b/chromium/device/serial/DEPS
index 4bebd41c4aa..8d4e6ba6d51 100644
--- a/chromium/device/serial/DEPS
+++ b/chromium/device/serial/DEPS
@@ -1,5 +1,6 @@
include_rules = [
"+dbus",
"+net/base",
+ "+services/device/public/interfaces",
"+third_party/re2",
]
diff --git a/chromium/device/serial/buffer.cc b/chromium/device/serial/buffer.cc
index c6eeea26076..6c2b1bee74f 100644
--- a/chromium/device/serial/buffer.cc
+++ b/chromium/device/serial/buffer.cc
@@ -14,14 +14,13 @@ ReadOnlyBuffer::~ReadOnlyBuffer() {
WritableBuffer::~WritableBuffer() {
}
-SendBuffer::SendBuffer(
- const std::vector<char>& data,
- const base::Callback<void(int, device::serial::SendError)>& callback)
- : data_(data), callback_(callback) {}
+SendBuffer::SendBuffer(const std::vector<uint8_t>& data,
+ SendCompleteCallback callback)
+ : data_(data), callback_(std::move(callback)) {}
SendBuffer::~SendBuffer() {}
-const char* SendBuffer::GetData() {
+const uint8_t* SendBuffer::GetData() {
return data_.data();
}
@@ -30,18 +29,18 @@ uint32_t SendBuffer::GetSize() {
}
void SendBuffer::Done(uint32_t bytes_read) {
- callback_.Run(bytes_read, device::serial::SendError::NONE);
+ std::move(callback_).Run(bytes_read, device::mojom::SerialSendError::NONE);
}
void SendBuffer::DoneWithError(uint32_t bytes_read, int32_t error) {
- callback_.Run(bytes_read, static_cast<device::serial::SendError>(error));
+ std::move(callback_).Run(bytes_read,
+ static_cast<device::mojom::SerialSendError>(error));
}
-ReceiveBuffer::ReceiveBuffer(
- scoped_refptr<net::IOBuffer> buffer,
- uint32_t size,
- const base::Callback<void(int, device::serial::ReceiveError)>& callback)
- : buffer_(buffer), size_(size), callback_(callback) {}
+ReceiveBuffer::ReceiveBuffer(scoped_refptr<net::IOBuffer> buffer,
+ uint32_t size,
+ ReceiveCompleteCallback callback)
+ : buffer_(buffer), size_(size), callback_(std::move(callback)) {}
ReceiveBuffer::~ReceiveBuffer() {}
@@ -54,12 +53,13 @@ uint32_t ReceiveBuffer::GetSize() {
}
void ReceiveBuffer::Done(uint32_t bytes_written) {
- callback_.Run(bytes_written, device::serial::ReceiveError::NONE);
+ std::move(callback_).Run(bytes_written,
+ device::mojom::SerialReceiveError::NONE);
}
void ReceiveBuffer::DoneWithError(uint32_t bytes_written, int32_t error) {
- callback_.Run(bytes_written,
- static_cast<device::serial::ReceiveError>(error));
+ std::move(callback_).Run(
+ bytes_written, static_cast<device::mojom::SerialReceiveError>(error));
}
} // namespace device
diff --git a/chromium/device/serial/buffer.h b/chromium/device/serial/buffer.h
index 53ef909a87c..710d64459f9 100644
--- a/chromium/device/serial/buffer.h
+++ b/chromium/device/serial/buffer.h
@@ -8,8 +8,8 @@
#include <stdint.h>
#include "base/callback.h"
-#include "device/serial/serial.mojom.h"
#include "net/base/io_buffer.h"
+#include "services/device/public/interfaces/serial.mojom.h"
namespace device {
@@ -20,7 +20,7 @@ namespace device {
class ReadOnlyBuffer {
public:
virtual ~ReadOnlyBuffer();
- virtual const char* GetData() = 0;
+ virtual const uint8_t* GetData() = 0;
virtual uint32_t GetSize() = 0;
virtual void Done(uint32_t bytes_read) = 0;
virtual void DoneWithError(uint32_t bytes_read, int32_t error) = 0;
@@ -43,29 +43,30 @@ class WritableBuffer {
// initialized via a character vector.
class SendBuffer : public device::ReadOnlyBuffer {
public:
- SendBuffer(
- const std::vector<char>& data,
- const base::Callback<void(int, device::serial::SendError)>& callback);
+ using SendCompleteCallback =
+ base::OnceCallback<void(int, device::mojom::SerialSendError)>;
+ SendBuffer(const std::vector<uint8_t>& data, SendCompleteCallback callback);
~SendBuffer() override;
- const char* GetData() override;
+ const uint8_t* GetData() override;
uint32_t GetSize() override;
void Done(uint32_t bytes_read) override;
void DoneWithError(uint32_t bytes_read, int32_t error) override;
private:
- const std::vector<char> data_;
- const base::Callback<void(int, device::serial::SendError)> callback_;
+ const std::vector<uint8_t> data_;
+ SendCompleteCallback callback_;
};
// A useful basic implementation of a WritableBuffer in which the data is
// stored in a net::IOBuffer.
class ReceiveBuffer : public device::WritableBuffer {
public:
- ReceiveBuffer(
- scoped_refptr<net::IOBuffer> buffer,
- uint32_t size,
- const base::Callback<void(int, device::serial::ReceiveError)>& callback);
+ using ReceiveCompleteCallback =
+ base::OnceCallback<void(int, device::mojom::SerialReceiveError)>;
+ ReceiveBuffer(scoped_refptr<net::IOBuffer> buffer,
+ uint32_t size,
+ ReceiveCompleteCallback callback);
~ReceiveBuffer() override;
char* GetData() override;
@@ -76,7 +77,7 @@ class ReceiveBuffer : public device::WritableBuffer {
private:
scoped_refptr<net::IOBuffer> buffer_;
const uint32_t size_;
- const base::Callback<void(int, device::serial::ReceiveError)> callback_;
+ ReceiveCompleteCallback callback_;
};
} // namespace device
diff --git a/chromium/device/serial/serial.mojom b/chromium/device/serial/serial.mojom
deleted file mode 100644
index 72ba3a260a3..00000000000
--- a/chromium/device/serial/serial.mojom
+++ /dev/null
@@ -1,85 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-module device.serial;
-
-struct DeviceInfo {
- string path;
- uint16 vendor_id;
- bool has_vendor_id = false;
- uint16 product_id;
- bool has_product_id = false;
- string? display_name;
-};
-
-enum SendError {
- NONE,
- DISCONNECTED,
- PENDING,
- TIMEOUT,
- SYSTEM_ERROR,
-};
-
-enum ReceiveError {
- NONE,
- DISCONNECTED,
- TIMEOUT,
- DEVICE_LOST,
- BREAK,
- FRAME_ERROR,
- OVERRUN,
- BUFFER_OVERFLOW,
- PARITY_ERROR,
- SYSTEM_ERROR,
-};
-
-enum DataBits {
- NONE,
- SEVEN,
- EIGHT,
-};
-
-enum ParityBit {
- NONE,
- NO_PARITY,
- ODD,
- EVEN,
-};
-
-enum StopBits {
- NONE,
- ONE,
- TWO,
-};
-
-struct ConnectionOptions {
- uint32 bitrate = 0;
- DataBits data_bits = NONE;
- ParityBit parity_bit = NONE;
- StopBits stop_bits = NONE;
- bool cts_flow_control;
- bool has_cts_flow_control = false;
-};
-
-struct ConnectionInfo {
- uint32 bitrate = 0;
- DataBits data_bits = NONE;
- ParityBit parity_bit = NONE;
- StopBits stop_bits = NONE;
- bool cts_flow_control;
-};
-
-struct HostControlSignals {
- bool dtr;
- bool has_dtr = false;
- bool rts;
- bool has_rts = false;
-};
-
-struct DeviceControlSignals {
- bool dcd;
- bool cts;
- bool ri;
- bool dsr;
-};
diff --git a/chromium/device/serial/serial_device_enumerator.h b/chromium/device/serial/serial_device_enumerator.h
index 82fece2b6e3..24dfebf0887 100644
--- a/chromium/device/serial/serial_device_enumerator.h
+++ b/chromium/device/serial/serial_device_enumerator.h
@@ -7,7 +7,7 @@
#include <memory>
-#include "device/serial/serial.mojom.h"
+#include "services/device/public/interfaces/serial.mojom.h"
namespace device {
@@ -19,7 +19,7 @@ class SerialDeviceEnumerator {
SerialDeviceEnumerator();
virtual ~SerialDeviceEnumerator();
- virtual std::vector<serial::DeviceInfoPtr> GetDevices() = 0;
+ virtual std::vector<mojom::SerialDeviceInfoPtr> GetDevices() = 0;
};
} // namespace device
diff --git a/chromium/device/serial/serial_device_enumerator_linux.cc b/chromium/device/serial/serial_device_enumerator_linux.cc
index f716e56f436..100f7dd4886 100644
--- a/chromium/device/serial/serial_device_enumerator_linux.cc
+++ b/chromium/device/serial/serial_device_enumerator_linux.cc
@@ -38,8 +38,9 @@ SerialDeviceEnumeratorLinux::SerialDeviceEnumeratorLinux() {
SerialDeviceEnumeratorLinux::~SerialDeviceEnumeratorLinux() {}
-std::vector<serial::DeviceInfoPtr> SerialDeviceEnumeratorLinux::GetDevices() {
- std::vector<serial::DeviceInfoPtr> devices;
+std::vector<mojom::SerialDeviceInfoPtr>
+SerialDeviceEnumeratorLinux::GetDevices() {
+ std::vector<mojom::SerialDeviceInfoPtr> devices;
ScopedUdevEnumeratePtr enumerate(udev_enumerate_new(udev_.get()));
if (!enumerate) {
LOG(ERROR) << "Serial device enumeration failed.";
@@ -67,7 +68,7 @@ std::vector<serial::DeviceInfoPtr> SerialDeviceEnumeratorLinux::GetDevices() {
udev_device_get_property_value(device.get(), kHostPathKey);
const char* bus = udev_device_get_property_value(device.get(), kHostBusKey);
if (path != NULL && bus != NULL) {
- serial::DeviceInfoPtr info(serial::DeviceInfo::New());
+ auto info = mojom::SerialDeviceInfo::New();
info->path = path;
const char* vendor_id =
diff --git a/chromium/device/serial/serial_device_enumerator_linux.h b/chromium/device/serial/serial_device_enumerator_linux.h
index 1acc8e46162..92f47ae265e 100644
--- a/chromium/device/serial/serial_device_enumerator_linux.h
+++ b/chromium/device/serial/serial_device_enumerator_linux.h
@@ -18,7 +18,7 @@ class SerialDeviceEnumeratorLinux : public SerialDeviceEnumerator {
~SerialDeviceEnumeratorLinux() override;
// Implementation for SerialDeviceEnumerator.
- std::vector<serial::DeviceInfoPtr> GetDevices() override;
+ std::vector<mojom::SerialDeviceInfoPtr> GetDevices() override;
private:
ScopedUdevPtr udev_;
diff --git a/chromium/device/serial/serial_device_enumerator_mac.cc b/chromium/device/serial/serial_device_enumerator_mac.cc
index 954ab7daf36..333da5b04e6 100644
--- a/chromium/device/serial/serial_device_enumerator_mac.cc
+++ b/chromium/device/serial/serial_device_enumerator_mac.cc
@@ -101,8 +101,8 @@ int Clamp(int value, int min, int max) {
// Returns an array of devices as retrieved through the new method of
// enumerating serial devices (IOKit). This new method gives more information
// about the devices than the old method.
-std::vector<serial::DeviceInfoPtr> GetDevicesNew() {
- std::vector<serial::DeviceInfoPtr> devices;
+std::vector<mojom::SerialDeviceInfoPtr> GetDevicesNew() {
+ std::vector<mojom::SerialDeviceInfoPtr> devices;
// Make a service query to find all serial devices.
CFMutableDictionaryRef matchingDict =
@@ -119,7 +119,7 @@ std::vector<serial::DeviceInfoPtr> GetDevicesNew() {
base::mac::ScopedIOObject<io_iterator_t> scoped_it(it);
base::mac::ScopedIOObject<io_service_t> scoped_device;
while (scoped_device.reset(IOIteratorNext(scoped_it.get())), scoped_device) {
- serial::DeviceInfoPtr callout_info(serial::DeviceInfo::New());
+ auto callout_info = mojom::SerialDeviceInfo::New();
uint16_t vendorId;
if (GetUInt16Property(scoped_device.get(), CFSTR(kUSBVendorID),
@@ -148,7 +148,7 @@ std::vector<serial::DeviceInfoPtr> GetDevicesNew() {
std::string dialinDevice;
if (GetStringProperty(scoped_device.get(), CFSTR(kIODialinDeviceKey),
&dialinDevice)) {
- serial::DeviceInfoPtr dialin_info = callout_info.Clone();
+ mojom::SerialDeviceInfoPtr dialin_info = callout_info.Clone();
dialin_info->path = dialinDevice;
devices.push_back(std::move(dialin_info));
}
@@ -167,7 +167,7 @@ std::vector<serial::DeviceInfoPtr> GetDevicesNew() {
// Returns an array of devices as retrieved through the old method of
// enumerating serial devices (pattern matching in /dev/). This old method gives
// less information about the devices than the new method.
-std::vector<serial::DeviceInfoPtr> GetDevicesOld() {
+std::vector<mojom::SerialDeviceInfoPtr> GetDevicesOld() {
const base::FilePath kDevRoot("/dev");
const int kFilesAndSymLinks =
base::FileEnumerator::FILES | base::FileEnumerator::SHOW_SYM_LINKS;
@@ -181,7 +181,7 @@ std::vector<serial::DeviceInfoPtr> GetDevicesOld() {
valid_patterns.insert("/dev/tty.*");
valid_patterns.insert("/dev/cu.*");
- std::vector<serial::DeviceInfoPtr> devices;
+ std::vector<mojom::SerialDeviceInfoPtr> devices;
base::FileEnumerator enumerator(kDevRoot, false, kFilesAndSymLinks);
do {
const base::FilePath next_device_path(enumerator.Next());
@@ -192,7 +192,7 @@ std::vector<serial::DeviceInfoPtr> GetDevicesOld() {
std::set<std::string>::const_iterator i = valid_patterns.begin();
for (; i != valid_patterns.end(); ++i) {
if (base::MatchPattern(next_device, *i)) {
- serial::DeviceInfoPtr info(serial::DeviceInfo::New());
+ auto info = mojom::SerialDeviceInfo::New();
info->path = next_device;
devices.push_back(std::move(info));
break;
@@ -214,9 +214,10 @@ SerialDeviceEnumeratorMac::SerialDeviceEnumeratorMac() {}
SerialDeviceEnumeratorMac::~SerialDeviceEnumeratorMac() {}
-std::vector<serial::DeviceInfoPtr> SerialDeviceEnumeratorMac::GetDevices() {
- std::vector<serial::DeviceInfoPtr> devices = GetDevicesNew();
- std::vector<serial::DeviceInfoPtr> old_devices = GetDevicesOld();
+std::vector<mojom::SerialDeviceInfoPtr>
+SerialDeviceEnumeratorMac::GetDevices() {
+ std::vector<mojom::SerialDeviceInfoPtr> devices = GetDevicesNew();
+ std::vector<mojom::SerialDeviceInfoPtr> old_devices = GetDevicesOld();
UMA_HISTOGRAM_SPARSE_SLOWLY(
"Hardware.Serial.NewMinusOldDeviceListSize",
diff --git a/chromium/device/serial/serial_device_enumerator_mac.h b/chromium/device/serial/serial_device_enumerator_mac.h
index 433d068254d..04c504f7239 100644
--- a/chromium/device/serial/serial_device_enumerator_mac.h
+++ b/chromium/device/serial/serial_device_enumerator_mac.h
@@ -17,7 +17,7 @@ class SerialDeviceEnumeratorMac : public SerialDeviceEnumerator {
~SerialDeviceEnumeratorMac() override;
// Implementation for SerialDeviceEnumerator.
- std::vector<serial::DeviceInfoPtr> GetDevices() override;
+ std::vector<mojom::SerialDeviceInfoPtr> GetDevices() override;
private:
DISALLOW_COPY_AND_ASSIGN(SerialDeviceEnumeratorMac);
diff --git a/chromium/device/serial/serial_device_enumerator_win.cc b/chromium/device/serial/serial_device_enumerator_win.cc
index 6864ba2d10c..ef617fa6b46 100644
--- a/chromium/device/serial/serial_device_enumerator_win.cc
+++ b/chromium/device/serial/serial_device_enumerator_win.cc
@@ -88,8 +88,8 @@ int Clamp(int value, int min, int max) {
// Returns an array of devices as retrieved through the new method of
// enumerating serial devices (SetupDi). This new method gives more information
// about the devices than the old method.
-std::vector<serial::DeviceInfoPtr> GetDevicesNew() {
- std::vector<serial::DeviceInfoPtr> devices;
+std::vector<mojom::SerialDeviceInfoPtr> GetDevicesNew() {
+ std::vector<mojom::SerialDeviceInfoPtr> devices;
// Make a device interface query to find all serial devices.
HDEVINFO dev_info =
@@ -109,7 +109,7 @@ std::vector<serial::DeviceInfoPtr> GetDevicesNew() {
// serial device. If the COM can't be found, ignore the device.
continue;
- serial::DeviceInfoPtr info(serial::DeviceInfo::New());
+ auto info = mojom::SerialDeviceInfo::New();
info->path = com_port;
std::string display_name;
@@ -140,12 +140,12 @@ std::vector<serial::DeviceInfoPtr> GetDevicesNew() {
// Returns an array of devices as retrieved through the old method of
// enumerating serial devices (searching the registry). This old method gives
// less information about the devices than the new method.
-std::vector<serial::DeviceInfoPtr> GetDevicesOld() {
+std::vector<mojom::SerialDeviceInfoPtr> GetDevicesOld() {
base::win::RegistryValueIterator iter_key(
HKEY_LOCAL_MACHINE, L"HARDWARE\\DEVICEMAP\\SERIALCOMM\\");
- std::vector<serial::DeviceInfoPtr> devices;
+ std::vector<mojom::SerialDeviceInfoPtr> devices;
for (; iter_key.Valid(); ++iter_key) {
- serial::DeviceInfoPtr info(serial::DeviceInfo::New());
+ auto info = mojom::SerialDeviceInfo::New();
info->path = base::UTF16ToASCII(iter_key.Value());
devices.push_back(std::move(info));
}
@@ -164,9 +164,10 @@ SerialDeviceEnumeratorWin::SerialDeviceEnumeratorWin() {}
SerialDeviceEnumeratorWin::~SerialDeviceEnumeratorWin() {}
-std::vector<serial::DeviceInfoPtr> SerialDeviceEnumeratorWin::GetDevices() {
- std::vector<serial::DeviceInfoPtr> devices = GetDevicesNew();
- std::vector<serial::DeviceInfoPtr> old_devices = GetDevicesOld();
+std::vector<mojom::SerialDeviceInfoPtr>
+SerialDeviceEnumeratorWin::GetDevices() {
+ std::vector<mojom::SerialDeviceInfoPtr> devices = GetDevicesNew();
+ std::vector<mojom::SerialDeviceInfoPtr> old_devices = GetDevicesOld();
UMA_HISTOGRAM_SPARSE_SLOWLY(
"Hardware.Serial.NewMinusOldDeviceListSize",
diff --git a/chromium/device/serial/serial_device_enumerator_win.h b/chromium/device/serial/serial_device_enumerator_win.h
index b6652505f1e..1eea2df00f6 100644
--- a/chromium/device/serial/serial_device_enumerator_win.h
+++ b/chromium/device/serial/serial_device_enumerator_win.h
@@ -17,7 +17,7 @@ class SerialDeviceEnumeratorWin : public SerialDeviceEnumerator {
~SerialDeviceEnumeratorWin() override;
// Implementation for SerialDeviceEnumerator.
- std::vector<serial::DeviceInfoPtr> GetDevices() override;
+ std::vector<mojom::SerialDeviceInfoPtr> GetDevices() override;
private:
DISALLOW_COPY_AND_ASSIGN(SerialDeviceEnumeratorWin);
diff --git a/chromium/device/serial/serial_io_handler.cc b/chromium/device/serial/serial_io_handler.cc
index 70f90a6135a..de1d8c178d7 100644
--- a/chromium/device/serial/serial_io_handler.cc
+++ b/chromium/device/serial/serial_io_handler.cc
@@ -26,9 +26,9 @@ SerialIoHandler::SerialIoHandler(
scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner)
: ui_thread_task_runner_(ui_thread_task_runner) {
options_.bitrate = 9600;
- options_.data_bits = serial::DataBits::EIGHT;
- options_.parity_bit = serial::ParityBit::NO_PARITY;
- options_.stop_bits = serial::StopBits::ONE;
+ options_.data_bits = mojom::SerialDataBits::EIGHT;
+ options_.parity_bit = mojom::SerialParityBit::NO_PARITY;
+ options_.stop_bits = mojom::SerialStopBits::ONE;
options_.cts_flow_control = false;
options_.has_cts_flow_control = true;
}
@@ -39,11 +39,11 @@ SerialIoHandler::~SerialIoHandler() {
}
void SerialIoHandler::Open(const std::string& port,
- const serial::ConnectionOptions& options,
- const OpenCompleteCallback& callback) {
+ const mojom::SerialConnectionOptions& options,
+ OpenCompleteCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- DCHECK(open_complete_.is_null());
- open_complete_ = callback;
+ DCHECK(!open_complete_);
+ open_complete_ = std::move(callback);
DCHECK(ui_thread_task_runner_.get());
MergeConnectionOptions(options);
port_ = port;
@@ -57,7 +57,7 @@ void SerialIoHandler::Open(const std::string& port,
base::ThreadTaskRunnerHandle::Get();
ui_thread_task_runner_->PostTask(
FROM_HERE,
- base::Bind(
+ base::BindOnce(
&chromeos::PermissionBrokerClient::OpenPath, base::Unretained(client),
port, base::Bind(&SerialIoHandler::OnPathOpened, this, task_runner),
base::Bind(&SerialIoHandler::OnPathOpenError, this, task_runner)));
@@ -65,8 +65,8 @@ void SerialIoHandler::Open(const std::string& port,
base::PostTaskWithTraits(
FROM_HERE,
{base::MayBlock(), base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
- base::Bind(&SerialIoHandler::StartOpen, this, port,
- base::ThreadTaskRunnerHandle::Get()));
+ base::BindOnce(&SerialIoHandler::StartOpen, this, port,
+ base::ThreadTaskRunnerHandle::Get()));
#endif // defined(OS_CHROMEOS)
}
@@ -78,7 +78,7 @@ void SerialIoHandler::OnPathOpened(
base::File file(fd.release());
io_thread_task_runner->PostTask(
FROM_HERE,
- base::Bind(&SerialIoHandler::FinishOpen, this, base::Passed(&file)));
+ base::BindOnce(&SerialIoHandler::FinishOpen, this, std::move(file)));
}
void SerialIoHandler::OnPathOpenError(
@@ -86,35 +86,33 @@ void SerialIoHandler::OnPathOpenError(
const std::string& error_name,
const std::string& error_message) {
io_thread_task_runner->PostTask(
- FROM_HERE, base::Bind(&SerialIoHandler::ReportPathOpenError, this,
- error_name, error_message));
+ FROM_HERE, base::BindOnce(&SerialIoHandler::ReportPathOpenError, this,
+ error_name, error_message));
}
void SerialIoHandler::ReportPathOpenError(const std::string& error_name,
const std::string& error_message) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- DCHECK(!open_complete_.is_null());
+ DCHECK(open_complete_);
LOG(ERROR) << "Permission broker failed to open '" << port_
<< "': " << error_name << ": " << error_message;
- OpenCompleteCallback callback = open_complete_;
- open_complete_.Reset();
- callback.Run(false);
+ std::move(open_complete_).Run(false);
}
#endif
void SerialIoHandler::MergeConnectionOptions(
- const serial::ConnectionOptions& options) {
+ const mojom::SerialConnectionOptions& options) {
if (options.bitrate) {
options_.bitrate = options.bitrate;
}
- if (options.data_bits != serial::DataBits::NONE) {
+ if (options.data_bits != mojom::SerialDataBits::NONE) {
options_.data_bits = options.data_bits;
}
- if (options.parity_bit != serial::ParityBit::NONE) {
+ if (options.parity_bit != mojom::SerialParityBit::NONE) {
options_.parity_bit = options.parity_bit;
}
- if (options.stop_bits != serial::StopBits::NONE) {
+ if (options.stop_bits != mojom::SerialStopBits::NONE) {
options_.stop_bits = options.stop_bits;
}
if (options.has_cts_flow_control) {
@@ -126,7 +124,7 @@ void SerialIoHandler::MergeConnectionOptions(
void SerialIoHandler::StartOpen(
const std::string& port,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) {
- DCHECK(!open_complete_.is_null());
+ DCHECK(open_complete_);
DCHECK(!file_.IsValid());
// It's the responsibility of the API wrapper around SerialIoHandler to
// validate the supplied path against the set of valid port names, and
@@ -138,20 +136,19 @@ void SerialIoHandler::StartOpen(
base::File::FLAG_EXCLUSIVE_WRITE | base::File::FLAG_ASYNC |
base::File::FLAG_TERMINAL_DEVICE;
base::File file(path, flags);
- io_task_runner->PostTask(FROM_HERE, base::Bind(&SerialIoHandler::FinishOpen,
- this, base::Passed(&file)));
+ io_task_runner->PostTask(
+ FROM_HERE,
+ base::BindOnce(&SerialIoHandler::FinishOpen, this, std::move(file)));
}
void SerialIoHandler::FinishOpen(base::File file) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- DCHECK(!open_complete_.is_null());
- OpenCompleteCallback callback = open_complete_;
- open_complete_.Reset();
+ DCHECK(open_complete_);
if (!file.IsValid()) {
LOG(ERROR) << "Failed to open serial port: "
<< base::File::ErrorToString(file.error_details());
- callback.Run(false);
+ std::move(open_complete_).Run(false);
return;
}
@@ -161,7 +158,7 @@ void SerialIoHandler::FinishOpen(base::File file) {
if (!success)
Close();
- callback.Run(success);
+ std::move(open_complete_).Run(success);
}
bool SerialIoHandler::PostOpen() {
@@ -173,7 +170,7 @@ void SerialIoHandler::Close() {
base::PostTaskWithTraits(
FROM_HERE,
{base::MayBlock(), base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
- base::Bind(&SerialIoHandler::DoClose, Passed(std::move(file_))));
+ base::BindOnce(&SerialIoHandler::DoClose, std::move(file_)));
}
}
@@ -201,12 +198,12 @@ void SerialIoHandler::Write(std::unique_ptr<ReadOnlyBuffer> buffer) {
}
void SerialIoHandler::ReadCompleted(int bytes_read,
- serial::ReceiveError error) {
+ mojom::SerialReceiveError error) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(IsReadPending());
std::unique_ptr<WritableBuffer> pending_read_buffer =
std::move(pending_read_buffer_);
- if (error == serial::ReceiveError::NONE) {
+ if (error == mojom::SerialReceiveError::NONE) {
pending_read_buffer->Done(bytes_read);
} else {
pending_read_buffer->DoneWithError(bytes_read, static_cast<int32_t>(error));
@@ -215,12 +212,12 @@ void SerialIoHandler::ReadCompleted(int bytes_read,
}
void SerialIoHandler::WriteCompleted(int bytes_written,
- serial::SendError error) {
+ mojom::SerialSendError error) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(IsWritePending());
std::unique_ptr<ReadOnlyBuffer> pending_write_buffer =
std::move(pending_write_buffer_);
- if (error == serial::SendError::NONE) {
+ if (error == mojom::SerialSendError::NONE) {
pending_write_buffer->Done(bytes_written);
} else {
pending_write_buffer->DoneWithError(bytes_written,
@@ -239,7 +236,7 @@ bool SerialIoHandler::IsWritePending() const {
return pending_write_buffer_ != NULL;
}
-void SerialIoHandler::CancelRead(serial::ReceiveError reason) {
+void SerialIoHandler::CancelRead(mojom::SerialReceiveError reason) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (IsReadPending() && !read_canceled_) {
read_canceled_ = true;
@@ -248,7 +245,7 @@ void SerialIoHandler::CancelRead(serial::ReceiveError reason) {
}
}
-void SerialIoHandler::CancelWrite(serial::SendError reason) {
+void SerialIoHandler::CancelWrite(mojom::SerialSendError reason) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (IsWritePending() && !write_canceled_) {
write_canceled_ = true;
@@ -257,23 +254,24 @@ void SerialIoHandler::CancelWrite(serial::SendError reason) {
}
}
-bool SerialIoHandler::ConfigurePort(const serial::ConnectionOptions& options) {
+bool SerialIoHandler::ConfigurePort(
+ const mojom::SerialConnectionOptions& options) {
MergeConnectionOptions(options);
return ConfigurePortImpl();
}
void SerialIoHandler::QueueReadCompleted(int bytes_read,
- serial::ReceiveError error) {
+ mojom::SerialReceiveError error) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
- base::Bind(&SerialIoHandler::ReadCompleted, this, bytes_read, error));
+ base::BindOnce(&SerialIoHandler::ReadCompleted, this, bytes_read, error));
}
void SerialIoHandler::QueueWriteCompleted(int bytes_written,
- serial::SendError error) {
+ mojom::SerialSendError error) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE,
- base::Bind(&SerialIoHandler::WriteCompleted, this, bytes_written, error));
+ FROM_HERE, base::BindOnce(&SerialIoHandler::WriteCompleted, this,
+ bytes_written, error));
}
} // namespace device
diff --git a/chromium/device/serial/serial_io_handler.h b/chromium/device/serial/serial_io_handler.h
index c0adb5e5c16..db2c28e655e 100644
--- a/chromium/device/serial/serial_io_handler.h
+++ b/chromium/device/serial/serial_io_handler.h
@@ -18,7 +18,7 @@
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "device/serial/buffer.h"
-#include "device/serial/serial.mojom.h"
+#include "services/device/public/interfaces/serial.mojom.h"
namespace device {
@@ -32,12 +32,12 @@ class SerialIoHandler : public base::RefCountedThreadSafe<SerialIoHandler> {
static scoped_refptr<SerialIoHandler> Create(
scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner);
- typedef base::Callback<void(bool success)> OpenCompleteCallback;
+ typedef base::OnceCallback<void(bool success)> OpenCompleteCallback;
// Initiates an asynchronous Open of the device.
virtual void Open(const std::string& port,
- const serial::ConnectionOptions& options,
- const OpenCompleteCallback& callback);
+ const mojom::SerialConnectionOptions& options,
+ OpenCompleteCallback callback);
#if defined(OS_CHROMEOS)
// Signals that the port has been opened.
@@ -73,10 +73,10 @@ class SerialIoHandler : public base::RefCountedThreadSafe<SerialIoHandler> {
bool IsWritePending() const;
// Attempts to cancel a pending read operation.
- void CancelRead(serial::ReceiveError reason);
+ void CancelRead(mojom::SerialReceiveError reason);
// Attempts to cancel a pending write operation.
- void CancelWrite(serial::SendError reason);
+ void CancelWrite(mojom::SerialSendError reason);
// Flushes input and output buffers.
virtual bool Flush() const = 0;
@@ -84,22 +84,22 @@ class SerialIoHandler : public base::RefCountedThreadSafe<SerialIoHandler> {
// Reads current control signals (DCD, CTS, etc.) into an existing
// DeviceControlSignals structure. Returns |true| iff the signals were
// successfully read.
- virtual serial::DeviceControlSignalsPtr GetControlSignals() const = 0;
+ virtual mojom::SerialDeviceControlSignalsPtr GetControlSignals() const = 0;
// Sets one or more control signals (DTR and/or RTS). Returns |true| iff
// the signals were successfully set. Unininitialized flags in the
// HostControlSignals structure are left unchanged.
virtual bool SetControlSignals(
- const serial::HostControlSignals& control_signals) = 0;
+ const mojom::SerialHostControlSignals& control_signals) = 0;
// Performs platform-specific port configuration. Returns |true| iff
// configuration was successful.
- bool ConfigurePort(const serial::ConnectionOptions& options);
+ bool ConfigurePort(const mojom::SerialConnectionOptions& options);
// Performs a platform-specific port configuration query. Fills values in an
// existing ConnectionInfo. Returns |true| iff port configuration was
// successfully retrieved.
- virtual serial::ConnectionInfoPtr GetPortInfo() const = 0;
+ virtual mojom::SerialConnectionInfoPtr GetPortInfo() const = 0;
// Initiates a BREAK signal. Places the transmission line in a break state
// until the |ClearBreak| is called.
@@ -143,22 +143,22 @@ class SerialIoHandler : public base::RefCountedThreadSafe<SerialIoHandler> {
// Called by the implementation to signal that the active read has completed.
// WARNING: Calling this method can destroy the SerialIoHandler instance
// if the associated I/O operation was the only thing keeping it alive.
- void ReadCompleted(int bytes_read, serial::ReceiveError error);
+ void ReadCompleted(int bytes_read, mojom::SerialReceiveError error);
// Called by the implementation to signal that the active write has completed.
// WARNING: Calling this method may destroy the SerialIoHandler instance
// if the associated I/O operation was the only thing keeping it alive.
- void WriteCompleted(int bytes_written, serial::SendError error);
+ void WriteCompleted(int bytes_written, mojom::SerialSendError error);
// Queues a ReadCompleted call on the current thread. This is used to allow
// ReadImpl to immediately signal completion with 0 bytes and an error,
// without being reentrant.
- void QueueReadCompleted(int bytes_read, serial::ReceiveError error);
+ void QueueReadCompleted(int bytes_read, mojom::SerialReceiveError error);
// Queues a WriteCompleted call on the current thread. This is used to allow
// WriteImpl to immediately signal completion with 0 bytes and an error,
// without being reentrant.
- void QueueWriteCompleted(int bytes_written, serial::SendError error);
+ void QueueWriteCompleted(int bytes_written, mojom::SerialSendError error);
const base::File& file() const { return file_; }
@@ -170,13 +170,13 @@ class SerialIoHandler : public base::RefCountedThreadSafe<SerialIoHandler> {
return pending_read_buffer_ ? pending_read_buffer_->GetSize() : 0;
}
- serial::ReceiveError read_cancel_reason() const {
+ mojom::SerialReceiveError read_cancel_reason() const {
return read_cancel_reason_;
}
bool read_canceled() const { return read_canceled_; }
- const char* pending_write_buffer() const {
+ const uint8_t* pending_write_buffer() const {
return pending_write_buffer_ ? pending_write_buffer_->GetData() : NULL;
}
@@ -184,11 +184,13 @@ class SerialIoHandler : public base::RefCountedThreadSafe<SerialIoHandler> {
return pending_write_buffer_ ? pending_write_buffer_->GetSize() : 0;
}
- serial::SendError write_cancel_reason() const { return write_cancel_reason_; }
+ mojom::SerialSendError write_cancel_reason() const {
+ return write_cancel_reason_;
+ }
bool write_canceled() const { return write_canceled_; }
- const serial::ConnectionOptions& options() const { return options_; }
+ const mojom::SerialConnectionOptions& options() const { return options_; }
// Possibly fixes up a serial port path name in a platform-specific manner.
static std::string MaybeFixUpPortName(const std::string& port_name);
@@ -204,7 +206,7 @@ class SerialIoHandler : public base::RefCountedThreadSafe<SerialIoHandler> {
private:
friend class base::RefCountedThreadSafe<SerialIoHandler>;
- void MergeConnectionOptions(const serial::ConnectionOptions& options);
+ void MergeConnectionOptions(const mojom::SerialConnectionOptions& options);
// Continues an Open operation on the FILE thread.
void StartOpen(const std::string& port,
@@ -223,14 +225,14 @@ class SerialIoHandler : public base::RefCountedThreadSafe<SerialIoHandler> {
base::File file_;
// Currently applied connection options.
- serial::ConnectionOptions options_;
+ mojom::SerialConnectionOptions options_;
std::unique_ptr<WritableBuffer> pending_read_buffer_;
- serial::ReceiveError read_cancel_reason_;
+ mojom::SerialReceiveError read_cancel_reason_;
bool read_canceled_;
std::unique_ptr<ReadOnlyBuffer> pending_write_buffer_;
- serial::SendError write_cancel_reason_;
+ mojom::SerialSendError write_cancel_reason_;
bool write_canceled_;
// Callback to handle the completion of a pending Open() request.
diff --git a/chromium/device/serial/serial_io_handler_posix.cc b/chromium/device/serial/serial_io_handler_posix.cc
index 8ffba1216eb..eca131fad62 100644
--- a/chromium/device/serial/serial_io_handler_posix.cc
+++ b/chromium/device/serial/serial_io_handler_posix.cc
@@ -200,28 +200,28 @@ bool SerialIoHandlerPosix::ConfigurePortImpl() {
#endif
}
- DCHECK(options().data_bits != serial::DataBits::NONE);
+ DCHECK(options().data_bits != mojom::SerialDataBits::NONE);
config.c_cflag &= ~CSIZE;
switch (options().data_bits) {
- case serial::DataBits::SEVEN:
+ case mojom::SerialDataBits::SEVEN:
config.c_cflag |= CS7;
break;
- case serial::DataBits::EIGHT:
+ case mojom::SerialDataBits::EIGHT:
default:
config.c_cflag |= CS8;
break;
}
- DCHECK(options().parity_bit != serial::ParityBit::NONE);
+ DCHECK(options().parity_bit != mojom::SerialParityBit::NONE);
switch (options().parity_bit) {
- case serial::ParityBit::EVEN:
+ case mojom::SerialParityBit::EVEN:
config.c_cflag |= PARENB;
config.c_cflag &= ~PARODD;
break;
- case serial::ParityBit::ODD:
+ case mojom::SerialParityBit::ODD:
config.c_cflag |= (PARODD | PARENB);
break;
- case serial::ParityBit::NO_PARITY:
+ case mojom::SerialParityBit::NO_PARITY:
default:
config.c_cflag &= ~(PARODD | PARENB);
break;
@@ -240,12 +240,12 @@ bool SerialIoHandlerPosix::ConfigurePortImpl() {
parity_check_enabled_ = false;
}
- DCHECK(options().stop_bits != serial::StopBits::NONE);
+ DCHECK(options().stop_bits != mojom::SerialStopBits::NONE);
switch (options().stop_bits) {
- case serial::StopBits::TWO:
+ case mojom::SerialStopBits::TWO:
config.c_cflag |= CSTOPB;
break;
- case serial::StopBits::ONE:
+ case mojom::SerialStopBits::ONE:
default:
config.c_cflag &= ~CSTOPB;
break;
@@ -308,12 +308,14 @@ void SerialIoHandlerPosix::AttemptRead(bool within_read) {
// The fd does not have data to read yet so continue waiting.
EnsureWatchingReads();
} else if (errno == ENXIO) {
- RunReadCompleted(within_read, 0, serial::ReceiveError::DEVICE_LOST);
+ RunReadCompleted(within_read, 0,
+ mojom::SerialReceiveError::DEVICE_LOST);
} else {
- RunReadCompleted(within_read, 0, serial::ReceiveError::SYSTEM_ERROR);
+ RunReadCompleted(within_read, 0,
+ mojom::SerialReceiveError::SYSTEM_ERROR);
}
} else if (bytes_read == 0) {
- RunReadCompleted(within_read, 0, serial::ReceiveError::DEVICE_LOST);
+ RunReadCompleted(within_read, 0, mojom::SerialReceiveError::DEVICE_LOST);
} else {
bool break_detected = false;
bool parity_error_detected = false;
@@ -323,13 +325,13 @@ void SerialIoHandlerPosix::AttemptRead(bool within_read) {
if (break_detected) {
RunReadCompleted(within_read, new_bytes_read,
- serial::ReceiveError::BREAK);
+ mojom::SerialReceiveError::BREAK);
} else if (parity_error_detected) {
RunReadCompleted(within_read, new_bytes_read,
- serial::ReceiveError::PARITY_ERROR);
+ mojom::SerialReceiveError::PARITY_ERROR);
} else {
RunReadCompleted(within_read, new_bytes_read,
- serial::ReceiveError::NONE);
+ mojom::SerialReceiveError::NONE);
}
}
} else {
@@ -341,7 +343,7 @@ void SerialIoHandlerPosix::AttemptRead(bool within_read) {
void SerialIoHandlerPosix::RunReadCompleted(bool within_read,
int bytes_read,
- serial::ReceiveError error) {
+ mojom::SerialReceiveError error) {
if (within_read) {
// Stop watching the fd to avoid more reads until the queued ReadCompleted()
// completes and releases the pending_read_buffer.
@@ -361,9 +363,9 @@ void SerialIoHandlerPosix::OnFileCanWriteWithoutBlocking() {
pending_write_buffer(),
pending_write_buffer_len()));
if (bytes_written < 0) {
- WriteCompleted(0, serial::SendError::SYSTEM_ERROR);
+ WriteCompleted(0, mojom::SerialSendError::SYSTEM_ERROR);
} else {
- WriteCompleted(bytes_written, serial::SendError::NONE);
+ WriteCompleted(bytes_written, mojom::SerialSendError::NONE);
}
} else {
// Stop watching the fd if we get notifications with no pending
@@ -401,15 +403,15 @@ bool SerialIoHandlerPosix::Flush() const {
return true;
}
-serial::DeviceControlSignalsPtr SerialIoHandlerPosix::GetControlSignals()
+mojom::SerialDeviceControlSignalsPtr SerialIoHandlerPosix::GetControlSignals()
const {
int status;
if (ioctl(file().GetPlatformFile(), TIOCMGET, &status) == -1) {
VPLOG(1) << "Failed to get port control signals";
- return serial::DeviceControlSignalsPtr();
+ return mojom::SerialDeviceControlSignalsPtr();
}
- serial::DeviceControlSignalsPtr signals(serial::DeviceControlSignals::New());
+ auto signals = mojom::SerialDeviceControlSignals::New();
signals->dcd = (status & TIOCM_CAR) != 0;
signals->cts = (status & TIOCM_CTS) != 0;
signals->dsr = (status & TIOCM_DSR) != 0;
@@ -418,7 +420,7 @@ serial::DeviceControlSignalsPtr SerialIoHandlerPosix::GetControlSignals()
}
bool SerialIoHandlerPosix::SetControlSignals(
- const serial::HostControlSignals& signals) {
+ const mojom::SerialHostControlSignals& signals) {
int status;
if (ioctl(file().GetPlatformFile(), TIOCMGET, &status) == -1) {
@@ -449,7 +451,7 @@ bool SerialIoHandlerPosix::SetControlSignals(
return true;
}
-serial::ConnectionInfoPtr SerialIoHandlerPosix::GetPortInfo() const {
+mojom::SerialConnectionInfoPtr SerialIoHandlerPosix::GetPortInfo() const {
#if defined(OS_LINUX)
struct termios2 config;
if (ioctl(file().GetPlatformFile(), TCGETS2, &config) < 0) {
@@ -458,10 +460,10 @@ serial::ConnectionInfoPtr SerialIoHandlerPosix::GetPortInfo() const {
if (tcgetattr(file().GetPlatformFile(), &config) == -1) {
#endif
VPLOG(1) << "Failed to get port info";
- return serial::ConnectionInfoPtr();
+ return mojom::SerialConnectionInfoPtr();
}
- serial::ConnectionInfoPtr info(serial::ConnectionInfo::New());
+ auto info = mojom::SerialConnectionInfo::New();
#if defined(OS_LINUX)
// Linux forces c_ospeed to contain the correct value, which is nice.
info->bitrate = config.c_ospeed;
@@ -479,20 +481,20 @@ serial::ConnectionInfoPtr SerialIoHandlerPosix::GetPortInfo() const {
#endif
if ((config.c_cflag & CSIZE) == CS7) {
- info->data_bits = serial::DataBits::SEVEN;
+ info->data_bits = mojom::SerialDataBits::SEVEN;
} else if ((config.c_cflag & CSIZE) == CS8) {
- info->data_bits = serial::DataBits::EIGHT;
+ info->data_bits = mojom::SerialDataBits::EIGHT;
} else {
- info->data_bits = serial::DataBits::NONE;
+ info->data_bits = mojom::SerialDataBits::NONE;
}
if (config.c_cflag & PARENB) {
- info->parity_bit = (config.c_cflag & PARODD) ? serial::ParityBit::ODD
- : serial::ParityBit::EVEN;
+ info->parity_bit = (config.c_cflag & PARODD) ? mojom::SerialParityBit::ODD
+ : mojom::SerialParityBit::EVEN;
} else {
- info->parity_bit = serial::ParityBit::NO_PARITY;
+ info->parity_bit = mojom::SerialParityBit::NO_PARITY;
}
- info->stop_bits =
- (config.c_cflag & CSTOPB) ? serial::StopBits::TWO : serial::StopBits::ONE;
+ info->stop_bits = (config.c_cflag & CSTOPB) ? mojom::SerialStopBits::TWO
+ : mojom::SerialStopBits::ONE;
info->cts_flow_control = (config.c_cflag & CRTSCTS) != 0;
return info;
}
diff --git a/chromium/device/serial/serial_io_handler_posix.h b/chromium/device/serial/serial_io_handler_posix.h
index ee5d129ae65..7b8abd0033c 100644
--- a/chromium/device/serial/serial_io_handler_posix.h
+++ b/chromium/device/serial/serial_io_handler_posix.h
@@ -30,10 +30,10 @@ class SerialIoHandlerPosix : public SerialIoHandler {
bool ConfigurePortImpl() override;
bool PostOpen() override;
bool Flush() const override;
- serial::DeviceControlSignalsPtr GetControlSignals() const override;
+ mojom::SerialDeviceControlSignalsPtr GetControlSignals() const override;
bool SetControlSignals(
- const serial::HostControlSignals& control_signals) override;
- serial::ConnectionInfoPtr GetPortInfo() const override;
+ const mojom::SerialHostControlSignals& control_signals) override;
+ mojom::SerialConnectionInfoPtr GetPortInfo() const override;
bool SetBreak() override;
bool ClearBreak() override;
int CheckReceiveError(char* buffer,
@@ -53,7 +53,7 @@ class SerialIoHandlerPosix : public SerialIoHandler {
void AttemptRead(bool within_read);
void RunReadCompleted(bool within_read,
int bytes_read,
- serial::ReceiveError error);
+ mojom::SerialReceiveError error);
// Called when file() is writable without blocking.
void OnFileCanWriteWithoutBlocking();
diff --git a/chromium/device/serial/serial_io_handler_win.cc b/chromium/device/serial/serial_io_handler_win.cc
index 9a25e9a69bb..3384a8e84ad 100644
--- a/chromium/device/serial/serial_io_handler_win.cc
+++ b/chromium/device/serial/serial_io_handler_win.cc
@@ -49,33 +49,33 @@ int BitrateToSpeedConstant(int bitrate) {
#undef BITRATE_TO_SPEED_CASE
}
-int DataBitsEnumToConstant(serial::DataBits data_bits) {
+int DataBitsEnumToConstant(mojom::SerialDataBits data_bits) {
switch (data_bits) {
- case serial::DataBits::SEVEN:
+ case mojom::SerialDataBits::SEVEN:
return 7;
- case serial::DataBits::EIGHT:
+ case mojom::SerialDataBits::EIGHT:
default:
return 8;
}
}
-int ParityBitEnumToConstant(serial::ParityBit parity_bit) {
+int ParityBitEnumToConstant(mojom::SerialParityBit parity_bit) {
switch (parity_bit) {
- case serial::ParityBit::EVEN:
+ case mojom::SerialParityBit::EVEN:
return EVENPARITY;
- case serial::ParityBit::ODD:
+ case mojom::SerialParityBit::ODD:
return ODDPARITY;
- case serial::ParityBit::NO_PARITY:
+ case mojom::SerialParityBit::NO_PARITY:
default:
return NOPARITY;
}
}
-int StopBitsEnumToConstant(serial::StopBits stop_bits) {
+int StopBitsEnumToConstant(mojom::SerialStopBits stop_bits) {
switch (stop_bits) {
- case serial::StopBits::TWO:
+ case mojom::SerialStopBits::TWO:
return TWOSTOPBITS;
- case serial::StopBits::ONE:
+ case mojom::SerialStopBits::ONE:
default:
return ONESTOPBIT;
}
@@ -109,35 +109,35 @@ int SpeedConstantToBitrate(int speed) {
#undef SPEED_TO_BITRATE_CASE
}
-serial::DataBits DataBitsConstantToEnum(int data_bits) {
+mojom::SerialDataBits DataBitsConstantToEnum(int data_bits) {
switch (data_bits) {
case 7:
- return serial::DataBits::SEVEN;
+ return mojom::SerialDataBits::SEVEN;
case 8:
default:
- return serial::DataBits::EIGHT;
+ return mojom::SerialDataBits::EIGHT;
}
}
-serial::ParityBit ParityBitConstantToEnum(int parity_bit) {
+mojom::SerialParityBit ParityBitConstantToEnum(int parity_bit) {
switch (parity_bit) {
case EVENPARITY:
- return serial::ParityBit::EVEN;
+ return mojom::SerialParityBit::EVEN;
case ODDPARITY:
- return serial::ParityBit::ODD;
+ return mojom::SerialParityBit::ODD;
case NOPARITY:
default:
- return serial::ParityBit::NO_PARITY;
+ return mojom::SerialParityBit::NO_PARITY;
}
}
-serial::StopBits StopBitsConstantToEnum(int stop_bits) {
+mojom::SerialStopBits StopBitsConstantToEnum(int stop_bits) {
switch (stop_bits) {
case TWOSTOPBITS:
- return serial::StopBits::TWO;
+ return mojom::SerialStopBits::TWO;
case ONESTOPBIT:
default:
- return serial::StopBits::ONE;
+ return mojom::SerialStopBits::ONE;
}
}
@@ -228,7 +228,7 @@ void SerialIoHandlerWin::OnDeviceRemoved(const std::string& device_path) {
}
if (port() == com_port)
- CancelRead(serial::ReceiveError::DEVICE_LOST);
+ CancelRead(mojom::SerialReceiveError::DEVICE_LOST);
}
bool SerialIoHandlerWin::PostOpen() {
@@ -278,7 +278,7 @@ void SerialIoHandlerWin::ReadImpl() {
file().GetPlatformFile(), &event_mask_, &comm_context_->overlapped);
if (!ok && GetLastError() != ERROR_IO_PENDING) {
VPLOG(1) << "Failed to receive serial event";
- QueueReadCompleted(0, serial::ReceiveError::SYSTEM_ERROR);
+ QueueReadCompleted(0, mojom::SerialReceiveError::SYSTEM_ERROR);
}
is_comm_pending_ = true;
}
@@ -295,7 +295,7 @@ void SerialIoHandlerWin::WriteImpl() {
&write_context_->overlapped);
if (!ok && GetLastError() != ERROR_IO_PENDING) {
VPLOG(1) << "Write failed";
- QueueWriteCompleted(0, serial::SendError::SYSTEM_ERROR);
+ QueueWriteCompleted(0, mojom::SerialSendError::SYSTEM_ERROR);
}
}
@@ -332,13 +332,13 @@ bool SerialIoHandlerWin::ConfigurePortImpl() {
DCHECK(options().bitrate);
config.BaudRate = BitrateToSpeedConstant(options().bitrate);
- DCHECK(options().data_bits != serial::DataBits::NONE);
+ DCHECK(options().data_bits != mojom::SerialDataBits::NONE);
config.ByteSize = DataBitsEnumToConstant(options().data_bits);
- DCHECK(options().parity_bit != serial::ParityBit::NONE);
+ DCHECK(options().parity_bit != mojom::SerialParityBit::NONE);
config.Parity = ParityBitEnumToConstant(options().parity_bit);
- DCHECK(options().stop_bits != serial::StopBits::NONE);
+ DCHECK(options().stop_bits != mojom::SerialStopBits::NONE);
config.StopBits = StopBitsEnumToConstant(options().stop_bits);
DCHECK(options().has_cts_flow_control);
@@ -380,17 +380,17 @@ void SerialIoHandlerWin::OnIOCompleted(
if (!ClearCommError(file().GetPlatformFile(), &errors, &status) ||
errors != 0) {
if (errors & CE_BREAK) {
- ReadCompleted(0, serial::ReceiveError::BREAK);
+ ReadCompleted(0, mojom::SerialReceiveError::BREAK);
} else if (errors & CE_FRAME) {
- ReadCompleted(0, serial::ReceiveError::FRAME_ERROR);
+ ReadCompleted(0, mojom::SerialReceiveError::FRAME_ERROR);
} else if (errors & CE_OVERRUN) {
- ReadCompleted(0, serial::ReceiveError::OVERRUN);
+ ReadCompleted(0, mojom::SerialReceiveError::OVERRUN);
} else if (errors & CE_RXOVER) {
- ReadCompleted(0, serial::ReceiveError::BUFFER_OVERFLOW);
+ ReadCompleted(0, mojom::SerialReceiveError::BUFFER_OVERFLOW);
} else if (errors & CE_RXPARITY) {
- ReadCompleted(0, serial::ReceiveError::PARITY_ERROR);
+ ReadCompleted(0, mojom::SerialReceiveError::PARITY_ERROR);
} else {
- ReadCompleted(0, serial::ReceiveError::SYSTEM_ERROR);
+ ReadCompleted(0, mojom::SerialReceiveError::SYSTEM_ERROR);
}
return;
}
@@ -398,7 +398,7 @@ void SerialIoHandlerWin::OnIOCompleted(
if (read_canceled()) {
ReadCompleted(bytes_transferred, read_cancel_reason());
} else if (error != ERROR_SUCCESS && error != ERROR_OPERATION_ABORTED) {
- ReadCompleted(0, serial::ReceiveError::SYSTEM_ERROR);
+ ReadCompleted(0, mojom::SerialReceiveError::SYSTEM_ERROR);
} else if (pending_read_buffer()) {
BOOL ok = ::ReadFile(file().GetPlatformFile(),
pending_read_buffer(),
@@ -407,26 +407,26 @@ void SerialIoHandlerWin::OnIOCompleted(
&read_context_->overlapped);
if (!ok && GetLastError() != ERROR_IO_PENDING) {
VPLOG(1) << "Read failed";
- ReadCompleted(0, serial::ReceiveError::SYSTEM_ERROR);
+ ReadCompleted(0, mojom::SerialReceiveError::SYSTEM_ERROR);
}
}
} else if (context == read_context_.get()) {
if (read_canceled()) {
ReadCompleted(bytes_transferred, read_cancel_reason());
} else if (error != ERROR_SUCCESS && error != ERROR_OPERATION_ABORTED) {
- ReadCompleted(0, serial::ReceiveError::SYSTEM_ERROR);
+ ReadCompleted(0, mojom::SerialReceiveError::SYSTEM_ERROR);
} else {
ReadCompleted(bytes_transferred,
error == ERROR_SUCCESS
- ? serial::ReceiveError::NONE
- : serial::ReceiveError::SYSTEM_ERROR);
+ ? mojom::SerialReceiveError::NONE
+ : mojom::SerialReceiveError::SYSTEM_ERROR);
}
} else if (context == write_context_.get()) {
DCHECK(pending_write_buffer());
if (write_canceled()) {
WriteCompleted(0, write_cancel_reason());
} else if (error != ERROR_SUCCESS && error != ERROR_OPERATION_ABORTED) {
- WriteCompleted(0, serial::SendError::SYSTEM_ERROR);
+ WriteCompleted(0, mojom::SerialSendError::SYSTEM_ERROR);
if (error == ERROR_GEN_FAILURE && IsReadPending()) {
// For devices using drivers such as FTDI, CP2xxx, when device is
// disconnected, the context is comm_context_ and the error is
@@ -435,14 +435,15 @@ void SerialIoHandlerWin::OnIOCompleted(
// disconnected, the context is write_context_ and the error is
// ERROR_GEN_FAILURE. In this situation, in addition to a write error
// signal, also need to generate a read error signal
- // serial::OnReceiveError which will notify the app about the
+ // mojom::SerialOnReceiveError which will notify the app about the
// disconnection.
- CancelRead(serial::ReceiveError::SYSTEM_ERROR);
+ CancelRead(mojom::SerialReceiveError::SYSTEM_ERROR);
}
} else {
- WriteCompleted(bytes_transferred, error == ERROR_SUCCESS
- ? serial::SendError::NONE
- : serial::SendError::SYSTEM_ERROR);
+ WriteCompleted(bytes_transferred,
+ error == ERROR_SUCCESS
+ ? mojom::SerialSendError::NONE
+ : mojom::SerialSendError::SYSTEM_ERROR);
}
} else {
NOTREACHED() << "Invalid IOContext";
@@ -457,14 +458,15 @@ bool SerialIoHandlerWin::Flush() const {
return true;
}
-serial::DeviceControlSignalsPtr SerialIoHandlerWin::GetControlSignals() const {
+mojom::SerialDeviceControlSignalsPtr SerialIoHandlerWin::GetControlSignals()
+ const {
DWORD status;
if (!GetCommModemStatus(file().GetPlatformFile(), &status)) {
VPLOG(1) << "Failed to get port control signals";
- return serial::DeviceControlSignalsPtr();
+ return mojom::SerialDeviceControlSignalsPtr();
}
- serial::DeviceControlSignalsPtr signals(serial::DeviceControlSignals::New());
+ auto signals = mojom::SerialDeviceControlSignals::New();
signals->dcd = (status & MS_RLSD_ON) != 0;
signals->cts = (status & MS_CTS_ON) != 0;
signals->dsr = (status & MS_DSR_ON) != 0;
@@ -473,7 +475,7 @@ serial::DeviceControlSignalsPtr SerialIoHandlerWin::GetControlSignals() const {
}
bool SerialIoHandlerWin::SetControlSignals(
- const serial::HostControlSignals& signals) {
+ const mojom::SerialHostControlSignals& signals) {
if (signals.has_dtr) {
if (!EscapeCommFunction(file().GetPlatformFile(),
signals.dtr ? SETDTR : CLRDTR)) {
@@ -491,14 +493,14 @@ bool SerialIoHandlerWin::SetControlSignals(
return true;
}
-serial::ConnectionInfoPtr SerialIoHandlerWin::GetPortInfo() const {
+mojom::SerialConnectionInfoPtr SerialIoHandlerWin::GetPortInfo() const {
DCB config = {0};
config.DCBlength = sizeof(config);
if (!GetCommState(file().GetPlatformFile(), &config)) {
VPLOG(1) << "Failed to get serial port info";
- return serial::ConnectionInfoPtr();
+ return mojom::SerialConnectionInfoPtr();
}
- serial::ConnectionInfoPtr info(serial::ConnectionInfo::New());
+ auto info = mojom::SerialConnectionInfo::New();
info->bitrate = SpeedConstantToBitrate(config.BaudRate);
info->data_bits = DataBitsConstantToEnum(config.ByteSize);
info->parity_bit = ParityBitConstantToEnum(config.Parity);
diff --git a/chromium/device/serial/serial_io_handler_win.h b/chromium/device/serial/serial_io_handler_win.h
index bb31bea18c2..96b495d517c 100644
--- a/chromium/device/serial/serial_io_handler_win.h
+++ b/chromium/device/serial/serial_io_handler_win.h
@@ -25,10 +25,10 @@ class SerialIoHandlerWin : public SerialIoHandler,
void CancelWriteImpl() override;
bool ConfigurePortImpl() override;
bool Flush() const override;
- serial::DeviceControlSignalsPtr GetControlSignals() const override;
+ mojom::SerialDeviceControlSignalsPtr GetControlSignals() const override;
bool SetControlSignals(
- const serial::HostControlSignals& control_signals) override;
- serial::ConnectionInfoPtr GetPortInfo() const override;
+ const mojom::SerialHostControlSignals& control_signals) override;
+ mojom::SerialConnectionInfoPtr GetPortInfo() const override;
bool SetBreak() override;
bool ClearBreak() override;
bool PostOpen() override;
diff --git a/chromium/device/serial/test_serial_io_handler.cc b/chromium/device/serial/test_serial_io_handler.cc
index 50c38dbc5ee..997b0a3e13e 100644
--- a/chromium/device/serial/test_serial_io_handler.cc
+++ b/chromium/device/serial/test_serial_io_handler.cc
@@ -10,7 +10,7 @@
#include <algorithm>
#include "base/bind.h"
-#include "device/serial/serial.mojom.h"
+#include "services/device/public/interfaces/serial.mojom.h"
namespace device {
@@ -26,12 +26,12 @@ scoped_refptr<SerialIoHandler> TestSerialIoHandler::Create() {
}
void TestSerialIoHandler::Open(const std::string& port,
- const serial::ConnectionOptions& options,
- const OpenCompleteCallback& callback) {
+ const mojom::SerialConnectionOptions& options,
+ OpenCompleteCallback callback) {
DCHECK(!opened_);
opened_ = true;
ConfigurePort(options);
- callback.Run(true);
+ std::move(callback).Run(true);
}
void TestSerialIoHandler::ReadImpl() {
@@ -42,9 +42,10 @@ void TestSerialIoHandler::ReadImpl() {
size_t num_bytes =
std::min(buffer_.size(), static_cast<size_t>(pending_read_buffer_len()));
- memcpy(pending_read_buffer(), buffer_.c_str(), num_bytes);
- buffer_ = buffer_.substr(num_bytes);
- ReadCompleted(static_cast<uint32_t>(num_bytes), serial::ReceiveError::NONE);
+ memcpy(pending_read_buffer(), buffer_.data(), num_bytes);
+ buffer_.erase(buffer_.begin(), buffer_.begin() + num_bytes);
+ ReadCompleted(static_cast<uint32_t>(num_bytes),
+ mojom::SerialReceiveError::NONE);
}
void TestSerialIoHandler::CancelReadImpl() {
@@ -52,14 +53,13 @@ void TestSerialIoHandler::CancelReadImpl() {
}
void TestSerialIoHandler::WriteImpl() {
- if (!send_callback_.is_null()) {
- base::Closure callback = send_callback_;
- send_callback_.Reset();
- callback.Run();
+ if (send_callback_) {
+ std::move(send_callback_).Run();
return;
}
- buffer_ += std::string(pending_write_buffer(), pending_write_buffer_len());
- WriteCompleted(pending_write_buffer_len(), serial::SendError::NONE);
+ buffer_.insert(buffer_.end(), pending_write_buffer(),
+ pending_write_buffer() + pending_write_buffer_len());
+ WriteCompleted(pending_write_buffer_len(), mojom::SerialSendError::NONE);
if (pending_read_buffer())
ReadImpl();
}
@@ -77,14 +77,15 @@ bool TestSerialIoHandler::ConfigurePortImpl() {
return true;
}
-serial::DeviceControlSignalsPtr TestSerialIoHandler::GetControlSignals() const {
- serial::DeviceControlSignalsPtr signals(serial::DeviceControlSignals::New());
+mojom::SerialDeviceControlSignalsPtr TestSerialIoHandler::GetControlSignals()
+ const {
+ auto signals = mojom::SerialDeviceControlSignals::New();
*signals = device_control_signals_;
return signals;
}
-serial::ConnectionInfoPtr TestSerialIoHandler::GetPortInfo() const {
- serial::ConnectionInfoPtr info(serial::ConnectionInfo::New());
+mojom::SerialConnectionInfoPtr TestSerialIoHandler::GetPortInfo() const {
+ auto info = mojom::SerialConnectionInfo::New();
*info = info_;
return info;
}
@@ -95,7 +96,7 @@ bool TestSerialIoHandler::Flush() const {
}
bool TestSerialIoHandler::SetControlSignals(
- const serial::HostControlSignals& signals) {
+ const mojom::SerialHostControlSignals& signals) {
if (signals.has_dtr)
dtr_ = signals.dtr;
if (signals.has_rts)
@@ -111,6 +112,15 @@ bool TestSerialIoHandler::ClearBreak() {
return true;
}
+void TestSerialIoHandler::ForceReceiveError(
+ device::mojom::SerialReceiveError error) {
+ ReadCompleted(0, error);
+}
+
+void TestSerialIoHandler::ForceSendError(device::mojom::SerialSendError error) {
+ WriteCompleted(0, error);
+}
+
TestSerialIoHandler::~TestSerialIoHandler() {
}
diff --git a/chromium/device/serial/test_serial_io_handler.h b/chromium/device/serial/test_serial_io_handler.h
index 508917843a6..208a28cf7a5 100644
--- a/chromium/device/serial/test_serial_io_handler.h
+++ b/chromium/device/serial/test_serial_io_handler.h
@@ -9,8 +9,8 @@
#include "base/callback.h"
#include "base/macros.h"
-#include "device/serial/serial.mojom.h"
#include "device/serial/serial_io_handler.h"
+#include "services/device/public/interfaces/serial.mojom.h"
namespace device {
@@ -22,22 +22,25 @@ class TestSerialIoHandler : public SerialIoHandler {
// SerialIoHandler overrides.
void Open(const std::string& port,
- const serial::ConnectionOptions& options,
- const OpenCompleteCallback& callback) override;
+ const mojom::SerialConnectionOptions& options,
+ OpenCompleteCallback callback) override;
void ReadImpl() override;
void CancelReadImpl() override;
void WriteImpl() override;
void CancelWriteImpl() override;
bool ConfigurePortImpl() override;
- serial::DeviceControlSignalsPtr GetControlSignals() const override;
- serial::ConnectionInfoPtr GetPortInfo() const override;
+ mojom::SerialDeviceControlSignalsPtr GetControlSignals() const override;
+ mojom::SerialConnectionInfoPtr GetPortInfo() const override;
bool Flush() const override;
- bool SetControlSignals(const serial::HostControlSignals& signals) override;
+ bool SetControlSignals(
+ const mojom::SerialHostControlSignals& signals) override;
bool SetBreak() override;
bool ClearBreak() override;
+ void ForceReceiveError(device::mojom::SerialReceiveError error);
+ void ForceSendError(device::mojom::SerialSendError error);
- serial::ConnectionInfo* connection_info() { return &info_; }
- serial::DeviceControlSignals* device_control_signals() {
+ mojom::SerialConnectionInfo* connection_info() { return &info_; }
+ mojom::SerialDeviceControlSignals* device_control_signals() {
return &device_control_signals_;
}
bool dtr() { return dtr_; }
@@ -45,8 +48,8 @@ class TestSerialIoHandler : public SerialIoHandler {
int flushes() { return flushes_; }
// This callback will be called when this IoHandler processes its next write,
// instead of the normal behavior of echoing the data to reads.
- void set_send_callback(const base::Closure& callback) {
- send_callback_ = callback;
+ void set_send_callback(base::OnceClosure callback) {
+ send_callback_ = std::move(callback);
}
protected:
@@ -54,13 +57,13 @@ class TestSerialIoHandler : public SerialIoHandler {
private:
bool opened_;
- serial::ConnectionInfo info_;
- serial::DeviceControlSignals device_control_signals_;
+ mojom::SerialConnectionInfo info_;
+ mojom::SerialDeviceControlSignals device_control_signals_;
bool dtr_;
bool rts_;
mutable int flushes_;
- std::string buffer_;
- base::Closure send_callback_;
+ std::vector<uint8_t> buffer_;
+ base::OnceClosure send_callback_;
DISALLOW_COPY_AND_ASSIGN(TestSerialIoHandler);
};
diff --git a/chromium/device/u2f/mock_u2f_device.cc b/chromium/device/u2f/mock_u2f_device.cc
index e833bbf6ef8..ac14cca1e5a 100644
--- a/chromium/device/u2f/mock_u2f_device.cc
+++ b/chromium/device/u2f/mock_u2f_device.cc
@@ -18,7 +18,7 @@ void MockU2fDevice::DeviceTransact(std::unique_ptr<U2fApduCommand> command,
// static
void MockU2fDevice::NotSatisfied(U2fApduCommand* cmd,
const DeviceCallback& cb) {
- cb.Run(true, base::MakeUnique<U2fApduResponse>(
+ cb.Run(true, std::make_unique<U2fApduResponse>(
std::vector<uint8_t>(),
U2fApduResponse::Status::SW_CONDITIONS_NOT_SATISFIED));
}
@@ -26,13 +26,13 @@ void MockU2fDevice::NotSatisfied(U2fApduCommand* cmd,
// static
void MockU2fDevice::WrongData(U2fApduCommand* cmd, const DeviceCallback& cb) {
cb.Run(true,
- base::MakeUnique<U2fApduResponse>(
+ std::make_unique<U2fApduResponse>(
std::vector<uint8_t>(), U2fApduResponse::Status::SW_WRONG_DATA));
}
// static
void MockU2fDevice::NoErrorSign(U2fApduCommand* cmd, const DeviceCallback& cb) {
- cb.Run(true, base::MakeUnique<U2fApduResponse>(
+ cb.Run(true, std::make_unique<U2fApduResponse>(
std::vector<uint8_t>({kSign}),
U2fApduResponse::Status::SW_NO_ERROR));
}
@@ -40,7 +40,7 @@ void MockU2fDevice::NoErrorSign(U2fApduCommand* cmd, const DeviceCallback& cb) {
// static
void MockU2fDevice::NoErrorRegister(U2fApduCommand* cmd,
const DeviceCallback& cb) {
- cb.Run(true, base::MakeUnique<U2fApduResponse>(
+ cb.Run(true, std::make_unique<U2fApduResponse>(
std::vector<uint8_t>({kRegister}),
U2fApduResponse::Status::SW_NO_ERROR));
}
diff --git a/chromium/device/u2f/u2f_apdu_command.cc b/chromium/device/u2f/u2f_apdu_command.cc
index a062f177754..7336b116637 100644
--- a/chromium/device/u2f/u2f_apdu_command.cc
+++ b/chromium/device/u2f/u2f_apdu_command.cc
@@ -73,7 +73,7 @@ std::unique_ptr<U2fApduCommand> U2fApduCommand::CreateFromMessage(
break;
}
- return base::MakeUnique<U2fApduCommand>(cla, ins, p1, p2, response_length,
+ return std::make_unique<U2fApduCommand>(cla, ins, p1, p2, response_length,
std::move(data), std::move(suffix));
}
@@ -135,7 +135,7 @@ std::unique_ptr<U2fApduCommand> U2fApduCommand::CreateRegister(
return nullptr;
}
- auto command = base::MakeUnique<U2fApduCommand>();
+ auto command = std::make_unique<U2fApduCommand>();
std::vector<uint8_t> data(challenge_digest.begin(), challenge_digest.end());
data.insert(data.end(), appid_digest.begin(), appid_digest.end());
command->set_ins(kInsU2fEnroll);
@@ -146,7 +146,7 @@ std::unique_ptr<U2fApduCommand> U2fApduCommand::CreateRegister(
// static
std::unique_ptr<U2fApduCommand> U2fApduCommand::CreateVersion() {
- auto command = base::MakeUnique<U2fApduCommand>();
+ auto command = std::make_unique<U2fApduCommand>();
command->set_ins(kInsU2fVersion);
command->set_response_length(kApduMaxResponseLength);
return command;
@@ -154,7 +154,7 @@ std::unique_ptr<U2fApduCommand> U2fApduCommand::CreateVersion() {
// static
std::unique_ptr<U2fApduCommand> U2fApduCommand::CreateLegacyVersion() {
- auto command = base::MakeUnique<U2fApduCommand>();
+ auto command = std::make_unique<U2fApduCommand>();
command->set_ins(kInsU2fVersion);
command->set_response_length(kApduMaxResponseLength);
// Early U2F drafts defined the U2F version command in extended
@@ -175,7 +175,7 @@ std::unique_ptr<U2fApduCommand> U2fApduCommand::CreateSign(
return nullptr;
}
- auto command = base::MakeUnique<U2fApduCommand>();
+ auto command = std::make_unique<U2fApduCommand>();
std::vector<uint8_t> data(challenge_digest.begin(), challenge_digest.end());
data.insert(data.end(), appid_digest.begin(), appid_digest.end());
data.push_back(static_cast<uint8_t>(key_handle.size()));
diff --git a/chromium/device/u2f/u2f_apdu_response.cc b/chromium/device/u2f/u2f_apdu_response.cc
index 30336d52c25..d418c5eeb5b 100644
--- a/chromium/device/u2f/u2f_apdu_response.cc
+++ b/chromium/device/u2f/u2f_apdu_response.cc
@@ -20,7 +20,7 @@ std::unique_ptr<U2fApduResponse> U2fApduResponse::CreateFromMessage(
response_status = static_cast<Status>(status_bytes);
std::vector<uint8_t> data(message.begin(), message.end() - 2);
- return base::MakeUnique<U2fApduResponse>(std::move(data), response_status);
+ return std::make_unique<U2fApduResponse>(std::move(data), response_status);
}
U2fApduResponse::U2fApduResponse(std::vector<uint8_t> message,
diff --git a/chromium/device/u2f/u2f_apdu_unittest.cc b/chromium/device/u2f/u2f_apdu_unittest.cc
index 4d83950d501..285539ae498 100644
--- a/chromium/device/u2f/u2f_apdu_unittest.cc
+++ b/chromium/device/u2f/u2f_apdu_unittest.cc
@@ -112,7 +112,7 @@ TEST_F(U2fApduTest, TestDeserializeResponse) {
}
TEST_F(U2fApduTest, TestSerializeCommand) {
- auto cmd = base::MakeUnique<U2fApduCommand>();
+ auto cmd = std::make_unique<U2fApduCommand>();
cmd->set_cla(0xA);
cmd->set_ins(0xB);
@@ -158,7 +158,7 @@ TEST_F(U2fApduTest, TestSerializeCommand) {
}
TEST_F(U2fApduTest, TestSerializeEdgeCases) {
- auto cmd = base::MakeUnique<U2fApduCommand>();
+ auto cmd = std::make_unique<U2fApduCommand>();
cmd->set_cla(0xA);
cmd->set_ins(0xB);
diff --git a/chromium/device/u2f/u2f_hid_device.cc b/chromium/device/u2f/u2f_hid_device.cc
index e54cf9a85d2..e418667ef79 100644
--- a/chromium/device/u2f/u2f_hid_device.cc
+++ b/chromium/device/u2f/u2f_hid_device.cc
@@ -20,12 +20,11 @@ namespace switches {
static constexpr char kEnableU2fHidTest[] = "enable-u2f-hid-tests";
} // namespace switches
-U2fHidDevice::U2fHidDevice(scoped_refptr<HidDeviceInfo> device_info)
+U2fHidDevice::U2fHidDevice(device::mojom::HidDeviceInfoPtr device_info)
: U2fDevice(),
state_(State::INIT),
- device_info_(device_info),
- weak_factory_(this) {
-}
+ device_info_(std::move(device_info)),
+ weak_factory_(this) {}
U2fHidDevice::~U2fHidDevice() {
// Cleanup connection
@@ -85,7 +84,7 @@ void U2fHidDevice::Transition(std::unique_ptr<U2fApduCommand> command,
void U2fHidDevice::Connect(const HidService::ConnectCallback& callback) {
HidService* hid_service = DeviceClient::Get()->GetHidService();
- hid_service->Connect(device_info_->device_id(), callback);
+ hid_service->Connect(device_info_->guid, callback);
}
void U2fHidDevice::OnConnect(std::unique_ptr<U2fApduCommand> command,
@@ -332,7 +331,7 @@ void U2fHidDevice::OnTimeout(const DeviceCallback& callback) {
std::string U2fHidDevice::GetId() {
std::ostringstream id("hid:", std::ios::ate);
- id << device_info_->device_id();
+ id << device_info_->guid;
return id.str();
}
diff --git a/chromium/device/u2f/u2f_hid_device.h b/chromium/device/u2f/u2f_hid_device.h
index 64bc0f2acfd..f84030c8a53 100644
--- a/chromium/device/u2f/u2f_hid_device.h
+++ b/chromium/device/u2f/u2f_hid_device.h
@@ -9,6 +9,7 @@
#include "base/cancelable_callback.h"
#include "device/hid/hid_service.h"
+#include "device/hid/public/interfaces/hid.mojom.h"
#include "u2f_device.h"
namespace net {
@@ -19,11 +20,10 @@ namespace device {
class U2fMessage;
class HidConnection;
-class HidDeviceInfo;
class U2fHidDevice : public U2fDevice {
public:
- U2fHidDevice(scoped_refptr<HidDeviceInfo>);
+ U2fHidDevice(device::mojom::HidDeviceInfoPtr);
~U2fHidDevice() final;
// Send a U2f command to this device
@@ -96,7 +96,7 @@ class U2fHidDevice : public U2fDevice {
base::CancelableClosure timeout_callback_;
std::list<std::pair<std::unique_ptr<U2fApduCommand>, DeviceCallback>>
pending_transactions_;
- scoped_refptr<HidDeviceInfo> device_info_;
+ device::mojom::HidDeviceInfoPtr device_info_;
scoped_refptr<HidConnection> connection_;
base::WeakPtrFactory<U2fHidDevice> weak_factory_;
diff --git a/chromium/device/u2f/u2f_hid_device_unittest.cc b/chromium/device/u2f/u2f_hid_device_unittest.cc
index f1f09159bd5..7d3d556d758 100644
--- a/chromium/device/u2f/u2f_hid_device_unittest.cc
+++ b/chromium/device/u2f/u2f_hid_device_unittest.cc
@@ -42,20 +42,20 @@ class MockHidErrorConnection : public device::HidConnection {
void PlatformClose() override {}
- void PlatformRead(const ReadCallback& callback) override {}
+ void PlatformRead(ReadCallback callback) override {}
void PlatformWrite(scoped_refptr<net::IOBuffer> buffer,
size_t size,
- const WriteCallback& callback) override {
- callback.Run(false);
+ WriteCallback callback) override {
+ std::move(callback).Run(false);
}
void PlatformGetFeatureReport(uint8_t report_id,
- const ReadCallback& callback) override {}
+ ReadCallback callback) override {}
void PlatformSendFeatureReport(scoped_refptr<net::IOBuffer> buffer,
size_t size,
- const WriteCallback& callback) override {}
+ WriteCallback callback) override {}
private:
~MockHidErrorConnection() override {}
@@ -74,13 +74,13 @@ class U2fDeviceEnumerate {
run_loop_() {}
~U2fDeviceEnumerate() {}
- void ReceivedCallback(
- const std::vector<scoped_refptr<HidDeviceInfo>>& devices) {
+ void ReceivedCallback(std::vector<device::mojom::HidDeviceInfoPtr> devices) {
std::list<std::unique_ptr<U2fHidDevice>> u2f_devices;
filter_.SetUsagePage(0xf1d0);
- for (auto device_info : devices) {
- if (filter_.Matches(device_info))
- u2f_devices.push_front(base::MakeUnique<U2fHidDevice>(device_info));
+ for (auto& device_info : devices) {
+ if (filter_.Matches(*device_info))
+ u2f_devices.push_front(
+ std::make_unique<U2fHidDevice>(std::move(device_info)));
}
devices_ = std::move(u2f_devices);
closure_.Run();
@@ -215,14 +215,14 @@ TEST_F(U2fHidDeviceTest, TestMultipleRequests) {
TEST_F(U2fHidDeviceTest, TestConnectionFailure) {
// Setup and enumerate mock device
- auto client = base::MakeUnique<MockDeviceClient>();
+ auto client = std::make_unique<MockDeviceClient>();
U2fDeviceEnumerate callback;
MockHidService* hid_service = client->hid_service();
HidCollectionInfo c_info;
c_info.usage = HidUsageAndPage(1, static_cast<HidUsageAndPage::Page>(0xf1d0));
- scoped_refptr<HidDeviceInfo> device0 =
- new HidDeviceInfo(kTestDeviceId, 0, 0, "Test Fido Device", "123FIDO",
- kHIDBusTypeUSB, c_info, 64, 64, 0);
+ scoped_refptr<HidDeviceInfo> device0 = new HidDeviceInfo(
+ kTestDeviceId, 0, 0, "Test Fido Device", "123FIDO",
+ device::mojom::HidBusType::kHIDBusTypeUSB, c_info, 64, 64, 0);
hid_service->AddDevice(device0);
hid_service->FirstEnumerationComplete();
hid_service->GetDevices(callback.callback());
@@ -260,14 +260,14 @@ TEST_F(U2fHidDeviceTest, TestConnectionFailure) {
TEST_F(U2fHidDeviceTest, TestDeviceError) {
// Setup and enumerate mock device
- auto client = base::MakeUnique<MockDeviceClient>();
+ auto client = std::make_unique<MockDeviceClient>();
U2fDeviceEnumerate callback;
MockHidService* hid_service = client->hid_service();
HidCollectionInfo c_info;
c_info.usage = HidUsageAndPage(1, static_cast<HidUsageAndPage::Page>(0xf1d0));
- scoped_refptr<HidDeviceInfo> device0 =
- new HidDeviceInfo(kTestDeviceId, 0, 0, "Test Fido Device", "123FIDO",
- kHIDBusTypeUSB, c_info, 64, 64, 0);
+ scoped_refptr<HidDeviceInfo> device0 = new HidDeviceInfo(
+ kTestDeviceId, 0, 0, "Test Fido Device", "123FIDO",
+ device::mojom::HidBusType::kHIDBusTypeUSB, c_info, 64, 64, 0);
hid_service->AddDevice(device0);
hid_service->FirstEnumerationComplete();
hid_service->GetDevices(callback.callback());
diff --git a/chromium/device/u2f/u2f_message.cc b/chromium/device/u2f/u2f_message.cc
index 0778025470c..ea30946741b 100644
--- a/chromium/device/u2f/u2f_message.cc
+++ b/chromium/device/u2f/u2f_message.cc
@@ -18,7 +18,7 @@ std::unique_ptr<U2fMessage> U2fMessage::Create(
if (data.size() > kMaxMessageSize)
return nullptr;
- return base::MakeUnique<U2fMessage>(channel_id, type, data);
+ return std::make_unique<U2fMessage>(channel_id, type, data);
}
// static
@@ -33,7 +33,7 @@ std::unique_ptr<U2fMessage> U2fMessage::CreateFromSerializedData(
if (init_packet == nullptr)
return nullptr;
- return base::MakeUnique<U2fMessage>(std::move(init_packet), remaining_size);
+ return std::make_unique<U2fMessage>(std::move(init_packet), remaining_size);
}
U2fMessage::U2fMessage(std::unique_ptr<U2fInitPacket> init_packet,
@@ -61,7 +61,7 @@ U2fMessage::U2fMessage(uint32_t channel_id,
remaining_bytes = 0;
}
- packets_.push_back(base::MakeUnique<U2fInitPacket>(
+ packets_.push_back(std::make_unique<U2fInitPacket>(
channel_id, static_cast<uint8_t>(type), std::vector<uint8_t>(first, last),
data.size()));
@@ -75,7 +75,7 @@ U2fMessage::U2fMessage(uint32_t channel_id,
remaining_bytes = 0;
}
- packets_.push_back(base::MakeUnique<U2fContinuationPacket>(
+ packets_.push_back(std::make_unique<U2fContinuationPacket>(
channel_id, sequence, std::vector<uint8_t>(first, last)));
sequence++;
}
diff --git a/chromium/device/u2f/u2f_message_unittest.cc b/chromium/device/u2f/u2f_message_unittest.cc
index 59f52c550b5..7fabd6d460e 100644
--- a/chromium/device/u2f/u2f_message_unittest.cc
+++ b/chromium/device/u2f/u2f_message_unittest.cc
@@ -18,11 +18,11 @@ TEST_F(U2fMessageTest, TestPacketSize) {
std::vector<uint8_t> data;
auto init_packet =
- base::MakeUnique<U2fInitPacket>(channel_id, 0, data, data.size());
+ std::make_unique<U2fInitPacket>(channel_id, 0, data, data.size());
EXPECT_EQ(65, init_packet->GetSerializedData()->size());
auto continuation_packet =
- base::MakeUnique<U2fContinuationPacket>(channel_id, 0, data);
+ std::make_unique<U2fContinuationPacket>(channel_id, 0, data);
EXPECT_EQ(65, continuation_packet->GetSerializedData()->size());
}
@@ -41,7 +41,7 @@ TEST_F(U2fMessageTest, TestPacketData) {
std::vector<uint8_t> data{10, 11};
uint8_t cmd = static_cast<uint8_t>(U2fMessage::Type::CMD_WINK);
auto init_packet =
- base::MakeUnique<U2fInitPacket>(channel_id, cmd, data, data.size());
+ std::make_unique<U2fInitPacket>(channel_id, cmd, data, data.size());
int index = 0;
scoped_refptr<net::IOBufferWithSize> serialized =
@@ -72,7 +72,7 @@ TEST_F(U2fMessageTest, TestPacketConstructors) {
std::vector<uint8_t> data{10, 11};
uint8_t cmd = static_cast<uint8_t>(U2fMessage::Type::CMD_WINK);
auto orig_packet =
- base::MakeUnique<U2fInitPacket>(channel_id, cmd, data, data.size());
+ std::make_unique<U2fInitPacket>(channel_id, cmd, data, data.size());
size_t payload_length = static_cast<size_t>(orig_packet->payload_length());
scoped_refptr<net::IOBufferWithSize> buffer =
diff --git a/chromium/device/u2f/u2f_packet.cc b/chromium/device/u2f/u2f_packet.cc
index 15eb47c2ac0..34549228029 100644
--- a/chromium/device/u2f/u2f_packet.cc
+++ b/chromium/device/u2f/u2f_packet.cc
@@ -64,7 +64,7 @@ std::unique_ptr<U2fInitPacket> U2fInitPacket::CreateFromSerializedData(
if (remaining_size == nullptr || serialized.size() != kPacketSize)
return nullptr;
- return base::MakeUnique<U2fInitPacket>(serialized, remaining_size);
+ return std::make_unique<U2fInitPacket>(serialized, remaining_size);
}
U2fInitPacket::U2fInitPacket(const std::vector<uint8_t>& serialized,
@@ -131,7 +131,7 @@ U2fContinuationPacket::CreateFromSerializedData(
if (remaining_size == nullptr || serialized.size() != kPacketSize)
return nullptr;
- return base::MakeUnique<U2fContinuationPacket>(serialized, remaining_size);
+ return std::make_unique<U2fContinuationPacket>(serialized, remaining_size);
}
U2fContinuationPacket::U2fContinuationPacket(
diff --git a/chromium/device/u2f/u2f_register.cc b/chromium/device/u2f/u2f_register.cc
index babfe9899f1..ae7b7d429c3 100644
--- a/chromium/device/u2f/u2f_register.cc
+++ b/chromium/device/u2f/u2f_register.cc
@@ -24,7 +24,7 @@ std::unique_ptr<U2fRequest> U2fRegister::TryRegistration(
const std::vector<uint8_t>& app_param,
const ResponseCallback& cb) {
std::unique_ptr<U2fRequest> request =
- base::MakeUnique<U2fRegister>(challenge_hash, app_param, cb);
+ std::make_unique<U2fRegister>(challenge_hash, app_param, cb);
request->Start();
return request;
}
diff --git a/chromium/device/u2f/u2f_request.cc b/chromium/device/u2f/u2f_request.cc
index a010352ba75..7fa5472ab5f 100644
--- a/chromium/device/u2f/u2f_request.cc
+++ b/chromium/device/u2f/u2f_request.cc
@@ -51,37 +51,40 @@ void U2fRequest::Start() {
void U2fRequest::Enumerate() {
HidService* hid_service = DeviceClient::Get()->GetHidService();
DCHECK(hid_service);
- hid_service_observer_.Add(hid_service);
- hid_service->GetDevices(
- base::Bind(&U2fRequest::OnEnumerate, weak_factory_.GetWeakPtr()));
+ hid_service->GetDevices(base::Bind(&U2fRequest::OnEnumerate,
+ weak_factory_.GetWeakPtr(), hid_service));
}
void U2fRequest::OnEnumerate(
- const std::vector<scoped_refptr<HidDeviceInfo>>& devices) {
- for (auto device_info : devices) {
- if (filter_.Matches(device_info))
- devices_.push_back(base::MakeUnique<U2fHidDevice>(device_info));
+ HidService* hid_service,
+ std::vector<device::mojom::HidDeviceInfoPtr> devices) {
+ for (auto& device_info : devices) {
+ if (filter_.Matches(*device_info))
+ devices_.push_back(
+ std::make_unique<U2fHidDevice>(std::move(device_info)));
}
+ hid_service_observer_.Add(hid_service);
+
state_ = State::IDLE;
Transition();
}
-void U2fRequest::OnDeviceAdded(scoped_refptr<HidDeviceInfo> device_info) {
+void U2fRequest::OnDeviceAdded(device::mojom::HidDeviceInfoPtr device_info) {
// Ignore non-U2F devices
- if (!filter_.Matches(device_info))
+ if (!filter_.Matches(*device_info))
return;
- auto device = base::MakeUnique<U2fHidDevice>(device_info);
+ auto device = std::make_unique<U2fHidDevice>(std::move(device_info));
AddDevice(std::move(device));
}
-void U2fRequest::OnDeviceRemoved(scoped_refptr<HidDeviceInfo> device_info) {
+void U2fRequest::OnDeviceRemoved(device::mojom::HidDeviceInfoPtr device_info) {
// Ignore non-U2F devices
- if (!filter_.Matches(device_info))
+ if (!filter_.Matches(*device_info))
return;
- auto device = base::MakeUnique<U2fHidDevice>(device_info);
+ auto device = std::make_unique<U2fHidDevice>(std::move(device_info));
// Check if the active device was removed
if (current_device_ && current_device_->GetId() == device->GetId()) {
diff --git a/chromium/device/u2f/u2f_request.h b/chromium/device/u2f/u2f_request.h
index f8d8f3ab840..49cec99d708 100644
--- a/chromium/device/u2f/u2f_request.h
+++ b/chromium/device/u2f/u2f_request.h
@@ -9,6 +9,7 @@
#include "base/scoped_observer.h"
#include "device/hid/hid_device_filter.h"
#include "device/hid/hid_service.h"
+#include "device/hid/public/interfaces/hid.mojom.h"
#include "u2f_device.h"
namespace device {
@@ -50,9 +51,10 @@ class U2fRequest : HidService::Observer {
void IterateDevice();
void OnWaitComplete();
void AddDevice(std::unique_ptr<U2fDevice> device);
- void OnDeviceAdded(scoped_refptr<HidDeviceInfo> device_info) override;
- void OnDeviceRemoved(scoped_refptr<HidDeviceInfo> device_info) override;
- void OnEnumerate(const std::vector<scoped_refptr<HidDeviceInfo>>& devices);
+ void OnDeviceAdded(device::mojom::HidDeviceInfoPtr device_info) override;
+ void OnDeviceRemoved(device::mojom::HidDeviceInfoPtr device_info) override;
+ void OnEnumerate(HidService* hid_service,
+ std::vector<device::mojom::HidDeviceInfoPtr> devices);
std::list<std::unique_ptr<U2fDevice>> devices_;
std::list<std::unique_ptr<U2fDevice>> attempted_devices_;
diff --git a/chromium/device/u2f/u2f_request_unittest.cc b/chromium/device/u2f/u2f_request_unittest.cc
index 718e83805a2..03261a301bc 100644
--- a/chromium/device/u2f/u2f_request_unittest.cc
+++ b/chromium/device/u2f/u2f_request_unittest.cc
@@ -10,6 +10,7 @@
#include "base/test/test_io_thread.h"
#include "device/base/mock_device_client.h"
#include "device/hid/mock_hid_service.h"
+#include "device/hid/public/interfaces/hid.mojom.h"
#include "device/test/test_device_client.h"
#include "device/test/usb_test_gadget.h"
#include "device/u2f/u2f_hid_device.h"
@@ -85,20 +86,32 @@ TEST_F(U2fRequestTest, TestAddRemoveDevice) {
TestResponseCallback cb;
FakeU2fRequest request(cb.callback());
request.Enumerate();
+
+ c_info.usage = HidUsageAndPage(1, static_cast<HidUsageAndPage::Page>(0xf1d0));
+ scoped_refptr<HidDeviceInfo> u2f_device_0 =
+ make_scoped_refptr(new HidDeviceInfo(
+ kTestDeviceId0, 0, 0, "Test Fido Device", "123FIDO",
+ device::mojom::HidBusType::kHIDBusTypeUSB, c_info, 64, 64, 0));
+ hid_service->AddDevice(u2f_device_0);
+
+ // Make sure the enumeration is finshed, so HidService is ready to send
+ // the OnDeviceAdded or OnDeviceRemoved to its observers.
+ cb.WaitForCallback();
EXPECT_EQ(static_cast<size_t>(0), request.devices_.size());
// Add one U2F device
- c_info.usage = HidUsageAndPage(1, static_cast<HidUsageAndPage::Page>(0xf1d0));
- scoped_refptr<HidDeviceInfo> u2f_device = make_scoped_refptr(
- new HidDeviceInfo(kTestDeviceId0, 0, 0, "Test Fido Device", "123FIDO",
- kHIDBusTypeUSB, c_info, 64, 64, 0));
- hid_service->AddDevice(u2f_device);
+ scoped_refptr<HidDeviceInfo> u2f_device_1 =
+ make_scoped_refptr(new HidDeviceInfo(
+ kTestDeviceId1, 0, 0, "Test Fido Device", "123FIDO",
+ device::mojom::HidBusType::kHIDBusTypeUSB, c_info, 64, 64, 0));
+ hid_service->AddDevice(u2f_device_1);
EXPECT_EQ(static_cast<size_t>(1), request.devices_.size());
// Add one non-U2F device. Verify that it is not added to our device list.
- scoped_refptr<HidDeviceInfo> other_device = make_scoped_refptr(
- new HidDeviceInfo(kTestDeviceId2, 0, 0, "Other Device", "OtherDevice",
- kHIDBusTypeUSB, std::vector<uint8_t>()));
+ scoped_refptr<HidDeviceInfo> other_device =
+ make_scoped_refptr(new HidDeviceInfo(
+ kTestDeviceId2, 0, 0, "Other Device", "OtherDevice",
+ device::mojom::HidBusType::kHIDBusTypeUSB, std::vector<uint8_t>()));
hid_service->AddDevice(other_device);
EXPECT_EQ(static_cast<size_t>(1), request.devices_.size());
@@ -107,7 +120,7 @@ TEST_F(U2fRequestTest, TestAddRemoveDevice) {
EXPECT_EQ(static_cast<size_t>(1), request.devices_.size());
// Remove the U2F device and verify that device list is empty.
- hid_service->RemoveDevice(kTestDeviceId0);
+ hid_service->RemoveDevice(kTestDeviceId1);
EXPECT_EQ(static_cast<size_t>(0), request.devices_.size());
}
@@ -117,14 +130,16 @@ TEST_F(U2fRequestTest, TestIterateDevice) {
HidCollectionInfo c_info;
// Add one U2F device and one non-U2f device
c_info.usage = HidUsageAndPage(1, static_cast<HidUsageAndPage::Page>(0xf1d0));
- scoped_refptr<HidDeviceInfo> device0 = make_scoped_refptr(
- new HidDeviceInfo(kTestDeviceId0, 0, 0, "Test Fido Device", "123FIDO",
- kHIDBusTypeUSB, c_info, 64, 64, 0));
- request.devices_.push_back(base::MakeUnique<U2fHidDevice>(device0));
- scoped_refptr<HidDeviceInfo> device1 = make_scoped_refptr(
- new HidDeviceInfo(kTestDeviceId1, 0, 0, "Test Fido Device", "123FIDO",
- kHIDBusTypeUSB, c_info, 64, 64, 0));
- request.devices_.push_back(base::MakeUnique<U2fHidDevice>(device1));
+ scoped_refptr<HidDeviceInfo> device0 = make_scoped_refptr(new HidDeviceInfo(
+ kTestDeviceId0, 0, 0, "Test Fido Device", "123FIDO",
+ device::mojom::HidBusType::kHIDBusTypeUSB, c_info, 64, 64, 0));
+ request.devices_.push_back(
+ std::make_unique<U2fHidDevice>(device0->device()->Clone()));
+ scoped_refptr<HidDeviceInfo> device1 = make_scoped_refptr(new HidDeviceInfo(
+ kTestDeviceId1, 0, 0, "Test Fido Device", "123FIDO",
+ device::mojom::HidBusType::kHIDBusTypeUSB, c_info, 64, 64, 0));
+ request.devices_.push_back(
+ std::make_unique<U2fHidDevice>(device1->device()->Clone()));
// Move first device to current
request.IterateDevice();
@@ -153,9 +168,10 @@ TEST_F(U2fRequestTest, TestBasicMachine) {
// Add one U2F device
HidCollectionInfo c_info;
c_info.usage = HidUsageAndPage(1, static_cast<HidUsageAndPage::Page>(0xf1d0));
- scoped_refptr<HidDeviceInfo> u2f_device = make_scoped_refptr(
- new HidDeviceInfo(kTestDeviceId0, 0, 0, "Test Fido Device", "123FIDO",
- kHIDBusTypeUSB, c_info, 64, 64, 0));
+ scoped_refptr<HidDeviceInfo> u2f_device =
+ make_scoped_refptr(new HidDeviceInfo(
+ kTestDeviceId0, 0, 0, "Test Fido Device", "123FIDO",
+ device::mojom::HidBusType::kHIDBusTypeUSB, c_info, 64, 64, 0));
hid_service->AddDevice(u2f_device);
cb.WaitForCallback();
EXPECT_EQ(U2fRequest::State::BUSY, request.state_);
diff --git a/chromium/device/u2f/u2f_sign.cc b/chromium/device/u2f/u2f_sign.cc
index a1f5b7d3d5a..efa71365617 100644
--- a/chromium/device/u2f/u2f_sign.cc
+++ b/chromium/device/u2f/u2f_sign.cc
@@ -27,7 +27,7 @@ std::unique_ptr<U2fRequest> U2fSign::TrySign(
const std::vector<uint8_t>& app_param,
const ResponseCallback& cb) {
std::unique_ptr<U2fRequest> request =
- base::MakeUnique<U2fSign>(registered_keys, challenge_hash, app_param, cb);
+ std::make_unique<U2fSign>(registered_keys, challenge_hash, app_param, cb);
request->Start();
return request;
}
diff --git a/chromium/device/usb/BUILD.gn b/chromium/device/usb/BUILD.gn
index 5cb128ff408..260e83b9d3e 100644
--- a/chromium/device/usb/BUILD.gn
+++ b/chromium/device/usb/BUILD.gn
@@ -16,8 +16,6 @@ generated_ids = "$target_gen_dir/usb_ids_gen.cc"
static_library("usb") {
sources = [
- "android/usb_jni_registrar.cc",
- "android/usb_jni_registrar.h",
"usb_configuration_android.cc",
"usb_configuration_android.h",
"usb_descriptors.cc",
diff --git a/chromium/device/usb/fake_usb_device_handle.cc b/chromium/device/usb/fake_usb_device_handle.cc
index 78c0134b761..afc6567617c 100644
--- a/chromium/device/usb/fake_usb_device_handle.cc
+++ b/chromium/device/usb/fake_usb_device_handle.cc
@@ -24,33 +24,32 @@ void FakeUsbDeviceHandle::Close() {
}
void FakeUsbDeviceHandle::SetConfiguration(int configuration_value,
- const ResultCallback& callback) {
+ ResultCallback callback) {
NOTIMPLEMENTED();
}
void FakeUsbDeviceHandle::ClaimInterface(int interface_number,
- const ResultCallback& callback) {
+ ResultCallback callback) {
NOTIMPLEMENTED();
}
void FakeUsbDeviceHandle::ReleaseInterface(int interface_number,
- const ResultCallback& callback) {
+ ResultCallback callback) {
NOTIMPLEMENTED();
}
void FakeUsbDeviceHandle::SetInterfaceAlternateSetting(
int interface_number,
int alternate_setting,
- const ResultCallback& callback) {
+ ResultCallback callback) {
NOTIMPLEMENTED();
}
-void FakeUsbDeviceHandle::ResetDevice(const ResultCallback& callback) {
+void FakeUsbDeviceHandle::ResetDevice(ResultCallback callback) {
NOTIMPLEMENTED();
}
-void FakeUsbDeviceHandle::ClearHalt(uint8_t endpoint,
- const ResultCallback& callback) {
+void FakeUsbDeviceHandle::ClearHalt(uint8_t endpoint, ResultCallback callback) {
NOTIMPLEMENTED();
}
@@ -64,9 +63,9 @@ void FakeUsbDeviceHandle::ControlTransfer(
scoped_refptr<net::IOBuffer> buffer,
size_t length,
unsigned int timeout,
- const UsbDeviceHandle::TransferCallback& callback) {
+ UsbDeviceHandle::TransferCallback callback) {
if (position_ == size_) {
- callback.Run(UsbTransferStatus::DISCONNECT, buffer, 0);
+ std::move(callback).Run(UsbTransferStatus::DISCONNECT, buffer, 0);
return;
}
@@ -84,9 +83,10 @@ void FakeUsbDeviceHandle::ControlTransfer(
position_ += bytes_transferred;
}
- callback.Run(UsbTransferStatus::COMPLETED, buffer, bytes_transferred);
+ std::move(callback).Run(UsbTransferStatus::COMPLETED, buffer,
+ bytes_transferred);
} else {
- callback.Run(UsbTransferStatus::TRANSFER_ERROR, buffer, 0);
+ std::move(callback).Run(UsbTransferStatus::TRANSFER_ERROR, buffer, 0);
}
}
@@ -94,7 +94,7 @@ void FakeUsbDeviceHandle::IsochronousTransferIn(
uint8_t endpoint_number,
const std::vector<uint32_t>& packet_lengths,
unsigned int timeout,
- const IsochronousTransferCallback& callback) {
+ IsochronousTransferCallback callback) {
NOTIMPLEMENTED();
}
@@ -103,7 +103,7 @@ void FakeUsbDeviceHandle::IsochronousTransferOut(
scoped_refptr<net::IOBuffer> buffer,
const std::vector<uint32_t>& packet_lengths,
unsigned int timeout,
- const IsochronousTransferCallback& callback) {
+ IsochronousTransferCallback callback) {
NOTIMPLEMENTED();
}
@@ -112,7 +112,7 @@ void FakeUsbDeviceHandle::GenericTransfer(UsbTransferDirection direction,
scoped_refptr<net::IOBuffer> buffer,
size_t length,
unsigned int timeout,
- const TransferCallback& callback) {
+ TransferCallback callback) {
NOTIMPLEMENTED();
}
diff --git a/chromium/device/usb/fake_usb_device_handle.h b/chromium/device/usb/fake_usb_device_handle.h
index ebfde3e85b3..d61dc4bb844 100644
--- a/chromium/device/usb/fake_usb_device_handle.h
+++ b/chromium/device/usb/fake_usb_device_handle.h
@@ -29,16 +29,14 @@ class FakeUsbDeviceHandle : public UsbDeviceHandle {
scoped_refptr<UsbDevice> GetDevice() const override;
void Close() override;
void SetConfiguration(int configuration_value,
- const ResultCallback& callback) override;
- void ClaimInterface(int interface_number,
- const ResultCallback& callback) override;
- void ReleaseInterface(int interface_number,
- const ResultCallback& callback) override;
+ ResultCallback callback) override;
+ void ClaimInterface(int interface_number, ResultCallback callback) override;
+ void ReleaseInterface(int interface_number, ResultCallback callback) override;
void SetInterfaceAlternateSetting(int interface_number,
int alternate_setting,
- const ResultCallback& callback) override;
- void ResetDevice(const ResultCallback& callback) override;
- void ClearHalt(uint8_t endpoint, const ResultCallback& callback) override;
+ ResultCallback callback) override;
+ void ResetDevice(ResultCallback callback) override;
+ void ClearHalt(uint8_t endpoint, ResultCallback callback) override;
void ControlTransfer(UsbTransferDirection direction,
UsbControlTransferType request_type,
@@ -49,27 +47,25 @@ class FakeUsbDeviceHandle : public UsbDeviceHandle {
scoped_refptr<net::IOBuffer> buffer,
size_t length,
unsigned int timeout,
- const TransferCallback& callback) override;
+ TransferCallback callback) override;
- void IsochronousTransferIn(
- uint8_t endpoint,
- const std::vector<uint32_t>& packet_lengths,
- unsigned int timeout,
- const IsochronousTransferCallback& callback) override;
+ void IsochronousTransferIn(uint8_t endpoint,
+ const std::vector<uint32_t>& packet_lengths,
+ unsigned int timeout,
+ IsochronousTransferCallback callback) override;
- void IsochronousTransferOut(
- uint8_t endpoint,
- scoped_refptr<net::IOBuffer> buffer,
- const std::vector<uint32_t>& packet_lengths,
- unsigned int timeout,
- const IsochronousTransferCallback& callback) override;
+ void IsochronousTransferOut(uint8_t endpoint,
+ scoped_refptr<net::IOBuffer> buffer,
+ const std::vector<uint32_t>& packet_lengths,
+ unsigned int timeout,
+ IsochronousTransferCallback callback) override;
void GenericTransfer(UsbTransferDirection direction,
uint8_t endpoint_number,
scoped_refptr<net::IOBuffer> buffer,
size_t length,
unsigned int timeout,
- const TransferCallback& callback) override;
+ TransferCallback callback) override;
const UsbInterfaceDescriptor* FindInterfaceByEndpoint(
uint8_t endpoint_address) override;
diff --git a/chromium/device/usb/mock_usb_device.h b/chromium/device/usb/mock_usb_device.h
index 6f3d0526c30..f03954e392c 100644
--- a/chromium/device/usb/mock_usb_device.h
+++ b/chromium/device/usb/mock_usb_device.h
@@ -44,7 +44,8 @@ class MockUsbDevice : public UsbDevice {
const std::string& serial_number,
const std::vector<UsbConfigDescriptor>& configurations);
- MOCK_METHOD1(Open, void(const OpenCallback&));
+ void Open(OpenCallback callback) { OpenInternal(callback); }
+ MOCK_METHOD1(OpenInternal, void(OpenCallback&));
void AddMockConfig(const UsbConfigDescriptor& config);
diff --git a/chromium/device/usb/mock_usb_device_handle.h b/chromium/device/usb/mock_usb_device_handle.h
index 15e6974f739..215160f12bd 100644
--- a/chromium/device/usb/mock_usb_device_handle.h
+++ b/chromium/device/usb/mock_usb_device_handle.h
@@ -22,20 +22,65 @@ class MockUsbDeviceHandle : public UsbDeviceHandle {
scoped_refptr<UsbDevice> GetDevice() const override;
MOCK_METHOD0(Close, void());
- MOCK_METHOD2(SetConfiguration,
- void(int configuration_value, const ResultCallback& callback));
- MOCK_METHOD2(ClaimInterface,
- void(int interface_number, const ResultCallback& callback));
- MOCK_METHOD2(ReleaseInterface,
- void(int interface_number, const ResultCallback& callback));
- MOCK_METHOD3(SetInterfaceAlternateSetting,
+
+ // TODO(crbug.com/729950): Use MOCK_METHOD directly once GMock gets the
+ // move-only type support.
+ void SetConfiguration(int configuration_value,
+ ResultCallback callback) override {
+ SetConfigurationInternal(configuration_value, callback);
+ }
+ MOCK_METHOD2(SetConfigurationInternal,
+ void(int configuration_value, ResultCallback& callback));
+
+ void ClaimInterface(int interface_number, ResultCallback callback) override {
+ ClaimInterfaceInternal(interface_number, callback);
+ }
+ MOCK_METHOD2(ClaimInterfaceInternal,
+ void(int interface_number, ResultCallback& callback));
+
+ void ReleaseInterface(int interface_number,
+ ResultCallback callback) override {
+ ReleaseInterfaceInternal(interface_number, callback);
+ }
+ MOCK_METHOD2(ReleaseInterfaceInternal,
+ void(int interface_number, ResultCallback& callback));
+
+ void SetInterfaceAlternateSetting(int interface_number,
+ int alternate_setting,
+ ResultCallback callback) override {
+ SetInterfaceAlternateSettingInternal(interface_number, alternate_setting,
+ callback);
+ }
+ MOCK_METHOD3(SetInterfaceAlternateSettingInternal,
void(int interface_number,
int alternate_setting,
- const ResultCallback& callback));
- MOCK_METHOD1(ResetDevice, void(const ResultCallback& callback));
- MOCK_METHOD2(ClearHalt,
- void(uint8_t endpoint, const ResultCallback& callback));
- MOCK_METHOD10(ControlTransfer,
+ ResultCallback& callback));
+
+ void ResetDevice(ResultCallback callback) override {
+ ResetDeviceInternal(callback);
+ }
+ MOCK_METHOD1(ResetDeviceInternal, void(ResultCallback& callback));
+
+ void ClearHalt(uint8_t endpoint, ResultCallback callback) override {
+ ClearHaltInternal(endpoint, callback);
+ }
+ MOCK_METHOD2(ClearHaltInternal,
+ void(uint8_t endpoint, ResultCallback& callback));
+
+ void ControlTransfer(UsbTransferDirection direction,
+ UsbControlTransferType request_type,
+ UsbControlTransferRecipient recipient,
+ uint8_t request,
+ uint16_t value,
+ uint16_t index,
+ scoped_refptr<net::IOBuffer> buffer,
+ size_t length,
+ unsigned int timeout,
+ TransferCallback callback) override {
+ ControlTransferInternal(direction, request_type, recipient, request, value,
+ index, buffer, length, timeout, callback);
+ }
+ MOCK_METHOD10(ControlTransferInternal,
void(UsbTransferDirection direction,
UsbControlTransferType request_type,
UsbControlTransferRecipient recipient,
@@ -45,25 +90,52 @@ class MockUsbDeviceHandle : public UsbDeviceHandle {
scoped_refptr<net::IOBuffer> buffer,
size_t length,
unsigned int timeout,
- const TransferCallback& callback));
- MOCK_METHOD4(IsochronousTransferIn,
+ TransferCallback& callback));
+
+ void IsochronousTransferIn(uint8_t endpoint,
+ const std::vector<uint32_t>& packet_lengths,
+ unsigned int timeout,
+ IsochronousTransferCallback callback) override {
+ IsochronousTransferInInternal(endpoint, packet_lengths, timeout, callback);
+ }
+ MOCK_METHOD4(IsochronousTransferInInternal,
void(uint8_t endpoint,
const std::vector<uint32_t>& packet_lengths,
unsigned int timeout,
- const IsochronousTransferCallback& callback));
- MOCK_METHOD5(IsochronousTransferOut,
+ IsochronousTransferCallback& callback));
+
+ void IsochronousTransferOut(uint8_t endpoint,
+ scoped_refptr<net::IOBuffer> buffer,
+ const std::vector<uint32_t>& packet_lengths,
+ unsigned int timeout,
+ IsochronousTransferCallback callback) override {
+ IsochronousTransferOutInternal(endpoint, buffer, packet_lengths, timeout,
+ callback);
+ }
+ MOCK_METHOD5(IsochronousTransferOutInternal,
void(uint8_t endpoint,
scoped_refptr<net::IOBuffer> buffer,
const std::vector<uint32_t>& packet_lengths,
unsigned int timeout,
- const IsochronousTransferCallback& callback));
- MOCK_METHOD6(GenericTransfer,
+ IsochronousTransferCallback& callback));
+
+ void GenericTransfer(UsbTransferDirection direction,
+ uint8_t endpoint,
+ scoped_refptr<net::IOBuffer> buffer,
+ size_t length,
+ unsigned int timeout,
+ TransferCallback callback) override {
+ GenericTransferInternal(direction, endpoint, buffer, length, timeout,
+ callback);
+ }
+ MOCK_METHOD6(GenericTransferInternal,
void(UsbTransferDirection direction,
uint8_t endpoint,
scoped_refptr<net::IOBuffer> buffer,
size_t length,
unsigned int timeout,
- const TransferCallback& callback));
+ TransferCallback& callback));
+
MOCK_METHOD1(FindInterfaceByEndpoint,
const UsbInterfaceDescriptor*(uint8_t endpoint_address));
diff --git a/chromium/device/usb/mojo/device_impl.cc b/chromium/device/usb/mojo/device_impl.cc
index 6bbb81bba61..e561d8010c5 100644
--- a/chromium/device/usb/mojo/device_impl.cc
+++ b/chromium/device/usb/mojo/device_impl.cc
@@ -35,7 +35,7 @@ scoped_refptr<net::IOBuffer> CreateTransferBuffer(size_t size) {
std::max(static_cast<size_t>(1u), static_cast<size_t>(size)));
}
-void OnTransferIn(const mojom::UsbDevice::GenericTransferInCallback& callback,
+void OnTransferIn(mojom::UsbDevice::GenericTransferInCallback callback,
UsbTransferStatus status,
scoped_refptr<net::IOBuffer> buffer,
size_t buffer_size) {
@@ -48,14 +48,15 @@ void OnTransferIn(const mojom::UsbDevice::GenericTransferInCallback& callback,
std::copy(buffer->data(), buffer->data() + buffer_size, data.begin());
}
- callback.Run(mojo::ConvertTo<mojom::UsbTransferStatus>(status), data);
+ std::move(callback).Run(mojo::ConvertTo<mojom::UsbTransferStatus>(status),
+ data);
}
-void OnTransferOut(const mojom::UsbDevice::GenericTransferOutCallback& callback,
+void OnTransferOut(mojom::UsbDevice::GenericTransferOutCallback callback,
UsbTransferStatus status,
scoped_refptr<net::IOBuffer> buffer,
size_t buffer_size) {
- callback.Run(mojo::ConvertTo<mojom::UsbTransferStatus>(status));
+ std::move(callback).Run(mojo::ConvertTo<mojom::UsbTransferStatus>(status));
}
std::vector<mojom::UsbIsochronousPacketPtr> BuildIsochronousPacketArray(
@@ -73,7 +74,7 @@ std::vector<mojom::UsbIsochronousPacketPtr> BuildIsochronousPacketArray(
}
void OnIsochronousTransferIn(
- const mojom::UsbDevice::IsochronousTransferInCallback& callback,
+ mojom::UsbDevice::IsochronousTransferInCallback callback,
scoped_refptr<net::IOBuffer> buffer,
const std::vector<UsbDeviceHandle::IsochronousPacket>& packets) {
std::vector<uint8_t> data;
@@ -90,16 +91,16 @@ void OnIsochronousTransferIn(
data.resize(buffer_size);
std::copy(buffer->data(), buffer->data() + buffer_size, data.begin());
}
- callback.Run(
+ std::move(callback).Run(
data,
mojo::ConvertTo<std::vector<mojom::UsbIsochronousPacketPtr>>(packets));
}
void OnIsochronousTransferOut(
- const mojom::UsbDevice::IsochronousTransferOutCallback& callback,
+ mojom::UsbDevice::IsochronousTransferOutCallback callback,
scoped_refptr<net::IOBuffer> buffer,
const std::vector<UsbDeviceHandle::IsochronousPacket>& packets) {
- callback.Run(
+ std::move(callback).Run(
mojo::ConvertTo<std::vector<mojom::UsbIsochronousPacketPtr>>(packets));
}
@@ -170,7 +171,7 @@ bool DeviceImpl::HasControlTransferPermission(
// static
void DeviceImpl::OnOpen(base::WeakPtr<DeviceImpl> self,
- const OpenCallback& callback,
+ OpenCallback callback,
scoped_refptr<UsbDeviceHandle> handle) {
if (!self) {
handle->Close();
@@ -180,62 +181,63 @@ void DeviceImpl::OnOpen(base::WeakPtr<DeviceImpl> self,
self->device_handle_ = std::move(handle);
if (self->device_handle_ && self->permission_provider_)
self->permission_provider_->IncrementConnectionCount();
- callback.Run(self->device_handle_ ? mojom::UsbOpenDeviceError::OK
- : mojom::UsbOpenDeviceError::ACCESS_DENIED);
+ std::move(callback).Run(self->device_handle_
+ ? mojom::UsbOpenDeviceError::OK
+ : mojom::UsbOpenDeviceError::ACCESS_DENIED);
}
-void DeviceImpl::OnPermissionGrantedForOpen(const OpenCallback& callback,
+void DeviceImpl::OnPermissionGrantedForOpen(OpenCallback callback,
bool granted) {
if (granted) {
- device_->Open(
- base::Bind(&DeviceImpl::OnOpen, weak_factory_.GetWeakPtr(), callback));
+ device_->Open(base::BindOnce(
+ &DeviceImpl::OnOpen, weak_factory_.GetWeakPtr(), std::move(callback)));
} else {
- callback.Run(mojom::UsbOpenDeviceError::ACCESS_DENIED);
+ std::move(callback).Run(mojom::UsbOpenDeviceError::ACCESS_DENIED);
}
}
-void DeviceImpl::Open(const OpenCallback& callback) {
+void DeviceImpl::Open(OpenCallback callback) {
if (device_handle_) {
- callback.Run(mojom::UsbOpenDeviceError::ALREADY_OPEN);
+ std::move(callback).Run(mojom::UsbOpenDeviceError::ALREADY_OPEN);
return;
}
if (!device_->permission_granted()) {
device_->RequestPermission(
- base::Bind(&DeviceImpl::OnPermissionGrantedForOpen,
- weak_factory_.GetWeakPtr(), callback));
+ base::BindOnce(&DeviceImpl::OnPermissionGrantedForOpen,
+ weak_factory_.GetWeakPtr(), std::move(callback)));
return;
}
- device_->Open(
- base::Bind(&DeviceImpl::OnOpen, weak_factory_.GetWeakPtr(), callback));
+ device_->Open(base::BindOnce(&DeviceImpl::OnOpen, weak_factory_.GetWeakPtr(),
+ std::move(callback)));
}
-void DeviceImpl::Close(const CloseCallback& callback) {
+void DeviceImpl::Close(CloseCallback callback) {
CloseHandle();
- callback.Run();
+ std::move(callback).Run();
}
void DeviceImpl::SetConfiguration(uint8_t value,
- const SetConfigurationCallback& callback) {
+ SetConfigurationCallback callback) {
if (!device_handle_) {
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
- device_handle_->SetConfiguration(value, callback);
+ device_handle_->SetConfiguration(value, std::move(callback));
}
void DeviceImpl::ClaimInterface(uint8_t interface_number,
- const ClaimInterfaceCallback& callback) {
+ ClaimInterfaceCallback callback) {
if (!device_handle_) {
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
const UsbConfigDescriptor* config = device_->active_configuration();
if (!config) {
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
@@ -245,61 +247,61 @@ void DeviceImpl::ClaimInterface(uint8_t interface_number,
return interface.interface_number == interface_number;
});
if (interface_it == config->interfaces.end()) {
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
- device_handle_->ClaimInterface(interface_number, callback);
+ device_handle_->ClaimInterface(interface_number, std::move(callback));
}
void DeviceImpl::ReleaseInterface(uint8_t interface_number,
- const ReleaseInterfaceCallback& callback) {
+ ReleaseInterfaceCallback callback) {
if (!device_handle_) {
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
- device_handle_->ReleaseInterface(interface_number, callback);
+ device_handle_->ReleaseInterface(interface_number, std::move(callback));
}
void DeviceImpl::SetInterfaceAlternateSetting(
uint8_t interface_number,
uint8_t alternate_setting,
- const SetInterfaceAlternateSettingCallback& callback) {
+ SetInterfaceAlternateSettingCallback callback) {
if (!device_handle_) {
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
- device_handle_->SetInterfaceAlternateSetting(interface_number,
- alternate_setting, callback);
+ device_handle_->SetInterfaceAlternateSetting(
+ interface_number, alternate_setting, std::move(callback));
}
-void DeviceImpl::Reset(const ResetCallback& callback) {
+void DeviceImpl::Reset(ResetCallback callback) {
if (!device_handle_) {
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
- device_handle_->ResetDevice(callback);
+ device_handle_->ResetDevice(std::move(callback));
}
-void DeviceImpl::ClearHalt(uint8_t endpoint,
- const ClearHaltCallback& callback) {
+void DeviceImpl::ClearHalt(uint8_t endpoint, ClearHaltCallback callback) {
if (!device_handle_) {
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
- device_handle_->ClearHalt(endpoint, callback);
+ device_handle_->ClearHalt(endpoint, std::move(callback));
}
void DeviceImpl::ControlTransferIn(UsbControlTransferParamsPtr params,
uint32_t length,
uint32_t timeout,
- const ControlTransferInCallback& callback) {
+ ControlTransferInCallback callback) {
if (!device_handle_) {
- callback.Run(mojom::UsbTransferStatus::TRANSFER_ERROR, base::nullopt);
+ std::move(callback).Run(mojom::UsbTransferStatus::TRANSFER_ERROR,
+ base::nullopt);
return;
}
@@ -308,19 +310,19 @@ void DeviceImpl::ControlTransferIn(UsbControlTransferParamsPtr params,
device_handle_->ControlTransfer(
UsbTransferDirection::INBOUND, params->type, params->recipient,
params->request, params->value, params->index, buffer, length, timeout,
- base::Bind(&OnTransferIn, callback));
+ base::BindOnce(&OnTransferIn, std::move(callback)));
} else {
- callback.Run(mojom::UsbTransferStatus::PERMISSION_DENIED, base::nullopt);
+ std::move(callback).Run(mojom::UsbTransferStatus::PERMISSION_DENIED,
+ base::nullopt);
}
}
-void DeviceImpl::ControlTransferOut(
- UsbControlTransferParamsPtr params,
- const std::vector<uint8_t>& data,
- uint32_t timeout,
- const ControlTransferOutCallback& callback) {
+void DeviceImpl::ControlTransferOut(UsbControlTransferParamsPtr params,
+ const std::vector<uint8_t>& data,
+ uint32_t timeout,
+ ControlTransferOutCallback callback) {
if (!device_handle_) {
- callback.Run(mojom::UsbTransferStatus::TRANSFER_ERROR);
+ std::move(callback).Run(mojom::UsbTransferStatus::TRANSFER_ERROR);
return;
}
@@ -330,35 +332,35 @@ void DeviceImpl::ControlTransferOut(
device_handle_->ControlTransfer(
UsbTransferDirection::OUTBOUND, params->type, params->recipient,
params->request, params->value, params->index, buffer, data.size(),
- timeout, base::Bind(&OnTransferOut, callback));
+ timeout, base::BindOnce(&OnTransferOut, std::move(callback)));
} else {
- callback.Run(mojom::UsbTransferStatus::PERMISSION_DENIED);
+ std::move(callback).Run(mojom::UsbTransferStatus::PERMISSION_DENIED);
}
}
void DeviceImpl::GenericTransferIn(uint8_t endpoint_number,
uint32_t length,
uint32_t timeout,
- const GenericTransferInCallback& callback) {
+ GenericTransferInCallback callback) {
if (!device_handle_) {
- callback.Run(mojom::UsbTransferStatus::TRANSFER_ERROR, base::nullopt);
+ std::move(callback).Run(mojom::UsbTransferStatus::TRANSFER_ERROR,
+ base::nullopt);
return;
}
uint8_t endpoint_address = endpoint_number | 0x80;
scoped_refptr<net::IOBuffer> buffer = CreateTransferBuffer(length);
- device_handle_->GenericTransfer(UsbTransferDirection::INBOUND,
- endpoint_address, buffer, length, timeout,
- base::Bind(&OnTransferIn, callback));
+ device_handle_->GenericTransfer(
+ UsbTransferDirection::INBOUND, endpoint_address, buffer, length, timeout,
+ base::BindOnce(&OnTransferIn, std::move(callback)));
}
-void DeviceImpl::GenericTransferOut(
- uint8_t endpoint_number,
- const std::vector<uint8_t>& data,
- uint32_t timeout,
- const GenericTransferOutCallback& callback) {
+void DeviceImpl::GenericTransferOut(uint8_t endpoint_number,
+ const std::vector<uint8_t>& data,
+ uint32_t timeout,
+ GenericTransferOutCallback callback) {
if (!device_handle_) {
- callback.Run(mojom::UsbTransferStatus::TRANSFER_ERROR);
+ std::move(callback).Run(mojom::UsbTransferStatus::TRANSFER_ERROR);
return;
}
@@ -367,25 +369,26 @@ void DeviceImpl::GenericTransferOut(
std::copy(data.begin(), data.end(), buffer->data());
device_handle_->GenericTransfer(
UsbTransferDirection::OUTBOUND, endpoint_address, buffer, data.size(),
- timeout, base::Bind(&OnTransferOut, callback));
+ timeout, base::BindOnce(&OnTransferOut, std::move(callback)));
}
void DeviceImpl::IsochronousTransferIn(
uint8_t endpoint_number,
const std::vector<uint32_t>& packet_lengths,
uint32_t timeout,
- const IsochronousTransferInCallback& callback) {
+ IsochronousTransferInCallback callback) {
if (!device_handle_) {
- callback.Run(base::nullopt,
- BuildIsochronousPacketArray(
- packet_lengths, mojom::UsbTransferStatus::TRANSFER_ERROR));
+ std::move(callback).Run(
+ base::nullopt,
+ BuildIsochronousPacketArray(packet_lengths,
+ mojom::UsbTransferStatus::TRANSFER_ERROR));
return;
}
uint8_t endpoint_address = endpoint_number | 0x80;
device_handle_->IsochronousTransferIn(
endpoint_address, packet_lengths, timeout,
- base::Bind(&OnIsochronousTransferIn, callback));
+ base::BindOnce(&OnIsochronousTransferIn, std::move(callback)));
}
void DeviceImpl::IsochronousTransferOut(
@@ -393,9 +396,9 @@ void DeviceImpl::IsochronousTransferOut(
const std::vector<uint8_t>& data,
const std::vector<uint32_t>& packet_lengths,
uint32_t timeout,
- const IsochronousTransferOutCallback& callback) {
+ IsochronousTransferOutCallback callback) {
if (!device_handle_) {
- callback.Run(BuildIsochronousPacketArray(
+ std::move(callback).Run(BuildIsochronousPacketArray(
packet_lengths, mojom::UsbTransferStatus::TRANSFER_ERROR));
return;
}
@@ -405,7 +408,7 @@ void DeviceImpl::IsochronousTransferOut(
std::copy(data.begin(), data.end(), buffer->data());
device_handle_->IsochronousTransferOut(
endpoint_address, buffer, packet_lengths, timeout,
- base::Bind(&OnIsochronousTransferOut, callback));
+ base::BindOnce(&OnIsochronousTransferOut, std::move(callback)));
}
void DeviceImpl::OnDeviceRemoved(scoped_refptr<device::UsbDevice> device) {
diff --git a/chromium/device/usb/mojo/device_impl.h b/chromium/device/usb/mojo/device_impl.h
index 02983cae5fe..052956a1eab 100644
--- a/chromium/device/usb/mojo/device_impl.h
+++ b/chromium/device/usb/mojo/device_impl.h
@@ -50,52 +50,50 @@ class DeviceImpl : public mojom::UsbDevice, public device::UsbDevice::Observer {
// Handles completion of an open request.
static void OnOpen(base::WeakPtr<DeviceImpl> device,
- const OpenCallback& callback,
+ OpenCallback callback,
scoped_refptr<device::UsbDeviceHandle> handle);
- void OnPermissionGrantedForOpen(const OpenCallback& callback, bool granted);
+ void OnPermissionGrantedForOpen(OpenCallback callback, bool granted);
// Device implementation:
- void Open(const OpenCallback& callback) override;
- void Close(const CloseCallback& callback) override;
+ void Open(OpenCallback callback) override;
+ void Close(CloseCallback callback) override;
void SetConfiguration(uint8_t value,
- const SetConfigurationCallback& callback) override;
+ SetConfigurationCallback callback) override;
void ClaimInterface(uint8_t interface_number,
- const ClaimInterfaceCallback& callback) override;
+ ClaimInterfaceCallback callback) override;
void ReleaseInterface(uint8_t interface_number,
- const ReleaseInterfaceCallback& callback) override;
+ ReleaseInterfaceCallback callback) override;
void SetInterfaceAlternateSetting(
uint8_t interface_number,
uint8_t alternate_setting,
- const SetInterfaceAlternateSettingCallback& callback) override;
- void Reset(const ResetCallback& callback) override;
- void ClearHalt(uint8_t endpoint, const ClearHaltCallback& callback) override;
+ SetInterfaceAlternateSettingCallback callback) override;
+ void Reset(ResetCallback callback) override;
+ void ClearHalt(uint8_t endpoint, ClearHaltCallback callback) override;
void ControlTransferIn(mojom::UsbControlTransferParamsPtr params,
uint32_t length,
uint32_t timeout,
- const ControlTransferInCallback& callback) override;
+ ControlTransferInCallback callback) override;
void ControlTransferOut(mojom::UsbControlTransferParamsPtr params,
const std::vector<uint8_t>& data,
uint32_t timeout,
- const ControlTransferOutCallback& callback) override;
+ ControlTransferOutCallback callback) override;
void GenericTransferIn(uint8_t endpoint_number,
uint32_t length,
uint32_t timeout,
- const GenericTransferInCallback& callback) override;
+ GenericTransferInCallback callback) override;
void GenericTransferOut(uint8_t endpoint_number,
const std::vector<uint8_t>& data,
uint32_t timeout,
- const GenericTransferOutCallback& callback) override;
- void IsochronousTransferIn(
- uint8_t endpoint_number,
- const std::vector<uint32_t>& packet_lengths,
- uint32_t timeout,
- const IsochronousTransferInCallback& callback) override;
- void IsochronousTransferOut(
- uint8_t endpoint_number,
- const std::vector<uint8_t>& data,
- const std::vector<uint32_t>& packet_lengths,
- uint32_t timeout,
- const IsochronousTransferOutCallback& callback) override;
+ GenericTransferOutCallback callback) override;
+ void IsochronousTransferIn(uint8_t endpoint_number,
+ const std::vector<uint32_t>& packet_lengths,
+ uint32_t timeout,
+ IsochronousTransferInCallback callback) override;
+ void IsochronousTransferOut(uint8_t endpoint_number,
+ const std::vector<uint8_t>& data,
+ const std::vector<uint32_t>& packet_lengths,
+ uint32_t timeout,
+ IsochronousTransferOutCallback callback) override;
// device::UsbDevice::Observer implementation:
void OnDeviceRemoved(scoped_refptr<device::UsbDevice> device) override;
diff --git a/chromium/device/usb/mojo/device_impl_unittest.cc b/chromium/device/usb/mojo/device_impl_unittest.cc
index 3d42e9d71c9..73a2755caf1 100644
--- a/chromium/device/usb/mojo/device_impl_unittest.cc
+++ b/chromium/device/usb/mojo/device_impl_unittest.cc
@@ -173,28 +173,29 @@ class USBDeviceImplTest : public testing::Test {
// Set up mock handle calls to respond based on mock device configs
// established by the test.
- ON_CALL(mock_device(), Open(_))
+ ON_CALL(mock_device(), OpenInternal(_))
.WillByDefault(Invoke(this, &USBDeviceImplTest::OpenMockHandle));
ON_CALL(mock_handle(), Close())
.WillByDefault(Invoke(this, &USBDeviceImplTest::CloseMockHandle));
- ON_CALL(mock_handle(), SetConfiguration(_, _))
+ ON_CALL(mock_handle(), SetConfigurationInternal(_, _))
.WillByDefault(Invoke(this, &USBDeviceImplTest::SetConfiguration));
- ON_CALL(mock_handle(), ClaimInterface(_, _))
+ ON_CALL(mock_handle(), ClaimInterfaceInternal(_, _))
.WillByDefault(Invoke(this, &USBDeviceImplTest::ClaimInterface));
- ON_CALL(mock_handle(), ReleaseInterface(_, _))
+ ON_CALL(mock_handle(), ReleaseInterfaceInternal(_, _))
.WillByDefault(Invoke(this, &USBDeviceImplTest::ReleaseInterface));
- ON_CALL(mock_handle(), SetInterfaceAlternateSetting(_, _, _))
+ ON_CALL(mock_handle(), SetInterfaceAlternateSettingInternal(_, _, _))
.WillByDefault(
Invoke(this, &USBDeviceImplTest::SetInterfaceAlternateSetting));
- ON_CALL(mock_handle(), ResetDevice(_))
+ ON_CALL(mock_handle(), ResetDeviceInternal(_))
.WillByDefault(Invoke(this, &USBDeviceImplTest::ResetDevice));
- ON_CALL(mock_handle(), ControlTransfer(_, _, _, _, _, _, _, _, _, _))
+ ON_CALL(mock_handle(),
+ ControlTransferInternal(_, _, _, _, _, _, _, _, _, _))
.WillByDefault(Invoke(this, &USBDeviceImplTest::ControlTransfer));
- ON_CALL(mock_handle(), GenericTransfer(_, _, _, _, _, _))
+ ON_CALL(mock_handle(), GenericTransferInternal(_, _, _, _, _, _))
.WillByDefault(Invoke(this, &USBDeviceImplTest::GenericTransfer));
- ON_CALL(mock_handle(), IsochronousTransferIn(_, _, _, _))
+ ON_CALL(mock_handle(), IsochronousTransferInInternal(_, _, _, _))
.WillByDefault(Invoke(this, &USBDeviceImplTest::IsochronousTransferIn));
- ON_CALL(mock_handle(), IsochronousTransferOut(_, _, _, _, _))
+ ON_CALL(mock_handle(), IsochronousTransferOutInternal(_, _, _, _, _))
.WillByDefault(
Invoke(this, &USBDeviceImplTest::IsochronousTransferOut));
@@ -235,10 +236,10 @@ class USBDeviceImplTest : public testing::Test {
}
private:
- void OpenMockHandle(const UsbDevice::OpenCallback& callback) {
+ void OpenMockHandle(UsbDevice::OpenCallback& callback) {
EXPECT_FALSE(is_device_open_);
is_device_open_ = true;
- callback.Run(mock_handle_);
+ std::move(callback).Run(mock_handle_);
}
void CloseMockHandle() {
@@ -247,72 +248,71 @@ class USBDeviceImplTest : public testing::Test {
}
void SetConfiguration(uint8_t value,
- const UsbDeviceHandle::ResultCallback& callback) {
+ UsbDeviceHandle::ResultCallback& callback) {
if (mock_configs_.find(value) != mock_configs_.end()) {
mock_device_->ActiveConfigurationChanged(value);
- callback.Run(true);
+ std::move(callback).Run(true);
} else {
- callback.Run(false);
+ std::move(callback).Run(false);
}
}
void ClaimInterface(uint8_t interface_number,
- const UsbDeviceHandle::ResultCallback& callback) {
+ UsbDeviceHandle::ResultCallback& callback) {
for (const auto& config : mock_configs_) {
for (const auto& interface : config.second.interfaces) {
if (interface.interface_number == interface_number) {
claimed_interfaces_.insert(interface_number);
- callback.Run(true);
+ std::move(callback).Run(true);
return;
}
}
}
- callback.Run(false);
+ std::move(callback).Run(false);
}
void ReleaseInterface(uint8_t interface_number,
- const UsbDeviceHandle::ResultCallback& callback) {
+ UsbDeviceHandle::ResultCallback& callback) {
if (base::ContainsKey(claimed_interfaces_, interface_number)) {
claimed_interfaces_.erase(interface_number);
- callback.Run(true);
+ std::move(callback).Run(true);
} else {
- callback.Run(false);
+ std::move(callback).Run(false);
}
}
- void SetInterfaceAlternateSetting(
- uint8_t interface_number,
- uint8_t alternate_setting,
- const UsbDeviceHandle::ResultCallback& callback) {
+ void SetInterfaceAlternateSetting(uint8_t interface_number,
+ uint8_t alternate_setting,
+ UsbDeviceHandle::ResultCallback& callback) {
for (const auto& config : mock_configs_) {
for (const auto& interface : config.second.interfaces) {
if (interface.interface_number == interface_number &&
interface.alternate_setting == alternate_setting) {
- callback.Run(true);
+ std::move(callback).Run(true);
return;
}
}
}
- callback.Run(false);
+ std::move(callback).Run(false);
}
- void ResetDevice(const UsbDeviceHandle::ResultCallback& callback) {
- callback.Run(allow_reset_);
+ void ResetDevice(UsbDeviceHandle::ResultCallback& callback) {
+ std::move(callback).Run(allow_reset_);
}
- void InboundTransfer(const UsbDeviceHandle::TransferCallback& callback) {
+ void InboundTransfer(UsbDeviceHandle::TransferCallback callback) {
ASSERT_GE(mock_inbound_data_.size(), 1u);
const std::vector<uint8_t>& bytes = mock_inbound_data_.front();
size_t length = bytes.size();
scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(length);
std::copy(bytes.begin(), bytes.end(), buffer->data());
mock_inbound_data_.pop();
- callback.Run(UsbTransferStatus::COMPLETED, buffer, length);
+ std::move(callback).Run(UsbTransferStatus::COMPLETED, buffer, length);
}
void OutboundTransfer(scoped_refptr<net::IOBuffer> buffer,
size_t length,
- const UsbDeviceHandle::TransferCallback& callback) {
+ UsbDeviceHandle::TransferCallback callback) {
ASSERT_GE(mock_outbound_data_.size(), 1u);
const std::vector<uint8_t>& bytes = mock_outbound_data_.front();
ASSERT_EQ(bytes.size(), length);
@@ -321,7 +321,7 @@ class USBDeviceImplTest : public testing::Test {
<< i;
}
mock_outbound_data_.pop();
- callback.Run(UsbTransferStatus::COMPLETED, buffer, length);
+ std::move(callback).Run(UsbTransferStatus::COMPLETED, buffer, length);
}
void ControlTransfer(UsbTransferDirection direction,
@@ -333,11 +333,11 @@ class USBDeviceImplTest : public testing::Test {
scoped_refptr<net::IOBuffer> buffer,
size_t length,
unsigned int timeout,
- const UsbDeviceHandle::TransferCallback& callback) {
+ UsbDeviceHandle::TransferCallback& callback) {
if (direction == UsbTransferDirection::INBOUND)
- InboundTransfer(callback);
+ InboundTransfer(std::move(callback));
else
- OutboundTransfer(buffer, length, callback);
+ OutboundTransfer(buffer, length, std::move(callback));
}
void GenericTransfer(UsbTransferDirection direction,
@@ -345,18 +345,18 @@ class USBDeviceImplTest : public testing::Test {
scoped_refptr<net::IOBuffer> buffer,
size_t length,
unsigned int timeout,
- const UsbDeviceHandle::TransferCallback& callback) {
+ UsbDeviceHandle::TransferCallback& callback) {
if (direction == UsbTransferDirection::INBOUND)
- InboundTransfer(callback);
+ InboundTransfer(std::move(callback));
else
- OutboundTransfer(buffer, length, callback);
+ OutboundTransfer(buffer, length, std::move(callback));
}
void IsochronousTransferIn(
uint8_t endpoint_number,
const std::vector<uint32_t>& packet_lengths,
unsigned int timeout,
- const UsbDeviceHandle::IsochronousTransferCallback& callback) {
+ UsbDeviceHandle::IsochronousTransferCallback& callback) {
ASSERT_FALSE(mock_inbound_data_.empty());
const std::vector<uint8_t>& bytes = mock_inbound_data_.front();
size_t length = bytes.size();
@@ -374,7 +374,7 @@ class USBDeviceImplTest : public testing::Test {
}
mock_inbound_packets_.pop();
- callback.Run(buffer, packets);
+ std::move(callback).Run(buffer, packets);
}
void IsochronousTransferOut(
@@ -382,7 +382,7 @@ class USBDeviceImplTest : public testing::Test {
scoped_refptr<net::IOBuffer> buffer,
const std::vector<uint32_t>& packet_lengths,
unsigned int timeout,
- const UsbDeviceHandle::IsochronousTransferCallback& callback) {
+ UsbDeviceHandle::IsochronousTransferCallback& callback) {
ASSERT_FALSE(mock_outbound_data_.empty());
const std::vector<uint8_t>& bytes = mock_outbound_data_.front();
size_t length =
@@ -404,7 +404,7 @@ class USBDeviceImplTest : public testing::Test {
}
mock_outbound_packets_.pop();
- callback.Run(buffer, packets);
+ std::move(callback).Run(buffer, packets);
}
std::unique_ptr<base::MessageLoop> message_loop_;
@@ -445,7 +445,7 @@ TEST_F(USBDeviceImplTest, Open) {
EXPECT_FALSE(is_device_open());
- EXPECT_CALL(mock_device(), Open(_));
+ EXPECT_CALL(mock_device(), OpenInternal(_));
EXPECT_CALL(permission_provider(), IncrementConnectionCount());
{
@@ -472,7 +472,7 @@ TEST_F(USBDeviceImplTest, Close) {
EXPECT_FALSE(is_device_open());
- EXPECT_CALL(mock_device(), Open(_));
+ EXPECT_CALL(mock_device(), OpenInternal(_));
{
base::RunLoop loop;
@@ -495,7 +495,7 @@ TEST_F(USBDeviceImplTest, Close) {
TEST_F(USBDeviceImplTest, SetInvalidConfiguration) {
UsbDevicePtr device = GetMockDeviceProxy();
- EXPECT_CALL(mock_device(), Open(_));
+ EXPECT_CALL(mock_device(), OpenInternal(_));
{
base::RunLoop loop;
@@ -504,7 +504,7 @@ TEST_F(USBDeviceImplTest, SetInvalidConfiguration) {
loop.Run();
}
- EXPECT_CALL(mock_handle(), SetConfiguration(42, _));
+ EXPECT_CALL(mock_handle(), SetConfigurationInternal(42, _));
{
// SetConfiguration should fail because 42 is not a valid mock
@@ -521,7 +521,7 @@ TEST_F(USBDeviceImplTest, SetInvalidConfiguration) {
TEST_F(USBDeviceImplTest, SetValidConfiguration) {
UsbDevicePtr device = GetMockDeviceProxy();
- EXPECT_CALL(mock_device(), Open(_));
+ EXPECT_CALL(mock_device(), OpenInternal(_));
{
base::RunLoop loop;
@@ -530,7 +530,7 @@ TEST_F(USBDeviceImplTest, SetValidConfiguration) {
loop.Run();
}
- EXPECT_CALL(mock_handle(), SetConfiguration(42, _));
+ EXPECT_CALL(mock_handle(), SetConfigurationInternal(42, _));
AddMockConfig(ConfigBuilder(42));
@@ -550,7 +550,7 @@ TEST_F(USBDeviceImplTest, SetValidConfiguration) {
TEST_F(USBDeviceImplTest, Reset) {
UsbDevicePtr device = GetMockDeviceProxy();
- EXPECT_CALL(mock_device(), Open(_));
+ EXPECT_CALL(mock_device(), OpenInternal(_));
{
base::RunLoop loop;
@@ -559,7 +559,7 @@ TEST_F(USBDeviceImplTest, Reset) {
loop.Run();
}
- EXPECT_CALL(mock_handle(), ResetDevice(_));
+ EXPECT_CALL(mock_handle(), ResetDeviceInternal(_));
set_allow_reset(true);
@@ -569,7 +569,7 @@ TEST_F(USBDeviceImplTest, Reset) {
loop.Run();
}
- EXPECT_CALL(mock_handle(), ResetDevice(_));
+ EXPECT_CALL(mock_handle(), ResetDeviceInternal(_));
set_allow_reset(false);
@@ -585,7 +585,7 @@ TEST_F(USBDeviceImplTest, Reset) {
TEST_F(USBDeviceImplTest, ClaimAndReleaseInterface) {
UsbDevicePtr device = GetMockDeviceProxy();
- EXPECT_CALL(mock_device(), Open(_));
+ EXPECT_CALL(mock_device(), OpenInternal(_));
{
base::RunLoop loop;
@@ -597,7 +597,7 @@ TEST_F(USBDeviceImplTest, ClaimAndReleaseInterface) {
// Now add a mock interface #1.
AddMockConfig(ConfigBuilder(1).AddInterface(1, 0, 1, 2, 3));
- EXPECT_CALL(mock_handle(), SetConfiguration(1, _));
+ EXPECT_CALL(mock_handle(), SetConfigurationInternal(1, _));
{
base::RunLoop loop;
@@ -614,7 +614,7 @@ TEST_F(USBDeviceImplTest, ClaimAndReleaseInterface) {
loop.Run();
}
- EXPECT_CALL(mock_handle(), ClaimInterface(1, _));
+ EXPECT_CALL(mock_handle(), ClaimInterfaceInternal(1, _));
{
base::RunLoop loop;
@@ -623,7 +623,7 @@ TEST_F(USBDeviceImplTest, ClaimAndReleaseInterface) {
loop.Run();
}
- EXPECT_CALL(mock_handle(), ReleaseInterface(2, _));
+ EXPECT_CALL(mock_handle(), ReleaseInterfaceInternal(2, _));
{
// Releasing a non-existent interface should fail.
@@ -633,7 +633,7 @@ TEST_F(USBDeviceImplTest, ClaimAndReleaseInterface) {
loop.Run();
}
- EXPECT_CALL(mock_handle(), ReleaseInterface(1, _));
+ EXPECT_CALL(mock_handle(), ReleaseInterfaceInternal(1, _));
{
// Now this should release the claimed interface and close the handle.
@@ -649,7 +649,7 @@ TEST_F(USBDeviceImplTest, ClaimAndReleaseInterface) {
TEST_F(USBDeviceImplTest, SetInterfaceAlternateSetting) {
UsbDevicePtr device = GetMockDeviceProxy();
- EXPECT_CALL(mock_device(), Open(_));
+ EXPECT_CALL(mock_device(), OpenInternal(_));
{
base::RunLoop loop;
@@ -663,7 +663,7 @@ TEST_F(USBDeviceImplTest, SetInterfaceAlternateSetting) {
.AddInterface(1, 42, 1, 2, 3)
.AddInterface(2, 0, 1, 2, 3));
- EXPECT_CALL(mock_handle(), SetInterfaceAlternateSetting(1, 42, _));
+ EXPECT_CALL(mock_handle(), SetInterfaceAlternateSettingInternal(1, 42, _));
{
base::RunLoop loop;
@@ -672,7 +672,7 @@ TEST_F(USBDeviceImplTest, SetInterfaceAlternateSetting) {
loop.Run();
}
- EXPECT_CALL(mock_handle(), SetInterfaceAlternateSetting(1, 100, _));
+ EXPECT_CALL(mock_handle(), SetInterfaceAlternateSettingInternal(1, 100, _));
{
base::RunLoop loop;
@@ -687,7 +687,7 @@ TEST_F(USBDeviceImplTest, SetInterfaceAlternateSetting) {
TEST_F(USBDeviceImplTest, ControlTransfer) {
UsbDevicePtr device = GetMockDeviceProxy();
- EXPECT_CALL(mock_device(), Open(_));
+ EXPECT_CALL(mock_device(), OpenInternal(_));
{
base::RunLoop loop;
@@ -698,7 +698,7 @@ TEST_F(USBDeviceImplTest, ControlTransfer) {
AddMockConfig(ConfigBuilder(1).AddInterface(7, 0, 1, 2, 3));
- EXPECT_CALL(mock_handle(), SetConfiguration(1, _));
+ EXPECT_CALL(mock_handle(), SetConfigurationInternal(1, _));
{
base::RunLoop loop;
@@ -715,10 +715,10 @@ TEST_F(USBDeviceImplTest, ControlTransfer) {
AddMockInboundData(fake_data);
EXPECT_CALL(mock_handle(),
- ControlTransfer(UsbTransferDirection::INBOUND,
- UsbControlTransferType::STANDARD,
- UsbControlTransferRecipient::DEVICE, 5, 6, 7, _,
- _, 0, _));
+ ControlTransferInternal(UsbTransferDirection::INBOUND,
+ UsbControlTransferType::STANDARD,
+ UsbControlTransferRecipient::DEVICE, 5, 6,
+ 7, _, _, 0, _));
{
auto params = mojom::UsbControlTransferParams::New();
@@ -739,10 +739,10 @@ TEST_F(USBDeviceImplTest, ControlTransfer) {
AddMockOutboundData(fake_data);
EXPECT_CALL(mock_handle(),
- ControlTransfer(UsbTransferDirection::OUTBOUND,
- UsbControlTransferType::STANDARD,
- UsbControlTransferRecipient::INTERFACE, 5, 6, 7,
- _, _, 0, _));
+ ControlTransferInternal(UsbTransferDirection::OUTBOUND,
+ UsbControlTransferType::STANDARD,
+ UsbControlTransferRecipient::INTERFACE, 5,
+ 6, 7, _, _, 0, _));
{
auto params = mojom::UsbControlTransferParams::New();
@@ -765,7 +765,7 @@ TEST_F(USBDeviceImplTest, ControlTransfer) {
TEST_F(USBDeviceImplTest, GenericTransfer) {
UsbDevicePtr device = GetMockDeviceProxy();
- EXPECT_CALL(mock_device(), Open(_));
+ EXPECT_CALL(mock_device(), OpenInternal(_));
{
base::RunLoop loop;
@@ -787,8 +787,8 @@ TEST_F(USBDeviceImplTest, GenericTransfer) {
AddMockInboundData(fake_inbound_data);
EXPECT_CALL(mock_handle(),
- GenericTransfer(UsbTransferDirection::OUTBOUND, 0x01, _,
- fake_outbound_data.size(), 0, _));
+ GenericTransferInternal(UsbTransferDirection::OUTBOUND, 0x01, _,
+ fake_outbound_data.size(), 0, _));
{
base::RunLoop loop;
@@ -800,8 +800,8 @@ TEST_F(USBDeviceImplTest, GenericTransfer) {
}
EXPECT_CALL(mock_handle(),
- GenericTransfer(UsbTransferDirection::INBOUND, 0x81, _,
- fake_inbound_data.size(), 0, _));
+ GenericTransferInternal(UsbTransferDirection::INBOUND, 0x81, _,
+ fake_inbound_data.size(), 0, _));
{
base::RunLoop loop;
@@ -819,7 +819,7 @@ TEST_F(USBDeviceImplTest, GenericTransfer) {
TEST_F(USBDeviceImplTest, IsochronousTransfer) {
UsbDevicePtr device = GetMockDeviceProxy();
- EXPECT_CALL(mock_device(), Open(_));
+ EXPECT_CALL(mock_device(), OpenInternal(_));
{
base::RunLoop loop;
@@ -852,8 +852,8 @@ TEST_F(USBDeviceImplTest, IsochronousTransfer) {
AddMockOutboundPackets(fake_outbound_data, fake_packets);
AddMockInboundPackets(fake_inbound_data, fake_packets);
- EXPECT_CALL(mock_handle(),
- IsochronousTransferOut(0x01, _, fake_packet_lengths, 0, _));
+ EXPECT_CALL(mock_handle(), IsochronousTransferOutInternal(
+ 0x01, _, fake_packet_lengths, 0, _));
{
base::RunLoop loop;
@@ -865,7 +865,7 @@ TEST_F(USBDeviceImplTest, IsochronousTransfer) {
}
EXPECT_CALL(mock_handle(),
- IsochronousTransferIn(0x81, fake_packet_lengths, 0, _));
+ IsochronousTransferInInternal(0x81, fake_packet_lengths, 0, _));
{
base::RunLoop loop;
diff --git a/chromium/device/usb/mojo/device_manager_impl.cc b/chromium/device/usb/mojo/device_manager_impl.cc
index 539ea3a1354..a3e9a002ad3 100644
--- a/chromium/device/usb/mojo/device_manager_impl.cc
+++ b/chromium/device/usb/mojo/device_manager_impl.cc
@@ -57,10 +57,10 @@ DeviceManagerImpl::~DeviceManagerImpl() {
}
void DeviceManagerImpl::GetDevices(mojom::UsbEnumerationOptionsPtr options,
- const GetDevicesCallback& callback) {
- usb_service_->GetDevices(base::Bind(&DeviceManagerImpl::OnGetDevices,
- weak_factory_.GetWeakPtr(),
- base::Passed(&options), callback));
+ GetDevicesCallback callback) {
+ usb_service_->GetDevices(
+ base::Bind(&DeviceManagerImpl::OnGetDevices, weak_factory_.GetWeakPtr(),
+ base::Passed(&options), base::Passed(&callback)));
}
void DeviceManagerImpl::GetDevice(const std::string& guid,
@@ -82,7 +82,7 @@ void DeviceManagerImpl::SetClient(mojom::UsbDeviceManagerClientPtr client) {
void DeviceManagerImpl::OnGetDevices(
mojom::UsbEnumerationOptionsPtr options,
- const GetDevicesCallback& callback,
+ GetDevicesCallback callback,
const std::vector<scoped_refptr<UsbDevice>>& devices) {
std::vector<mojom::UsbDeviceFilterPtr> filters;
if (options)
@@ -98,7 +98,7 @@ void DeviceManagerImpl::OnGetDevices(
}
}
- callback.Run(std::move(device_infos));
+ std::move(callback).Run(std::move(device_infos));
}
void DeviceManagerImpl::OnDeviceAdded(scoped_refptr<UsbDevice> device) {
diff --git a/chromium/device/usb/mojo/device_manager_impl.h b/chromium/device/usb/mojo/device_manager_impl.h
index 49be73e1e2d..42d9ba15969 100644
--- a/chromium/device/usb/mojo/device_manager_impl.h
+++ b/chromium/device/usb/mojo/device_manager_impl.h
@@ -42,14 +42,14 @@ class DeviceManagerImpl : public mojom::UsbDeviceManager,
// DeviceManager implementation:
void GetDevices(mojom::UsbEnumerationOptionsPtr options,
- const GetDevicesCallback& callback) override;
+ GetDevicesCallback callback) override;
void GetDevice(const std::string& guid,
mojom::UsbDeviceRequest device_request) override;
void SetClient(mojom::UsbDeviceManagerClientPtr client) override;
// Callbacks to handle the async responses from the underlying UsbService.
void OnGetDevices(mojom::UsbEnumerationOptionsPtr options,
- const GetDevicesCallback& callback,
+ GetDevicesCallback callback,
const std::vector<scoped_refptr<UsbDevice>>& devices);
// UsbService::Observer implementation:
diff --git a/chromium/device/usb/public/interfaces/BUILD.gn b/chromium/device/usb/public/interfaces/BUILD.gn
index ea8c6a56472..2a7be4e8da9 100644
--- a/chromium/device/usb/public/interfaces/BUILD.gn
+++ b/chromium/device/usb/public/interfaces/BUILD.gn
@@ -14,7 +14,4 @@ mojom("interfaces") {
deps = [
"//mojo/common:common_custom_types",
]
-
- # TODO(crbug.com/714018): Convert the implementation to use OnceCallback.
- use_once_callback = false
}
diff --git a/chromium/device/usb/usb_descriptors.cc b/chromium/device/usb/usb_descriptors.cc
index ae25c1b79c6..84aa02e7dfa 100644
--- a/chromium/device/usb/usb_descriptors.cc
+++ b/chromium/device/usb/usb_descriptors.cc
@@ -80,20 +80,19 @@ void ParseInterfaceAssociationDescriptors(
void OnDoneReadingConfigDescriptors(
scoped_refptr<UsbDeviceHandle> device_handle,
std::unique_ptr<UsbDeviceDescriptor> desc,
- const base::Callback<void(std::unique_ptr<UsbDeviceDescriptor>)>&
- callback) {
+ base::OnceCallback<void(std::unique_ptr<UsbDeviceDescriptor>)> callback) {
if (desc->num_configurations == desc->configurations.size()) {
- callback.Run(std::move(desc));
+ std::move(callback).Run(std::move(desc));
} else {
LOG(ERROR) << "Failed to read all configuration descriptors. Expected "
<< static_cast<int>(desc->num_configurations) << ", got "
<< desc->configurations.size() << ".";
- callback.Run(nullptr);
+ std::move(callback).Run(nullptr);
}
}
void OnReadConfigDescriptor(UsbDeviceDescriptor* desc,
- const base::Closure& closure,
+ base::Closure closure,
UsbTransferStatus status,
scoped_refptr<IOBuffer> buffer,
size_t length) {
@@ -105,13 +104,13 @@ void OnReadConfigDescriptor(UsbDeviceDescriptor* desc,
} else {
LOG(ERROR) << "Failed to read configuration descriptor.";
}
- closure.Run();
+ std::move(closure).Run();
}
void OnReadConfigDescriptorHeader(scoped_refptr<UsbDeviceHandle> device_handle,
UsbDeviceDescriptor* desc,
uint8_t index,
- const base::Closure& closure,
+ base::Closure closure,
UsbTransferStatus status,
scoped_refptr<IOBuffer> header,
size_t length) {
@@ -124,23 +123,23 @@ void OnReadConfigDescriptorHeader(scoped_refptr<UsbDeviceHandle> device_handle,
UsbControlTransferRecipient::DEVICE, kGetDescriptorRequest,
kConfigurationDescriptorType << 8 | index, 0, buffer, total_length,
kControlTransferTimeoutMs,
- base::Bind(&OnReadConfigDescriptor, desc, closure));
+ base::Bind(&OnReadConfigDescriptor, desc, base::Passed(&closure)));
} else {
LOG(ERROR) << "Failed to read length for configuration "
<< static_cast<int>(index) << ".";
- closure.Run();
+ std::move(closure).Run();
}
}
void OnReadDeviceDescriptor(
scoped_refptr<UsbDeviceHandle> device_handle,
- const base::Callback<void(std::unique_ptr<UsbDeviceDescriptor>)>& callback,
+ base::OnceCallback<void(std::unique_ptr<UsbDeviceDescriptor>)> callback,
UsbTransferStatus status,
scoped_refptr<IOBuffer> buffer,
size_t length) {
if (status != UsbTransferStatus::COMPLETED) {
LOG(ERROR) << "Failed to read device descriptor.";
- callback.Run(nullptr);
+ std::move(callback).Run(nullptr);
return;
}
@@ -148,12 +147,12 @@ void OnReadDeviceDescriptor(
if (!desc->Parse(
std::vector<uint8_t>(buffer->data(), buffer->data() + length))) {
LOG(ERROR) << "Device descriptor parsing error.";
- callback.Run(nullptr);
+ std::move(callback).Run(nullptr);
return;
}
if (desc->num_configurations == 0) {
- callback.Run(std::move(desc));
+ std::move(callback).Run(std::move(desc));
return;
}
@@ -161,8 +160,8 @@ void OnReadDeviceDescriptor(
UsbDeviceDescriptor* desc_ptr = desc.get();
base::Closure closure = base::BarrierClosure(
num_configurations,
- base::Bind(OnDoneReadingConfigDescriptors, device_handle,
- base::Passed(&desc), callback));
+ base::BindOnce(OnDoneReadingConfigDescriptors, device_handle,
+ std::move(desc), std::move(callback)));
for (uint8_t i = 0; i < num_configurations; ++i) {
scoped_refptr<IOBufferWithSize> header = new IOBufferWithSize(4);
device_handle->ControlTransfer(
@@ -170,20 +169,20 @@ void OnReadDeviceDescriptor(
UsbControlTransferRecipient::DEVICE, kGetDescriptorRequest,
kConfigurationDescriptorType << 8 | i, 0, header, header->size(),
kControlTransferTimeoutMs,
- base::Bind(&OnReadConfigDescriptorHeader, device_handle, desc_ptr, i,
- closure));
+ base::BindOnce(&OnReadConfigDescriptorHeader, device_handle, desc_ptr,
+ i, closure));
}
}
void StoreStringDescriptor(IndexMap::iterator it,
- const base::Closure& callback,
+ base::Closure callback,
const base::string16& string) {
it->second = string;
- callback.Run();
+ std::move(callback).Run();
}
void OnReadStringDescriptor(
- const base::Callback<void(const base::string16&)>& callback,
+ base::OnceCallback<void(const base::string16&)> callback,
UsbTransferStatus status,
scoped_refptr<IOBuffer> buffer,
size_t length) {
@@ -192,9 +191,9 @@ void OnReadStringDescriptor(
ParseUsbStringDescriptor(
std::vector<uint8_t>(buffer->data(), buffer->data() + length),
&string)) {
- callback.Run(string);
+ std::move(callback).Run(string);
} else {
- callback.Run(base::string16());
+ std::move(callback).Run(base::string16());
}
}
@@ -202,18 +201,19 @@ void ReadStringDescriptor(
scoped_refptr<UsbDeviceHandle> device_handle,
uint8_t index,
uint16_t language_id,
- const base::Callback<void(const base::string16&)>& callback) {
+ base::OnceCallback<void(const base::string16&)> callback) {
scoped_refptr<IOBufferWithSize> buffer = new IOBufferWithSize(255);
device_handle->ControlTransfer(
UsbTransferDirection::INBOUND, UsbControlTransferType::STANDARD,
UsbControlTransferRecipient::DEVICE, kGetDescriptorRequest,
kStringDescriptorType << 8 | index, language_id, buffer, buffer->size(),
- kControlTransferTimeoutMs, base::Bind(&OnReadStringDescriptor, callback));
+ kControlTransferTimeoutMs,
+ base::Bind(&OnReadStringDescriptor, base::Passed(&callback)));
}
void OnReadLanguageIds(scoped_refptr<UsbDeviceHandle> device_handle,
IndexMapPtr index_map,
- const base::Callback<void(IndexMapPtr)>& callback,
+ base::OnceCallback<void(IndexMapPtr)> callback,
const base::string16& languages) {
// Default to English unless the device provides a language and then just pick
// the first one.
@@ -223,13 +223,13 @@ void OnReadLanguageIds(scoped_refptr<UsbDeviceHandle> device_handle,
for (auto it = index_map->begin(); it != index_map->end(); ++it)
iterator_map[it->first] = it;
- base::Closure barrier =
- base::BarrierClosure(static_cast<int>(iterator_map.size()),
- base::Bind(callback, base::Passed(&index_map)));
+ base::Closure barrier = base::BarrierClosure(
+ static_cast<int>(iterator_map.size()),
+ base::BindOnce(std::move(callback), std::move(index_map)));
for (const auto& map_entry : iterator_map) {
ReadStringDescriptor(
device_handle, map_entry.first, language_id,
- base::Bind(&StoreStringDescriptor, map_entry.second, barrier));
+ base::BindOnce(&StoreStringDescriptor, map_entry.second, barrier));
}
}
@@ -494,9 +494,9 @@ bool UsbDeviceDescriptor::Parse(const std::vector<uint8_t>& buffer) {
return true;
}
-void ReadUsbDescriptors(scoped_refptr<UsbDeviceHandle> device_handle,
- const base::Callback<void(
- std::unique_ptr<UsbDeviceDescriptor>)>& callback) {
+void ReadUsbDescriptors(
+ scoped_refptr<UsbDeviceHandle> device_handle,
+ base::OnceCallback<void(std::unique_ptr<UsbDeviceDescriptor>)> callback) {
scoped_refptr<IOBufferWithSize> buffer =
new IOBufferWithSize(kDeviceDescriptorLength);
device_handle->ControlTransfer(
@@ -504,7 +504,8 @@ void ReadUsbDescriptors(scoped_refptr<UsbDeviceHandle> device_handle,
UsbControlTransferRecipient::DEVICE, kGetDescriptorRequest,
kDeviceDescriptorType << 8, 0, buffer, buffer->size(),
kControlTransferTimeoutMs,
- base::Bind(&OnReadDeviceDescriptor, device_handle, callback));
+ base::Bind(&OnReadDeviceDescriptor, device_handle,
+ base::Passed(&callback)));
}
bool ParseUsbStringDescriptor(const std::vector<uint8_t>& descriptor,
@@ -528,18 +529,18 @@ bool ParseUsbStringDescriptor(const std::vector<uint8_t>& descriptor,
// For each key in |index_map| this function reads that string descriptor from
// |device_handle| and updates the value in in |index_map|.
-void ReadUsbStringDescriptors(
- scoped_refptr<UsbDeviceHandle> device_handle,
- IndexMapPtr index_map,
- const base::Callback<void(IndexMapPtr)>& callback) {
+void ReadUsbStringDescriptors(scoped_refptr<UsbDeviceHandle> device_handle,
+ IndexMapPtr index_map,
+ base::OnceCallback<void(IndexMapPtr)> callback) {
if (index_map->empty()) {
- callback.Run(std::move(index_map));
+ std::move(callback).Run(std::move(index_map));
return;
}
- ReadStringDescriptor(device_handle, 0, 0,
- base::Bind(&OnReadLanguageIds, device_handle,
- base::Passed(&index_map), callback));
+ ReadStringDescriptor(
+ device_handle, 0, 0,
+ base::BindOnce(&OnReadLanguageIds, device_handle, std::move(index_map),
+ std::move(callback)));
}
} // namespace device
diff --git a/chromium/device/usb/usb_descriptors.h b/chromium/device/usb/usb_descriptors.h
index b0f5be6b6f4..75fdc492f7b 100644
--- a/chromium/device/usb/usb_descriptors.h
+++ b/chromium/device/usb/usb_descriptors.h
@@ -134,7 +134,7 @@ struct UsbDeviceDescriptor {
void ReadUsbDescriptors(
scoped_refptr<UsbDeviceHandle> device_handle,
- const base::Callback<void(std::unique_ptr<UsbDeviceDescriptor>)>& callback);
+ base::OnceCallback<void(std::unique_ptr<UsbDeviceDescriptor>)> callback);
bool ParseUsbStringDescriptor(const std::vector<uint8_t>& descriptor,
base::string16* output);
@@ -142,8 +142,8 @@ bool ParseUsbStringDescriptor(const std::vector<uint8_t>& descriptor,
void ReadUsbStringDescriptors(
scoped_refptr<UsbDeviceHandle> device_handle,
std::unique_ptr<std::map<uint8_t, base::string16>> index_map,
- const base::Callback<
- void(std::unique_ptr<std::map<uint8_t, base::string16>>)>& callback);
+ base::OnceCallback<void(std::unique_ptr<std::map<uint8_t, base::string16>>)>
+ callback);
} // namespace device
diff --git a/chromium/device/usb/usb_descriptors_unittest.cc b/chromium/device/usb/usb_descriptors_unittest.cc
index 06cc682473f..71576ac7114 100644
--- a/chromium/device/usb/usb_descriptors_unittest.cc
+++ b/chromium/device/usb/usb_descriptors_unittest.cc
@@ -22,7 +22,7 @@ namespace {
ACTION_P2(InvokeCallback, data, length) {
size_t transferred_length = std::min(length, arg7);
memcpy(arg6->data(), data, transferred_length);
- arg9.Run(UsbTransferStatus::COMPLETED, arg6, transferred_length);
+ std::move(arg9).Run(UsbTransferStatus::COMPLETED, arg6, transferred_length);
}
void ExpectStringDescriptors(
@@ -223,29 +223,29 @@ TEST_F(UsbDescriptorsTest, ReadDescriptors) {
scoped_refptr<MockUsbDeviceHandle> device_handle(
new MockUsbDeviceHandle(nullptr));
EXPECT_CALL(*device_handle,
- ControlTransfer(UsbTransferDirection::INBOUND,
- UsbControlTransferType::STANDARD,
- UsbControlTransferRecipient::DEVICE, 0x06, 0x0100,
- 0x0000, _, _, _, _))
+ ControlTransferInternal(UsbTransferDirection::INBOUND,
+ UsbControlTransferType::STANDARD,
+ UsbControlTransferRecipient::DEVICE, 0x06,
+ 0x0100, 0x0000, _, _, _, _))
.WillOnce(InvokeCallback(kDeviceDescriptor, sizeof(kDeviceDescriptor)));
EXPECT_CALL(*device_handle,
- ControlTransfer(UsbTransferDirection::INBOUND,
- UsbControlTransferType::STANDARD,
- UsbControlTransferRecipient::DEVICE, 0x06, 0x0200,
- 0x0000, _, _, _, _))
+ ControlTransferInternal(UsbTransferDirection::INBOUND,
+ UsbControlTransferType::STANDARD,
+ UsbControlTransferRecipient::DEVICE, 0x06,
+ 0x0200, 0x0000, _, _, _, _))
.Times(2)
.WillRepeatedly(
InvokeCallback(kConfig1Descriptor, sizeof(kConfig1Descriptor)));
EXPECT_CALL(*device_handle,
- ControlTransfer(UsbTransferDirection::INBOUND,
- UsbControlTransferType::STANDARD,
- UsbControlTransferRecipient::DEVICE, 0x06, 0x0201,
- 0x0000, _, _, _, _))
+ ControlTransferInternal(UsbTransferDirection::INBOUND,
+ UsbControlTransferType::STANDARD,
+ UsbControlTransferRecipient::DEVICE, 0x06,
+ 0x0201, 0x0000, _, _, _, _))
.Times(2)
.WillRepeatedly(
InvokeCallback(kConfig2Descriptor, sizeof(kConfig2Descriptor)));
- ReadUsbDescriptors(device_handle, base::Bind(&OnReadDescriptors));
+ ReadUsbDescriptors(device_handle, base::BindOnce(&OnReadDescriptors));
}
TEST_F(UsbDescriptorsTest, NoInterfaceAssociations) {
@@ -407,37 +407,37 @@ TEST_F(UsbDescriptorsTest, ReadStringDescriptors) {
new MockUsbDeviceHandle(nullptr));
static const uint8_t kStringDescriptor0[] = {0x04, 0x03, 0x21, 0x43};
EXPECT_CALL(*device_handle,
- ControlTransfer(UsbTransferDirection::INBOUND,
- UsbControlTransferType::STANDARD,
- UsbControlTransferRecipient::DEVICE, 0x06, 0x0300,
- 0x0000, _, _, _, _))
+ ControlTransferInternal(UsbTransferDirection::INBOUND,
+ UsbControlTransferType::STANDARD,
+ UsbControlTransferRecipient::DEVICE, 0x06,
+ 0x0300, 0x0000, _, _, _, _))
.WillOnce(InvokeCallback(kStringDescriptor0, sizeof(kStringDescriptor0)));
static const uint8_t kStringDescriptor1[] = {0x12, 0x03, 'S', 0, 't', 0,
'r', 0, 'i', 0, 'n', 0,
'g', 0, ' ', 0, '1', 0};
EXPECT_CALL(*device_handle,
- ControlTransfer(UsbTransferDirection::INBOUND,
- UsbControlTransferType::STANDARD,
- UsbControlTransferRecipient::DEVICE, 0x06, 0x0301,
- 0x4321, _, _, _, _))
+ ControlTransferInternal(UsbTransferDirection::INBOUND,
+ UsbControlTransferType::STANDARD,
+ UsbControlTransferRecipient::DEVICE, 0x06,
+ 0x0301, 0x4321, _, _, _, _))
.WillOnce(InvokeCallback(kStringDescriptor1, sizeof(kStringDescriptor1)));
static const uint8_t kStringDescriptor2[] = {0x12, 0x03, 'S', 0, 't', 0,
'r', 0, 'i', 0, 'n', 0,
'g', 0, ' ', 0, '2', 0};
EXPECT_CALL(*device_handle,
- ControlTransfer(UsbTransferDirection::INBOUND,
- UsbControlTransferType::STANDARD,
- UsbControlTransferRecipient::DEVICE, 0x06, 0x0302,
- 0x4321, _, _, _, _))
+ ControlTransferInternal(UsbTransferDirection::INBOUND,
+ UsbControlTransferType::STANDARD,
+ UsbControlTransferRecipient::DEVICE, 0x06,
+ 0x0302, 0x4321, _, _, _, _))
.WillOnce(InvokeCallback(kStringDescriptor2, sizeof(kStringDescriptor2)));
static const uint8_t kStringDescriptor3[] = {0x12, 0x03, 'S', 0, 't', 0,
'r', 0, 'i', 0, 'n', 0,
'g', 0, ' ', 0, '3', 0};
EXPECT_CALL(*device_handle,
- ControlTransfer(UsbTransferDirection::INBOUND,
- UsbControlTransferType::STANDARD,
- UsbControlTransferRecipient::DEVICE, 0x06, 0x0303,
- 0x4321, _, _, _, _))
+ ControlTransferInternal(UsbTransferDirection::INBOUND,
+ UsbControlTransferType::STANDARD,
+ UsbControlTransferRecipient::DEVICE, 0x06,
+ 0x0303, 0x4321, _, _, _, _))
.WillOnce(InvokeCallback(kStringDescriptor3, sizeof(kStringDescriptor3)));
ReadUsbStringDescriptors(device_handle, std::move(string_map),
diff --git a/chromium/device/usb/usb_device.cc b/chromium/device/usb/usb_device.cc
index b6198d021e6..1a2ac366bae 100644
--- a/chromium/device/usb/usb_device.cc
+++ b/chromium/device/usb/usb_device.cc
@@ -51,16 +51,16 @@ UsbDevice::UsbDevice(uint16_t usb_version,
UsbDevice::~UsbDevice() {}
-void UsbDevice::CheckUsbAccess(const ResultCallback& callback) {
+void UsbDevice::CheckUsbAccess(ResultCallback callback) {
// By default assume that access to the device is allowed. This is implemented
// on Chrome OS by checking with permission_broker.
- callback.Run(true);
+ std::move(callback).Run(true);
}
-void UsbDevice::RequestPermission(const ResultCallback& callback) {
+void UsbDevice::RequestPermission(ResultCallback callback) {
// By default assume that access to the device is allowed. This is implemented
// on Android by calling android.hardware.usb.UsbManger.requestPermission.
- callback.Run(true);
+ std::move(callback).Run(true);
}
bool UsbDevice::permission_granted() const {
diff --git a/chromium/device/usb/usb_device.h b/chromium/device/usb/usb_device.h
index 27fc6b4571f..e6427af4212 100644
--- a/chromium/device/usb/usb_device.h
+++ b/chromium/device/usb/usb_device.h
@@ -31,8 +31,8 @@ class UsbDeviceHandle;
// method.
class UsbDevice : public base::RefCountedThreadSafe<UsbDevice> {
public:
- using OpenCallback = base::Callback<void(scoped_refptr<UsbDeviceHandle>)>;
- using ResultCallback = base::Callback<void(bool success)>;
+ using OpenCallback = base::OnceCallback<void(scoped_refptr<UsbDeviceHandle>)>;
+ using ResultCallback = base::OnceCallback<void(bool success)>;
// This observer interface should be used by objects that need only be
// notified about the removal of a particular device as it is more efficient
@@ -74,17 +74,17 @@ class UsbDevice : public base::RefCountedThreadSafe<UsbDevice> {
// On ChromeOS the permission_broker service must be used to open USB devices.
// This function asks it to check whether a future Open call will be allowed.
// On all other platforms this is a no-op and always returns true.
- virtual void CheckUsbAccess(const ResultCallback& callback);
+ virtual void CheckUsbAccess(ResultCallback callback);
// On Android applications must request permission from the user to access a
// USB device before it can be opened. After permission is granted the device
// properties may contain information not previously available. On all other
// platforms this is a no-op and always returns true.
- virtual void RequestPermission(const ResultCallback& callback);
+ virtual void RequestPermission(ResultCallback callback);
virtual bool permission_granted() const;
// Creates a UsbDeviceHandle for further manipulation.
- virtual void Open(const OpenCallback& callback) = 0;
+ virtual void Open(OpenCallback callback) = 0;
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
diff --git a/chromium/device/usb/usb_device_android.cc b/chromium/device/usb/usb_device_android.cc
index 35be3b026a6..410b7576825 100644
--- a/chromium/device/usb/usb_device_android.cc
+++ b/chromium/device/usb/usb_device_android.cc
@@ -59,17 +59,17 @@ scoped_refptr<UsbDeviceAndroid> UsbDeviceAndroid::Create(
manufacturer_string, product_string, serial_number, wrapper));
}
-void UsbDeviceAndroid::RequestPermission(const ResultCallback& callback) {
+void UsbDeviceAndroid::RequestPermission(ResultCallback callback) {
if (!permission_granted_ && service_) {
- request_permission_callbacks_.push_back(callback);
+ request_permission_callbacks_.push_back(std::move(callback));
service_->RequestDevicePermission(j_object_, device_id_);
} else {
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(callback, permission_granted_));
+ FROM_HERE, base::BindOnce(std::move(callback), permission_granted_));
}
}
-void UsbDeviceAndroid::Open(const OpenCallback& callback) {
+void UsbDeviceAndroid::Open(OpenCallback callback) {
scoped_refptr<UsbDeviceHandle> device_handle;
if (service_) {
JNIEnv* env = base::android::AttachCurrentThread();
@@ -81,7 +81,7 @@ void UsbDeviceAndroid::Open(const OpenCallback& callback) {
}
}
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(callback, device_handle));
+ FROM_HERE, base::BindOnce(std::move(callback), device_handle));
}
bool UsbDeviceAndroid::permission_granted() const {
@@ -163,8 +163,8 @@ void UsbDeviceAndroid::CallRequestPermissionCallbacks(bool granted) {
permission_granted_ = granted;
std::list<ResultCallback> callbacks;
callbacks.swap(request_permission_callbacks_);
- for (const auto& callback : callbacks)
- callback.Run(granted);
+ for (auto& callback : callbacks)
+ std::move(callback).Run(granted);
}
void UsbDeviceAndroid::OnDeviceOpenedToReadDescriptors(
diff --git a/chromium/device/usb/usb_device_android.h b/chromium/device/usb/usb_device_android.h
index 70782635e79..751b985c8e6 100644
--- a/chromium/device/usb/usb_device_android.h
+++ b/chromium/device/usb/usb_device_android.h
@@ -21,9 +21,9 @@ class UsbDeviceAndroid : public UsbDevice {
const base::android::JavaRef<jobject>& usb_device);
// UsbDevice:
- void RequestPermission(const ResultCallback& callback) override;
+ void RequestPermission(ResultCallback callback) override;
bool permission_granted() const override;
- void Open(const OpenCallback& callback) override;
+ void Open(OpenCallback callback) override;
jint device_id() const { return device_id_; }
void PermissionGranted(bool granted);
diff --git a/chromium/device/usb/usb_device_handle.h b/chromium/device/usb/usb_device_handle.h
index d592a8d4b2e..c9be37a3c73 100644
--- a/chromium/device/usb/usb_device_handle.h
+++ b/chromium/device/usb/usb_device_handle.h
@@ -40,12 +40,12 @@ class UsbDeviceHandle : public base::RefCountedThreadSafe<UsbDeviceHandle> {
UsbTransferStatus status;
};
- using ResultCallback = base::Callback<void(bool)>;
- using TransferCallback = base::Callback<
+ using ResultCallback = base::OnceCallback<void(bool)>;
+ using TransferCallback = base::OnceCallback<
void(UsbTransferStatus, scoped_refptr<net::IOBuffer>, size_t)>;
using IsochronousTransferCallback =
- base::Callback<void(scoped_refptr<net::IOBuffer>,
- const std::vector<IsochronousPacket>& packets)>;
+ base::OnceCallback<void(scoped_refptr<net::IOBuffer>,
+ const std::vector<IsochronousPacket>& packets)>;
virtual scoped_refptr<UsbDevice> GetDevice() const = 0;
@@ -58,16 +58,16 @@ class UsbDeviceHandle : public base::RefCountedThreadSafe<UsbDeviceHandle> {
// Device manipulation operations.
virtual void SetConfiguration(int configuration_value,
- const ResultCallback& callback) = 0;
+ ResultCallback callback) = 0;
virtual void ClaimInterface(int interface_number,
- const ResultCallback& callback) = 0;
+ ResultCallback callback) = 0;
virtual void ReleaseInterface(int interface_number,
- const ResultCallback& callback) = 0;
+ ResultCallback callback) = 0;
virtual void SetInterfaceAlternateSetting(int interface_number,
int alternate_setting,
- const ResultCallback& callback) = 0;
- virtual void ResetDevice(const ResultCallback& callback) = 0;
- virtual void ClearHalt(uint8_t endpoint, const ResultCallback& callback) = 0;
+ ResultCallback callback) = 0;
+ virtual void ResetDevice(ResultCallback callback) = 0;
+ virtual void ClearHalt(uint8_t endpoint, ResultCallback callback) = 0;
// The transfer functions may be called from any thread. The provided callback
// will be run on the caller's thread.
@@ -80,27 +80,27 @@ class UsbDeviceHandle : public base::RefCountedThreadSafe<UsbDeviceHandle> {
scoped_refptr<net::IOBuffer> buffer,
size_t length,
unsigned int timeout,
- const TransferCallback& callback) = 0;
+ TransferCallback callback) = 0;
virtual void IsochronousTransferIn(
uint8_t endpoint_number,
const std::vector<uint32_t>& packet_lengths,
unsigned int timeout,
- const IsochronousTransferCallback& callback) = 0;
+ IsochronousTransferCallback callback) = 0;
virtual void IsochronousTransferOut(
uint8_t endpoint_number,
scoped_refptr<net::IOBuffer> buffer,
const std::vector<uint32_t>& packet_lengths,
unsigned int timeout,
- const IsochronousTransferCallback& callback) = 0;
+ IsochronousTransferCallback callback) = 0;
virtual void GenericTransfer(UsbTransferDirection direction,
uint8_t endpoint_number,
scoped_refptr<net::IOBuffer> buffer,
size_t length,
unsigned int timeout,
- const TransferCallback& callback) = 0;
+ TransferCallback callback) = 0;
// Gets the interface containing |endpoint_address|. Returns nullptr if no
// claimed interface contains that endpoint.
diff --git a/chromium/device/usb/usb_device_handle_impl.cc b/chromium/device/usb/usb_device_handle_impl.cc
index 3740c89f39c..4599fd6850c 100644
--- a/chromium/device/usb/usb_device_handle_impl.cc
+++ b/chromium/device/usb/usb_device_handle_impl.cc
@@ -108,21 +108,21 @@ static UsbTransferStatus ConvertTransferStatus(
static void RunTransferCallback(
scoped_refptr<base::TaskRunner> callback_task_runner,
- const UsbDeviceHandle::TransferCallback& callback,
+ UsbDeviceHandle::TransferCallback callback,
UsbTransferStatus status,
scoped_refptr<net::IOBuffer> buffer,
size_t result) {
if (callback_task_runner->RunsTasksInCurrentSequence()) {
- callback.Run(status, buffer, result);
+ std::move(callback).Run(status, buffer, result);
} else {
callback_task_runner->PostTask(
- FROM_HERE, base::Bind(callback, status, buffer, result));
+ FROM_HERE, base::BindOnce(std::move(callback), status, buffer, result));
}
}
void ReportIsochronousTransferError(
scoped_refptr<base::TaskRunner> callback_task_runner,
- const UsbDeviceHandle::IsochronousTransferCallback& callback,
+ UsbDeviceHandle::IsochronousTransferCallback callback,
const std::vector<uint32_t> packet_lengths,
UsbTransferStatus status) {
std::vector<UsbDeviceHandle::IsochronousPacket> packets(
@@ -133,10 +133,10 @@ void ReportIsochronousTransferError(
packets[i].status = status;
}
if (callback_task_runner->RunsTasksInCurrentSequence()) {
- callback.Run(nullptr, packets);
+ std::move(callback).Run(nullptr, packets);
} else {
- callback_task_runner->PostTask(FROM_HERE,
- base::Bind(callback, nullptr, packets));
+ callback_task_runner->PostTask(
+ FROM_HERE, base::BindOnce(std::move(callback), nullptr, packets));
}
}
@@ -155,8 +155,8 @@ class UsbDeviceHandleImpl::InterfaceClaimer
alternate_setting_ = alternate_setting;
}
- void set_release_callback(const ResultCallback& callback) {
- release_callback_ = callback;
+ void set_release_callback(ResultCallback callback) {
+ release_callback_ = std::move(callback);
}
private:
@@ -190,8 +190,9 @@ UsbDeviceHandleImpl::InterfaceClaimer::~InterfaceClaimer() {
<< ConvertPlatformUsbErrorToString(rc);
}
if (!release_callback_.is_null()) {
- task_runner_->PostTask(FROM_HERE,
- base::Bind(release_callback_, rc == LIBUSB_SUCCESS));
+ task_runner_->PostTask(
+ FROM_HERE,
+ base::BindOnce(std::move(release_callback_), rc == LIBUSB_SUCCESS));
}
}
@@ -199,6 +200,8 @@ UsbDeviceHandleImpl::InterfaceClaimer::~InterfaceClaimer() {
// the UsbDeviceHandle that created it.
class UsbDeviceHandleImpl::Transfer {
public:
+ // These functions takes |*callback| if they successfully create Transfer
+ // instance, otherwise |*callback| left unchanged.
static std::unique_ptr<Transfer> CreateControlTransfer(
scoped_refptr<UsbDeviceHandleImpl> device_handle,
uint8_t type,
@@ -209,7 +212,7 @@ class UsbDeviceHandleImpl::Transfer {
scoped_refptr<net::IOBuffer> buffer,
unsigned int timeout,
scoped_refptr<base::TaskRunner> callback_task_runner,
- const TransferCallback& callback);
+ TransferCallback* callback);
static std::unique_ptr<Transfer> CreateBulkTransfer(
scoped_refptr<UsbDeviceHandleImpl> device_handle,
uint8_t endpoint,
@@ -217,7 +220,7 @@ class UsbDeviceHandleImpl::Transfer {
int length,
unsigned int timeout,
scoped_refptr<base::TaskRunner> callback_task_runner,
- const TransferCallback& callback);
+ TransferCallback* callback);
static std::unique_ptr<Transfer> CreateInterruptTransfer(
scoped_refptr<UsbDeviceHandleImpl> device_handle,
uint8_t endpoint,
@@ -225,7 +228,7 @@ class UsbDeviceHandleImpl::Transfer {
int length,
unsigned int timeout,
scoped_refptr<base::TaskRunner> callback_task_runner,
- const TransferCallback& callback);
+ TransferCallback* callback);
static std::unique_ptr<Transfer> CreateIsochronousTransfer(
scoped_refptr<UsbDeviceHandleImpl> device_handle,
uint8_t endpoint,
@@ -234,7 +237,7 @@ class UsbDeviceHandleImpl::Transfer {
const std::vector<uint32_t>& packet_lengths,
unsigned int timeout,
scoped_refptr<base::TaskRunner> callback_task_runner,
- const IsochronousTransferCallback& callback);
+ IsochronousTransferCallback* callback);
~Transfer();
@@ -258,12 +261,12 @@ class UsbDeviceHandleImpl::Transfer {
scoped_refptr<net::IOBuffer> buffer,
size_t length,
scoped_refptr<base::TaskRunner> callback_task_runner,
- const TransferCallback& callback);
+ TransferCallback callback);
Transfer(scoped_refptr<UsbDeviceHandleImpl> device_handle,
scoped_refptr<InterfaceClaimer> claimed_interface,
scoped_refptr<net::IOBuffer> buffer,
scoped_refptr<base::TaskRunner> callback_task_runner,
- const IsochronousTransferCallback& callback);
+ IsochronousTransferCallback callback);
static void LIBUSB_CALL PlatformCallback(PlatformUsbTransferHandle handle);
@@ -294,14 +297,16 @@ UsbDeviceHandleImpl::Transfer::CreateControlTransfer(
scoped_refptr<net::IOBuffer> buffer,
unsigned int timeout,
scoped_refptr<base::TaskRunner> callback_task_runner,
- const TransferCallback& callback) {
- std::unique_ptr<Transfer> transfer(new Transfer(
- device_handle, nullptr, UsbTransferType::CONTROL, buffer,
- length + LIBUSB_CONTROL_SETUP_SIZE, callback_task_runner, callback));
+ TransferCallback* callback) {
+ std::unique_ptr<Transfer> transfer(
+ new Transfer(device_handle, nullptr, UsbTransferType::CONTROL, buffer,
+ length + LIBUSB_CONTROL_SETUP_SIZE, callback_task_runner,
+ std::move(*callback)));
transfer->platform_transfer_ = libusb_alloc_transfer(0);
if (!transfer->platform_transfer_) {
USB_LOG(ERROR) << "Failed to allocate control transfer.";
+ *callback = std::move(transfer->callback_);
return nullptr;
}
@@ -325,14 +330,16 @@ UsbDeviceHandleImpl::Transfer::CreateBulkTransfer(
int length,
unsigned int timeout,
scoped_refptr<base::TaskRunner> callback_task_runner,
- const TransferCallback& callback) {
+ TransferCallback* callback) {
std::unique_ptr<Transfer> transfer(new Transfer(
device_handle, device_handle->GetClaimedInterfaceForEndpoint(endpoint),
- UsbTransferType::BULK, buffer, length, callback_task_runner, callback));
+ UsbTransferType::BULK, buffer, length, callback_task_runner,
+ std::move(*callback)));
transfer->platform_transfer_ = libusb_alloc_transfer(0);
if (!transfer->platform_transfer_) {
USB_LOG(ERROR) << "Failed to allocate bulk transfer.";
+ *callback = std::move(transfer->callback_);
return nullptr;
}
@@ -354,15 +361,16 @@ UsbDeviceHandleImpl::Transfer::CreateInterruptTransfer(
int length,
unsigned int timeout,
scoped_refptr<base::TaskRunner> callback_task_runner,
- const TransferCallback& callback) {
+ TransferCallback* callback) {
std::unique_ptr<Transfer> transfer(new Transfer(
device_handle, device_handle->GetClaimedInterfaceForEndpoint(endpoint),
UsbTransferType::INTERRUPT, buffer, length, callback_task_runner,
- callback));
+ std::move(*callback)));
transfer->platform_transfer_ = libusb_alloc_transfer(0);
if (!transfer->platform_transfer_) {
USB_LOG(ERROR) << "Failed to allocate interrupt transfer.";
+ *callback = std::move(transfer->callback_);
return nullptr;
}
@@ -385,15 +393,16 @@ UsbDeviceHandleImpl::Transfer::CreateIsochronousTransfer(
const std::vector<uint32_t>& packet_lengths,
unsigned int timeout,
scoped_refptr<base::TaskRunner> callback_task_runner,
- const IsochronousTransferCallback& callback) {
+ IsochronousTransferCallback* callback) {
std::unique_ptr<Transfer> transfer(new Transfer(
device_handle, device_handle->GetClaimedInterfaceForEndpoint(endpoint),
- buffer, callback_task_runner, callback));
+ buffer, callback_task_runner, std::move(*callback)));
int num_packets = static_cast<int>(packet_lengths.size());
transfer->platform_transfer_ = libusb_alloc_transfer(num_packets);
if (!transfer->platform_transfer_) {
USB_LOG(ERROR) << "Failed to allocate isochronous transfer.";
+ *callback = std::move(transfer->iso_callback_);
return nullptr;
}
@@ -415,14 +424,14 @@ UsbDeviceHandleImpl::Transfer::Transfer(
scoped_refptr<net::IOBuffer> buffer,
size_t length,
scoped_refptr<base::TaskRunner> callback_task_runner,
- const TransferCallback& callback)
+ TransferCallback callback)
: transfer_type_(transfer_type),
device_handle_(device_handle),
buffer_(buffer),
claimed_interface_(claimed_interface),
length_(length),
callback_task_runner_(callback_task_runner),
- callback_(callback) {
+ callback_(std::move(callback)) {
task_runner_ = base::ThreadTaskRunnerHandle::Get();
}
@@ -431,13 +440,13 @@ UsbDeviceHandleImpl::Transfer::Transfer(
scoped_refptr<InterfaceClaimer> claimed_interface,
scoped_refptr<net::IOBuffer> buffer,
scoped_refptr<base::TaskRunner> callback_task_runner,
- const IsochronousTransferCallback& callback)
+ IsochronousTransferCallback callback)
: transfer_type_(UsbTransferType::ISOCHRONOUS),
device_handle_(device_handle),
buffer_(buffer),
claimed_interface_(claimed_interface),
callback_task_runner_(callback_task_runner),
- iso_callback_(callback) {
+ iso_callback_(std::move(callback)) {
task_runner_ = base::ThreadTaskRunnerHandle::Get();
}
@@ -521,7 +530,7 @@ void LIBUSB_CALL UsbDeviceHandleImpl::Transfer::PlatformCallback(
void UsbDeviceHandleImpl::Transfer::TransferComplete(UsbTransferStatus status,
size_t bytes_transferred) {
- base::Closure closure;
+ base::OnceClosure closure;
if (transfer_type_ == UsbTransferType::ISOCHRONOUS) {
DCHECK_NE(LIBUSB_TRANSFER_COMPLETED, platform_transfer_->status);
std::vector<IsochronousPacket> packets(platform_transfer_->num_iso_packets);
@@ -530,13 +539,15 @@ void UsbDeviceHandleImpl::Transfer::TransferComplete(UsbTransferStatus status,
packets[i].transferred_length = 0;
packets[i].status = status;
}
- closure = base::Bind(iso_callback_, buffer_, packets);
+ closure = base::BindOnce(std::move(iso_callback_), buffer_, packets);
} else {
- closure = base::Bind(callback_, status, buffer_, bytes_transferred);
+ closure = base::BindOnce(std::move(callback_), status, buffer_,
+ bytes_transferred);
}
task_runner_->PostTask(
- FROM_HERE, base::Bind(&UsbDeviceHandleImpl::TransferComplete,
- device_handle_, base::Unretained(this), closure));
+ FROM_HERE,
+ base::BindOnce(&UsbDeviceHandleImpl::TransferComplete, device_handle_,
+ base::Unretained(this), std::move(closure)));
}
void UsbDeviceHandleImpl::Transfer::IsochronousTransferComplete() {
@@ -548,10 +559,11 @@ void UsbDeviceHandleImpl::Transfer::IsochronousTransferComplete() {
packets[i].status =
ConvertTransferStatus(platform_transfer_->iso_packet_desc[i].status);
}
- task_runner_->PostTask(
- FROM_HERE, base::Bind(&UsbDeviceHandleImpl::TransferComplete,
- device_handle_, base::Unretained(this),
- base::Bind(iso_callback_, buffer_, packets)));
+ task_runner_->PostTask(FROM_HERE,
+ base::BindOnce(&UsbDeviceHandleImpl::TransferComplete,
+ device_handle_, base::Unretained(this),
+ base::BindOnce(std::move(iso_callback_),
+ buffer_, packets)));
}
scoped_refptr<UsbDevice> UsbDeviceHandleImpl::GetDevice() const {
@@ -586,10 +598,10 @@ void UsbDeviceHandleImpl::Close() {
}
void UsbDeviceHandleImpl::SetConfiguration(int configuration_value,
- const ResultCallback& callback) {
+ ResultCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!device_) {
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
@@ -600,33 +612,34 @@ void UsbDeviceHandleImpl::SetConfiguration(int configuration_value,
blocking_task_runner_->PostTask(
FROM_HERE,
- base::Bind(&UsbDeviceHandleImpl::SetConfigurationOnBlockingThread, this,
- configuration_value, callback));
+ base::BindOnce(&UsbDeviceHandleImpl::SetConfigurationOnBlockingThread,
+ this, configuration_value, std::move(callback)));
}
void UsbDeviceHandleImpl::ClaimInterface(int interface_number,
- const ResultCallback& callback) {
+ ResultCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!device_) {
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
if (base::ContainsKey(claimed_interfaces_, interface_number)) {
- callback.Run(true);
+ std::move(callback).Run(true);
return;
}
blocking_task_runner_->PostTask(
FROM_HERE,
- base::Bind(&UsbDeviceHandleImpl::ClaimInterfaceOnBlockingThread, this,
- interface_number, callback));
+ base::BindOnce(&UsbDeviceHandleImpl::ClaimInterfaceOnBlockingThread, this,
+ interface_number, std::move(callback)));
}
void UsbDeviceHandleImpl::ReleaseInterface(int interface_number,
- const ResultCallback& callback) {
+ ResultCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!device_ || !base::ContainsKey(claimed_interfaces_, interface_number)) {
- task_runner_->PostTask(FROM_HERE, base::Bind(callback, false));
+ task_runner_->PostTask(FROM_HERE,
+ base::BindOnce(std::move(callback), false));
return;
}
@@ -639,7 +652,7 @@ void UsbDeviceHandleImpl::ReleaseInterface(int interface_number,
}
}
interface_claimer->AddRef();
- interface_claimer->set_release_callback(callback);
+ interface_claimer->set_release_callback(std::move(callback));
blocking_task_runner_->ReleaseSoon(FROM_HERE, interface_claimer);
claimed_interfaces_.erase(interface_number);
@@ -649,37 +662,37 @@ void UsbDeviceHandleImpl::ReleaseInterface(int interface_number,
void UsbDeviceHandleImpl::SetInterfaceAlternateSetting(
int interface_number,
int alternate_setting,
- const ResultCallback& callback) {
+ ResultCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!device_ || !base::ContainsKey(claimed_interfaces_, interface_number)) {
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
blocking_task_runner_->PostTask(
FROM_HERE,
- base::Bind(
+ base::BindOnce(
&UsbDeviceHandleImpl::SetInterfaceAlternateSettingOnBlockingThread,
- this, interface_number, alternate_setting, callback));
+ this, interface_number, alternate_setting, std::move(callback)));
}
-void UsbDeviceHandleImpl::ResetDevice(const ResultCallback& callback) {
+void UsbDeviceHandleImpl::ResetDevice(ResultCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!device_) {
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
blocking_task_runner_->PostTask(
- FROM_HERE, base::Bind(&UsbDeviceHandleImpl::ResetDeviceOnBlockingThread,
- this, callback));
+ FROM_HERE,
+ base::BindOnce(&UsbDeviceHandleImpl::ResetDeviceOnBlockingThread, this,
+ std::move(callback)));
}
-void UsbDeviceHandleImpl::ClearHalt(uint8_t endpoint,
- const ResultCallback& callback) {
+void UsbDeviceHandleImpl::ClearHalt(uint8_t endpoint, ResultCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!device_) {
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
@@ -692,8 +705,8 @@ void UsbDeviceHandleImpl::ClearHalt(uint8_t endpoint,
}
blocking_task_runner_->PostTask(
- FROM_HERE, base::Bind(&UsbDeviceHandleImpl::ClearHaltOnBlockingThread,
- this, endpoint, callback));
+ FROM_HERE, base::BindOnce(&UsbDeviceHandleImpl::ClearHaltOnBlockingThread,
+ this, endpoint, std::move(callback)));
}
void UsbDeviceHandleImpl::ControlTransfer(UsbTransferDirection direction,
@@ -705,17 +718,18 @@ void UsbDeviceHandleImpl::ControlTransfer(UsbTransferDirection direction,
scoped_refptr<net::IOBuffer> buffer,
size_t length,
unsigned int timeout,
- const TransferCallback& callback) {
+ TransferCallback callback) {
if (task_runner_->BelongsToCurrentThread()) {
ControlTransferInternal(direction, request_type, recipient, request, value,
index, buffer, length, timeout, task_runner_,
- callback);
+ std::move(callback));
} else {
task_runner_->PostTask(
- FROM_HERE, base::Bind(&UsbDeviceHandleImpl::ControlTransferInternal,
- this, direction, request_type, recipient, request,
- value, index, buffer, length, timeout,
- base::ThreadTaskRunnerHandle::Get(), callback));
+ FROM_HERE, base::BindOnce(&UsbDeviceHandleImpl::ControlTransferInternal,
+ this, direction, request_type, recipient,
+ request, value, index, buffer, length,
+ timeout, base::ThreadTaskRunnerHandle::Get(),
+ std::move(callback)));
}
}
@@ -723,18 +737,19 @@ void UsbDeviceHandleImpl::IsochronousTransferIn(
uint8_t endpoint_number,
const std::vector<uint32_t>& packet_lengths,
unsigned int timeout,
- const IsochronousTransferCallback& callback) {
+ IsochronousTransferCallback callback) {
uint8_t endpoint_address =
ConvertTransferDirection(UsbTransferDirection::INBOUND) | endpoint_number;
if (task_runner_->BelongsToCurrentThread()) {
IsochronousTransferInInternal(endpoint_address, packet_lengths, timeout,
- task_runner_, callback);
+ task_runner_, std::move(callback));
} else {
task_runner_->PostTask(
FROM_HERE,
- base::Bind(&UsbDeviceHandleImpl::IsochronousTransferInInternal, this,
- endpoint_address, packet_lengths, timeout,
- base::ThreadTaskRunnerHandle::Get(), callback));
+ base::BindOnce(&UsbDeviceHandleImpl::IsochronousTransferInInternal,
+ this, endpoint_address, packet_lengths, timeout,
+ base::ThreadTaskRunnerHandle::Get(),
+ std::move(callback)));
}
}
@@ -743,19 +758,20 @@ void UsbDeviceHandleImpl::IsochronousTransferOut(
scoped_refptr<net::IOBuffer> buffer,
const std::vector<uint32_t>& packet_lengths,
unsigned int timeout,
- const IsochronousTransferCallback& callback) {
+ IsochronousTransferCallback callback) {
uint8_t endpoint_address =
ConvertTransferDirection(UsbTransferDirection::OUTBOUND) |
endpoint_number;
if (task_runner_->BelongsToCurrentThread()) {
IsochronousTransferOutInternal(endpoint_address, buffer, packet_lengths,
- timeout, task_runner_, callback);
+ timeout, task_runner_, std::move(callback));
} else {
task_runner_->PostTask(
FROM_HERE,
- base::Bind(&UsbDeviceHandleImpl::IsochronousTransferOutInternal, this,
- endpoint_address, buffer, packet_lengths, timeout,
- base::ThreadTaskRunnerHandle::Get(), callback));
+ base::BindOnce(&UsbDeviceHandleImpl::IsochronousTransferOutInternal,
+ this, endpoint_address, buffer, packet_lengths, timeout,
+ base::ThreadTaskRunnerHandle::Get(),
+ std::move(callback)));
}
}
@@ -764,17 +780,18 @@ void UsbDeviceHandleImpl::GenericTransfer(UsbTransferDirection direction,
scoped_refptr<net::IOBuffer> buffer,
size_t length,
unsigned int timeout,
- const TransferCallback& callback) {
+ TransferCallback callback) {
uint8_t endpoint_address =
ConvertTransferDirection(direction) | endpoint_number;
if (task_runner_->BelongsToCurrentThread()) {
GenericTransferInternal(endpoint_address, buffer, length, timeout,
- task_runner_, callback);
+ task_runner_, std::move(callback));
} else {
task_runner_->PostTask(
- FROM_HERE, base::Bind(&UsbDeviceHandleImpl::GenericTransferInternal,
- this, endpoint_address, buffer, length, timeout,
- base::ThreadTaskRunnerHandle::Get(), callback));
+ FROM_HERE, base::BindOnce(&UsbDeviceHandleImpl::GenericTransferInternal,
+ this, endpoint_address, buffer, length,
+ timeout, base::ThreadTaskRunnerHandle::Get(),
+ std::move(callback)));
}
}
@@ -810,28 +827,28 @@ UsbDeviceHandleImpl::~UsbDeviceHandleImpl() {
libusb_close(handle_);
} else {
blocking_task_runner_->PostTask(FROM_HERE,
- base::Bind(&libusb_close, handle_));
+ base::BindOnce(&libusb_close, handle_));
}
}
void UsbDeviceHandleImpl::SetConfigurationOnBlockingThread(
int configuration_value,
- const ResultCallback& callback) {
+ ResultCallback callback) {
int rv = libusb_set_configuration(handle_, configuration_value);
if (rv != LIBUSB_SUCCESS) {
USB_LOG(EVENT) << "Failed to set configuration " << configuration_value
<< ": " << ConvertPlatformUsbErrorToString(rv);
}
task_runner_->PostTask(
- FROM_HERE, base::Bind(&UsbDeviceHandleImpl::SetConfigurationComplete,
- this, rv == LIBUSB_SUCCESS, callback));
+ FROM_HERE,
+ base::BindOnce(&UsbDeviceHandleImpl::SetConfigurationComplete, this,
+ rv == LIBUSB_SUCCESS, std::move(callback)));
}
-void UsbDeviceHandleImpl::SetConfigurationComplete(
- bool success,
- const ResultCallback& callback) {
+void UsbDeviceHandleImpl::SetConfigurationComplete(bool success,
+ ResultCallback callback) {
if (!device_) {
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
@@ -839,12 +856,12 @@ void UsbDeviceHandleImpl::SetConfigurationComplete(
device_->RefreshActiveConfiguration();
RefreshEndpointMap();
}
- callback.Run(success);
+ std::move(callback).Run(success);
}
void UsbDeviceHandleImpl::ClaimInterfaceOnBlockingThread(
int interface_number,
- const ResultCallback& callback) {
+ ResultCallback callback) {
int rv = libusb_claim_interface(handle_, interface_number);
scoped_refptr<InterfaceClaimer> interface_claimer;
if (rv == LIBUSB_SUCCESS) {
@@ -855,13 +872,13 @@ void UsbDeviceHandleImpl::ClaimInterfaceOnBlockingThread(
<< ConvertPlatformUsbErrorToString(rv);
}
task_runner_->PostTask(
- FROM_HERE, base::Bind(&UsbDeviceHandleImpl::ClaimInterfaceComplete, this,
- interface_claimer, callback));
+ FROM_HERE, base::BindOnce(&UsbDeviceHandleImpl::ClaimInterfaceComplete,
+ this, interface_claimer, std::move(callback)));
}
void UsbDeviceHandleImpl::ClaimInterfaceComplete(
scoped_refptr<InterfaceClaimer> interface_claimer,
- const ResultCallback& callback) {
+ ResultCallback callback) {
if (!device_) {
if (interface_claimer) {
// Ensure that the InterfaceClaimer is released on the blocking thread.
@@ -871,7 +888,7 @@ void UsbDeviceHandleImpl::ClaimInterfaceComplete(
blocking_task_runner_->ReleaseSoon(FROM_HERE, raw_interface_claimer);
}
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
@@ -880,13 +897,13 @@ void UsbDeviceHandleImpl::ClaimInterfaceComplete(
interface_claimer;
RefreshEndpointMap();
}
- callback.Run(interface_claimer != nullptr);
+ std::move(callback).Run(interface_claimer != nullptr);
}
void UsbDeviceHandleImpl::SetInterfaceAlternateSettingOnBlockingThread(
int interface_number,
int alternate_setting,
- const ResultCallback& callback) {
+ ResultCallback callback) {
int rv = libusb_set_interface_alt_setting(handle_, interface_number,
alternate_setting);
if (rv != LIBUSB_SUCCESS) {
@@ -896,18 +913,18 @@ void UsbDeviceHandleImpl::SetInterfaceAlternateSettingOnBlockingThread(
}
task_runner_->PostTask(
FROM_HERE,
- base::Bind(&UsbDeviceHandleImpl::SetInterfaceAlternateSettingComplete,
- this, interface_number, alternate_setting,
- rv == LIBUSB_SUCCESS, callback));
+ base::BindOnce(&UsbDeviceHandleImpl::SetInterfaceAlternateSettingComplete,
+ this, interface_number, alternate_setting,
+ rv == LIBUSB_SUCCESS, std::move(callback)));
}
void UsbDeviceHandleImpl::SetInterfaceAlternateSettingComplete(
int interface_number,
int alternate_setting,
bool success,
- const ResultCallback& callback) {
+ ResultCallback callback) {
if (!device_) {
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
@@ -916,28 +933,28 @@ void UsbDeviceHandleImpl::SetInterfaceAlternateSettingComplete(
alternate_setting);
RefreshEndpointMap();
}
- callback.Run(success);
+ std::move(callback).Run(success);
}
-void UsbDeviceHandleImpl::ResetDeviceOnBlockingThread(
- const ResultCallback& callback) {
+void UsbDeviceHandleImpl::ResetDeviceOnBlockingThread(ResultCallback callback) {
int rv = libusb_reset_device(handle_);
if (rv != LIBUSB_SUCCESS) {
USB_LOG(EVENT) << "Failed to reset device: "
<< ConvertPlatformUsbErrorToString(rv);
}
- task_runner_->PostTask(FROM_HERE, base::Bind(callback, rv == LIBUSB_SUCCESS));
+ task_runner_->PostTask(
+ FROM_HERE, base::BindOnce(std::move(callback), rv == LIBUSB_SUCCESS));
}
-void UsbDeviceHandleImpl::ClearHaltOnBlockingThread(
- uint8_t endpoint,
- const ResultCallback& callback) {
+void UsbDeviceHandleImpl::ClearHaltOnBlockingThread(uint8_t endpoint,
+ ResultCallback callback) {
int rv = libusb_clear_halt(handle_, endpoint);
if (rv != LIBUSB_SUCCESS) {
USB_LOG(EVENT) << "Failed to clear halt: "
<< ConvertPlatformUsbErrorToString(rv);
}
- task_runner_->PostTask(FROM_HERE, base::Bind(callback, rv == LIBUSB_SUCCESS));
+ task_runner_->PostTask(
+ FROM_HERE, base::BindOnce(std::move(callback), rv == LIBUSB_SUCCESS));
}
void UsbDeviceHandleImpl::RefreshEndpointMap() {
@@ -982,18 +999,18 @@ void UsbDeviceHandleImpl::ControlTransferInternal(
size_t length,
unsigned int timeout,
scoped_refptr<base::TaskRunner> callback_task_runner,
- const TransferCallback& callback) {
+ TransferCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!device_) {
- RunTransferCallback(callback_task_runner, callback,
+ RunTransferCallback(callback_task_runner, std::move(callback),
UsbTransferStatus::DISCONNECT, buffer, 0);
return;
}
if (!base::IsValueInRangeForNumericType<uint16_t>(length)) {
USB_LOG(USER) << "Transfer too long.";
- RunTransferCallback(callback_task_runner, callback,
+ RunTransferCallback(callback_task_runner, std::move(callback),
UsbTransferStatus::TRANSFER_ERROR, buffer, 0);
return;
}
@@ -1002,7 +1019,7 @@ void UsbDeviceHandleImpl::ControlTransferInternal(
scoped_refptr<net::IOBuffer> resized_buffer =
new net::IOBufferWithSize(resized_length);
if (!resized_buffer.get()) {
- RunTransferCallback(callback_task_runner, callback,
+ RunTransferCallback(callback_task_runner, std::move(callback),
UsbTransferStatus::TRANSFER_ERROR, buffer, 0);
return;
}
@@ -1012,9 +1029,10 @@ void UsbDeviceHandleImpl::ControlTransferInternal(
std::unique_ptr<Transfer> transfer = Transfer::CreateControlTransfer(
this, CreateRequestType(direction, request_type, recipient), request,
value, index, static_cast<uint16_t>(length), resized_buffer, timeout,
- callback_task_runner, callback);
+ callback_task_runner, &callback);
if (!transfer) {
- RunTransferCallback(callback_task_runner, callback,
+ DCHECK(callback);
+ RunTransferCallback(callback_task_runner, std::move(callback),
UsbTransferStatus::TRANSFER_ERROR, buffer, 0);
return;
}
@@ -1027,11 +1045,11 @@ void UsbDeviceHandleImpl::IsochronousTransferInInternal(
const std::vector<uint32_t>& packet_lengths,
unsigned int timeout,
scoped_refptr<base::TaskRunner> callback_task_runner,
- const IsochronousTransferCallback& callback) {
+ IsochronousTransferCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!device_) {
- ReportIsochronousTransferError(callback_task_runner, callback,
+ ReportIsochronousTransferError(callback_task_runner, std::move(callback),
packet_lengths,
UsbTransferStatus::DISCONNECT);
return;
@@ -1042,8 +1060,8 @@ void UsbDeviceHandleImpl::IsochronousTransferInInternal(
scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(length));
std::unique_ptr<Transfer> transfer = Transfer::CreateIsochronousTransfer(
this, endpoint_address, buffer, length, packet_lengths, timeout,
- callback_task_runner, callback);
-
+ callback_task_runner, &callback);
+ DCHECK(transfer);
SubmitTransfer(std::move(transfer));
}
@@ -1053,11 +1071,11 @@ void UsbDeviceHandleImpl::IsochronousTransferOutInternal(
const std::vector<uint32_t>& packet_lengths,
unsigned int timeout,
scoped_refptr<base::TaskRunner> callback_task_runner,
- const IsochronousTransferCallback& callback) {
+ IsochronousTransferCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!device_) {
- ReportIsochronousTransferError(callback_task_runner, callback,
+ ReportIsochronousTransferError(callback_task_runner, std::move(callback),
packet_lengths,
UsbTransferStatus::DISCONNECT);
return;
@@ -1067,8 +1085,8 @@ void UsbDeviceHandleImpl::IsochronousTransferOutInternal(
std::accumulate(packet_lengths.begin(), packet_lengths.end(), 0u);
std::unique_ptr<Transfer> transfer = Transfer::CreateIsochronousTransfer(
this, endpoint_address, buffer, length, packet_lengths, timeout,
- callback_task_runner, callback);
-
+ callback_task_runner, &callback);
+ DCHECK(transfer);
SubmitTransfer(std::move(transfer));
}
@@ -1078,11 +1096,11 @@ void UsbDeviceHandleImpl::GenericTransferInternal(
size_t length,
unsigned int timeout,
scoped_refptr<base::TaskRunner> callback_task_runner,
- const TransferCallback& callback) {
+ TransferCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!device_) {
- RunTransferCallback(callback_task_runner, callback,
+ RunTransferCallback(callback_task_runner, std::move(callback),
UsbTransferStatus::DISCONNECT, buffer, 0);
return;
}
@@ -1092,14 +1110,14 @@ void UsbDeviceHandleImpl::GenericTransferInternal(
USB_LOG(DEBUG) << "Failed to submit transfer because endpoint "
<< static_cast<int>(endpoint_address)
<< " not part of a claimed interface.";
- RunTransferCallback(callback_task_runner, callback,
+ RunTransferCallback(callback_task_runner, std::move(callback),
UsbTransferStatus::TRANSFER_ERROR, buffer, 0);
return;
}
if (!base::IsValueInRangeForNumericType<int>(length)) {
USB_LOG(DEBUG) << "Transfer too long.";
- RunTransferCallback(callback_task_runner, callback,
+ RunTransferCallback(callback_task_runner, std::move(callback),
UsbTransferStatus::TRANSFER_ERROR, buffer, 0);
return;
}
@@ -1109,44 +1127,45 @@ void UsbDeviceHandleImpl::GenericTransferInternal(
if (transfer_type == UsbTransferType::BULK) {
transfer = Transfer::CreateBulkTransfer(this, endpoint_address, buffer,
static_cast<int>(length), timeout,
- callback_task_runner, callback);
+ callback_task_runner, &callback);
} else if (transfer_type == UsbTransferType::INTERRUPT) {
transfer = Transfer::CreateInterruptTransfer(
this, endpoint_address, buffer, static_cast<int>(length), timeout,
- callback_task_runner, callback);
+ callback_task_runner, &callback);
} else {
USB_LOG(DEBUG) << "Endpoint " << static_cast<int>(endpoint_address)
<< " is not a bulk or interrupt endpoint.";
- RunTransferCallback(callback_task_runner, callback,
+ RunTransferCallback(callback_task_runner, std::move(callback),
UsbTransferStatus::TRANSFER_ERROR, buffer, 0);
return;
}
-
+ DCHECK(transfer);
SubmitTransfer(std::move(transfer));
}
void UsbDeviceHandleImpl::SubmitTransfer(std::unique_ptr<Transfer> transfer) {
DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(transfer);
// Transfer is owned by libusb until its completion callback is run. This
// object holds a weak reference.
transfers_.insert(transfer.get());
blocking_task_runner_->PostTask(
FROM_HERE,
- base::Bind(&Transfer::Submit, base::Unretained(transfer.release())));
+ base::BindOnce(&Transfer::Submit, base::Unretained(transfer.release())));
}
void UsbDeviceHandleImpl::TransferComplete(Transfer* transfer,
- const base::Closure& callback) {
+ base::OnceClosure callback) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(base::ContainsKey(transfers_, transfer))
<< "Missing transfer completed";
transfers_.erase(transfer);
if (transfer->callback_task_runner()->RunsTasksInCurrentSequence()) {
- callback.Run();
+ std::move(callback).Run();
} else {
- transfer->callback_task_runner()->PostTask(FROM_HERE, callback);
+ transfer->callback_task_runner()->PostTask(FROM_HERE, std::move(callback));
}
// libusb_free_transfer races with libusb_submit_transfer and only work-
diff --git a/chromium/device/usb/usb_device_handle_impl.h b/chromium/device/usb/usb_device_handle_impl.h
index 1322e192f0b..c5e7847e8fa 100644
--- a/chromium/device/usb/usb_device_handle_impl.h
+++ b/chromium/device/usb/usb_device_handle_impl.h
@@ -50,16 +50,14 @@ class UsbDeviceHandleImpl : public UsbDeviceHandle {
scoped_refptr<UsbDevice> GetDevice() const override;
void Close() override;
void SetConfiguration(int configuration_value,
- const ResultCallback& callback) override;
- void ClaimInterface(int interface_number,
- const ResultCallback& callback) override;
- void ReleaseInterface(int interface_number,
- const ResultCallback& callback) override;
+ ResultCallback callback) override;
+ void ClaimInterface(int interface_number, ResultCallback callback) override;
+ void ReleaseInterface(int interface_number, ResultCallback callback) override;
void SetInterfaceAlternateSetting(int interface_number,
int alternate_setting,
- const ResultCallback& callback) override;
- void ResetDevice(const ResultCallback& callback) override;
- void ClearHalt(uint8_t endpoint, const ResultCallback& callback) override;
+ ResultCallback callback) override;
+ void ResetDevice(ResultCallback callback) override;
+ void ClearHalt(uint8_t endpoint, ResultCallback callback) override;
void ControlTransfer(UsbTransferDirection direction,
UsbControlTransferType request_type,
@@ -70,27 +68,25 @@ class UsbDeviceHandleImpl : public UsbDeviceHandle {
scoped_refptr<net::IOBuffer> buffer,
size_t length,
unsigned int timeout,
- const TransferCallback& callback) override;
+ TransferCallback callback) override;
- void IsochronousTransferIn(
- uint8_t endpoint,
- const std::vector<uint32_t>& packet_lengths,
- unsigned int timeout,
- const IsochronousTransferCallback& callback) override;
+ void IsochronousTransferIn(uint8_t endpoint,
+ const std::vector<uint32_t>& packet_lengths,
+ unsigned int timeout,
+ IsochronousTransferCallback callback) override;
- void IsochronousTransferOut(
- uint8_t endpoint,
- scoped_refptr<net::IOBuffer> buffer,
- const std::vector<uint32_t>& packet_lengths,
- unsigned int timeout,
- const IsochronousTransferCallback& callback) override;
+ void IsochronousTransferOut(uint8_t endpoint,
+ scoped_refptr<net::IOBuffer> buffer,
+ const std::vector<uint32_t>& packet_lengths,
+ unsigned int timeout,
+ IsochronousTransferCallback callback) override;
void GenericTransfer(UsbTransferDirection direction,
uint8_t endpoint_number,
scoped_refptr<net::IOBuffer> buffer,
size_t length,
unsigned int timeout,
- const TransferCallback& callback) override;
+ TransferCallback callback) override;
const UsbInterfaceDescriptor* FindInterfaceByEndpoint(
uint8_t endpoint_address) override;
@@ -113,23 +109,21 @@ class UsbDeviceHandleImpl : public UsbDeviceHandle {
class Transfer;
void SetConfigurationOnBlockingThread(int configuration_value,
- const ResultCallback& callback);
- void SetConfigurationComplete(bool success, const ResultCallback& callback);
+ ResultCallback callback);
+ void SetConfigurationComplete(bool success, ResultCallback callback);
void ClaimInterfaceOnBlockingThread(int interface_number,
- const ResultCallback& callback);
+ ResultCallback callback);
void ClaimInterfaceComplete(scoped_refptr<InterfaceClaimer> interface_claimer,
- const ResultCallback& callback);
- void SetInterfaceAlternateSettingOnBlockingThread(
- int interface_number,
- int alternate_setting,
- const ResultCallback& callback);
+ ResultCallback callback);
+ void SetInterfaceAlternateSettingOnBlockingThread(int interface_number,
+ int alternate_setting,
+ ResultCallback callback);
void SetInterfaceAlternateSettingComplete(int interface_number,
int alternate_setting,
bool success,
- const ResultCallback& callback);
- void ResetDeviceOnBlockingThread(const ResultCallback& callback);
- void ClearHaltOnBlockingThread(uint8_t endpoint,
- const ResultCallback& callback);
+ ResultCallback callback);
+ void ResetDeviceOnBlockingThread(ResultCallback callback);
+ void ClearHaltOnBlockingThread(uint8_t endpoint, ResultCallback callback);
// Refresh endpoint_map_ after ClaimInterface, ReleaseInterface and
// SetInterfaceAlternateSetting.
@@ -151,14 +145,14 @@ class UsbDeviceHandleImpl : public UsbDeviceHandle {
size_t length,
unsigned int timeout,
scoped_refptr<base::TaskRunner> callback_task_runner,
- const TransferCallback& callback);
+ TransferCallback callback);
void IsochronousTransferInInternal(
uint8_t endpoint_address,
const std::vector<uint32_t>& packet_lengths,
unsigned int timeout,
scoped_refptr<base::TaskRunner> callback_task_runner,
- const IsochronousTransferCallback& callback);
+ IsochronousTransferCallback callback);
void IsochronousTransferOutInternal(
uint8_t endpoint_address,
@@ -166,7 +160,7 @@ class UsbDeviceHandleImpl : public UsbDeviceHandle {
const std::vector<uint32_t>& packet_lengths,
unsigned int timeout,
scoped_refptr<base::TaskRunner> callback_task_runner,
- const IsochronousTransferCallback& callback);
+ IsochronousTransferCallback callback);
void GenericTransferInternal(
uint8_t endpoint_address,
@@ -174,7 +168,7 @@ class UsbDeviceHandleImpl : public UsbDeviceHandle {
size_t length,
unsigned int timeout,
scoped_refptr<base::TaskRunner> callback_task_runner,
- const TransferCallback& callback);
+ TransferCallback callback);
// Submits a transfer and starts tracking it. Retains the buffer and copies
// the completion callback until the transfer finishes, whereupon it invokes
@@ -183,7 +177,7 @@ class UsbDeviceHandleImpl : public UsbDeviceHandle {
// Removes the transfer from the in-flight transfer set and invokes the
// completion callback.
- void TransferComplete(Transfer* transfer, const base::Closure& callback);
+ void TransferComplete(Transfer* transfer, base::OnceClosure callback);
scoped_refptr<UsbDeviceImpl> device_;
diff --git a/chromium/device/usb/usb_device_handle_unittest.cc b/chromium/device/usb/usb_device_handle_unittest.cc
index 9cc86808276..093b4e1c8c3 100644
--- a/chromium/device/usb/usb_device_handle_unittest.cc
+++ b/chromium/device/usb/usb_device_handle_unittest.cc
@@ -351,7 +351,7 @@ TEST_F(UsbDeviceHandleTest, CancelOnClose) {
ASSERT_EQ(UsbTransferStatus::CANCELLED, completion.status());
}
-TEST_F(UsbDeviceHandleTest, CancelOnDisconnect) {
+TEST_F(UsbDeviceHandleTest, ErrorOnDisconnect) {
if (!UsbTestGadget::IsTestEnabled()) {
return;
}
@@ -379,7 +379,12 @@ TEST_F(UsbDeviceHandleTest, CancelOnDisconnect) {
ASSERT_TRUE(gadget->Disconnect());
completion.WaitForResult();
- ASSERT_EQ(UsbTransferStatus::DISCONNECT, completion.status());
+ // Depending on timing the transfer can be cancelled by the disconnection, be
+ // rejected because the device is already missing or result in another generic
+ // error as the device drops off the bus.
+ EXPECT_TRUE(completion.status() == UsbTransferStatus::CANCELLED ||
+ completion.status() == UsbTransferStatus::DISCONNECT ||
+ completion.status() == UsbTransferStatus::TRANSFER_ERROR);
handle->Close();
}
diff --git a/chromium/device/usb/usb_device_handle_usbfs.cc b/chromium/device/usb/usb_device_handle_usbfs.cc
index 37b3bb1c132..e69b55d985a 100644
--- a/chromium/device/usb/usb_device_handle_usbfs.cc
+++ b/chromium/device/usb/usb_device_handle_usbfs.cc
@@ -119,14 +119,11 @@ UsbTransferStatus ConvertTransferResult(int rc) {
return UsbTransferStatus::COMPLETED;
case EPIPE:
return UsbTransferStatus::STALLED;
- case ENODEV:
- case ESHUTDOWN:
- case EPROTO:
- return UsbTransferStatus::DISCONNECT;
default:
- // TODO(reillyg): Add a specific error message whenever one of the cases
- // above fails to match.
- USB_LOG(ERROR) << "Unknown system error: "
+ // Other errors are difficult to map to UsbTransferStatus and may be
+ // emitted in situations that vary by host controller. Log the specific
+ // error and return a generic one.
+ USB_LOG(ERROR) << "Low-level transfer error: "
<< logging::SystemErrorCodeToString(rc);
return UsbTransferStatus::TRANSFER_ERROR;
}
@@ -144,14 +141,13 @@ class UsbDeviceHandleUsbfs::FileThreadHelper {
void Start();
void ReleaseFileDescriptor();
- void SetConfiguration(int configuration_value,
- const ResultCallback& callback);
- void ReleaseInterface(int interface_number, const ResultCallback& callback);
+ void SetConfiguration(int configuration_value, ResultCallback callback);
+ void ReleaseInterface(int interface_number, ResultCallback callback);
void SetInterface(int interface_number,
int alternate_setting,
- const ResultCallback& callback);
- void ResetDevice(const ResultCallback& callback);
- void ClearHalt(uint8_t endpoint_address, const ResultCallback& callback);
+ ResultCallback callback);
+ void ResetDevice(ResultCallback callback);
+ void ClearHalt(uint8_t endpoint_address, ResultCallback callback);
void DiscardUrb(Transfer* transfer);
private:
@@ -170,10 +166,10 @@ class UsbDeviceHandleUsbfs::FileThreadHelper {
struct UsbDeviceHandleUsbfs::Transfer {
Transfer() = delete;
Transfer(scoped_refptr<net::IOBuffer> buffer,
- const TransferCallback& callback,
+ TransferCallback callback,
scoped_refptr<base::SingleThreadTaskRunner> callback_runner);
Transfer(scoped_refptr<net::IOBuffer> buffer,
- const IsochronousTransferCallback& callback);
+ IsochronousTransferCallback callback);
~Transfer();
void* operator new(std::size_t size, size_t number_of_iso_packets);
@@ -191,9 +187,10 @@ struct UsbDeviceHandleUsbfs::Transfer {
bool discarded = false;
bool reaped = false;
- private:
TransferCallback callback;
IsochronousTransferCallback isoc_callback;
+
+ private:
scoped_refptr<base::SingleThreadTaskRunner> callback_runner;
DISALLOW_COPY_AND_ASSIGN(Transfer);
@@ -238,7 +235,7 @@ void UsbDeviceHandleUsbfs::FileThreadHelper::ReleaseFileDescriptor() {
void UsbDeviceHandleUsbfs::FileThreadHelper::SetConfiguration(
int configuration_value,
- const ResultCallback& callback) {
+ ResultCallback callback) {
DCHECK(sequence_checker_.CalledOnValidSequence());
int rc = HANDLE_EINTR(
@@ -246,32 +243,34 @@ void UsbDeviceHandleUsbfs::FileThreadHelper::SetConfiguration(
if (rc)
USB_PLOG(DEBUG) << "Failed to set configuration " << configuration_value;
task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&UsbDeviceHandleUsbfs::SetConfigurationComplete,
- device_handle_, configuration_value, rc == 0, callback));
+ FROM_HERE, base::BindOnce(&UsbDeviceHandleUsbfs::SetConfigurationComplete,
+ device_handle_, configuration_value, rc == 0,
+ std::move(callback)));
}
void UsbDeviceHandleUsbfs::FileThreadHelper::ReleaseInterface(
int interface_number,
- const ResultCallback& callback) {
+ ResultCallback callback) {
DCHECK(sequence_checker_.CalledOnValidSequence());
int rc = HANDLE_EINTR(
ioctl(fd_.get(), USBDEVFS_RELEASEINTERFACE, &interface_number));
if (rc) {
USB_PLOG(DEBUG) << "Failed to release interface " << interface_number;
- task_runner_->PostTask(FROM_HERE, base::Bind(callback, false));
+ task_runner_->PostTask(FROM_HERE,
+ base::BindOnce(std::move(callback), false));
} else {
task_runner_->PostTask(
- FROM_HERE, base::Bind(&UsbDeviceHandleUsbfs::ReleaseInterfaceComplete,
- device_handle_, interface_number, callback));
+ FROM_HERE,
+ base::BindOnce(&UsbDeviceHandleUsbfs::ReleaseInterfaceComplete,
+ device_handle_, interface_number, std::move(callback)));
}
}
void UsbDeviceHandleUsbfs::FileThreadHelper::SetInterface(
int interface_number,
int alternate_setting,
- const ResultCallback& callback) {
+ ResultCallback callback) {
DCHECK(sequence_checker_.CalledOnValidSequence());
usbdevfs_setinterface cmd = {0};
@@ -282,11 +281,12 @@ void UsbDeviceHandleUsbfs::FileThreadHelper::SetInterface(
USB_PLOG(DEBUG) << "Failed to set interface " << interface_number
<< " to alternate setting " << alternate_setting;
}
- task_runner_->PostTask(FROM_HERE, base::Bind(callback, rc == 0));
+ task_runner_->PostTask(FROM_HERE,
+ base::BindOnce(std::move(callback), rc == 0));
}
void UsbDeviceHandleUsbfs::FileThreadHelper::ResetDevice(
- const ResultCallback& callback) {
+ ResultCallback callback) {
DCHECK(sequence_checker_.CalledOnValidSequence());
// TODO(reillyg): libusb releases interfaces before and then reclaims
@@ -295,12 +295,13 @@ void UsbDeviceHandleUsbfs::FileThreadHelper::ResetDevice(
int rc = HANDLE_EINTR(ioctl(fd_.get(), USBDEVFS_RESET, nullptr));
if (rc)
USB_PLOG(DEBUG) << "Failed to reset the device";
- task_runner_->PostTask(FROM_HERE, base::Bind(callback, rc == 0));
+ task_runner_->PostTask(FROM_HERE,
+ base::BindOnce(std::move(callback), rc == 0));
}
void UsbDeviceHandleUsbfs::FileThreadHelper::ClearHalt(
uint8_t endpoint_address,
- const ResultCallback& callback) {
+ ResultCallback callback) {
DCHECK(sequence_checker_.CalledOnValidSequence());
int tmp_endpoint = endpoint_address;
@@ -309,7 +310,8 @@ void UsbDeviceHandleUsbfs::FileThreadHelper::ClearHalt(
USB_PLOG(DEBUG) << "Failed to clear the stall condition on endpoint "
<< static_cast<int>(endpoint_address);
}
- task_runner_->PostTask(FROM_HERE, base::Bind(callback, rc == 0));
+ task_runner_->PostTask(FROM_HERE,
+ base::BindOnce(std::move(callback), rc == 0));
}
void UsbDeviceHandleUsbfs::FileThreadHelper::DiscardUrb(Transfer* transfer) {
@@ -353,18 +355,19 @@ void UsbDeviceHandleUsbfs::FileThreadHelper::OnFileCanWriteWithoutBlocking() {
UsbDeviceHandleUsbfs::Transfer::Transfer(
scoped_refptr<net::IOBuffer> buffer,
- const TransferCallback& callback,
+ TransferCallback callback,
scoped_refptr<base::SingleThreadTaskRunner> callback_runner)
- : buffer(buffer), callback(callback), callback_runner(callback_runner) {
+ : buffer(buffer),
+ callback(std::move(callback)),
+ callback_runner(callback_runner) {
memset(&urb, 0, sizeof(urb));
urb.usercontext = this;
urb.buffer = buffer->data();
}
-UsbDeviceHandleUsbfs::Transfer::Transfer(
- scoped_refptr<net::IOBuffer> buffer,
- const IsochronousTransferCallback& callback)
- : buffer(buffer), isoc_callback(callback) {
+UsbDeviceHandleUsbfs::Transfer::Transfer(scoped_refptr<net::IOBuffer> buffer,
+ IsochronousTransferCallback callback)
+ : buffer(buffer), isoc_callback(std::move(callback)) {
memset(&urb, 0, sizeof(urb) +
sizeof(usbdevfs_iso_packet_desc) * urb.number_of_packets);
urb.usercontext = this;
@@ -388,10 +391,11 @@ void UsbDeviceHandleUsbfs::Transfer::RunCallback(UsbTransferStatus status,
DCHECK_NE(urb.type, USBDEVFS_URB_TYPE_ISO);
DCHECK(callback);
if (!callback_runner || callback_runner->BelongsToCurrentThread()) {
- callback.Run(status, buffer, bytes_transferred);
+ std::move(callback).Run(status, buffer, bytes_transferred);
} else {
callback_runner->PostTask(
- FROM_HERE, base::Bind(callback, status, buffer, bytes_transferred));
+ FROM_HERE,
+ base::BindOnce(std::move(callback), status, buffer, bytes_transferred));
}
callback.Reset();
}
@@ -400,8 +404,7 @@ void UsbDeviceHandleUsbfs::Transfer::RunIsochronousCallback(
const std::vector<IsochronousPacket>& packets) {
DCHECK_EQ(urb.type, USBDEVFS_URB_TYPE_ISO);
DCHECK(isoc_callback);
- isoc_callback.Run(buffer, packets);
- isoc_callback.Reset();
+ std::move(isoc_callback).Run(buffer, packets);
}
UsbDeviceHandleUsbfs::UsbDeviceHandleUsbfs(
@@ -450,10 +453,11 @@ void UsbDeviceHandleUsbfs::Close() {
}
void UsbDeviceHandleUsbfs::SetConfiguration(int configuration_value,
- const ResultCallback& callback) {
+ ResultCallback callback) {
DCHECK(sequence_checker_.CalledOnValidSequence());
if (!device_) {
- task_runner_->PostTask(FROM_HERE, base::Bind(callback, false));
+ task_runner_->PostTask(FROM_HERE,
+ base::BindOnce(std::move(callback), false));
return;
}
@@ -462,22 +466,24 @@ void UsbDeviceHandleUsbfs::SetConfiguration(int configuration_value,
// block.
blocking_task_runner_->PostTask(
FROM_HERE,
- base::Bind(&UsbDeviceHandleUsbfs::FileThreadHelper::SetConfiguration,
- base::Unretained(helper_.get()), configuration_value,
- callback));
+ base::BindOnce(&UsbDeviceHandleUsbfs::FileThreadHelper::SetConfiguration,
+ base::Unretained(helper_.get()), configuration_value,
+ std::move(callback)));
}
void UsbDeviceHandleUsbfs::ClaimInterface(int interface_number,
- const ResultCallback& callback) {
+ ResultCallback callback) {
DCHECK(sequence_checker_.CalledOnValidSequence());
if (!device_) {
- task_runner_->PostTask(FROM_HERE, base::Bind(callback, false));
+ task_runner_->PostTask(FROM_HERE,
+ base::BindOnce(std::move(callback), false));
return;
}
if (base::ContainsKey(interfaces_, interface_number)) {
USB_LOG(DEBUG) << "Interface " << interface_number << " already claimed.";
- task_runner_->PostTask(FROM_HERE, base::Bind(callback, false));
+ task_runner_->PostTask(FROM_HERE,
+ base::BindOnce(std::move(callback), false));
return;
}
@@ -489,14 +495,16 @@ void UsbDeviceHandleUsbfs::ClaimInterface(int interface_number,
interfaces_[interface_number].alternate_setting = 0;
RefreshEndpointInfo();
}
- task_runner_->PostTask(FROM_HERE, base::Bind(callback, rc == 0));
+ task_runner_->PostTask(FROM_HERE,
+ base::BindOnce(std::move(callback), rc == 0));
}
void UsbDeviceHandleUsbfs::ReleaseInterface(int interface_number,
- const ResultCallback& callback) {
+ ResultCallback callback) {
DCHECK(sequence_checker_.CalledOnValidSequence());
if (!device_) {
- task_runner_->PostTask(FROM_HERE, base::Bind(callback, false));
+ task_runner_->PostTask(FROM_HERE,
+ base::BindOnce(std::move(callback), false));
return;
}
@@ -505,17 +513,19 @@ void UsbDeviceHandleUsbfs::ReleaseInterface(int interface_number,
// where it is okay to block.
blocking_task_runner_->PostTask(
FROM_HERE,
- base::Bind(&UsbDeviceHandleUsbfs::FileThreadHelper::ReleaseInterface,
- base::Unretained(helper_.get()), interface_number, callback));
+ base::BindOnce(&UsbDeviceHandleUsbfs::FileThreadHelper::ReleaseInterface,
+ base::Unretained(helper_.get()), interface_number,
+ std::move(callback)));
}
void UsbDeviceHandleUsbfs::SetInterfaceAlternateSetting(
int interface_number,
int alternate_setting,
- const ResultCallback& callback) {
+ ResultCallback callback) {
DCHECK(sequence_checker_.CalledOnValidSequence());
if (!device_) {
- task_runner_->PostTask(FROM_HERE, base::Bind(callback, false));
+ task_runner_->PostTask(FROM_HERE,
+ base::BindOnce(std::move(callback), false));
return;
}
@@ -524,15 +534,16 @@ void UsbDeviceHandleUsbfs::SetInterfaceAlternateSetting(
// to block.
blocking_task_runner_->PostTask(
FROM_HERE,
- base::Bind(&UsbDeviceHandleUsbfs::FileThreadHelper::SetInterface,
- base::Unretained(helper_.get()), interface_number,
- alternate_setting, callback));
+ base::BindOnce(&UsbDeviceHandleUsbfs::FileThreadHelper::SetInterface,
+ base::Unretained(helper_.get()), interface_number,
+ alternate_setting, std::move(callback)));
}
-void UsbDeviceHandleUsbfs::ResetDevice(const ResultCallback& callback) {
+void UsbDeviceHandleUsbfs::ResetDevice(ResultCallback callback) {
DCHECK(sequence_checker_.CalledOnValidSequence());
if (!device_) {
- task_runner_->PostTask(FROM_HERE, base::Bind(callback, false));
+ task_runner_->PostTask(FROM_HERE,
+ base::BindOnce(std::move(callback), false));
return;
}
@@ -541,15 +552,16 @@ void UsbDeviceHandleUsbfs::ResetDevice(const ResultCallback& callback) {
// is okay to block.
blocking_task_runner_->PostTask(
FROM_HERE,
- base::Bind(&UsbDeviceHandleUsbfs::FileThreadHelper::ResetDevice,
- base::Unretained(helper_.get()), callback));
+ base::BindOnce(&UsbDeviceHandleUsbfs::FileThreadHelper::ResetDevice,
+ base::Unretained(helper_.get()), std::move(callback)));
}
void UsbDeviceHandleUsbfs::ClearHalt(uint8_t endpoint_address,
- const ResultCallback& callback) {
+ ResultCallback callback) {
DCHECK(sequence_checker_.CalledOnValidSequence());
if (!device_) {
- task_runner_->PostTask(FROM_HERE, base::Bind(callback, false));
+ task_runner_->PostTask(FROM_HERE,
+ base::BindOnce(std::move(callback), false));
return;
}
@@ -558,8 +570,9 @@ void UsbDeviceHandleUsbfs::ClearHalt(uint8_t endpoint_address,
// to block.
blocking_task_runner_->PostTask(
FROM_HERE,
- base::Bind(&UsbDeviceHandleUsbfs::FileThreadHelper::ClearHalt,
- base::Unretained(helper_.get()), endpoint_address, callback));
+ base::BindOnce(&UsbDeviceHandleUsbfs::FileThreadHelper::ClearHalt,
+ base::Unretained(helper_.get()), endpoint_address,
+ std::move(callback)));
}
void UsbDeviceHandleUsbfs::ControlTransfer(
@@ -572,17 +585,17 @@ void UsbDeviceHandleUsbfs::ControlTransfer(
scoped_refptr<net::IOBuffer> buffer,
size_t length,
unsigned int timeout,
- const TransferCallback& callback) {
+ TransferCallback callback) {
DCHECK(sequence_checker_.CalledOnValidSequence());
if (!device_) {
task_runner_->PostTask(
- FROM_HERE,
- base::Bind(callback, UsbTransferStatus::DISCONNECT, nullptr, 0));
+ FROM_HERE, base::BindOnce(std::move(callback),
+ UsbTransferStatus::DISCONNECT, nullptr, 0));
return;
}
- std::unique_ptr<Transfer> transfer(new (0)
- Transfer(buffer, callback, nullptr));
+ std::unique_ptr<Transfer> transfer(
+ new (0) Transfer(buffer, std::move(callback), nullptr));
transfer->control_transfer_buffer =
BuildControlTransferBuffer(direction, request_type, recipient, request,
value, index, buffer, length);
@@ -598,7 +611,8 @@ void UsbDeviceHandleUsbfs::ControlTransfer(
rc = logging::GetLastSystemErrorCode();
USB_PLOG(DEBUG) << "Failed to submit control transfer";
task_runner_->PostTask(
- FROM_HERE, base::Bind(callback, ConvertTransferResult(rc), nullptr, 0));
+ FROM_HERE, base::BindOnce(std::move(transfer->callback),
+ ConvertTransferResult(rc), nullptr, 0));
} else {
SetUpTimeoutCallback(transfer.get(), timeout);
transfers_.push_back(std::move(transfer));
@@ -609,14 +623,14 @@ void UsbDeviceHandleUsbfs::IsochronousTransferIn(
uint8_t endpoint_number,
const std::vector<uint32_t>& packet_lengths,
unsigned int timeout,
- const IsochronousTransferCallback& callback) {
+ IsochronousTransferCallback callback) {
DCHECK(sequence_checker_.CalledOnValidSequence());
uint8_t endpoint_address = USB_DIR_IN | endpoint_number;
size_t total_length =
std::accumulate(packet_lengths.begin(), packet_lengths.end(), 0u);
scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(total_length));
IsochronousTransferInternal(endpoint_address, buffer, total_length,
- packet_lengths, timeout, callback);
+ packet_lengths, timeout, std::move(callback));
}
void UsbDeviceHandleUsbfs::IsochronousTransferOut(
@@ -624,13 +638,13 @@ void UsbDeviceHandleUsbfs::IsochronousTransferOut(
scoped_refptr<net::IOBuffer> buffer,
const std::vector<uint32_t>& packet_lengths,
unsigned int timeout,
- const IsochronousTransferCallback& callback) {
+ IsochronousTransferCallback callback) {
DCHECK(sequence_checker_.CalledOnValidSequence());
uint8_t endpoint_address = USB_DIR_OUT | endpoint_number;
size_t total_length =
std::accumulate(packet_lengths.begin(), packet_lengths.end(), 0u);
IsochronousTransferInternal(endpoint_address, buffer, total_length,
- packet_lengths, timeout, callback);
+ packet_lengths, timeout, std::move(callback));
}
void UsbDeviceHandleUsbfs::GenericTransfer(UsbTransferDirection direction,
@@ -638,16 +652,17 @@ void UsbDeviceHandleUsbfs::GenericTransfer(UsbTransferDirection direction,
scoped_refptr<net::IOBuffer> buffer,
size_t length,
unsigned int timeout,
- const TransferCallback& callback) {
+ TransferCallback callback) {
if (task_runner_->BelongsToCurrentThread()) {
GenericTransferInternal(direction, endpoint_number, buffer, length, timeout,
- callback, task_runner_);
+ std::move(callback), task_runner_);
} else {
task_runner_->PostTask(
FROM_HERE,
- base::Bind(&UsbDeviceHandleUsbfs::GenericTransferInternal, this,
- direction, endpoint_number, buffer, length, timeout,
- callback, base::ThreadTaskRunnerHandle::Get()));
+ base::BindOnce(&UsbDeviceHandleUsbfs::GenericTransferInternal, this,
+ direction, endpoint_number, buffer, length, timeout,
+ std::move(callback),
+ base::ThreadTaskRunnerHandle::Get()));
}
}
@@ -675,10 +690,9 @@ void UsbDeviceHandleUsbfs::CloseBlocking() {
helper_.reset();
}
-void UsbDeviceHandleUsbfs::SetConfigurationComplete(
- int configuration_value,
- bool success,
- const ResultCallback& callback) {
+void UsbDeviceHandleUsbfs::SetConfigurationComplete(int configuration_value,
+ bool success,
+ ResultCallback callback) {
DCHECK(sequence_checker_.CalledOnValidSequence());
if (success && device_) {
device_->ActiveConfigurationChanged(configuration_value);
@@ -686,18 +700,17 @@ void UsbDeviceHandleUsbfs::SetConfigurationComplete(
// is set then this will do nothing. Investigate.
RefreshEndpointInfo();
}
- callback.Run(success);
+ std::move(callback).Run(success);
}
-void UsbDeviceHandleUsbfs::ReleaseInterfaceComplete(
- int interface_number,
- const ResultCallback& callback) {
+void UsbDeviceHandleUsbfs::ReleaseInterfaceComplete(int interface_number,
+ ResultCallback callback) {
DCHECK(sequence_checker_.CalledOnValidSequence());
auto it = interfaces_.find(interface_number);
DCHECK(it != interfaces_.end());
interfaces_.erase(it);
RefreshEndpointInfo();
- callback.Run(true);
+ std::move(callback).Run(true);
}
void UsbDeviceHandleUsbfs::IsochronousTransferInternal(
@@ -706,10 +719,10 @@ void UsbDeviceHandleUsbfs::IsochronousTransferInternal(
size_t total_length,
const std::vector<uint32_t>& packet_lengths,
unsigned int timeout,
- const IsochronousTransferCallback& callback) {
+ IsochronousTransferCallback callback) {
DCHECK(sequence_checker_.CalledOnValidSequence());
if (!device_) {
- ReportIsochronousError(packet_lengths, callback,
+ ReportIsochronousError(packet_lengths, std::move(callback),
UsbTransferStatus::DISCONNECT);
return;
}
@@ -718,13 +731,13 @@ void UsbDeviceHandleUsbfs::IsochronousTransferInternal(
if (it == endpoints_.end()) {
USB_LOG(USER) << "Endpoint address " << static_cast<int>(endpoint_address)
<< " is not part of a claimed interface.";
- ReportIsochronousError(packet_lengths, callback,
+ ReportIsochronousError(packet_lengths, std::move(callback),
UsbTransferStatus::TRANSFER_ERROR);
return;
}
std::unique_ptr<Transfer> transfer(new (packet_lengths.size())
- Transfer(buffer, callback));
+ Transfer(buffer, std::move(callback)));
transfer->urb.type = USBDEVFS_URB_TYPE_ISO;
transfer->urb.endpoint = endpoint_address;
transfer->urb.buffer_length = total_length;
@@ -740,7 +753,8 @@ void UsbDeviceHandleUsbfs::IsochronousTransferInternal(
if (rc) {
rc = logging::GetLastSystemErrorCode();
USB_PLOG(DEBUG) << "Failed to submit transfer";
- ReportIsochronousError(packet_lengths, callback, ConvertTransferResult(rc));
+ ReportIsochronousError(packet_lengths, std::move(transfer->isoc_callback),
+ ConvertTransferResult(rc));
} else {
SetUpTimeoutCallback(transfer.get(), timeout);
transfers_.push_back(std::move(transfer));
@@ -753,13 +767,13 @@ void UsbDeviceHandleUsbfs::GenericTransferInternal(
scoped_refptr<net::IOBuffer> buffer,
size_t length,
unsigned int timeout,
- const TransferCallback& callback,
+ TransferCallback callback,
scoped_refptr<base::SingleThreadTaskRunner> callback_runner) {
DCHECK(sequence_checker_.CalledOnValidSequence());
if (!device_) {
callback_runner->PostTask(
- FROM_HERE,
- base::Bind(callback, UsbTransferStatus::DISCONNECT, nullptr, 0));
+ FROM_HERE, base::BindOnce(std::move(callback),
+ UsbTransferStatus::DISCONNECT, nullptr, 0));
return;
}
@@ -771,12 +785,13 @@ void UsbDeviceHandleUsbfs::GenericTransferInternal(
<< " is not part of a claimed interface.";
callback_runner->PostTask(
FROM_HERE,
- base::Bind(callback, UsbTransferStatus::TRANSFER_ERROR, nullptr, 0));
+ base::BindOnce(std::move(callback), UsbTransferStatus::TRANSFER_ERROR,
+ nullptr, 0));
return;
}
std::unique_ptr<Transfer> transfer(
- new (0) Transfer(buffer, callback, callback_runner));
+ new (0) Transfer(buffer, std::move(callback), callback_runner));
transfer->urb.endpoint = endpoint_address;
transfer->urb.buffer_length = length;
transfer->urb.type = ConvertTransferType(it->second.type);
@@ -790,7 +805,8 @@ void UsbDeviceHandleUsbfs::GenericTransferInternal(
rc = logging::GetLastSystemErrorCode();
USB_PLOG(DEBUG) << "Failed to submit transfer";
callback_runner->PostTask(
- FROM_HERE, base::Bind(callback, ConvertTransferResult(rc), nullptr, 0));
+ FROM_HERE, base::BindOnce(std::move(transfer->callback),
+ ConvertTransferResult(rc), nullptr, 0));
} else {
SetUpTimeoutCallback(transfer.get(), timeout);
transfers_.push_back(std::move(transfer));
@@ -878,7 +894,7 @@ void UsbDeviceHandleUsbfs::RefreshEndpointInfo() {
void UsbDeviceHandleUsbfs::ReportIsochronousError(
const std::vector<uint32_t>& packet_lengths,
- const UsbDeviceHandle::IsochronousTransferCallback& callback,
+ UsbDeviceHandle::IsochronousTransferCallback callback,
UsbTransferStatus status) {
DCHECK(sequence_checker_.CalledOnValidSequence());
std::vector<UsbDeviceHandle::IsochronousPacket> packets(
@@ -888,7 +904,8 @@ void UsbDeviceHandleUsbfs::ReportIsochronousError(
packets[i].transferred_length = 0;
packets[i].status = status;
}
- task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr, packets));
+ task_runner_->PostTask(FROM_HERE,
+ base::BindOnce(std::move(callback), nullptr, packets));
}
void UsbDeviceHandleUsbfs::SetUpTimeoutCallback(Transfer* transfer,
diff --git a/chromium/device/usb/usb_device_handle_usbfs.h b/chromium/device/usb/usb_device_handle_usbfs.h
index e8aa0637383..57446f54490 100644
--- a/chromium/device/usb/usb_device_handle_usbfs.h
+++ b/chromium/device/usb/usb_device_handle_usbfs.h
@@ -40,16 +40,14 @@ class UsbDeviceHandleUsbfs : public UsbDeviceHandle {
scoped_refptr<UsbDevice> GetDevice() const override;
void Close() override;
void SetConfiguration(int configuration_value,
- const ResultCallback& callback) override;
- void ClaimInterface(int interface_number,
- const ResultCallback& callback) override;
- void ReleaseInterface(int interface_number,
- const ResultCallback& callback) override;
+ ResultCallback callback) override;
+ void ClaimInterface(int interface_number, ResultCallback callback) override;
+ void ReleaseInterface(int interface_number, ResultCallback callback) override;
void SetInterfaceAlternateSetting(int interface_number,
int alternate_setting,
- const ResultCallback& callback) override;
- void ResetDevice(const ResultCallback& callback) override;
- void ClearHalt(uint8_t endpoint, const ResultCallback& callback) override;
+ ResultCallback callback) override;
+ void ResetDevice(ResultCallback callback) override;
+ void ClearHalt(uint8_t endpoint, ResultCallback callback) override;
void ControlTransfer(UsbTransferDirection direction,
UsbControlTransferType request_type,
UsbControlTransferRecipient recipient,
@@ -59,18 +57,16 @@ class UsbDeviceHandleUsbfs : public UsbDeviceHandle {
scoped_refptr<net::IOBuffer> buffer,
size_t length,
unsigned int timeout,
- const TransferCallback& callback) override;
- void IsochronousTransferIn(
- uint8_t endpoint_number,
- const std::vector<uint32_t>& packet_lengths,
- unsigned int timeout,
- const IsochronousTransferCallback& callback) override;
- void IsochronousTransferOut(
- uint8_t endpoint_number,
- scoped_refptr<net::IOBuffer> buffer,
- const std::vector<uint32_t>& packet_lengths,
- unsigned int timeout,
- const IsochronousTransferCallback& callback) override;
+ TransferCallback callback) override;
+ void IsochronousTransferIn(uint8_t endpoint_number,
+ const std::vector<uint32_t>& packet_lengths,
+ unsigned int timeout,
+ IsochronousTransferCallback callback) override;
+ void IsochronousTransferOut(uint8_t endpoint_number,
+ scoped_refptr<net::IOBuffer> buffer,
+ const std::vector<uint32_t>& packet_lengths,
+ unsigned int timeout,
+ IsochronousTransferCallback callback) override;
// To support DevTools this function may be called from any thread and on
// completion |callback| will be run on that thread.
void GenericTransfer(UsbTransferDirection direction,
@@ -78,7 +74,7 @@ class UsbDeviceHandleUsbfs : public UsbDeviceHandle {
scoped_refptr<net::IOBuffer> buffer,
size_t length,
unsigned int timeout,
- const TransferCallback& callback) override;
+ TransferCallback callback) override;
const UsbInterfaceDescriptor* FindInterfaceByEndpoint(
uint8_t endpoint_address) override;
@@ -109,29 +105,28 @@ class UsbDeviceHandleUsbfs : public UsbDeviceHandle {
void SetConfigurationComplete(int configuration_value,
bool success,
- const ResultCallback& callback);
- void ReleaseInterfaceComplete(int interface_number,
- const ResultCallback& callback);
+ ResultCallback callback);
+ void ReleaseInterfaceComplete(int interface_number, ResultCallback callback);
void IsochronousTransferInternal(uint8_t endpoint_address,
scoped_refptr<net::IOBuffer> buffer,
size_t total_length,
const std::vector<uint32_t>& packet_lengths,
unsigned int timeout,
- const IsochronousTransferCallback& callback);
+ IsochronousTransferCallback callback);
void GenericTransferInternal(
UsbTransferDirection direction,
uint8_t endpoint_number,
scoped_refptr<net::IOBuffer> buffer,
size_t length,
unsigned int timeout,
- const TransferCallback& callback,
+ TransferCallback callback,
scoped_refptr<base::SingleThreadTaskRunner> callback_runner);
void ReapedUrbs(const std::vector<usbdevfs_urb*>& urbs);
void TransferComplete(std::unique_ptr<Transfer> transfer);
void RefreshEndpointInfo();
void ReportIsochronousError(
const std::vector<uint32_t>& packet_lengths,
- const UsbDeviceHandle::IsochronousTransferCallback& callback,
+ UsbDeviceHandle::IsochronousTransferCallback callback,
UsbTransferStatus status);
void SetUpTimeoutCallback(Transfer* transfer, unsigned int timeout);
void OnTimeout(Transfer* transfer);
diff --git a/chromium/device/usb/usb_device_handle_win.cc b/chromium/device/usb/usb_device_handle_win.cc
index f8a54a28a38..6ed5484ebd8 100644
--- a/chromium/device/usb/usb_device_handle_win.cc
+++ b/chromium/device/usb/usb_device_handle_win.cc
@@ -104,56 +104,55 @@ void UsbDeviceHandleWin::Close() {
}
void UsbDeviceHandleWin::SetConfiguration(int configuration_value,
- const ResultCallback& callback) {
+ ResultCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!device_) {
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
}
void UsbDeviceHandleWin::ClaimInterface(int interface_number,
- const ResultCallback& callback) {
+ ResultCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!device_) {
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
}
void UsbDeviceHandleWin::ReleaseInterface(int interface_number,
- const ResultCallback& callback) {
+ ResultCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!device_) {
- task_runner_->PostTask(FROM_HERE, base::Bind(callback, false));
+ task_runner_->PostTask(FROM_HERE,
+ base::BindOnce(std::move(callback), false));
return;
}
}
-void UsbDeviceHandleWin::SetInterfaceAlternateSetting(
- int interface_number,
- int alternate_setting,
- const ResultCallback& callback) {
+void UsbDeviceHandleWin::SetInterfaceAlternateSetting(int interface_number,
+ int alternate_setting,
+ ResultCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!device_) {
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
}
-void UsbDeviceHandleWin::ResetDevice(const ResultCallback& callback) {
+void UsbDeviceHandleWin::ResetDevice(ResultCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!device_) {
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
}
-void UsbDeviceHandleWin::ClearHalt(uint8_t endpoint,
- const ResultCallback& callback) {
+void UsbDeviceHandleWin::ClearHalt(uint8_t endpoint, ResultCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!device_) {
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
}
@@ -167,13 +166,13 @@ void UsbDeviceHandleWin::ControlTransfer(UsbTransferDirection direction,
scoped_refptr<net::IOBuffer> buffer,
size_t length,
unsigned int timeout,
- const TransferCallback& callback) {
+ TransferCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!device_) {
task_runner_->PostTask(
- FROM_HERE,
- base::Bind(callback, UsbTransferStatus::DISCONNECT, nullptr, 0));
+ FROM_HERE, base::BindOnce(std::move(callback),
+ UsbTransferStatus::DISCONNECT, nullptr, 0));
return;
}
@@ -193,9 +192,9 @@ void UsbDeviceHandleWin::ControlTransfer(UsbTransferDirection direction,
node_connection_info, sizeof(*node_connection_info),
node_connection_info, sizeof(*node_connection_info),
nullptr, request->overlapped()),
- base::Bind(&UsbDeviceHandleWin::GotNodeConnectionInformation,
- weak_factory_.GetWeakPtr(), callback,
- base::Owned(node_connection_info), buffer, length));
+ base::BindOnce(&UsbDeviceHandleWin::GotNodeConnectionInformation,
+ weak_factory_.GetWeakPtr(), std::move(callback),
+ base::Owned(node_connection_info), buffer, length));
return;
} else if (((value >> 8) == USB_CONFIGURATION_DESCRIPTOR_TYPE) ||
((value >> 8) == USB_STRING_DESCRIPTOR_TYPE)) {
@@ -217,9 +216,9 @@ void UsbDeviceHandleWin::ControlTransfer(UsbTransferDirection direction,
request_buffer->data(), size,
request_buffer->data(), size, nullptr,
request->overlapped()),
- base::Bind(&UsbDeviceHandleWin::GotDescriptorFromNodeConnection,
- weak_factory_.GetWeakPtr(), callback, request_buffer,
- buffer, length));
+ base::BindOnce(&UsbDeviceHandleWin::GotDescriptorFromNodeConnection,
+ weak_factory_.GetWeakPtr(), std::move(callback),
+ request_buffer, buffer, length));
return;
}
}
@@ -227,21 +226,22 @@ void UsbDeviceHandleWin::ControlTransfer(UsbTransferDirection direction,
// Unsupported transfer for hub.
task_runner_->PostTask(
FROM_HERE,
- base::Bind(callback, UsbTransferStatus::TRANSFER_ERROR, nullptr, 0));
+ base::BindOnce(std::move(callback), UsbTransferStatus::TRANSFER_ERROR,
+ nullptr, 0));
return;
}
// Regular control transfers unimplemented.
task_runner_->PostTask(
- FROM_HERE,
- base::Bind(callback, UsbTransferStatus::TRANSFER_ERROR, nullptr, 0));
+ FROM_HERE, base::BindOnce(std::move(callback),
+ UsbTransferStatus::TRANSFER_ERROR, nullptr, 0));
}
void UsbDeviceHandleWin::IsochronousTransferIn(
uint8_t endpoint_number,
const std::vector<uint32_t>& packet_lengths,
unsigned int timeout,
- const IsochronousTransferCallback& callback) {
+ IsochronousTransferCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
}
@@ -250,7 +250,7 @@ void UsbDeviceHandleWin::IsochronousTransferOut(
scoped_refptr<net::IOBuffer> buffer,
const std::vector<uint32_t>& packet_lengths,
unsigned int timeout,
- const IsochronousTransferCallback& callback) {
+ IsochronousTransferCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
}
@@ -259,7 +259,7 @@ void UsbDeviceHandleWin::GenericTransfer(UsbTransferDirection direction,
scoped_refptr<net::IOBuffer> buffer,
size_t length,
unsigned int timeout,
- const TransferCallback& callback) {
+ TransferCallback callback) {
// This one must be callable from any thread.
}
@@ -282,7 +282,7 @@ UsbDeviceHandleWin::UsbDeviceHandleWin(
UsbDeviceHandleWin::~UsbDeviceHandleWin() {}
UsbDeviceHandleWin::Request* UsbDeviceHandleWin::MakeRequest(HANDLE handle) {
- auto request = base::MakeUnique<Request>(hub_handle_.Get());
+ auto request = std::make_unique<Request>(hub_handle_.Get());
Request* request_ptr = request.get();
requests_[request_ptr] = std::move(request);
return request_ptr;
@@ -298,7 +298,7 @@ std::unique_ptr<UsbDeviceHandleWin::Request> UsbDeviceHandleWin::UnlinkRequest(
}
void UsbDeviceHandleWin::GotNodeConnectionInformation(
- const TransferCallback& callback,
+ TransferCallback callback,
void* node_connection_info_ptr,
scoped_refptr<net::IOBuffer> buffer,
size_t buffer_length,
@@ -313,7 +313,7 @@ void UsbDeviceHandleWin::GotNodeConnectionInformation(
if (win32_result != ERROR_SUCCESS) {
SetLastError(win32_result);
USB_PLOG(ERROR) << "Failed to get node connection information";
- callback.Run(UsbTransferStatus::TRANSFER_ERROR, nullptr, 0);
+ std::move(callback).Run(UsbTransferStatus::TRANSFER_ERROR, nullptr, 0);
return;
}
@@ -321,11 +321,12 @@ void UsbDeviceHandleWin::GotNodeConnectionInformation(
bytes_transferred = std::min(sizeof(USB_DEVICE_DESCRIPTOR), buffer_length);
memcpy(buffer->data(), &node_connection_info->DeviceDescriptor,
bytes_transferred);
- callback.Run(UsbTransferStatus::COMPLETED, buffer, bytes_transferred);
+ std::move(callback).Run(UsbTransferStatus::COMPLETED, buffer,
+ bytes_transferred);
}
void UsbDeviceHandleWin::GotDescriptorFromNodeConnection(
- const TransferCallback& callback,
+ TransferCallback callback,
scoped_refptr<net::IOBuffer> request_buffer,
scoped_refptr<net::IOBuffer> original_buffer,
size_t original_buffer_length,
@@ -337,7 +338,7 @@ void UsbDeviceHandleWin::GotDescriptorFromNodeConnection(
if (win32_result != ERROR_SUCCESS) {
SetLastError(win32_result);
USB_PLOG(ERROR) << "Failed to read descriptor from node connection";
- callback.Run(UsbTransferStatus::TRANSFER_ERROR, nullptr, 0);
+ std::move(callback).Run(UsbTransferStatus::TRANSFER_ERROR, nullptr, 0);
return;
}
@@ -346,8 +347,8 @@ void UsbDeviceHandleWin::GotDescriptorFromNodeConnection(
memcpy(original_buffer->data(),
request_buffer->data() + sizeof(USB_DESCRIPTOR_REQUEST),
bytes_transferred);
- callback.Run(UsbTransferStatus::COMPLETED, original_buffer,
- bytes_transferred);
+ std::move(callback).Run(UsbTransferStatus::COMPLETED, original_buffer,
+ bytes_transferred);
}
} // namespace device
diff --git a/chromium/device/usb/usb_device_handle_win.h b/chromium/device/usb/usb_device_handle_win.h
index 75b65f644f5..d7102e3426e 100644
--- a/chromium/device/usb/usb_device_handle_win.h
+++ b/chromium/device/usb/usb_device_handle_win.h
@@ -35,16 +35,14 @@ class UsbDeviceHandleWin : public UsbDeviceHandle {
scoped_refptr<UsbDevice> GetDevice() const override;
void Close() override;
void SetConfiguration(int configuration_value,
- const ResultCallback& callback) override;
- void ClaimInterface(int interface_number,
- const ResultCallback& callback) override;
- void ReleaseInterface(int interface_number,
- const ResultCallback& callback) override;
+ ResultCallback callback) override;
+ void ClaimInterface(int interface_number, ResultCallback callback) override;
+ void ReleaseInterface(int interface_number, ResultCallback callback) override;
void SetInterfaceAlternateSetting(int interface_number,
int alternate_setting,
- const ResultCallback& callback) override;
- void ResetDevice(const ResultCallback& callback) override;
- void ClearHalt(uint8_t endpoint, const ResultCallback& callback) override;
+ ResultCallback callback) override;
+ void ResetDevice(ResultCallback callback) override;
+ void ClearHalt(uint8_t endpoint, ResultCallback callback) override;
void ControlTransfer(UsbTransferDirection direction,
UsbControlTransferType request_type,
@@ -55,27 +53,25 @@ class UsbDeviceHandleWin : public UsbDeviceHandle {
scoped_refptr<net::IOBuffer> buffer,
size_t length,
unsigned int timeout,
- const TransferCallback& callback) override;
+ TransferCallback callback) override;
- void IsochronousTransferIn(
- uint8_t endpoint,
- const std::vector<uint32_t>& packet_lengths,
- unsigned int timeout,
- const IsochronousTransferCallback& callback) override;
+ void IsochronousTransferIn(uint8_t endpoint,
+ const std::vector<uint32_t>& packet_lengths,
+ unsigned int timeout,
+ IsochronousTransferCallback callback) override;
- void IsochronousTransferOut(
- uint8_t endpoint,
- scoped_refptr<net::IOBuffer> buffer,
- const std::vector<uint32_t>& packet_lengths,
- unsigned int timeout,
- const IsochronousTransferCallback& callback) override;
+ void IsochronousTransferOut(uint8_t endpoint,
+ scoped_refptr<net::IOBuffer> buffer,
+ const std::vector<uint32_t>& packet_lengths,
+ unsigned int timeout,
+ IsochronousTransferCallback callback) override;
void GenericTransfer(UsbTransferDirection direction,
uint8_t endpoint_number,
scoped_refptr<net::IOBuffer> buffer,
size_t length,
unsigned int timeout,
- const TransferCallback& callback) override;
+ TransferCallback callback) override;
const UsbInterfaceDescriptor* FindInterfaceByEndpoint(
uint8_t endpoint_address) override;
@@ -95,7 +91,7 @@ class UsbDeviceHandleWin : public UsbDeviceHandle {
Request* MakeRequest(HANDLE handle);
std::unique_ptr<Request> UnlinkRequest(Request* request);
- void GotNodeConnectionInformation(const TransferCallback& callback,
+ void GotNodeConnectionInformation(TransferCallback callback,
void* node_connection_info,
scoped_refptr<net::IOBuffer> buffer,
size_t buffer_length,
@@ -103,7 +99,7 @@ class UsbDeviceHandleWin : public UsbDeviceHandle {
DWORD win32_result,
size_t bytes_transferred);
void GotDescriptorFromNodeConnection(
- const TransferCallback& callback,
+ TransferCallback callback,
scoped_refptr<net::IOBuffer> request_buffer,
scoped_refptr<net::IOBuffer> original_buffer,
size_t original_buffer_length,
diff --git a/chromium/device/usb/usb_device_impl.cc b/chromium/device/usb/usb_device_impl.cc
index bdda9ca9ee3..0b384ca3301 100644
--- a/chromium/device/usb/usb_device_impl.cc
+++ b/chromium/device/usb/usb_device_impl.cc
@@ -54,15 +54,16 @@ UsbDeviceImpl::~UsbDeviceImpl() {
libusb_unref_device(platform_device_);
}
-void UsbDeviceImpl::Open(const OpenCallback& callback) {
+void UsbDeviceImpl::Open(OpenCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner =
UsbService::CreateBlockingTaskRunner();
blocking_task_runner->PostTask(
FROM_HERE,
- base::Bind(&UsbDeviceImpl::OpenOnBlockingThread, this, callback,
- base::ThreadTaskRunnerHandle::Get(), blocking_task_runner));
+ base::BindOnce(&UsbDeviceImpl::OpenOnBlockingThread, this,
+ std::move(callback), base::ThreadTaskRunnerHandle::Get(),
+ blocking_task_runner));
}
void UsbDeviceImpl::ReadAllConfigurations() {
@@ -101,7 +102,7 @@ void UsbDeviceImpl::RefreshActiveConfiguration() {
}
void UsbDeviceImpl::OpenOnBlockingThread(
- const OpenCallback& callback,
+ OpenCallback callback,
scoped_refptr<base::TaskRunner> task_runner,
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) {
base::ThreadRestrictions::AssertIOAllowed();
@@ -109,24 +110,25 @@ void UsbDeviceImpl::OpenOnBlockingThread(
const int rv = libusb_open(platform_device_, &handle);
if (LIBUSB_SUCCESS == rv) {
task_runner->PostTask(
- FROM_HERE, base::Bind(&UsbDeviceImpl::Opened, this, handle, callback,
- blocking_task_runner));
+ FROM_HERE, base::BindOnce(&UsbDeviceImpl::Opened, this, handle,
+ std::move(callback), blocking_task_runner));
} else {
USB_LOG(EVENT) << "Failed to open device: "
<< ConvertPlatformUsbErrorToString(rv);
- task_runner->PostTask(FROM_HERE, base::Bind(callback, nullptr));
+ task_runner->PostTask(FROM_HERE,
+ base::BindOnce(std::move(callback), nullptr));
}
}
void UsbDeviceImpl::Opened(
PlatformUsbDeviceHandle platform_handle,
- const OpenCallback& callback,
+ OpenCallback callback,
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) {
DCHECK(thread_checker_.CalledOnValidThread());
scoped_refptr<UsbDeviceHandle> device_handle = new UsbDeviceHandleImpl(
context_, this, platform_handle, blocking_task_runner);
handles().push_back(device_handle.get());
- callback.Run(device_handle);
+ std::move(callback).Run(device_handle);
}
} // namespace device
diff --git a/chromium/device/usb/usb_device_impl.h b/chromium/device/usb/usb_device_impl.h
index 0447f885d2c..d0b1fd1d906 100644
--- a/chromium/device/usb/usb_device_impl.h
+++ b/chromium/device/usb/usb_device_impl.h
@@ -41,7 +41,7 @@ typedef struct libusb_device_handle* PlatformUsbDeviceHandle;
class UsbDeviceImpl : public UsbDevice {
public:
// UsbDevice implementation:
- void Open(const OpenCallback& callback) override;
+ void Open(OpenCallback callback) override;
// These functions are used during enumeration only. The values must not
// change during the object's lifetime.
@@ -79,11 +79,11 @@ class UsbDeviceImpl : public UsbDevice {
private:
void GetAllConfigurations();
void OpenOnBlockingThread(
- const OpenCallback& callback,
+ OpenCallback callback,
scoped_refptr<base::TaskRunner> task_runner,
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner);
void Opened(PlatformUsbDeviceHandle platform_handle,
- const OpenCallback& callback,
+ OpenCallback callback,
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner);
base::ThreadChecker thread_checker_;
diff --git a/chromium/device/usb/usb_device_linux.cc b/chromium/device/usb/usb_device_linux.cc
index dc423de1020..9c7884cd950 100644
--- a/chromium/device/usb/usb_device_linux.cc
+++ b/chromium/device/usb/usb_device_linux.cc
@@ -45,71 +45,77 @@ UsbDeviceLinux::~UsbDeviceLinux() {}
#if defined(OS_CHROMEOS)
-void UsbDeviceLinux::CheckUsbAccess(const ResultCallback& callback) {
+void UsbDeviceLinux::CheckUsbAccess(ResultCallback callback) {
DCHECK(sequence_checker_.CalledOnValidSequence());
chromeos::PermissionBrokerClient* client =
chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient();
DCHECK(client) << "Could not get permission broker client.";
- client->CheckPathAccess(device_path_, callback);
+ client->CheckPathAccess(device_path_,
+ base::AdaptCallbackForRepeating(std::move(callback)));
}
#endif // defined(OS_CHROMEOS)
-void UsbDeviceLinux::Open(const OpenCallback& callback) {
+void UsbDeviceLinux::Open(OpenCallback callback) {
DCHECK(sequence_checker_.CalledOnValidSequence());
#if defined(OS_CHROMEOS)
chromeos::PermissionBrokerClient* client =
chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient();
+ auto copyable_callback = base::AdaptCallbackForRepeating(std::move(callback));
DCHECK(client) << "Could not get permission broker client.";
client->OpenPath(
device_path_,
- base::Bind(&UsbDeviceLinux::OnOpenRequestComplete, this, callback),
- base::Bind(&UsbDeviceLinux::OnOpenRequestError, this, callback));
+ base::Bind(&UsbDeviceLinux::OnOpenRequestComplete, this,
+ copyable_callback),
+ base::Bind(&UsbDeviceLinux::OnOpenRequestError, this, copyable_callback));
#else
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner =
UsbService::CreateBlockingTaskRunner();
blocking_task_runner->PostTask(
FROM_HERE,
- base::Bind(&UsbDeviceLinux::OpenOnBlockingThread, this, callback,
- base::ThreadTaskRunnerHandle::Get(), blocking_task_runner));
+ base::BindOnce(&UsbDeviceLinux::OpenOnBlockingThread, this,
+ std::move(callback), base::ThreadTaskRunnerHandle::Get(),
+ blocking_task_runner));
#endif // defined(OS_CHROMEOS)
}
#if defined(OS_CHROMEOS)
-void UsbDeviceLinux::OnOpenRequestComplete(const OpenCallback& callback,
+void UsbDeviceLinux::OnOpenRequestComplete(OpenCallback callback,
base::ScopedFD fd) {
if (!fd.is_valid()) {
USB_LOG(EVENT) << "Did not get valid device handle from permission broker.";
- callback.Run(nullptr);
+ std::move(callback).Run(nullptr);
return;
}
- Opened(std::move(fd), callback, UsbService::CreateBlockingTaskRunner());
+ Opened(std::move(fd), std::move(callback),
+ UsbService::CreateBlockingTaskRunner());
}
-void UsbDeviceLinux::OnOpenRequestError(const OpenCallback& callback,
+void UsbDeviceLinux::OnOpenRequestError(OpenCallback callback,
const std::string& error_name,
const std::string& error_message) {
USB_LOG(EVENT) << "Permission broker failed to open the device: "
<< error_name << ": " << error_message;
- callback.Run(nullptr);
+ std::move(callback).Run(nullptr);
}
#else
void UsbDeviceLinux::OpenOnBlockingThread(
- const OpenCallback& callback,
+ OpenCallback callback,
scoped_refptr<base::SequencedTaskRunner> task_runner,
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) {
base::ScopedFD fd(HANDLE_EINTR(open(device_path_.c_str(), O_RDWR)));
if (fd.is_valid()) {
task_runner->PostTask(
- FROM_HERE, base::Bind(&UsbDeviceLinux::Opened, this, base::Passed(&fd),
- callback, blocking_task_runner));
+ FROM_HERE, base::BindOnce(&UsbDeviceLinux::Opened, this, std::move(fd),
+ std::move(callback), blocking_task_runner));
} else {
USB_PLOG(EVENT) << "Failed to open " << device_path_;
- task_runner->PostTask(FROM_HERE, base::Bind(callback, nullptr));
+ task_runner->PostTask(FROM_HERE,
+ base::BindOnce(std::move(callback), nullptr));
}
}
@@ -117,13 +123,13 @@ void UsbDeviceLinux::OpenOnBlockingThread(
void UsbDeviceLinux::Opened(
base::ScopedFD fd,
- const OpenCallback& callback,
+ OpenCallback callback,
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) {
DCHECK(sequence_checker_.CalledOnValidSequence());
scoped_refptr<UsbDeviceHandle> device_handle =
new UsbDeviceHandleUsbfs(this, std::move(fd), blocking_task_runner);
handles().push_back(device_handle.get());
- callback.Run(device_handle);
+ std::move(callback).Run(device_handle);
}
} // namespace device
diff --git a/chromium/device/usb/usb_device_linux.h b/chromium/device/usb/usb_device_linux.h
index 4ec2f7ca0f9..f18710e7abc 100644
--- a/chromium/device/usb/usb_device_linux.h
+++ b/chromium/device/usb/usb_device_linux.h
@@ -28,9 +28,9 @@ class UsbDeviceLinux : public UsbDevice {
public:
// UsbDevice implementation:
#if defined(OS_CHROMEOS)
- void CheckUsbAccess(const ResultCallback& callback) override;
+ void CheckUsbAccess(ResultCallback callback) override;
#endif // OS_CHROMEOS
- void Open(const OpenCallback& callback) override;
+ void Open(OpenCallback callback) override;
const std::string& device_path() const { return device_path_; }
@@ -53,18 +53,18 @@ class UsbDeviceLinux : public UsbDevice {
private:
#if defined(OS_CHROMEOS)
- void OnOpenRequestComplete(const OpenCallback& callback, base::ScopedFD fd);
- void OnOpenRequestError(const OpenCallback& callback,
+ void OnOpenRequestComplete(OpenCallback callback, base::ScopedFD fd);
+ void OnOpenRequestError(OpenCallback callback,
const std::string& error_name,
const std::string& error_message);
#else
void OpenOnBlockingThread(
- const OpenCallback& callback,
+ OpenCallback callback,
scoped_refptr<base::SequencedTaskRunner> task_runner,
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner);
#endif // defined(OS_CHROMEOS)
void Opened(base::ScopedFD fd,
- const OpenCallback& callback,
+ OpenCallback callback,
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner);
base::SequenceChecker sequence_checker_;
diff --git a/chromium/device/usb/usb_device_win.cc b/chromium/device/usb/usb_device_win.cc
index 18e83ef8718..3752f31651e 100644
--- a/chromium/device/usb/usb_device_win.cc
+++ b/chromium/device/usb/usb_device_win.cc
@@ -29,12 +29,13 @@ UsbDeviceWin::UsbDeviceWin(
UsbDeviceWin::~UsbDeviceWin() {}
-void UsbDeviceWin::Open(const OpenCallback& callback) {
+void UsbDeviceWin::Open(OpenCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
- task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr));
+ task_runner_->PostTask(FROM_HERE,
+ base::BindOnce(std::move(callback), nullptr));
}
-void UsbDeviceWin::ReadDescriptors(const base::Callback<void(bool)>& callback) {
+void UsbDeviceWin::ReadDescriptors(base::OnceCallback<void(bool)> callback) {
DCHECK(thread_checker_.CalledOnValidThread());
scoped_refptr<UsbDeviceHandle> device_handle;
base::win::ScopedHandle handle(
@@ -45,29 +46,30 @@ void UsbDeviceWin::ReadDescriptors(const base::Callback<void(bool)>& callback) {
new UsbDeviceHandleWin(this, std::move(handle), blocking_task_runner_);
} else {
USB_PLOG(ERROR) << "Failed to open " << hub_path_;
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
- ReadUsbDescriptors(device_handle, base::Bind(&UsbDeviceWin::OnReadDescriptors,
- this, callback, device_handle));
+ ReadUsbDescriptors(device_handle,
+ base::BindOnce(&UsbDeviceWin::OnReadDescriptors, this,
+ std::move(callback), device_handle));
}
void UsbDeviceWin::OnReadDescriptors(
- const base::Callback<void(bool)>& callback,
+ base::OnceCallback<void(bool)> callback,
scoped_refptr<UsbDeviceHandle> device_handle,
std::unique_ptr<UsbDeviceDescriptor> descriptor) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!descriptor) {
USB_LOG(ERROR) << "Failed to read descriptors from " << device_path_ << ".";
device_handle->Close();
- callback.Run(false);
+ std::move(callback).Run(false);
return;
}
descriptor_ = *descriptor;
- auto string_map = base::MakeUnique<std::map<uint8_t, base::string16>>();
+ auto string_map = std::make_unique<std::map<uint8_t, base::string16>>();
if (descriptor_.i_manufacturer)
(*string_map)[descriptor_.i_manufacturer] = base::string16();
if (descriptor_.i_product)
@@ -75,13 +77,14 @@ void UsbDeviceWin::OnReadDescriptors(
if (descriptor_.i_serial_number)
(*string_map)[descriptor_.i_serial_number] = base::string16();
- ReadUsbStringDescriptors(device_handle, std::move(string_map),
- base::Bind(&UsbDeviceWin::OnReadStringDescriptors,
- this, callback, device_handle));
+ ReadUsbStringDescriptors(
+ device_handle, std::move(string_map),
+ base::BindOnce(&UsbDeviceWin::OnReadStringDescriptors, this,
+ std::move(callback), device_handle));
}
void UsbDeviceWin::OnReadStringDescriptors(
- const base::Callback<void(bool)>& callback,
+ base::OnceCallback<void(bool)> callback,
scoped_refptr<UsbDeviceHandle> device_handle,
std::unique_ptr<std::map<uint8_t, base::string16>> string_map) {
DCHECK(thread_checker_.CalledOnValidThread());
@@ -94,7 +97,7 @@ void UsbDeviceWin::OnReadStringDescriptors(
if (descriptor_.i_serial_number)
serial_number_ = (*string_map)[descriptor_.i_serial_number];
- callback.Run(true);
+ std::move(callback).Run(true);
}
} // namespace device
diff --git a/chromium/device/usb/usb_device_win.h b/chromium/device/usb/usb_device_win.h
index dd17683a757..1bfc1282f0a 100644
--- a/chromium/device/usb/usb_device_win.h
+++ b/chromium/device/usb/usb_device_win.h
@@ -22,7 +22,7 @@ struct UsbDeviceDescriptor;
class UsbDeviceWin : public UsbDevice {
public:
// UsbDevice implementation:
- void Open(const OpenCallback& callback) override;
+ void Open(OpenCallback callback) override;
protected:
friend class UsbServiceWin;
@@ -43,15 +43,15 @@ class UsbDeviceWin : public UsbDevice {
// Opens the device's parent hub in order to read the device, configuration
// and string descriptors.
- void ReadDescriptors(const base::Callback<void(bool)>& callback);
+ void ReadDescriptors(base::OnceCallback<void(bool)> callback);
private:
- void OpenOnBlockingThread(const OpenCallback& callback);
- void OnReadDescriptors(const base::Callback<void(bool)>& callback,
+ void OpenOnBlockingThread(OpenCallback callback);
+ void OnReadDescriptors(base::OnceCallback<void(bool)> callback,
scoped_refptr<UsbDeviceHandle> device_handle,
std::unique_ptr<UsbDeviceDescriptor> descriptor);
void OnReadStringDescriptors(
- const base::Callback<void(bool)>& callback,
+ base::OnceCallback<void(bool)> callback,
scoped_refptr<UsbDeviceHandle> device_handle,
std::unique_ptr<std::map<uint8_t, base::string16>> string_map);
diff --git a/chromium/device/usb/usb_service_android.cc b/chromium/device/usb/usb_service_android.cc
index e29880d400b..1878d4aa1ef 100644
--- a/chromium/device/usb/usb_service_android.cc
+++ b/chromium/device/usb/usb_service_android.cc
@@ -20,11 +20,6 @@ using base::android::ScopedJavaLocalRef;
namespace device {
-// static
-bool UsbServiceAndroid::RegisterJNI(JNIEnv* env) {
- return RegisterNativesImpl(env); // Generated in ChromeUsbService_jni.h
-}
-
UsbServiceAndroid::UsbServiceAndroid()
: UsbService(nullptr), weak_factory_(this) {
JNIEnv* env = AttachCurrentThread();
diff --git a/chromium/device/usb/usb_service_android.h b/chromium/device/usb/usb_service_android.h
index ae1ec5a3f22..9f392093049 100644
--- a/chromium/device/usb/usb_service_android.h
+++ b/chromium/device/usb/usb_service_android.h
@@ -22,9 +22,6 @@ class UsbDeviceAndroid;
// does not return any devices.
class UsbServiceAndroid : public UsbService {
public:
- // Register C++ methods exposed to Java using JNI.
- static bool RegisterJNI(JNIEnv* env);
-
UsbServiceAndroid();
~UsbServiceAndroid() override;
diff --git a/chromium/device/usb/usb_service_linux.cc b/chromium/device/usb/usb_service_linux.cc
index e882c4d3bf7..a366f2dc76f 100644
--- a/chromium/device/usb/usb_service_linux.cc
+++ b/chromium/device/usb/usb_service_linux.cc
@@ -182,7 +182,7 @@ void UsbServiceLinux::FileThreadHelper::OnDeviceRemoved(
UsbServiceLinux::UsbServiceLinux()
: UsbService(CreateBlockingTaskRunner()), weak_factory_(this) {
- helper_ = base::MakeUnique<FileThreadHelper>(weak_factory_.GetWeakPtr());
+ helper_ = std::make_unique<FileThreadHelper>(weak_factory_.GetWeakPtr());
blocking_task_runner()->PostTask(
FROM_HERE,
base::Bind(&FileThreadHelper::Start, base::Unretained(helper_.get())));
diff --git a/chromium/device/usb/usb_service_win.cc b/chromium/device/usb/usb_service_win.cc
index c0b2a75e367..c4cd0242f7f 100644
--- a/chromium/device/usb/usb_service_win.cc
+++ b/chromium/device/usb/usb_service_win.cc
@@ -285,7 +285,7 @@ UsbServiceWin::UsbServiceWin()
if (device_monitor)
device_observer_.Add(device_monitor);
- helper_ = base::MakeUnique<BlockingTaskHelper>(weak_factory_.GetWeakPtr());
+ helper_ = std::make_unique<BlockingTaskHelper>(weak_factory_.GetWeakPtr());
blocking_task_runner()->PostTask(
FROM_HERE, base::Bind(&BlockingTaskHelper::EnumerateDevices,
base::Unretained(helper_.get())));
diff --git a/chromium/device/usb/webusb_descriptors_unittest.cc b/chromium/device/usb/webusb_descriptors_unittest.cc
index ecdafe5c147..6f6b81a86fd 100644
--- a/chromium/device/usb/webusb_descriptors_unittest.cc
+++ b/chromium/device/usb/webusb_descriptors_unittest.cc
@@ -44,7 +44,7 @@ const uint8_t kExampleUrlDescriptor1[] = {
ACTION_P2(InvokeCallback, data, length) {
size_t transferred_length = std::min(length, arg7);
memcpy(arg6->data(), data, transferred_length);
- arg9.Run(UsbTransferStatus::COMPLETED, arg6, transferred_length);
+ std::move(arg9).Run(UsbTransferStatus::COMPLETED, arg6, transferred_length);
}
void ExpectLandingPage(const GURL& landing_page) {
@@ -254,18 +254,18 @@ TEST_F(WebUsbDescriptorsTest, ReadDescriptors) {
new MockUsbDeviceHandle(nullptr));
EXPECT_CALL(*device_handle,
- ControlTransfer(UsbTransferDirection::INBOUND,
- UsbControlTransferType::STANDARD,
- UsbControlTransferRecipient::DEVICE, 0x06, 0x0F00,
- 0x0000, _, _, _, _))
+ ControlTransferInternal(UsbTransferDirection::INBOUND,
+ UsbControlTransferType::STANDARD,
+ UsbControlTransferRecipient::DEVICE, 0x06,
+ 0x0F00, 0x0000, _, _, _, _))
.Times(2)
.WillRepeatedly(
InvokeCallback(kExampleBosDescriptor, sizeof(kExampleBosDescriptor)));
EXPECT_CALL(*device_handle,
- ControlTransfer(UsbTransferDirection::INBOUND,
- UsbControlTransferType::VENDOR,
- UsbControlTransferRecipient::DEVICE, 0x42, 0x0001,
- 0x0002, _, _, _, _))
+ ControlTransferInternal(UsbTransferDirection::INBOUND,
+ UsbControlTransferType::VENDOR,
+ UsbControlTransferRecipient::DEVICE, 0x42,
+ 0x0001, 0x0002, _, _, _, _))
.WillOnce(InvokeCallback(kExampleUrlDescriptor1,
sizeof(kExampleUrlDescriptor1)));
diff --git a/chromium/device/vr/android/gvr/cardboard_gamepad_data_fetcher.cc b/chromium/device/vr/android/gvr/cardboard_gamepad_data_fetcher.cc
index 30d7a8887c8..91b3ffb4ccc 100644
--- a/chromium/device/vr/android/gvr/cardboard_gamepad_data_fetcher.cc
+++ b/chromium/device/vr/android/gvr/cardboard_gamepad_data_fetcher.cc
@@ -37,7 +37,7 @@ CardboardGamepadDataFetcher::Factory::~Factory() {
std::unique_ptr<GamepadDataFetcher>
CardboardGamepadDataFetcher::Factory::CreateDataFetcher() {
- return base::MakeUnique<CardboardGamepadDataFetcher>(data_provider_,
+ return std::make_unique<CardboardGamepadDataFetcher>(data_provider_,
display_id_);
}
diff --git a/chromium/device/vr/android/gvr/cardboard_gamepad_data_provider.h b/chromium/device/vr/android/gvr/cardboard_gamepad_data_provider.h
index fbe30fd493a..bfd3dce8bd1 100644
--- a/chromium/device/vr/android/gvr/cardboard_gamepad_data_provider.h
+++ b/chromium/device/vr/android/gvr/cardboard_gamepad_data_provider.h
@@ -11,6 +11,7 @@ class CardboardGamepadDataFetcher;
// Filled in by vr_shell and consumed by CardboardGamepadDataFetcher.
struct CardboardGamepadData {
+ CardboardGamepadData() : timestamp(0), is_screen_touching(false) {}
int64_t timestamp;
bool is_screen_touching;
};
diff --git a/chromium/device/vr/android/gvr/gvr_delegate.cc b/chromium/device/vr/android/gvr/gvr_delegate.cc
index 6151bdef7e3..dfdeb66a2e5 100644
--- a/chromium/device/vr/android/gvr/gvr_delegate.cc
+++ b/chromium/device/vr/android/gvr/gvr_delegate.cc
@@ -6,7 +6,6 @@
#include "base/trace_event/trace_event.h"
#include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/gvr.h"
-#include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/gvr_types.h"
#include "ui/gfx/geometry/vector3d_f.h"
#include "ui/gfx/transform.h"
#include "ui/gfx/transform_util.h"
diff --git a/chromium/device/vr/android/gvr/gvr_delegate.h b/chromium/device/vr/android/gvr/gvr_delegate.h
index fbf6f46a754..cde47067939 100644
--- a/chromium/device/vr/android/gvr/gvr_delegate.h
+++ b/chromium/device/vr/android/gvr/gvr_delegate.h
@@ -9,7 +9,6 @@
#include "device/vr/vr_export.h"
#include "device/vr/vr_service.mojom.h"
-#include "gpu/command_buffer/common/mailbox_holder.h"
#include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/gvr_types.h"
#include "ui/gfx/geometry/size.h"
@@ -45,19 +44,6 @@ class DEVICE_VR_EXPORT GvrDelegate {
static mojom::VRDisplayInfoPtr CreateVRDisplayInfo(gvr::GvrApi* gvr_api,
gfx::Size recommended_size,
uint32_t device_id);
-
- virtual void SetWebVRSecureOrigin(bool secure_origin) = 0;
- virtual void UpdateVSyncInterval(base::TimeTicks vsync_timebase,
- base::TimeDelta vsync_interval) = 0;
- virtual void CreateVRDisplayInfo(
- const base::Callback<void(mojom::VRDisplayInfoPtr)>& callback,
- uint32_t device_id) = 0;
- virtual void ConnectPresentingService(
- device::mojom::VRSubmitFrameClientPtr submit_client,
- device::mojom::VRPresentationProviderRequest request) = 0;
-
- protected:
- virtual ~GvrDelegate() {}
};
} // namespace device
diff --git a/chromium/device/vr/android/gvr/gvr_delegate_provider.h b/chromium/device/vr/android/gvr/gvr_delegate_provider.h
index 0aba329049f..4ee01bb9120 100644
--- a/chromium/device/vr/android/gvr/gvr_delegate_provider.h
+++ b/chromium/device/vr/android/gvr/gvr_delegate_provider.h
@@ -11,8 +11,6 @@
namespace device {
-class GvrDelegate;
-class GvrDeviceProvider;
class VRDisplayImpl;
class DEVICE_VR_EXPORT GvrDelegateProvider {
@@ -21,17 +19,15 @@ class DEVICE_VR_EXPORT GvrDelegateProvider {
const base::Callback<GvrDelegateProvider*()>& provider_callback);
static GvrDelegateProvider* GetInstance();
- virtual void SetDeviceProvider(GvrDeviceProvider* device_provider) = 0;
- virtual void ClearDeviceProvider() = 0;
+ virtual void SetDeviceId(unsigned int device_id) = 0;
virtual void RequestWebVRPresent(
mojom::VRSubmitFrameClientPtr submit_client,
mojom::VRPresentationProviderRequest request,
const base::Callback<void(bool)>& callback) = 0;
virtual void ExitWebVRPresent() = 0;
- virtual GvrDelegate* GetDelegate() = 0;
virtual void OnDisplayAdded(VRDisplayImpl* display) = 0;
virtual void OnDisplayRemoved(VRDisplayImpl* display) = 0;
- virtual void OnListeningForActivateChanged(VRDisplayImpl* display);
+ virtual void OnListeningForActivateChanged(VRDisplayImpl* display) = 0;
virtual void CreateVRDisplayInfo(
const base::Callback<void(mojom::VRDisplayInfoPtr)>& callback,
uint32_t device_id) = 0;
diff --git a/chromium/device/vr/android/gvr/gvr_device.cc b/chromium/device/vr/android/gvr/gvr_device.cc
index daa90a87bda..4ff8f53f14e 100644
--- a/chromium/device/vr/android/gvr/gvr_device.cc
+++ b/chromium/device/vr/android/gvr/gvr_device.cc
@@ -20,14 +20,15 @@
namespace device {
-GvrDevice::GvrDevice(GvrDeviceProvider* provider)
- : VRDevice(), gvr_provider_(provider) {}
+GvrDevice::GvrDevice() : VRDevice() {
+ GetGvrDelegateProvider();
+}
GvrDevice::~GvrDevice() {}
void GvrDevice::CreateVRDisplayInfo(
const base::Callback<void(mojom::VRDisplayInfoPtr)>& on_created) {
- GvrDelegateProvider* delegate_provider = gvr_provider_->GetDelegateProvider();
+ GvrDelegateProvider* delegate_provider = GetGvrDelegateProvider();
if (delegate_provider) {
delegate_provider->CreateVRDisplayInfo(on_created, id());
} else {
@@ -38,7 +39,7 @@ void GvrDevice::CreateVRDisplayInfo(
void GvrDevice::RequestPresent(mojom::VRSubmitFrameClientPtr submit_client,
mojom::VRPresentationProviderRequest request,
const base::Callback<void(bool)>& callback) {
- GvrDelegateProvider* delegate_provider = gvr_provider_->GetDelegateProvider();
+ GvrDelegateProvider* delegate_provider = GetGvrDelegateProvider();
if (!delegate_provider)
return callback.Run(false);
@@ -48,15 +49,8 @@ void GvrDevice::RequestPresent(mojom::VRSubmitFrameClientPtr submit_client,
std::move(request), callback);
}
-void GvrDevice::SetSecureOrigin(bool secure_origin) {
- secure_origin_ = secure_origin;
- GvrDelegate* delegate = GetGvrDelegate();
- if (delegate)
- delegate->SetWebVRSecureOrigin(secure_origin_);
-}
-
void GvrDevice::ExitPresent() {
- GvrDelegateProvider* delegate_provider = gvr_provider_->GetDelegateProvider();
+ GvrDelegateProvider* delegate_provider = GetGvrDelegateProvider();
if (delegate_provider)
delegate_provider->ExitWebVRPresent();
OnExitPresent();
@@ -65,7 +59,7 @@ void GvrDevice::ExitPresent() {
void GvrDevice::GetNextMagicWindowPose(
VRDisplayImpl* display,
mojom::VRDisplay::GetNextMagicWindowPoseCallback callback) {
- GvrDelegateProvider* delegate_provider = gvr_provider_->GetDelegateProvider();
+ GvrDelegateProvider* delegate_provider = GetGvrDelegateProvider();
if (!delegate_provider) {
std::move(callback).Run(nullptr);
return;
@@ -74,40 +68,33 @@ void GvrDevice::GetNextMagicWindowPose(
}
void GvrDevice::OnDisplayAdded(VRDisplayImpl* display) {
- GvrDelegateProvider* delegate_provider = gvr_provider_->GetDelegateProvider();
+ GvrDelegateProvider* delegate_provider = GetGvrDelegateProvider();
if (!delegate_provider)
return;
delegate_provider->OnDisplayAdded(display);
}
void GvrDevice::OnDisplayRemoved(VRDisplayImpl* display) {
- GvrDelegateProvider* delegate_provider = gvr_provider_->GetDelegateProvider();
+ GvrDelegateProvider* delegate_provider = GetGvrDelegateProvider();
if (!delegate_provider)
return;
delegate_provider->OnDisplayRemoved(display);
}
void GvrDevice::OnListeningForActivateChanged(VRDisplayImpl* display) {
- GvrDelegateProvider* delegate_provider = gvr_provider_->GetDelegateProvider();
+ GvrDelegateProvider* delegate_provider = GetGvrDelegateProvider();
if (!delegate_provider)
return;
delegate_provider->OnListeningForActivateChanged(display);
}
-void GvrDevice::OnDelegateChanged() {
- GvrDelegate* delegate = GetGvrDelegate();
- // Notify the clients that this device has changed
- if (delegate)
- delegate->SetWebVRSecureOrigin(secure_origin_);
-
- OnChanged();
-}
-
-GvrDelegate* GvrDevice::GetGvrDelegate() {
- GvrDelegateProvider* delegate_provider = gvr_provider_->GetDelegateProvider();
+GvrDelegateProvider* GvrDevice::GetGvrDelegateProvider() {
+ // GvrDelegateProvider::GetInstance() may fail transiently, so every time we
+ // try to get it, set the device ID.
+ GvrDelegateProvider* delegate_provider = GvrDelegateProvider::GetInstance();
if (delegate_provider)
- return delegate_provider->GetDelegate();
- return nullptr;
+ delegate_provider->SetDeviceId(id());
+ return delegate_provider;
}
} // namespace device
diff --git a/chromium/device/vr/android/gvr/gvr_device.h b/chromium/device/vr/android/gvr/gvr_device.h
index de8aa74f0af..3d487471374 100644
--- a/chromium/device/vr/android/gvr/gvr_device.h
+++ b/chromium/device/vr/android/gvr/gvr_device.h
@@ -10,13 +10,12 @@
namespace device {
-class GvrDeviceProvider;
-class GvrDelegate;
+class GvrDelegateProvider;
class VRDisplayImpl;
class DEVICE_VR_EXPORT GvrDevice : public VRDevice {
public:
- GvrDevice(GvrDeviceProvider* provider);
+ GvrDevice();
~GvrDevice() override;
// VRDevice
@@ -26,7 +25,6 @@ class DEVICE_VR_EXPORT GvrDevice : public VRDevice {
void RequestPresent(mojom::VRSubmitFrameClientPtr submit_client,
mojom::VRPresentationProviderRequest request,
const base::Callback<void(bool)>& callback) override;
- void SetSecureOrigin(bool secure_origin) override;
void ExitPresent() override;
void GetNextMagicWindowPose(
VRDisplayImpl* display,
@@ -35,13 +33,8 @@ class DEVICE_VR_EXPORT GvrDevice : public VRDevice {
void OnDisplayRemoved(VRDisplayImpl* display) override;
void OnListeningForActivateChanged(VRDisplayImpl* display) override;
- void OnDelegateChanged();
-
private:
- GvrDelegate* GetGvrDelegate();
-
- GvrDeviceProvider* gvr_provider_;
- bool secure_origin_ = false;
+ GvrDelegateProvider* GetGvrDelegateProvider();
DISALLOW_COPY_AND_ASSIGN(GvrDevice);
};
diff --git a/chromium/device/vr/android/gvr/gvr_device_provider.cc b/chromium/device/vr/android/gvr/gvr_device_provider.cc
index dcaa1804021..e1f37c07c8e 100644
--- a/chromium/device/vr/android/gvr/gvr_device_provider.cc
+++ b/chromium/device/vr/android/gvr/gvr_device_provider.cc
@@ -10,35 +10,15 @@
namespace device {
-GvrDeviceProvider::GvrDeviceProvider()
- : vr_device_(base::MakeUnique<GvrDevice>(this)) {}
-
-GvrDeviceProvider::~GvrDeviceProvider() {
- GvrDelegateProvider* delegate_provider = GvrDelegateProvider::GetInstance();
- if (delegate_provider) {
- delegate_provider->ExitWebVRPresent();
- delegate_provider->ClearDeviceProvider();
- }
-}
+GvrDeviceProvider::GvrDeviceProvider() = default;
+GvrDeviceProvider::~GvrDeviceProvider() = default;
void GvrDeviceProvider::GetDevices(std::vector<VRDevice*>* devices) {
devices->push_back(vr_device_.get());
}
-GvrDelegateProvider* GvrDeviceProvider::GetDelegateProvider() {
- GvrDelegateProvider* provider = GvrDelegateProvider::GetInstance();
- Initialize(provider);
- return provider;
-}
-
void GvrDeviceProvider::Initialize() {
- Initialize(GvrDelegateProvider::GetInstance());
-}
-
-void GvrDeviceProvider::Initialize(GvrDelegateProvider* provider) {
- if (!provider)
- return;
- provider->SetDeviceProvider(this);
+ vr_device_ = std::make_unique<GvrDevice>();
}
} // namespace device
diff --git a/chromium/device/vr/android/gvr/gvr_device_provider.h b/chromium/device/vr/android/gvr/gvr_device_provider.h
index 9f05cc21a0b..8ad684dcc84 100644
--- a/chromium/device/vr/android/gvr/gvr_device_provider.h
+++ b/chromium/device/vr/android/gvr/gvr_device_provider.h
@@ -9,14 +9,13 @@
#include "base/macros.h"
#include "device/vr/vr_device_provider.h"
-#include "device/vr/vr_export.h"
namespace device {
class GvrDelegateProvider;
class GvrDevice;
-class DEVICE_VR_EXPORT GvrDeviceProvider : public VRDeviceProvider {
+class GvrDeviceProvider : public VRDeviceProvider {
public:
GvrDeviceProvider();
~GvrDeviceProvider() override;
@@ -24,10 +23,6 @@ class DEVICE_VR_EXPORT GvrDeviceProvider : public VRDeviceProvider {
void GetDevices(std::vector<VRDevice*>* devices) override;
void Initialize() override;
- device::GvrDelegateProvider* GetDelegateProvider();
-
- GvrDevice* Device() { return vr_device_.get(); }
-
private:
void Initialize(device::GvrDelegateProvider* provider);
std::unique_ptr<GvrDevice> vr_device_;
diff --git a/chromium/device/vr/android/gvr/gvr_gamepad_data_fetcher.cc b/chromium/device/vr/android/gvr/gvr_gamepad_data_fetcher.cc
index a24b4a24b8d..cc39726ea7f 100644
--- a/chromium/device/vr/android/gvr/gvr_gamepad_data_fetcher.cc
+++ b/chromium/device/vr/android/gvr/gvr_gamepad_data_fetcher.cc
@@ -37,7 +37,7 @@ GvrGamepadDataFetcher::Factory::~Factory() {
std::unique_ptr<GamepadDataFetcher>
GvrGamepadDataFetcher::Factory::CreateDataFetcher() {
- return base::MakeUnique<GvrGamepadDataFetcher>(data_provider_, display_id_);
+ return std::make_unique<GvrGamepadDataFetcher>(data_provider_, display_id_);
}
GamepadSource GvrGamepadDataFetcher::Factory::source() {
@@ -47,7 +47,7 @@ GamepadSource GvrGamepadDataFetcher::Factory::source() {
GvrGamepadDataFetcher::GvrGamepadDataFetcher(
GvrGamepadDataProvider* data_provider,
unsigned int display_id)
- : display_id_(display_id), gamepad_data_({}) {
+ : display_id_(display_id) {
// Called on UI thread.
DVLOG(1) << __FUNCTION__ << "=" << this;
data_provider->RegisterGvrGamepadDataFetcher(this);
diff --git a/chromium/device/vr/android/gvr/gvr_gamepad_data_provider.h b/chromium/device/vr/android/gvr/gvr_gamepad_data_provider.h
index 53a84e114fc..4d70730d4e2 100644
--- a/chromium/device/vr/android/gvr/gvr_gamepad_data_provider.h
+++ b/chromium/device/vr/android/gvr/gvr_gamepad_data_provider.h
@@ -16,6 +16,12 @@ class GvrGamepadDataFetcher;
// Subset of GVR controller data needed for the gamepad API. Filled in
// by vr_shell's VrController and consumed by GvrGamepadDataFetcher.
struct GvrGamepadData {
+ GvrGamepadData()
+ : timestamp(0),
+ is_touching(false),
+ controller_button_pressed(false),
+ right_handed(true),
+ connected(false) {}
int64_t timestamp;
gfx::Vector2dF touch_pos;
gfx::Quaternion orientation;
diff --git a/chromium/device/vr/openvr/openvr_device.cc b/chromium/device/vr/openvr/openvr_device.cc
index 185f0682aa3..5f4edd26fb4 100644
--- a/chromium/device/vr/openvr/openvr_device.cc
+++ b/chromium/device/vr/openvr/openvr_device.cc
@@ -181,7 +181,7 @@ void OpenVRDevice::CreateVRDisplayInfo(
// If it is the first initialization, OpenVRRenderLoop instance needs to be
// created and the polling event callback needs to be registered.
if (!render_loop_) {
- render_loop_ = base::MakeUnique<OpenVRRenderLoop>(vr_system_);
+ render_loop_ = std::make_unique<OpenVRRenderLoop>(vr_system_);
render_loop_->RegisterPollingEventCallback(base::Bind(
&OpenVRDevice::OnPollingEvents, weak_ptr_factory_.GetWeakPtr()));
@@ -197,10 +197,6 @@ void OpenVRDevice::RequestPresent(mojom::VRSubmitFrameClientPtr submit_client,
// We don't support presentation currently.
}
-void OpenVRDevice::SetSecureOrigin(bool secure_origin) {
- // We don't support presentation currently, so don't do anything.
-}
-
void OpenVRDevice::ExitPresent() {
// We don't support presentation currently, so don't do anything.
}
diff --git a/chromium/device/vr/openvr/openvr_device.h b/chromium/device/vr/openvr/openvr_device.h
index 1c5ed7109bd..a5c8d564c8e 100644
--- a/chromium/device/vr/openvr/openvr_device.h
+++ b/chromium/device/vr/openvr/openvr_device.h
@@ -33,7 +33,6 @@ class OpenVRDevice : public VRDevice {
void RequestPresent(mojom::VRSubmitFrameClientPtr submit_client,
mojom::VRPresentationProviderRequest request,
const base::Callback<void(bool)>& callback) override;
- void SetSecureOrigin(bool secure_origin) override;
void ExitPresent() override;
void GetNextMagicWindowPose(
mojom::VRDisplay::GetNextMagicWindowPoseCallback callback) override;
diff --git a/chromium/device/vr/openvr/openvr_gamepad_data_fetcher.cc b/chromium/device/vr/openvr/openvr_gamepad_data_fetcher.cc
index cccdb372909..13ff7b29b44 100644
--- a/chromium/device/vr/openvr/openvr_gamepad_data_fetcher.cc
+++ b/chromium/device/vr/openvr/openvr_gamepad_data_fetcher.cc
@@ -46,7 +46,7 @@ OpenVRGamepadDataFetcher::Factory::~Factory() {
std::unique_ptr<GamepadDataFetcher>
OpenVRGamepadDataFetcher::Factory::CreateDataFetcher() {
- return base::MakeUnique<OpenVRGamepadDataFetcher>(display_id_, vr_system_);
+ return std::make_unique<OpenVRGamepadDataFetcher>(display_id_, vr_system_);
}
GamepadSource OpenVRGamepadDataFetcher::Factory::source() {
diff --git a/chromium/device/vr/vr_device.h b/chromium/device/vr/vr_device.h
index 2c1f39d36c3..995e698735b 100644
--- a/chromium/device/vr/vr_device.h
+++ b/chromium/device/vr/vr_device.h
@@ -34,7 +34,6 @@ class DEVICE_VR_EXPORT VRDevice {
virtual void RequestPresent(mojom::VRSubmitFrameClientPtr submit_client,
mojom::VRPresentationProviderRequest request,
const base::Callback<void(bool)>& callback) = 0;
- virtual void SetSecureOrigin(bool secure_origin) = 0;
virtual void ExitPresent() = 0;
virtual void GetNextMagicWindowPose(
VRDisplayImpl* display,
@@ -48,6 +47,7 @@ class DEVICE_VR_EXPORT VRDevice {
bool IsAccessAllowed(VRDisplayImpl* display);
bool CheckPresentingDisplay(VRDisplayImpl* display);
+ VRDisplayImpl* GetPresentingDisplay() { return presenting_display_; }
void OnChanged();
void OnExitPresent();
diff --git a/chromium/device/vr/vr_device_manager.cc b/chromium/device/vr/vr_device_manager.cc
index a5537301d60..111760c7294 100644
--- a/chromium/device/vr/vr_device_manager.cc
+++ b/chromium/device/vr/vr_device_manager.cc
@@ -29,11 +29,11 @@ VRDeviceManager* g_vr_device_manager = nullptr;
VRDeviceManager::VRDeviceManager() : keep_alive_(false) {
// Register VRDeviceProviders for the current platform
#if defined(OS_ANDROID)
- RegisterProvider(base::MakeUnique<GvrDeviceProvider>());
+ RegisterProvider(std::make_unique<GvrDeviceProvider>());
#endif
#if BUILDFLAG(ENABLE_OPENVR)
- RegisterProvider(base::MakeUnique<OpenVRDeviceProvider>());
+ RegisterProvider(std::make_unique<OpenVRDeviceProvider>());
#endif
}
@@ -102,9 +102,8 @@ unsigned int VRDeviceManager::GetNumberOfConnectedDevices() {
VRDevice* VRDeviceManager::GetDevice(unsigned int index) {
DCHECK(thread_checker_.CalledOnValidThread());
- if (index == 0) {
- return NULL;
- }
+ if (index == 0)
+ return nullptr;
DeviceMap::iterator iter = devices_.find(index);
if (iter == devices_.end()) {
diff --git a/chromium/device/vr/vr_device_manager.h b/chromium/device/vr/vr_device_manager.h
index 499eb45f8ab..e4e2f8c3b12 100644
--- a/chromium/device/vr/vr_device_manager.h
+++ b/chromium/device/vr/vr_device_manager.h
@@ -26,9 +26,9 @@ namespace device {
// Singleton used to provide the platform's VR devices to VRServiceImpl
// instances.
-class VRDeviceManager {
+class DEVICE_VR_EXPORT VRDeviceManager {
public:
- DEVICE_VR_EXPORT virtual ~VRDeviceManager();
+ virtual ~VRDeviceManager();
// Returns the VRDeviceManager singleton.
static VRDeviceManager* GetInstance();
@@ -38,10 +38,12 @@ class VRDeviceManager {
// Automatically connects all currently available VR devices by querying
// the device providers and, for each returned device, calling
// VRServiceImpl::ConnectDevice.
- DEVICE_VR_EXPORT void AddService(VRServiceImpl* service);
+ void AddService(VRServiceImpl* service);
void RemoveService(VRServiceImpl* service);
- DEVICE_VR_EXPORT unsigned int GetNumberOfConnectedDevices();
+ unsigned int GetNumberOfConnectedDevices();
+
+ VRDevice* GetDevice(unsigned int index);
private:
friend class VRDeviceManagerTest;
@@ -50,10 +52,7 @@ class VRDeviceManager {
VRDeviceManager();
// Constructor for testing.
- DEVICE_VR_EXPORT explicit VRDeviceManager(
- std::unique_ptr<VRDeviceProvider> provider);
-
- DEVICE_VR_EXPORT VRDevice* GetDevice(unsigned int index);
+ explicit VRDeviceManager(std::unique_ptr<VRDeviceProvider> provider);
void InitializeProviders();
void RegisterProvider(std::unique_ptr<VRDeviceProvider> provider);
diff --git a/chromium/device/vr/vr_display_impl.cc b/chromium/device/vr/vr_display_impl.cc
index 2dc5f5f2649..fe903291604 100644
--- a/chromium/device/vr/vr_display_impl.cc
+++ b/chromium/device/vr/vr_display_impl.cc
@@ -59,8 +59,7 @@ void VRDisplayImpl::OnDeactivate(mojom::VRDisplayEventReason reason) {
client_->OnDeactivate(reason);
}
-void VRDisplayImpl::RequestPresent(bool secure_origin,
- mojom::VRSubmitFrameClientPtr submit_client,
+void VRDisplayImpl::RequestPresent(mojom::VRSubmitFrameClientPtr submit_client,
mojom::VRPresentationProviderRequest request,
RequestPresentCallback callback) {
if (!device_->IsAccessAllowed(this)) {
@@ -68,19 +67,16 @@ void VRDisplayImpl::RequestPresent(bool secure_origin,
return;
}
- device_->RequestPresent(std::move(submit_client), std::move(request),
- base::Bind(&VRDisplayImpl::RequestPresentResult,
- weak_ptr_factory_.GetWeakPtr(),
- base::Passed(&callback), secure_origin));
+ device_->RequestPresent(
+ std::move(submit_client), std::move(request),
+ base::Bind(&VRDisplayImpl::RequestPresentResult,
+ weak_ptr_factory_.GetWeakPtr(), base::Passed(&callback)));
}
void VRDisplayImpl::RequestPresentResult(RequestPresentCallback callback,
- bool secure_origin,
bool success) {
- if (success) {
+ if (success)
device_->SetPresentingDisplay(this);
- device_->SetSecureOrigin(secure_origin);
- }
std::move(callback).Run(success);
}
diff --git a/chromium/device/vr/vr_display_impl.h b/chromium/device/vr/vr_display_impl.h
index b09ce5fc93c..b1ff4de16fa 100644
--- a/chromium/device/vr/vr_display_impl.h
+++ b/chromium/device/vr/vr_display_impl.h
@@ -48,15 +48,13 @@ class DEVICE_VR_EXPORT VRDisplayImpl : public mojom::VRDisplay {
private:
friend class VRDisplayImplTest;
- void RequestPresent(bool secure_origin,
- mojom::VRSubmitFrameClientPtr submit_client,
+ void RequestPresent(mojom::VRSubmitFrameClientPtr submit_client,
mojom::VRPresentationProviderRequest request,
RequestPresentCallback callback) override;
void ExitPresent() override;
void GetNextMagicWindowPose(GetNextMagicWindowPoseCallback callback) override;
void RequestPresentResult(RequestPresentCallback callback,
- bool secure_origin,
bool success);
mojo::Binding<mojom::VRDisplay> binding_;
diff --git a/chromium/device/vr/vr_display_impl_unittest.cc b/chromium/device/vr/vr_display_impl_unittest.cc
index a1628dbf55b..731056f615e 100644
--- a/chromium/device/vr/vr_display_impl_unittest.cc
+++ b/chromium/device/vr/vr_display_impl_unittest.cc
@@ -53,7 +53,7 @@ class VRDisplayImplTest : public testing::Test {
device::mojom::VRSubmitFrameClientPtr submit_client = nullptr;
device::mojom::VRPresentationProviderRequest request = nullptr;
display_impl->RequestPresent(
- true, std::move(submit_client), std::move(request),
+ std::move(submit_client), std::move(request),
base::Bind(&VRDisplayImplTest::onPresentComplete,
base::Unretained(this)));
}
diff --git a/chromium/device/vr/vr_service.mojom b/chromium/device/vr/vr_service.mojom
index 075bfdef460..4c8e693ba0a 100644
--- a/chromium/device/vr/vr_service.mojom
+++ b/chromium/device/vr/vr_service.mojom
@@ -84,16 +84,17 @@ interface VRSubmitFrameClient {
OnSubmitFrameRendered();
};
-// Represents a physical VR device that can be used to present WebVR content, or get orientation
-// data (VRPose) when not presenting (aka magic window).
+// Represents a physical VR device that can be used to present WebVR content,
+// or get orientation data (VRPose) when not presenting (aka magic window).
interface VRDisplay {
- RequestPresent(bool secure_origin, VRSubmitFrameClient client,
+ RequestPresent(VRSubmitFrameClient client,
VRPresentationProvider& request) => (bool success);
ExitPresent();
GetNextMagicWindowPose() => (VRPose? pose);
};
-// Provides the necessary functionality for a presenting WebVR page to draw frames for a VrDisplay.
+// Provides the necessary functionality for a presenting WebVR page to draw
+// frames for a VrDisplay.
interface VRPresentationProvider {
enum VSyncStatus { SUCCESS, CLOSING };
diff --git a/chromium/device/vr/vr_service_impl.cc b/chromium/device/vr/vr_service_impl.cc
index 19eaad516a8..96aa3faca14 100644
--- a/chromium/device/vr/vr_service_impl.cc
+++ b/chromium/device/vr/vr_service_impl.cc
@@ -36,7 +36,7 @@ VRServiceImpl::~VRServiceImpl() {
void VRServiceImpl::Create(int render_frame_process_id,
int render_frame_routing_id,
mojom::VRServiceRequest request) {
- mojo::MakeStrongBinding(base::MakeUnique<VRServiceImpl>(
+ mojo::MakeStrongBinding(std::make_unique<VRServiceImpl>(
render_frame_process_id, render_frame_routing_id),
std::move(request));
}
@@ -102,7 +102,7 @@ void VRServiceImpl::OnVRDisplayInfoCreated(
// we do mark that we have handled it and verify we haven't changed stacks.
DCHECK(in_set_client_);
} else {
- displays_[device] = base::MakeUnique<VRDisplayImpl>(
+ displays_[device] = std::make_unique<VRDisplayImpl>(
device, render_frame_process_id_, render_frame_routing_id_,
client_.get(), std::move(display_info));
connected_devices_++;