Clean up web bluetooth related code
This CL cleans up web bluetooth related code so that inside a C++ class, it uses member variable directly instead of using getter. BUG=None Review-Url: https://codereview.chromium.org/2736433003 Cr-Commit-Position: refs/heads/master@{#454929}
This commit is contained in:
device/bluetooth/bluez
third_party/WebKit/Source/modules/bluetooth
@ -76,9 +76,6 @@ class BluetoothRemoteGattCharacteristicBlueZ
|
||||
private:
|
||||
friend class BluetoothRemoteGattServiceBlueZ;
|
||||
|
||||
using PendingStartNotifyCall =
|
||||
std::pair<NotifySessionCallback, ErrorCallback>;
|
||||
|
||||
BluetoothRemoteGattCharacteristicBlueZ(
|
||||
BluetoothRemoteGattServiceBlueZ* service,
|
||||
const dbus::ObjectPath& object_path);
|
||||
|
@ -380,7 +380,7 @@ void BluetoothRemoteGATTCharacteristic::GetDescriptorsCallback(
|
||||
return;
|
||||
|
||||
// If the device is disconnected, reject.
|
||||
if (!service()->device()->gatt()->RemoveFromActiveAlgorithms(resolver)) {
|
||||
if (!m_service->device()->gatt()->RemoveFromActiveAlgorithms(resolver)) {
|
||||
resolver->reject(BluetoothError::createDOMException(
|
||||
blink::mojom::WebBluetoothResult::GATT_SERVER_DISCONNECTED));
|
||||
return;
|
||||
@ -392,7 +392,7 @@ void BluetoothRemoteGATTCharacteristic::GetDescriptorsCallback(
|
||||
if (quantity == mojom::blink::WebBluetoothGATTQueryQuantity::SINGLE) {
|
||||
DCHECK_EQ(1u, descriptors->size());
|
||||
resolver->resolve(
|
||||
service()->device()->getOrCreateBluetoothRemoteGATTDescriptor(
|
||||
m_service->device()->getOrCreateBluetoothRemoteGATTDescriptor(
|
||||
std::move(descriptors.value()[0]), this));
|
||||
return;
|
||||
}
|
||||
@ -401,7 +401,7 @@ void BluetoothRemoteGATTCharacteristic::GetDescriptorsCallback(
|
||||
gattDescriptors.reserveInitialCapacity(descriptors->size());
|
||||
for (auto& descriptor : descriptors.value()) {
|
||||
gattDescriptors.push_back(
|
||||
service()->device()->getOrCreateBluetoothRemoteGATTDescriptor(
|
||||
m_service->device()->getOrCreateBluetoothRemoteGATTDescriptor(
|
||||
std::move(descriptor), this));
|
||||
}
|
||||
resolver->resolve(gattDescriptors);
|
||||
|
@ -63,7 +63,7 @@ void BluetoothRemoteGATTServer::ConnectCallback(
|
||||
return;
|
||||
|
||||
if (result == mojom::blink::WebBluetoothResult::SUCCESS) {
|
||||
m_device->bluetooth()->addToConnectedDevicesMap(device()->id(), device());
|
||||
m_device->bluetooth()->addToConnectedDevicesMap(m_device->id(), m_device);
|
||||
setConnected(true);
|
||||
resolver->resolve(this);
|
||||
} else {
|
||||
@ -77,7 +77,7 @@ ScriptPromise BluetoothRemoteGATTServer::connect(ScriptState* scriptState) {
|
||||
|
||||
mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service();
|
||||
service->RemoteServerConnect(
|
||||
device()->id(), convertToBaseCallback(WTF::bind(
|
||||
m_device->id(), convertToBaseCallback(WTF::bind(
|
||||
&BluetoothRemoteGATTServer::ConnectCallback,
|
||||
wrapPersistent(this), wrapPersistent(resolver))));
|
||||
|
||||
@ -87,10 +87,10 @@ ScriptPromise BluetoothRemoteGATTServer::connect(ScriptState* scriptState) {
|
||||
void BluetoothRemoteGATTServer::disconnect(ScriptState* scriptState) {
|
||||
if (!m_connected)
|
||||
return;
|
||||
device()->cleanupDisconnectedDeviceAndFireEvent();
|
||||
m_device->bluetooth()->removeFromConnectedDevicesMap(device()->id());
|
||||
m_device->cleanupDisconnectedDeviceAndFireEvent();
|
||||
m_device->bluetooth()->removeFromConnectedDevicesMap(m_device->id());
|
||||
mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service();
|
||||
service->RemoteServerDisconnect(device()->id());
|
||||
service->RemoteServerDisconnect(m_device->id());
|
||||
}
|
||||
|
||||
// Callback that allows us to resolve the promise with a single service or
|
||||
@ -119,7 +119,7 @@ void BluetoothRemoteGATTServer::GetPrimaryServicesCallback(
|
||||
DCHECK_EQ(1u, services->size());
|
||||
resolver->resolve(m_device->getOrCreateRemoteGATTService(
|
||||
std::move(services.value()[0]), true /* isPrimary */,
|
||||
device()->id()));
|
||||
m_device->id()));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -128,7 +128,7 @@ void BluetoothRemoteGATTServer::GetPrimaryServicesCallback(
|
||||
|
||||
for (auto& service : services.value()) {
|
||||
gattServices.push_back(m_device->getOrCreateRemoteGATTService(
|
||||
std::move(service), true /* isPrimary */, device()->id()));
|
||||
std::move(service), true /* isPrimary */, m_device->id()));
|
||||
}
|
||||
resolver->resolve(gattServices);
|
||||
} else {
|
||||
@ -180,7 +180,7 @@ ScriptPromise BluetoothRemoteGATTServer::getPrimaryServicesImpl(
|
||||
ScriptState* scriptState,
|
||||
mojom::blink::WebBluetoothGATTQueryQuantity quantity,
|
||||
String servicesUUID) {
|
||||
if (!connected()) {
|
||||
if (!m_connected) {
|
||||
return ScriptPromise::rejectWithDOMException(
|
||||
scriptState,
|
||||
DOMException::create(NetworkError, kGATTServerNotConnected));
|
||||
@ -192,7 +192,7 @@ ScriptPromise BluetoothRemoteGATTServer::getPrimaryServicesImpl(
|
||||
|
||||
mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service();
|
||||
service->RemoteServerGetPrimaryServices(
|
||||
device()->id(), quantity, servicesUUID,
|
||||
m_device->id(), quantity, servicesUUID,
|
||||
convertToBaseCallback(
|
||||
WTF::bind(&BluetoothRemoteGATTServer::GetPrimaryServicesCallback,
|
||||
wrapPersistent(this), servicesUUID, quantity,
|
||||
|
@ -47,7 +47,7 @@ void BluetoothRemoteGATTService::GetCharacteristicsCallback(
|
||||
return;
|
||||
|
||||
// If the device is disconnected, reject.
|
||||
if (!device()->gatt()->RemoveFromActiveAlgorithms(resolver)) {
|
||||
if (!m_device->gatt()->RemoveFromActiveAlgorithms(resolver)) {
|
||||
resolver->reject(BluetoothError::createDOMException(
|
||||
mojom::blink::WebBluetoothResult::
|
||||
GATT_SERVER_DISCONNECTED_WHILE_RETRIEVING_CHARACTERISTICS));
|
||||
@ -59,7 +59,7 @@ void BluetoothRemoteGATTService::GetCharacteristicsCallback(
|
||||
|
||||
if (quantity == mojom::blink::WebBluetoothGATTQueryQuantity::SINGLE) {
|
||||
DCHECK_EQ(1u, characteristics->size());
|
||||
resolver->resolve(device()->getOrCreateRemoteGATTCharacteristic(
|
||||
resolver->resolve(m_device->getOrCreateRemoteGATTCharacteristic(
|
||||
resolver->getExecutionContext(),
|
||||
std::move(characteristics.value()[0]), this));
|
||||
return;
|
||||
@ -69,7 +69,7 @@ void BluetoothRemoteGATTService::GetCharacteristicsCallback(
|
||||
gattCharacteristics.reserveInitialCapacity(characteristics->size());
|
||||
for (auto& characteristic : characteristics.value()) {
|
||||
gattCharacteristics.push_back(
|
||||
device()->getOrCreateRemoteGATTCharacteristic(
|
||||
m_device->getOrCreateRemoteGATTCharacteristic(
|
||||
resolver->getExecutionContext(), std::move(characteristic),
|
||||
this));
|
||||
}
|
||||
@ -125,7 +125,7 @@ ScriptPromise BluetoothRemoteGATTService::getCharacteristicsImpl(
|
||||
ScriptState* scriptState,
|
||||
mojom::blink::WebBluetoothGATTQueryQuantity quantity,
|
||||
const String& characteristicsUUID) {
|
||||
if (!device()->gatt()->connected()) {
|
||||
if (!m_device->gatt()->connected()) {
|
||||
return ScriptPromise::rejectWithDOMException(
|
||||
scriptState,
|
||||
BluetoothError::createDOMException(
|
||||
@ -133,7 +133,7 @@ ScriptPromise BluetoothRemoteGATTService::getCharacteristicsImpl(
|
||||
GATT_SERVER_NOT_CONNECTED_CANNOT_RETRIEVE_CHARACTERISTICS));
|
||||
}
|
||||
|
||||
if (!device()->isValidService(m_service->instance_id)) {
|
||||
if (!m_device->isValidService(m_service->instance_id)) {
|
||||
return ScriptPromise::rejectWithDOMException(
|
||||
scriptState, BluetoothError::createDOMException(
|
||||
BluetoothErrorCode::InvalidService,
|
||||
@ -144,7 +144,7 @@ ScriptPromise BluetoothRemoteGATTService::getCharacteristicsImpl(
|
||||
|
||||
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
|
||||
ScriptPromise promise = resolver->promise();
|
||||
device()->gatt()->AddToActiveAlgorithms(resolver);
|
||||
m_device->gatt()->AddToActiveAlgorithms(resolver);
|
||||
|
||||
mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service();
|
||||
service->RemoteServiceGetCharacteristics(
|
||||
|
Reference in New Issue
Block a user