0

Reland "bluetooth: Use base::span when writing characteristics and descriptors"

This reverts commit 01792837d2.

Reason for revert: Fixed Cast target.

Original change's description:
> Revert "bluetooth: Use base::span when writing characteristics and descriptors"
>
> This reverts commit c128543f07.
>
> Reason for revert: Failures caused tree closure https://ci.chromium.org/ui/p/chromium/builders/ci/linux-cast-arm64-rel/5543/overview
>
> Original change's description:
> > bluetooth: Use base::span when writing characteristics and descriptors
> >
> > Updates the platform-independent API, platform-specific backends and
> > tests.
> >
> > Change-Id: Ia39d59f568ea7cc25f75d15a11a1fb48fb2b5d52
> > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5980562
> > Auto-Submit: Reilly Grant <reillyg@chromium.org>
> > Reviewed-by: Jon Mann <jonmann@chromium.org>
> > Commit-Queue: Jon Mann <jonmann@chromium.org>
> > Reviewed-by: Jon Mann <jonmann@google.com>
> > Reviewed-by: Jack Hsieh <chengweih@chromium.org>
> > Cr-Commit-Position: refs/heads/main@{#1377107}
>
> Change-Id: I0135c4a4f0b55089565267021d8614160a0c0cad
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5984963
> Owners-Override: Angela Yoeurng <yoangela@chromium.org>
> Commit-Queue: Angela Yoeurng <yoangela@chromium.org>
> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Auto-Submit: Angela Yoeurng <yoangela@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1377117}

Change-Id: Ia4f31fc8c0c7d87c6bafa3b6b82b8185e49fceb6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5990173
Auto-Submit: Reilly Grant <reillyg@chromium.org>
Reviewed-by: Jack Hsieh <chengweih@chromium.org>
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Reviewed-by: Jon Mann <jonmann@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1380771}
This commit is contained in:
Reilly Grant
2024-11-09 02:20:42 +00:00
committed by Chromium LUCI CQ
parent 633fdf6725
commit c81cdeb133
52 changed files with 248 additions and 182 deletions
ash/quick_pair/fast_pair_handshake
chrome/browser/extensions/api/bluetooth_low_energy
chromeos/ash/services/secure_channel
content
device
bluetooth
bluetooth_remote_gatt_characteristic.hbluetooth_remote_gatt_characteristic_android.ccbluetooth_remote_gatt_characteristic_android.hbluetooth_remote_gatt_characteristic_mac.hbluetooth_remote_gatt_characteristic_mac.mmbluetooth_remote_gatt_characteristic_winrt.ccbluetooth_remote_gatt_characteristic_winrt.hbluetooth_remote_gatt_descriptor.hbluetooth_remote_gatt_descriptor_android.ccbluetooth_remote_gatt_descriptor_android.hbluetooth_remote_gatt_descriptor_mac.hbluetooth_remote_gatt_descriptor_mac.mmbluetooth_remote_gatt_descriptor_winrt.ccbluetooth_remote_gatt_descriptor_winrt.h
bluez
cast
dbus
emulation
floss
test
fido

