| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/bluetooth/BluetoothRemoteGATTServer.h" | 5 #include "modules/bluetooth/BluetoothRemoteGATTServer.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
| 8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
| 9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
| 11 #include "core/dom/ExceptionCode.h" | 11 #include "core/dom/ExceptionCode.h" |
| 12 #include "core/events/Event.h" | 12 #include "core/events/Event.h" |
| 13 #include "modules/bluetooth/Bluetooth.h" | 13 #include "modules/bluetooth/Bluetooth.h" |
| 14 #include "modules/bluetooth/BluetoothDevice.h" | 14 #include "modules/bluetooth/BluetoothDevice.h" |
| 15 #include "modules/bluetooth/BluetoothError.h" | 15 #include "modules/bluetooth/BluetoothError.h" |
| 16 #include "modules/bluetooth/BluetoothRemoteGATTService.h" | 16 #include "modules/bluetooth/BluetoothRemoteGATTService.h" |
| 17 #include "modules/bluetooth/BluetoothUUID.h" | 17 #include "modules/bluetooth/BluetoothUUID.h" |
| 18 #include <utility> | 18 #include <utility> |
| 19 | 19 |
| 20 namespace blink { | 20 namespace blink { |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 const char kGATTServerDisconnected[] = | |
| 25 "GATT Server disconnected while retrieving services."; | |
| 26 const char kGATTServerNotConnected[] = | 24 const char kGATTServerNotConnected[] = |
| 27 "GATT Server is disconnected. Cannot retrieve services."; | 25 "GATT Server is disconnected. Cannot retrieve services. (Re)connect first " |
| 26 "with `device.gatt.connect`."; |
| 28 | 27 |
| 29 } // namespace | 28 } // namespace |
| 30 | 29 |
| 31 BluetoothRemoteGATTServer::BluetoothRemoteGATTServer(BluetoothDevice* device) | 30 BluetoothRemoteGATTServer::BluetoothRemoteGATTServer(BluetoothDevice* device) |
| 32 : m_device(device), m_connected(false) {} | 31 : m_device(device), m_connected(false) {} |
| 33 | 32 |
| 34 BluetoothRemoteGATTServer* BluetoothRemoteGATTServer::create( | 33 BluetoothRemoteGATTServer* BluetoothRemoteGATTServer::create( |
| 35 BluetoothDevice* device) { | 34 BluetoothDevice* device) { |
| 36 return new BluetoothRemoteGATTServer(device); | 35 return new BluetoothRemoteGATTServer(device); |
| 37 } | 36 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 ScriptPromiseResolver* resolver, | 100 ScriptPromiseResolver* resolver, |
| 102 mojom::blink::WebBluetoothResult result, | 101 mojom::blink::WebBluetoothResult result, |
| 103 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTServicePtr>> services) { | 102 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTServicePtr>> services) { |
| 104 if (!resolver->getExecutionContext() || | 103 if (!resolver->getExecutionContext() || |
| 105 resolver->getExecutionContext()->isContextDestroyed()) | 104 resolver->getExecutionContext()->isContextDestroyed()) |
| 106 return; | 105 return; |
| 107 | 106 |
| 108 // If the device is disconnected, reject. | 107 // If the device is disconnected, reject. |
| 109 if (!RemoveFromActiveAlgorithms(resolver)) { | 108 if (!RemoveFromActiveAlgorithms(resolver)) { |
| 110 resolver->reject( | 109 resolver->reject( |
| 111 DOMException::create(NetworkError, kGATTServerDisconnected)); | 110 DOMException::create(NetworkError, kGATTServerNotConnected)); |
| 112 return; | 111 return; |
| 113 } | 112 } |
| 114 | 113 |
| 115 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { | 114 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { |
| 116 DCHECK(services); | 115 DCHECK(services); |
| 117 | 116 |
| 118 if (quantity == mojom::blink::WebBluetoothGATTQueryQuantity::SINGLE) { | 117 if (quantity == mojom::blink::WebBluetoothGATTQueryQuantity::SINGLE) { |
| 119 DCHECK_EQ(1u, services->size()); | 118 DCHECK_EQ(1u, services->size()); |
| 120 resolver->resolve(m_device->getOrCreateRemoteGATTService( | 119 resolver->resolve(m_device->getOrCreateRemoteGATTService( |
| 121 std::move(services.value()[0]), true /* isPrimary */, | 120 std::move(services.value()[0]), true /* isPrimary */, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); | 185 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); |
| 187 service->RemoteServerGetPrimaryServices( | 186 service->RemoteServerGetPrimaryServices( |
| 188 device()->id(), quantity, servicesUUID, | 187 device()->id(), quantity, servicesUUID, |
| 189 convertToBaseCallback( | 188 convertToBaseCallback( |
| 190 WTF::bind(&BluetoothRemoteGATTServer::GetPrimaryServicesCallback, | 189 WTF::bind(&BluetoothRemoteGATTServer::GetPrimaryServicesCallback, |
| 191 wrapPersistent(this), quantity, wrapPersistent(resolver)))); | 190 wrapPersistent(this), quantity, wrapPersistent(resolver)))); |
| 192 return promise; | 191 return promise; |
| 193 } | 192 } |
| 194 | 193 |
| 195 } // namespace blink | 194 } // namespace blink |
| OLD | NEW |