@ -271,7 +271,7 @@ class FakeBluetoothGattCharacteristic
std::move(callback).Run(std::move(fake_notify_session));
}
void WriteRemoteCharacteristic(const std::vector<uint8_t>& value,
void WriteRemoteCharacteristic(base::span<const uint8_t> value,
WriteType write_type,
base::OnceClosure callback,
ErrorCallback error_callback) override {

@ -13,6 +13,7 @@
#include <tuple>
#include <utility>
#include "base/containers/to_vector.h"
#include "base/memory/raw_ptr_exclusion.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/gmock_move_support.h"
@ -59,7 +60,7 @@ using testing::Invoke;
using testing::Return;
using testing::ReturnRef;
using testing::ReturnRefOfCopy;
using testing::SaveArg;
using testing::WithArg;
namespace {
@ -777,7 +778,11 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, WriteCharacteristicValue) {
.Times(2)
.WillOnce(InvokeCallbackArgument<2>(
BluetoothGattService::GattErrorCode::kFailed))
.WillOnce(DoAll(SaveArg<0>(&write_value), InvokeCallbackArgument<1>()));
.WillOnce(
DoAll(WithArg<0>([&write_value](base::span<const uint8_t> value) {
write_value = base::ToVector(value);
}),
InvokeCallbackArgument<1>()));
EXPECT_CALL(*chrc0_, GetValue()).Times(1).WillOnce(ReturnRef(write_value));
@ -1069,7 +1074,11 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, WriteDescriptorValue) {
.Times(2)
.WillOnce(InvokeCallbackArgument<2>(
BluetoothGattService::GattErrorCode::kFailed))
.WillOnce(DoAll(SaveArg<0>(&write_value), InvokeCallbackArgument<1>()));
.WillOnce(
DoAll(WithArg<0>([&write_value](base::span<const uint8_t> value) {
write_value = base::ToVector(value);
}),
InvokeCallbackArgument<1>()));
EXPECT_CALL(*desc0_, GetValue()).Times(1).WillOnce(ReturnRef(write_value));

@ -9,6 +9,7 @@
#include <memory>
#include <utility>
#include "base/containers/to_vector.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/ptr_util.h"
@ -46,6 +47,7 @@ using ::testing::DoAll;
using ::testing::NiceMock;
using ::testing::Return;
using ::testing::SaveArg;
using ::testing::WithArg;
using ::testing::WithArgs;
typedef BluetoothLowEnergyWeaveClientConnection::SubStatus SubStatus;
@ -506,10 +508,12 @@ class SecureChannelBluetoothLowEnergyWeaveClientConnectionTest
void NotifySessionStarted(
TestBluetoothLowEnergyWeaveClientConnection* connection) {
EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic_(_, _, _, _))
.WillOnce(
DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_),
MoveArg<2>(&write_remote_characteristic_success_callback_),
MoveArg<3>(&write_remote_characteristic_error_callback_)));
.WillOnce(DoAll(
WithArg<0>([this](base::span<const uint8_t> value) {
last_value_written_on_tx_characteristic_ = base::ToVector(value);
}),
MoveArg<2>(&write_remote_characteristic_success_callback_),
MoveArg<3>(&write_remote_characteristic_error_callback_)));
EXPECT_FALSE(notify_session_error_callback_.is_null());
ASSERT_FALSE(notify_session_success_callback_.is_null());
@ -567,7 +571,10 @@ class SecureChannelBluetoothLowEnergyWeaveClientConnectionTest
if (connection->IsConnected()) {
EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic_(_, _, _, _))
.WillOnce(
DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_),
DoAll(WithArg<0>([this](base::span<const uint8_t> value) {
last_value_written_on_tx_characteristic_ =
base::ToVector(value);
}),
MoveArg<2>(&write_remote_characteristic_success_callback_),
MoveArg<3>(&write_remote_characteristic_error_callback_)));
}
@ -591,7 +598,10 @@ class SecureChannelBluetoothLowEnergyWeaveClientConnectionTest
if (was_connected) {
EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic_(_, _, _, _))
.WillOnce(
DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_),
DoAll(WithArg<0>([this](base::span<const uint8_t> value) {
last_value_written_on_tx_characteristic_ =
base::ToVector(value);
}),
MoveArg<2>(&write_remote_characteristic_success_callback_),
MoveArg<3>(&write_remote_characteristic_error_callback_)));
}
@ -805,10 +815,12 @@ TEST_F(SecureChannelBluetoothLowEnergyWeaveClientConnectionTest,
EXPECT_EQ(connection->sub_status(), SubStatus::CONNECTED_AND_IDLE);
EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic_(_, _, _, _))
.WillOnce(
DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_),
MoveArg<2>(&write_remote_characteristic_success_callback_),
MoveArg<3>(&write_remote_characteristic_error_callback_)));
.WillOnce(DoAll(
WithArg<0>([this](base::span<const uint8_t> value) {
last_value_written_on_tx_characteristic_ = base::ToVector(value);
}),
MoveArg<2>(&write_remote_characteristic_success_callback_),
MoveArg<3>(&write_remote_characteristic_error_callback_)));
// Call Disconnect() twice; this should only result in one "close connection"
// message (verified via WillOnce() above).
@ -964,10 +976,12 @@ TEST_F(SecureChannelBluetoothLowEnergyWeaveClientConnectionTest,
EXPECT_EQ(0, connection_observer_->num_send_completed());
EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic_(_, _, _, _))
.Times(kMaxNumberOfTries - 1)
.WillRepeatedly(
DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_),
MoveArg<2>(&write_remote_characteristic_success_callback_),
MoveArg<3>(&write_remote_characteristic_error_callback_)));
.WillRepeatedly(DoAll(
WithArg<0>([this](base::span<const uint8_t> value) {
last_value_written_on_tx_characteristic_ = base::ToVector(value);
}),
MoveArg<2>(&write_remote_characteristic_success_callback_),
MoveArg<3>(&write_remote_characteristic_error_callback_)));
for (int i = 0; i < kMaxNumberOfTries; i++) {
EXPECT_EQ(last_value_written_on_tx_characteristic_, kConnectionRequest);
@ -1043,10 +1057,12 @@ TEST_F(SecureChannelBluetoothLowEnergyWeaveClientConnectionTest,
// Expecting a first call of WriteRemoteCharacteristic, after SendMessage is
// called.
EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic_(_, _, _, _))
.WillOnce(
DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_),
MoveArg<2>(&write_remote_characteristic_success_callback_),
MoveArg<3>(&write_remote_characteristic_error_callback_)));
.WillOnce(DoAll(
WithArg<0>([this](base::span<const uint8_t> value) {
last_value_written_on_tx_characteristic_ = base::ToVector(value);
}),
MoveArg<2>(&write_remote_characteristic_success_callback_),
MoveArg<3>(&write_remote_characteristic_error_callback_)));
connection->SendMessage(
std::make_unique<FakeWireMessage>(kSmallMessage, kTestFeature));
@ -1076,10 +1092,12 @@ TEST_F(SecureChannelBluetoothLowEnergyWeaveClientConnectionTest,
// Expecting a first call of WriteRemoteCharacteristic, after SendMessage is
// called.
EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic_(_, _, _, _))
.WillOnce(
DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_),
MoveArg<2>(&write_remote_characteristic_success_callback_),
MoveArg<3>(&write_remote_characteristic_error_callback_)));
.WillOnce(DoAll(
WithArg<0>([this](base::span<const uint8_t> value) {
last_value_written_on_tx_characteristic_ = base::ToVector(value);
}),
MoveArg<2>(&write_remote_characteristic_success_callback_),
MoveArg<3>(&write_remote_characteristic_error_callback_)));
connection->SendMessage(
std::make_unique<FakeWireMessage>(kLargeMessage, kTestFeature));
@ -1090,10 +1108,12 @@ TEST_F(SecureChannelBluetoothLowEnergyWeaveClientConnectionTest,
last_value_written_on_tx_characteristic_.end());
EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic_(_, _, _, _))
.WillOnce(
DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_),
MoveArg<2>(&write_remote_characteristic_success_callback_),
MoveArg<3>(&write_remote_characteristic_error_callback_)));
.WillOnce(DoAll(
WithArg<0>([this](base::span<const uint8_t> value) {
last_value_written_on_tx_characteristic_ = base::ToVector(value);
}),
MoveArg<2>(&write_remote_characteristic_success_callback_),
MoveArg<3>(&write_remote_characteristic_error_callback_)));
RunWriteCharacteristicSuccessCallback();
VerifyGattWriteCharacteristicResult(true /* success */, 2 /* num_writes */);
@ -1127,10 +1147,12 @@ TEST_F(SecureChannelBluetoothLowEnergyWeaveClientConnectionTest,
EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic_(_, _, _, _))
.Times(kMaxNumberOfTries)
.WillRepeatedly(
DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_),
MoveArg<2>(&write_remote_characteristic_success_callback_),
MoveArg<3>(&write_remote_characteristic_error_callback_)));
.WillRepeatedly(DoAll(
WithArg<0>([this](base::span<const uint8_t> value) {
last_value_written_on_tx_characteristic_ = base::ToVector(value);
}),
MoveArg<2>(&write_remote_characteristic_success_callback_),
MoveArg<3>(&write_remote_characteristic_error_callback_)));
connection->SendMessage(
std::make_unique<FakeWireMessage>(kSmallMessage, kTestFeature));
@ -1188,10 +1210,12 @@ TEST_F(SecureChannelBluetoothLowEnergyWeaveClientConnectionTest,
InitializeConnection(connection.get(), kDefaultMaxPacketSize);
EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic_(_, _, _, _))
.WillOnce(
DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_),
MoveArg<2>(&write_remote_characteristic_success_callback_),
MoveArg<3>(&write_remote_characteristic_error_callback_)));
.WillOnce(DoAll(
WithArg<0>([this](base::span<const uint8_t> value) {
last_value_written_on_tx_characteristic_ = base::ToVector(value);
}),
MoveArg<2>(&write_remote_characteristic_success_callback_),
MoveArg<3>(&write_remote_characteristic_error_callback_)));
connection->GattCharacteristicValueChanged(
adapter_.get(), rx_characteristic_.get(), kErroneousPacket);
@ -1218,10 +1242,12 @@ TEST_F(SecureChannelBluetoothLowEnergyWeaveClientConnectionTest,
InitializeConnection(connection.get(), kLargeMaxPacketSize);
EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic_(_, _, _, _))
.WillOnce(
DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_),
MoveArg<2>(&write_remote_characteristic_success_callback_),
MoveArg<3>(&write_remote_characteristic_error_callback_)));
.WillOnce(DoAll(
WithArg<0>([this](base::span<const uint8_t> value) {
last_value_written_on_tx_characteristic_ = base::ToVector(value);
}),
MoveArg<2>(&write_remote_characteristic_success_callback_),
MoveArg<3>(&write_remote_characteristic_error_callback_)));
connection->SendMessage(
std::make_unique<FakeWireMessage>(kLargeMessage, kTestFeature));
@ -1232,10 +1258,12 @@ TEST_F(SecureChannelBluetoothLowEnergyWeaveClientConnectionTest,
EXPECT_EQ(last_value_written_on_tx_characteristic_, kLargePackets0);
EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic_(_, _, _, _))
.WillOnce(
DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_),
MoveArg<2>(&write_remote_characteristic_success_callback_),
MoveArg<3>(&write_remote_characteristic_error_callback_)));
.WillOnce(DoAll(
WithArg<0>([this](base::span<const uint8_t> value) {
last_value_written_on_tx_characteristic_ = base::ToVector(value);
}),
MoveArg<2>(&write_remote_characteristic_success_callback_),
MoveArg<3>(&write_remote_characteristic_error_callback_)));
RunWriteCharacteristicSuccessCallback();
VerifyGattWriteCharacteristicResult(true /* success */, 2 /* num_writes */);
@ -1264,10 +1292,12 @@ TEST_F(SecureChannelBluetoothLowEnergyWeaveClientConnectionTest,
InitializeConnection(connection, kDefaultMaxPacketSize);
EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic_(_, _, _, _))
.WillOnce(
DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_),
MoveArg<2>(&write_remote_characteristic_success_callback_),
MoveArg<3>(&write_remote_characteristic_error_callback_)));
.WillOnce(DoAll(
WithArg<0>([this](base::span<const uint8_t> value) {
last_value_written_on_tx_characteristic_ = base::ToVector(value);
}),
MoveArg<2>(&write_remote_characteristic_success_callback_),
MoveArg<3>(&write_remote_characteristic_error_callback_)));
connection->GattCharacteristicValueChanged(
adapter_.get(), rx_characteristic_.get(), kErroneousPacket);
@ -1298,10 +1328,12 @@ TEST_F(SecureChannelBluetoothLowEnergyWeaveClientConnectionTest,
EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic_(_, _, _, _))
.Times(2)
.WillRepeatedly(
DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_),
MoveArg<2>(&write_remote_characteristic_success_callback_),
MoveArg<3>(&write_remote_characteristic_error_callback_)));
.WillRepeatedly(DoAll(
WithArg<0>([this](base::span<const uint8_t> value) {
last_value_written_on_tx_characteristic_ = base::ToVector(value);
}),
MoveArg<2>(&write_remote_characteristic_success_callback_),
MoveArg<3>(&write_remote_characteristic_error_callback_)));
connection->SendMessage(
std::make_unique<FakeWireMessage>(kSmallMessage, kTestFeature));
@ -1334,10 +1366,12 @@ TEST_F(SecureChannelBluetoothLowEnergyWeaveClientConnectionTest,
EXPECT_EQ(connection->sub_status(), SubStatus::CONNECTED_AND_IDLE);
EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic_(_, _, _, _))
.WillOnce(
DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_),
MoveArg<2>(&write_remote_characteristic_success_callback_),
MoveArg<3>(&write_remote_characteristic_error_callback_)));
.WillOnce(DoAll(
WithArg<0>([this](base::span<const uint8_t> value) {
last_value_written_on_tx_characteristic_ = base::ToVector(value);
}),
MoveArg<2>(&write_remote_characteristic_success_callback_),
MoveArg<3>(&write_remote_characteristic_error_callback_)));
connection->Disconnect();
EXPECT_EQ(connection->sub_status(), SubStatus::CONNECTED_AND_SENDING_MESSAGE);
@ -1350,7 +1384,10 @@ TEST_F(SecureChannelBluetoothLowEnergyWeaveClientConnectionTest,
if (i != kMaxNumberOfTries - 1) {
EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic_(_, _, _, _))
.WillOnce(
DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_),
DoAll(WithArg<0>([this](base::span<const uint8_t> value) {
last_value_written_on_tx_characteristic_ =
base::ToVector(value);
}),
MoveArg<2>(&write_remote_characteristic_success_callback_),
MoveArg<3>(&write_remote_characteristic_error_callback_)));
}

@ -16,6 +16,7 @@
#include "base/containers/contains.h"
#include "base/containers/queue.h"
#include "base/containers/to_vector.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
@ -1170,26 +1171,23 @@ void WebBluetoothServiceImpl::RemoteCharacteristicWriteValue(
BluetoothGattCharacteristic::ErrorCallback write_error_callback =
base::BindOnce(&WebBluetoothServiceImpl::OnCharacteristicWriteValueFailed,
weak_ptr_factory_.GetWeakPtr(), characteristic_instance_id,
std::vector<uint8_t>(value.begin(), value.end()),
write_type, std::move(split_callback.second));
base::ToVector(value), write_type,
std::move(split_callback.second));
using WebBluetoothWriteType = blink::mojom::WebBluetoothWriteType;
using WriteType = BluetoothRemoteGattCharacteristic::WriteType;
switch (write_type) {
case WebBluetoothWriteType::kWriteDefaultDeprecated:
query_result.characteristic->DeprecatedWriteRemoteCharacteristic(
std::vector<uint8_t>(value.begin(), value.end()),
std::move(write_callback), std::move(write_error_callback));
value, std::move(write_callback), std::move(write_error_callback));
break;
case WebBluetoothWriteType::kWriteWithResponse:
query_result.characteristic->WriteRemoteCharacteristic(
std::vector<uint8_t>(value.begin(), value.end()),
WriteType::kWithResponse, std::move(write_callback),
value, WriteType::kWithResponse, std::move(write_callback),
std::move(write_error_callback));
break;
case WebBluetoothWriteType::kWriteWithoutResponse:
query_result.characteristic->WriteRemoteCharacteristic(
std::vector<uint8_t>(value.begin(), value.end()),
WriteType::kWithoutResponse, std::move(write_callback),
value, WriteType::kWithoutResponse, std::move(write_callback),
std::move(write_error_callback));
break;
}
@ -1383,14 +1381,13 @@ void WebBluetoothServiceImpl::RemoteDescriptorWriteValue(
// the callee interface.
auto split_callback = base::SplitOnceCallback(std::move(callback));
query_result.descriptor->WriteRemoteDescriptor(
std::vector<uint8_t>(value.begin(), value.end()),
value,
base::BindOnce(&WebBluetoothServiceImpl::OnDescriptorWriteValueSuccess,
weak_ptr_factory_.GetWeakPtr(),
std::move(split_callback.first)),
base::BindOnce(&WebBluetoothServiceImpl::OnDescriptorWriteValueFailed,
weak_ptr_factory_.GetWeakPtr(), descriptor_instance_id,
std::vector<uint8_t>(value.begin(), value.end()),
std::move(split_callback.second)));
base::ToVector(value), std::move(split_callback.second)));
}
void WebBluetoothServiceImpl::RequestScanningStart(

@ -765,7 +765,7 @@ WebTestBluetoothAdapterProvider::GetDisconnectingHealthThermometer(
// expectation.
ON_CALL(*client_config, WriteRemoteDescriptor_(_, _, _))
.WillByDefault(
Invoke([](const std::vector<uint8_t>&, base::OnceClosure&,
Invoke([](base::span<const uint8_t>, base::OnceClosure&,
BluetoothRemoteGattDescriptor::ErrorCallback&) {
NOTREACHED();
}));
@ -1058,7 +1058,7 @@ scoped_refptr<NiceMockBluetoothAdapter> WebTestBluetoothAdapterProvider::
ON_CALL(*measurement_interval, WriteRemoteCharacteristic_(_, _, _, _))
.WillByDefault(
Invoke([adapter_ptr, device_ptr, disconnect, succeeds](
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
BluetoothRemoteGattCharacteristic::WriteType write_type,
base::OnceClosure& callback,
BluetoothRemoteGattCharacteristic::ErrorCallback&
@ -1084,7 +1084,7 @@ scoped_refptr<NiceMockBluetoothAdapter> WebTestBluetoothAdapterProvider::
ON_CALL(*measurement_interval, DeprecatedWriteRemoteCharacteristic_(_, _, _))
.WillByDefault(Invoke(
[adapter_ptr, device_ptr, disconnect, succeeds](
const std::vector<uint8_t>& value, base::OnceClosure& callback,
base::span<const uint8_t> value, base::OnceClosure& callback,
BluetoothRemoteGattCharacteristic::ErrorCallback&
error_callback) {
base::OnceClosure pending;
@ -1165,7 +1165,7 @@ scoped_refptr<NiceMockBluetoothAdapter> WebTestBluetoothAdapterProvider::
ON_CALL(*user_descriptor, WriteRemoteDescriptor_(_, _, _))
.WillByDefault(Invoke(
[adapter_ptr, device_ptr, disconnect, succeeds](
const std::vector<uint8_t>& value, base::OnceClosure& callback,
base::span<const uint8_t> value, base::OnceClosure& callback,
BluetoothRemoteGattDescriptor::ErrorCallback& error_callback) {
base::OnceClosure pending;
if (succeeds) {
@ -1599,7 +1599,7 @@ WebTestBluetoothAdapterProvider::GetGenericAccessService(
// expectation error correctly as a web test failure.
ON_CALL(*peripheral_privacy_flag, WriteRemoteCharacteristic_(_, _, _, _))
.WillByDefault(Invoke(
[](const std::vector<uint8_t>&,
[](base::span<const uint8_t>,
BluetoothRemoteGattCharacteristic::WriteType, base::OnceClosure&,
BluetoothRemoteGattCharacteristic::ErrorCallback&) {
NOTREACHED();
@ -1611,7 +1611,7 @@ WebTestBluetoothAdapterProvider::GetGenericAccessService(
ON_CALL(*peripheral_privacy_flag,
DeprecatedWriteRemoteCharacteristic_(_, _, _))
.WillByDefault(
Invoke([](const std::vector<uint8_t>&, base::OnceClosure&,
Invoke([](base::span<const uint8_t>, base::OnceClosure&,
BluetoothRemoteGattCharacteristic::ErrorCallback&) {
NOTREACHED();
}));
@ -1697,7 +1697,7 @@ WebTestBluetoothAdapterProvider::GetDisconnectingService(
ON_CALL(*disconnection_characteristic, WriteRemoteCharacteristic_(_, _, _, _))
.WillByDefault(
Invoke([adapter, device](
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
BluetoothRemoteGattCharacteristic::WriteType write_type,
base::OnceClosure& success,
BluetoothRemoteGattCharacteristic::ErrorCallback& error) {
@ -1710,7 +1710,7 @@ WebTestBluetoothAdapterProvider::GetDisconnectingService(
DeprecatedWriteRemoteCharacteristic_(_, _, _))
.WillByDefault(Invoke(
[adapter, device](
const std::vector<uint8_t>& value, base::OnceClosure& success,
base::span<const uint8_t> value, base::OnceClosure& success,
BluetoothRemoteGattCharacteristic::ErrorCallback& error) {
device->SetConnected(false);
for (auto& observer : adapter->GetObservers())

@ -153,7 +153,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattCharacteristic
// using the specified |write_type|. |callback| is called to signal success
// and |error_callback| for failures. This method only applies to remote
// characteristics and will fail for those that are locally hosted.
virtual void WriteRemoteCharacteristic(const std::vector<uint8_t>& value,
virtual void WriteRemoteCharacteristic(base::span<const uint8_t> value,
WriteType write_type,
base::OnceClosure callback,
ErrorCallback error_callback) = 0;
@ -165,7 +165,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattCharacteristic
// This method only applies to remote characteristics and will fail for those
// that are locally hosted.
virtual void DeprecatedWriteRemoteCharacteristic(
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) = 0;
@ -177,7 +177,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattCharacteristic
// Callers should use BluetoothDevice::ExecuteWrite() to commit or
// BluetoothDevice::AbortWrite() to abort the change.
virtual void PrepareWriteRemoteCharacteristic(
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) = 0;
#endif // BUILDFLAG(IS_CHROMEOS)

@ -152,7 +152,7 @@ void BluetoothRemoteGattCharacteristicAndroid::ReadRemoteCharacteristic(
}
void BluetoothRemoteGattCharacteristicAndroid::WriteRemoteCharacteristic(
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
WriteType write_type,
base::OnceClosure callback,
ErrorCallback error_callback) {
@ -191,7 +191,7 @@ void BluetoothRemoteGattCharacteristicAndroid::WriteRemoteCharacteristic(
}
void BluetoothRemoteGattCharacteristicAndroid::
DeprecatedWriteRemoteCharacteristic(const std::vector<uint8_t>& value,
DeprecatedWriteRemoteCharacteristic(base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) {
if (read_pending_ || write_pending_) {

@ -69,12 +69,12 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattCharacteristicAndroid
std::vector<BluetoothRemoteGattDescriptor*> GetDescriptorsByUUID(
const BluetoothUUID& uuid) const override;
void ReadRemoteCharacteristic(ValueCallback callback) override;
void WriteRemoteCharacteristic(const std::vector<uint8_t>& value,
void WriteRemoteCharacteristic(base::span<const uint8_t> value,
WriteType write_type,
base::OnceClosure callback,
ErrorCallback error_callback) override;
void DeprecatedWriteRemoteCharacteristic(
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) override;

@ -49,12 +49,12 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattCharacteristicMac
BluetoothRemoteGattService* GetService() const override;
bool IsNotifying() const override;
void ReadRemoteCharacteristic(ValueCallback callback) override;
void WriteRemoteCharacteristic(const std::vector<uint8_t>& value,
void WriteRemoteCharacteristic(base::span<const uint8_t> value,
WriteType write_type,
base::OnceClosure callback,
ErrorCallback error_callback) override;
void DeprecatedWriteRemoteCharacteristic(
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) override;

@ -161,7 +161,7 @@ void BluetoothRemoteGattCharacteristicMac::ReadRemoteCharacteristic(
}
void BluetoothRemoteGattCharacteristicMac::WriteRemoteCharacteristic(
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
WriteType write_type,
base::OnceClosure callback,
ErrorCallback error_callback) {
@ -201,7 +201,7 @@ void BluetoothRemoteGattCharacteristicMac::WriteRemoteCharacteristic(
}
void BluetoothRemoteGattCharacteristicMac::DeprecatedWriteRemoteCharacteristic(
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) {
if (!IsWritable()) {

@ -211,7 +211,7 @@ void BluetoothRemoteGattCharacteristicWinrt::ReadRemoteCharacteristic(
}
void BluetoothRemoteGattCharacteristicWinrt::WriteRemoteCharacteristic(
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
WriteType write_type,
base::OnceClosure callback,
ErrorCallback error_callback) {
@ -293,7 +293,7 @@ void BluetoothRemoteGattCharacteristicWinrt::WriteRemoteCharacteristic(
}
void BluetoothRemoteGattCharacteristicWinrt::
DeprecatedWriteRemoteCharacteristic(const std::vector<uint8_t>& value,
DeprecatedWriteRemoteCharacteristic(base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) {
if (!(GetProperties() & PROPERTY_WRITE) &&

@ -52,12 +52,12 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattCharacteristicWinrt
const std::vector<uint8_t>& GetValue() const override;
BluetoothRemoteGattService* GetService() const override;
void ReadRemoteCharacteristic(ValueCallback callback) override;
void WriteRemoteCharacteristic(const std::vector<uint8_t>& value,
void WriteRemoteCharacteristic(base::span<const uint8_t> value,
WriteType write_type,
base::OnceClosure callback,
ErrorCallback error_callback) override;
void DeprecatedWriteRemoteCharacteristic(
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) override;

@ -65,7 +65,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattDescriptor
// called to signal success and |error_callback| for failures. This method
// only applies to remote descriptors and will fail for those that are locally
// hosted.
virtual void WriteRemoteDescriptor(const std::vector<uint8_t>& new_value,
virtual void WriteRemoteDescriptor(base::span<const uint8_t> new_value,
base::OnceClosure callback,
ErrorCallback error_callback) = 0;

@ -106,7 +106,7 @@ void BluetoothRemoteGattDescriptorAndroid::ReadRemoteDescriptor(
}
void BluetoothRemoteGattDescriptorAndroid::WriteRemoteDescriptor(
const std::vector<uint8_t>& new_value,
base::span<const uint8_t> new_value,
base::OnceClosure callback,
ErrorCallback error_callback) {
if (read_pending_ || write_pending_) {

@ -52,7 +52,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattDescriptorAndroid
BluetoothRemoteGattCharacteristic::Permissions GetPermissions()
const override;
void ReadRemoteDescriptor(ValueCallback callback) override;
void WriteRemoteDescriptor(const std::vector<uint8_t>& value,
void WriteRemoteDescriptor(base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) override;

@ -36,7 +36,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattDescriptorMac
const std::vector<uint8_t>& GetValue() const override;
BluetoothRemoteGattCharacteristic* GetCharacteristic() const override;
void ReadRemoteDescriptor(ValueCallback callback) override;
void WriteRemoteDescriptor(const std::vector<uint8_t>& new_value,
void WriteRemoteDescriptor(base::span<const uint8_t> new_value,
base::OnceClosure callback,
ErrorCallback error_callback) override;

@ -110,7 +110,7 @@ void BluetoothRemoteGattDescriptorMac::ReadRemoteDescriptor(
}
void BluetoothRemoteGattDescriptorMac::WriteRemoteDescriptor(
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) {
if (destructor_called_ || HasPendingRead() || HasPendingWrite()) {

@ -148,7 +148,7 @@ void BluetoothRemoteGattDescriptorWinrt::ReadRemoteDescriptor(
}
void BluetoothRemoteGattDescriptorWinrt::WriteRemoteDescriptor(
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) {
if (pending_read_callback_ || pending_write_callbacks_) {

@ -49,7 +49,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattDescriptorWinrt
const std::vector<uint8_t>& GetValue() const override;
BluetoothRemoteGattCharacteristic* GetCharacteristic() const override;
void ReadRemoteDescriptor(ValueCallback callback) override;
void WriteRemoteDescriptor(const std::vector<uint8_t>& value,
void WriteRemoteDescriptor(base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) override;

@ -32,8 +32,8 @@ namespace bluez {
namespace {
// Stream operator for logging vector<uint8_t>.
std::ostream& operator<<(std::ostream& out, const std::vector<uint8_t> bytes) {
// Stream operator for logging span<uint8_t>.
std::ostream& operator<<(std::ostream& out, base::span<const uint8_t> bytes) {
out << "[";
for (auto iter = bytes.begin(); iter != bytes.end(); ++iter) {
out << base::StringPrintf("%02X", *iter);
@ -174,7 +174,7 @@ void BluetoothRemoteGattCharacteristicBlueZ::ReadRemoteCharacteristic(
}
void BluetoothRemoteGattCharacteristicBlueZ::WriteRemoteCharacteristic(
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
WriteType write_type,
base::OnceClosure callback,
ErrorCallback error_callback) {
@ -204,7 +204,7 @@ void BluetoothRemoteGattCharacteristicBlueZ::WriteRemoteCharacteristic(
}
void BluetoothRemoteGattCharacteristicBlueZ::
DeprecatedWriteRemoteCharacteristic(const std::vector<uint8_t>& value,
DeprecatedWriteRemoteCharacteristic(base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) {
DVLOG(1) << "Sending GATT characteristic write request to characteristic: "
@ -222,7 +222,7 @@ void BluetoothRemoteGattCharacteristicBlueZ::
#if BUILDFLAG(IS_CHROMEOS)
void BluetoothRemoteGattCharacteristicBlueZ::PrepareWriteRemoteCharacteristic(
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) {
DVLOG(1) << "Sending GATT characteristic prepare write request to "

@ -60,16 +60,16 @@ class BluetoothRemoteGattCharacteristicBlueZ
device::BluetoothRemoteGattService* GetService() const override;
bool IsNotifying() const override;
void ReadRemoteCharacteristic(ValueCallback callback) override;
void WriteRemoteCharacteristic(const std::vector<uint8_t>& value,
void WriteRemoteCharacteristic(base::span<const uint8_t> value,
WriteType write_type,
base::OnceClosure callback,
ErrorCallback error_callback) override;
void DeprecatedWriteRemoteCharacteristic(
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) override;
#if BUILDFLAG(IS_CHROMEOS)
void PrepareWriteRemoteCharacteristic(const std::vector<uint8_t>& value,
void PrepareWriteRemoteCharacteristic(base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) override;
#endif // BUILDFLAG(IS_CHROMEOS)

@ -25,8 +25,8 @@ namespace bluez {
namespace {
// Stream operator for logging vector<uint8_t>.
std::ostream& operator<<(std::ostream& out, const std::vector<uint8_t> bytes) {
// Stream operator for logging span<uint8_t>.
std::ostream& operator<<(std::ostream& out, base::span<const uint8_t> bytes) {
out << "[";
for (auto iter = bytes.begin(); iter != bytes.end(); ++iter) {
out << base::StringPrintf("%02X", *iter);
@ -96,7 +96,7 @@ void BluetoothRemoteGattDescriptorBlueZ::ReadRemoteDescriptor(
}
void BluetoothRemoteGattDescriptorBlueZ::WriteRemoteDescriptor(
const std::vector<uint8_t>& new_value,
base::span<const uint8_t> new_value,
base::OnceClosure callback,
ErrorCallback error_callback) {
DVLOG(1) << "Sending GATT characteristic descriptor write request to "

@ -41,7 +41,7 @@ class BluetoothRemoteGattDescriptorBlueZ
device::BluetoothRemoteGattCharacteristic::Permissions GetPermissions()
const override;
void ReadRemoteDescriptor(ValueCallback callback) override;
void WriteRemoteDescriptor(const std::vector<uint8_t>& new_value,
void WriteRemoteDescriptor(base::span<const uint8_t> new_value,
base::OnceClosure callback,
ErrorCallback error_callback) override;

@ -7,6 +7,7 @@
#include <memory>
#include "base/containers/queue.h"
#include "base/containers/to_vector.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/logging.h"
@ -140,7 +141,7 @@ void BluetoothRemoteGattCharacteristicCast::ReadRemoteCharacteristic(
}
void BluetoothRemoteGattCharacteristicCast::WriteRemoteCharacteristic(
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
WriteType write_type,
base::OnceClosure callback,
ErrorCallback error_callback) {
@ -156,24 +157,27 @@ void BluetoothRemoteGattCharacteristicCast::WriteRemoteCharacteristic(
break;
}
std::vector<uint8_t> value_vector = base::ToVector(value);
remote_characteristic_->WriteAuth(
chromecast::bluetooth_v2_shlib::Gatt::Client::AUTH_REQ_NONE,
chromecast_write_type, value,
chromecast_write_type, value_vector,
base::BindOnce(
&BluetoothRemoteGattCharacteristicCast::OnWriteRemoteCharacteristic,
weak_factory_.GetWeakPtr(), value, std::move(callback),
weak_factory_.GetWeakPtr(), value_vector, std::move(callback),
std::move(error_callback)));
}
void BluetoothRemoteGattCharacteristicCast::DeprecatedWriteRemoteCharacteristic(
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) {
std::vector<uint8_t> value_vector = base::ToVector(value);
remote_characteristic_->Write(
value,
value_vector,
base::BindOnce(
&BluetoothRemoteGattCharacteristicCast::OnWriteRemoteCharacteristic,
weak_factory_.GetWeakPtr(), value, std::move(callback),
weak_factory_.GetWeakPtr(), value_vector, std::move(callback),
std::move(error_callback)));
}

@ -51,12 +51,12 @@ class BluetoothRemoteGattCharacteristicCast
const std::vector<uint8_t>& GetValue() const override;
BluetoothRemoteGattService* GetService() const override;
void ReadRemoteCharacteristic(ValueCallback callback) override;
void WriteRemoteCharacteristic(const std::vector<uint8_t>& value,
void WriteRemoteCharacteristic(base::span<const uint8_t> value,
WriteType write_type,
base::OnceClosure callback,
ErrorCallback error_callback) override;
void DeprecatedWriteRemoteCharacteristic(
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) override;

@ -5,8 +5,10 @@
#include "device/bluetooth/cast/bluetooth_remote_gatt_descriptor_cast.h"
#include <stdint.h>
#include <vector>
#include "base/containers/to_vector.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "chromecast/device/bluetooth/le/remote_descriptor.h"
@ -57,14 +59,15 @@ void BluetoothRemoteGattDescriptorCast::ReadRemoteDescriptor(
}
void BluetoothRemoteGattDescriptorCast::WriteRemoteDescriptor(
const std::vector<uint8_t>& new_value,
base::span<const uint8_t> new_value,
base::OnceClosure callback,
ErrorCallback error_callback) {
std::vector<uint8_t> new_value_vector = base::ToVector(new_value);
remote_descriptor_->Write(
new_value,
new_value_vector,
base::BindOnce(
&BluetoothRemoteGattDescriptorCast::OnWriteRemoteDescriptor,
weak_factory_.GetWeakPtr(), new_value, std::move(callback),
weak_factory_.GetWeakPtr(), new_value_vector, std::move(callback),
std::move(error_callback)));
}

@ -46,7 +46,7 @@ class BluetoothRemoteGattDescriptorCast : public BluetoothRemoteGattDescriptor {
const std::vector<uint8_t>& GetValue() const override;
BluetoothRemoteGattCharacteristic* GetCharacteristic() const override;
void ReadRemoteDescriptor(ValueCallback callback) override;
void WriteRemoteDescriptor(const std::vector<uint8_t>& new_value,
void WriteRemoteDescriptor(base::span<const uint8_t> new_value,
base::OnceClosure callback,
ErrorCallback error_callback) override;

@ -123,7 +123,7 @@ class BluetoothGattCharacteristicClientImpl
// BluetoothGattCharacteristicClient override.
void WriteValue(const dbus::ObjectPath& object_path,
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
std::string_view type_option,
base::OnceClosure callback,
ErrorCallback error_callback) override {
@ -159,7 +159,7 @@ class BluetoothGattCharacteristicClientImpl
}
void PrepareWriteValue(const dbus::ObjectPath& object_path,
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) override {
dbus::ObjectProxy* object_proxy =

@ -116,7 +116,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothGattCharacteristicClient
// bluetooth_gatt_characteristic::kTypeRequest or kTypeCommand, or "" to omit
// the option. Invokes |callback| on success and |error_callback| on failure.
virtual void WriteValue(const dbus::ObjectPath& object_path,
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
std::string_view type_option,
base::OnceClosure callback,
ErrorCallback error_callback) = 0;
@ -125,7 +125,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothGattCharacteristicClient
// object path |object_path| with value |value|.
// Invokes |callback| on success and |error_callback| on failure.
virtual void PrepareWriteValue(const dbus::ObjectPath& object_path,
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) = 0;

@ -126,7 +126,7 @@ class BluetoothGattDescriptorClientImpl
// BluetoothGattDescriptorClientImpl override.
void WriteValue(const dbus::ObjectPath& object_path,
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) override {
dbus::ObjectProxy* object_proxy =

@ -103,7 +103,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothGattDescriptorClient
// |object_path| with value |value|. Invokes |callback| on success and
// |error_callback| on failure.
virtual void WriteValue(const dbus::ObjectPath& object_path,
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) = 0;

@ -16,6 +16,7 @@
#include "base/base64.h"
#include "base/containers/contains.h"
#include "base/containers/to_vector.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/logging.h"
@ -1996,8 +1997,8 @@ void FakeBluetoothDeviceClient::CreateTestDevice(
void FakeBluetoothDeviceClient::AddPrepareWriteRequest(
const dbus::ObjectPath& object_path,
const std::vector<uint8_t>& value) {
prepare_write_requests_.emplace_back(object_path, value);
base::span<const uint8_t> value) {
prepare_write_requests_.emplace_back(object_path, base::ToVector(value));
}
} // namespace bluez

@ -210,7 +210,7 @@ class DEVICE_BLUETOOTH_EXPORT FakeBluetoothDeviceClient
// Adds a pending prepare write request to |object_path|.
void AddPrepareWriteRequest(const dbus::ObjectPath& object_path,
const std::vector<uint8_t>& value);
base::span<const uint8_t> value);
static const char kTestPinCode[];
static const int kTestPassKey;

@ -213,7 +213,7 @@ void FakeBluetoothGattCharacteristicClient::ReadValue(
void FakeBluetoothGattCharacteristicClient::WriteValue(
const dbus::ObjectPath& object_path,
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
std::string_view type_option,
base::OnceClosure callback,
ErrorCallback error_callback) {
@ -289,7 +289,7 @@ void FakeBluetoothGattCharacteristicClient::WriteValue(
void FakeBluetoothGattCharacteristicClient::PrepareWriteValue(
const dbus::ObjectPath& object_path,
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) {
if (!authenticated_) {

@ -63,12 +63,12 @@ class DEVICE_BLUETOOTH_EXPORT FakeBluetoothGattCharacteristicClient
ValueCallback callback,
ErrorCallback error_callback) override;
void WriteValue(const dbus::ObjectPath& object_path,
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
std::string_view type_option,
base::OnceClosure callback,
ErrorCallback error_callback) override;
void PrepareWriteValue(const dbus::ObjectPath& object_path,
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) override;
#if BUILDFLAG(IS_CHROMEOS)

@ -128,7 +128,7 @@ void FakeBluetoothGattDescriptorClient::ReadValue(
void FakeBluetoothGattDescriptorClient::WriteValue(
const dbus::ObjectPath& object_path,
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) {
if (!base::Contains(properties_, object_path)) {

@ -59,7 +59,7 @@ class DEVICE_BLUETOOTH_EXPORT FakeBluetoothGattDescriptorClient
ValueCallback callback,
ErrorCallback error_callback) override;
void WriteValue(const dbus::ObjectPath& object_path,
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) override;

@ -8,6 +8,7 @@
#include <utility>
#include <vector>
#include "base/containers/to_vector.h"
#include "base/functional/bind.h"
#include "base/ranges/algorithm.h"
#include "base/strings/stringprintf.h"
@ -143,7 +144,7 @@ void FakeRemoteGattCharacteristic::ReadRemoteCharacteristic(
}
void FakeRemoteGattCharacteristic::WriteRemoteCharacteristic(
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
WriteType write_type,
base::OnceClosure callback,
ErrorCallback error_callback) {
@ -161,7 +162,7 @@ void FakeRemoteGattCharacteristic::WriteRemoteCharacteristic(
// characteristic only supports write without response but we still need to
// run the callback because that's the guarantee the API makes.
if (write_type == WriteType::kWithoutResponse) {
last_written_value_ = value;
last_written_value_ = base::ToVector(value);
last_write_type_ = mojom_write_type;
base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, std::move(callback));
@ -172,11 +173,12 @@ void FakeRemoteGattCharacteristic::WriteRemoteCharacteristic(
FROM_HERE,
base::BindOnce(&FakeRemoteGattCharacteristic::DispatchWriteResponse,
weak_ptr_factory_.GetWeakPtr(), std::move(callback),
std::move(error_callback), value, mojom_write_type));
std::move(error_callback), base::ToVector(value),
mojom_write_type));
}
void FakeRemoteGattCharacteristic::DeprecatedWriteRemoteCharacteristic(
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) {
const mojom::WriteType write_type = mojom::WriteType::kWriteDefaultDeprecated;
@ -184,7 +186,7 @@ void FakeRemoteGattCharacteristic::DeprecatedWriteRemoteCharacteristic(
// characteristic only supports write without response but we still need to
// run the callback because that's the guarantee the API makes.
if (properties_ & PROPERTY_WRITE_WITHOUT_RESPONSE) {
last_written_value_ = value;
last_written_value_ = base::ToVector(value);
last_write_type_ = write_type;
base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, std::move(callback));
@ -195,12 +197,13 @@ void FakeRemoteGattCharacteristic::DeprecatedWriteRemoteCharacteristic(
FROM_HERE,
base::BindOnce(&FakeRemoteGattCharacteristic::DispatchWriteResponse,
weak_ptr_factory_.GetWeakPtr(), std::move(callback),
std::move(error_callback), value, write_type));
std::move(error_callback), base::ToVector(value),
write_type));
}
#if BUILDFLAG(IS_CHROMEOS)
void FakeRemoteGattCharacteristic::PrepareWriteRemoteCharacteristic(
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) {
NOTIMPLEMENTED();

@ -89,16 +89,16 @@ class FakeRemoteGattCharacteristic
const std::vector<uint8_t>& GetValue() const override;
device::BluetoothRemoteGattService* GetService() const override;
void ReadRemoteCharacteristic(ValueCallback callback) override;
void WriteRemoteCharacteristic(const std::vector<uint8_t>& value,
void WriteRemoteCharacteristic(base::span<const uint8_t> value,
WriteType write_type,
base::OnceClosure callback,
ErrorCallback error_callback) override;
void DeprecatedWriteRemoteCharacteristic(
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) override;
#if BUILDFLAG(IS_CHROMEOS)
void PrepareWriteRemoteCharacteristic(const std::vector<uint8_t>& value,
void PrepareWriteRemoteCharacteristic(base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) override;
#endif // BUILDFLAG(IS_CHROMEOS)

@ -6,6 +6,7 @@
#include <utility>
#include "base/containers/to_vector.h"
#include "base/functional/bind.h"
#include "base/task/single_thread_task_runner.h"
#include "device/bluetooth/public/mojom/emulation/fake_bluetooth.mojom.h"
@ -68,14 +69,14 @@ void FakeRemoteGattDescriptor::ReadRemoteDescriptor(ValueCallback callback) {
}
void FakeRemoteGattDescriptor::WriteRemoteDescriptor(
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) {
base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE,
base::BindOnce(&FakeRemoteGattDescriptor::DispatchWriteResponse,
weak_ptr_factory_.GetWeakPtr(), std::move(callback),
std::move(error_callback), value));
std::move(error_callback), base::ToVector(value)));
}
void FakeRemoteGattDescriptor::DispatchReadResponse(ValueCallback callback) {
@ -104,14 +105,14 @@ void FakeRemoteGattDescriptor::DispatchReadResponse(ValueCallback callback) {
void FakeRemoteGattDescriptor::DispatchWriteResponse(
base::OnceClosure callback,
ErrorCallback error_callback,
const std::vector<uint8_t>& value) {
std::vector<uint8_t> value) {
DCHECK(next_write_response_);
uint16_t gatt_code = next_write_response_.value();
next_write_response_.reset();
switch (gatt_code) {
case mojom::kGATTSuccess:
last_written_value_ = value;
last_written_value_ = std::move(value);
std::move(callback).Run();
break;
case mojom::kGATTInvalidHandle:

@ -59,7 +59,7 @@ class FakeRemoteGattDescriptor : public device::BluetoothRemoteGattDescriptor {
const std::vector<uint8_t>& GetValue() const override;
device::BluetoothRemoteGattCharacteristic* GetCharacteristic() const override;
void ReadRemoteDescriptor(ValueCallback callback) override;
void WriteRemoteDescriptor(const std::vector<uint8_t>& value,
void WriteRemoteDescriptor(base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) override;
@ -68,7 +68,7 @@ class FakeRemoteGattDescriptor : public device::BluetoothRemoteGattDescriptor {
void DispatchWriteResponse(base::OnceClosure callback,
ErrorCallback error_callback,
const std::vector<uint8_t>& value);
std::vector<uint8_t> value);
const std::string descriptor_id_;
const device::BluetoothUUID descriptor_uuid_;

@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "device/bluetooth/floss/bluetooth_remote_gatt_characteristic_floss.h"
#include "base/containers/to_vector.h"
#include "base/memory/ptr_util.h"
#include "base/notreached.h"
#include "base/strings/stringprintf.h"
@ -111,7 +112,7 @@ void BluetoothRemoteGattCharacteristicFloss::ReadRemoteCharacteristic(
}
void BluetoothRemoteGattCharacteristicFloss::WriteRemoteCharacteristic(
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
device::BluetoothRemoteGattCharacteristic::WriteType write_type,
base::OnceClosure callback,
ErrorCallback error_callback) {
@ -126,7 +127,7 @@ void BluetoothRemoteGattCharacteristicFloss::WriteRemoteCharacteristic(
}
void BluetoothRemoteGattCharacteristicFloss::
DeprecatedWriteRemoteCharacteristic(const std::vector<uint8_t>& value,
DeprecatedWriteRemoteCharacteristic(base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) {
Properties props = GetProperties();
@ -141,7 +142,7 @@ void BluetoothRemoteGattCharacteristicFloss::
#if BUILDFLAG(IS_CHROMEOS)
void BluetoothRemoteGattCharacteristicFloss::PrepareWriteRemoteCharacteristic(
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) {
// Make sure we're using reliable writes before starting a prepared write.
@ -157,7 +158,7 @@ void BluetoothRemoteGattCharacteristicFloss::PrepareWriteRemoteCharacteristic(
#endif // BUILDFLAG(IS_CHROMEOS)
void BluetoothRemoteGattCharacteristicFloss::WriteRemoteCharacteristicImpl(
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
floss::WriteType write_type,
base::OnceClosure callback,
ErrorCallback error_callback) {
@ -167,7 +168,7 @@ void BluetoothRemoteGattCharacteristicFloss::WriteRemoteCharacteristicImpl(
base::BindOnce(
&BluetoothRemoteGattCharacteristicFloss::OnWriteCharacteristic,
weak_ptr_factory_.GetWeakPtr(), std::move(callback),
std::move(error_callback), value),
std::move(error_callback), base::ToVector(value)),
device_address_, characteristic_->instance_id, write_type, auth, value);
}

@ -48,7 +48,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattCharacteristicFloss
device::BluetoothRemoteGattService* GetService() const override;
void ReadRemoteCharacteristic(ValueCallback callback) override;
void WriteRemoteCharacteristic(
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
device::BluetoothRemoteGattCharacteristic::WriteType write_type,
base::OnceClosure callback,
ErrorCallback error_callback) override;
@ -56,11 +56,11 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattCharacteristicFloss
// places. This simply calls |WriteRemoteCharacteristic| with a default value
// for |WriteType| to make it easy to remove in the future.
void DeprecatedWriteRemoteCharacteristic(
const std::vector<uint8_t>& value,
base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) override;
#if BUILDFLAG(IS_CHROMEOS)
void PrepareWriteRemoteCharacteristic(const std::vector<uint8_t>& value,
void PrepareWriteRemoteCharacteristic(base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) override;
#endif // BUILDFLAG(IS_CHROMEOS)
@ -105,7 +105,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattCharacteristicFloss
ErrorCallback error_callback) override;
// Common impl for various writes calls.
void WriteRemoteCharacteristicImpl(const std::vector<uint8_t>& value,
void WriteRemoteCharacteristicImpl(base::span<const uint8_t> value,
floss::WriteType write_type,
base::OnceClosure callback,
ErrorCallback error_callback);

@ -6,6 +6,7 @@
#include <memory>
#include "base/containers/to_vector.h"
#include "base/memory/ptr_util.h"
#include "base/strings/stringprintf.h"
#include "base/task/single_thread_task_runner.h"
@ -90,7 +91,7 @@ void BluetoothRemoteGattDescriptorFloss::ReadRemoteDescriptor(
}
void BluetoothRemoteGattDescriptorFloss::WriteRemoteDescriptor(
const std::vector<uint8_t>& new_value,
base::span<const uint8_t> new_value,
base::OnceClosure callback,
ErrorCallback error_callback) {
AuthRequired auth = characteristic_->GetAuthForWrite();
@ -98,7 +99,7 @@ void BluetoothRemoteGattDescriptorFloss::WriteRemoteDescriptor(
FlossDBusManager::Get()->GetGattManagerClient()->WriteDescriptor(
base::BindOnce(&BluetoothRemoteGattDescriptorFloss::OnWriteDescriptor,
weak_ptr_factory_.GetWeakPtr(), std::move(callback),
std::move(error_callback), new_value),
std::move(error_callback), base::ToVector(new_value)),
service_->GetDevice()->GetAddress(), descriptor_->instance_id, auth,
new_value);
}

@ -46,7 +46,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattDescriptorFloss
device::BluetoothRemoteGattCharacteristic::Permissions GetPermissions()
const override;
void ReadRemoteDescriptor(ValueCallback callback) override;
void WriteRemoteDescriptor(const std::vector<uint8_t>& new_value,
void WriteRemoteDescriptor(base::span<const uint8_t> new_value,
base::OnceClosure callback,
ErrorCallback error_callback) override;

@ -624,6 +624,14 @@ class DEVICE_BLUETOOTH_EXPORT FlossDBusClient {
writer->CloseContainer(&array);
}
// Specialized write for base::span<const uint8_t>.
static void WriteDBusParam(dbus::MessageWriter* writer,
base::span<const uint8_t> value) {
dbus::MessageWriter array_writer(nullptr);
writer->AppendArrayOfBytes(value);
writer->CloseContainer(&array_writer);
}
// Optional container type needs to be explicitly listed here.
template <typename T>
static void WriteDBusParam(dbus::MessageWriter* writer,

@ -415,7 +415,7 @@ void FlossGattManagerClient::WriteCharacteristic(
const int32_t handle,
const WriteType write_type,
const AuthRequired auth_required,
const std::vector<uint8_t> data) {
base::span<const uint8_t> data) {
CallGattMethod(std::move(callback), gatt::kWriteCharacteristic, client_id_,
remote_device, handle, write_type, auth_required, data);
}
@ -432,7 +432,7 @@ void FlossGattManagerClient::WriteDescriptor(ResponseCallback<Void> callback,
const std::string& remote_device,
const int32_t handle,
const AuthRequired auth_required,
const std::vector<uint8_t> data) {
base::span<const uint8_t> data) {
CallGattMethod<Void>(std::move(callback), gatt::kWriteDescriptor, client_id_,
remote_device, handle, auth_required, data);
}

@ -438,7 +438,7 @@ class DEVICE_BLUETOOTH_EXPORT FlossGattManagerClient
const int32_t handle,
const WriteType write_type,
const AuthRequired auth_required,
const std::vector<uint8_t> data);
base::span<const uint8_t> data);
// Reads the descriptor for a given characteristic |handle|.
virtual void ReadDescriptor(ResponseCallback<Void> callback,
@ -451,7 +451,7 @@ class DEVICE_BLUETOOTH_EXPORT FlossGattManagerClient
const std::string& remote_device,
const int32_t handle,
const AuthRequired auth_required,
const std::vector<uint8_t> data);
base::span<const uint8_t> data);
// Register for updates on a specific characteristic.
virtual void RegisterForNotification(ResponseCallback<GattStatus> callback,

@ -75,34 +75,34 @@ class MockBluetoothGattCharacteristic
ReadRemoteCharacteristic_(c);
}
MOCK_METHOD1(ReadRemoteCharacteristic_, void(ValueCallback&));
void WriteRemoteCharacteristic(const std::vector<uint8_t>& v,
void WriteRemoteCharacteristic(base::span<const uint8_t> v,
WriteType t,
base::OnceClosure c,
ErrorCallback ec) override {
WriteRemoteCharacteristic_(v, t, c, ec);
}
MOCK_METHOD4(WriteRemoteCharacteristic_,
void(const std::vector<uint8_t>&,
void(base::span<const uint8_t>,
WriteType,
base::OnceClosure&,
ErrorCallback&));
void DeprecatedWriteRemoteCharacteristic(const std::vector<uint8_t>& v,
void DeprecatedWriteRemoteCharacteristic(base::span<const uint8_t> v,
base::OnceClosure c,
ErrorCallback ec) override {
DeprecatedWriteRemoteCharacteristic_(v, c, ec);
}
MOCK_METHOD3(DeprecatedWriteRemoteCharacteristic_,
void(const std::vector<uint8_t>&,
void(base::span<const uint8_t>,
base::OnceClosure&,
ErrorCallback&));
#if BUILDFLAG(IS_CHROMEOS)
void PrepareWriteRemoteCharacteristic(const std::vector<uint8_t>& v,
void PrepareWriteRemoteCharacteristic(base::span<const uint8_t> v,
base::OnceClosure c,
ErrorCallback ec) override {
PrepareWriteRemoteCharacteristic_(v, c, ec);
}
MOCK_METHOD3(PrepareWriteRemoteCharacteristic_,
void(const std::vector<uint8_t>&,
void(base::span<const uint8_t>,
base::OnceClosure&,
ErrorCallback&));
#endif // BUILDFLAG(IS_CHROMEOS)

@ -44,13 +44,13 @@ class MockBluetoothGattDescriptor : public BluetoothRemoteGattDescriptor {
ReadRemoteDescriptor_(c);
}
MOCK_METHOD1(ReadRemoteDescriptor_, void(ValueCallback&));
void WriteRemoteDescriptor(const std::vector<uint8_t>& v,
void WriteRemoteDescriptor(base::span<const uint8_t> v,
base::OnceClosure c,
ErrorCallback ec) override {
WriteRemoteDescriptor_(v, c, ec);
}
MOCK_METHOD3(WriteRemoteDescriptor_,
void(const std::vector<uint8_t>&,
void(base::span<const uint8_t>,
base::OnceClosure&,
ErrorCallback&));
};

@ -406,7 +406,7 @@ void FidoBleConnection::WriteServiceRevision(ServiceRevision service_revision) {
DCHECK(service_revision_bitfield_id_);
fido_service->GetCharacteristic(*service_revision_bitfield_id_)
->WriteRemoteCharacteristic(
{static_cast<uint8_t>(service_revision)},
base::byte_span_from_ref(static_cast<uint8_t>(service_revision)),
BluetoothRemoteGattCharacteristic::WriteType::kWithResponse,
base::BindOnce(OnWriteRemoteCharacteristic,
std::move(split_callback.first)),

@ -181,7 +181,8 @@ class FidoBleConnectionTest : public ::testing::Test {
ON_CALL(*fido_service_revision_bitfield_, WriteRemoteCharacteristic_)
.WillByDefault(Invoke(
[=](auto&, BluetoothRemoteGattCharacteristic::WriteType,
[=](base::span<const uint8_t> value,
BluetoothRemoteGattCharacteristic::WriteType,
base::OnceClosure& callback,
const BluetoothRemoteGattCharacteristic::ErrorCallback&) {
base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
@ -317,7 +318,7 @@ class FidoBleConnectionTest : public ::testing::Test {
EXPECT_CALL(
*fido_service_revision_bitfield_,
WriteRemoteCharacteristic_(
expected_data,
testing::ElementsAreArray(expected_data),
BluetoothRemoteGattCharacteristic::WriteType::kWithResponse, _, _))
.WillOnce(
Invoke([success](const auto& data,