| 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" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 } | 57 } |
| 58 | 58 |
| 59 void BluetoothRemoteGATTServer::ConnectCallback( | 59 void BluetoothRemoteGATTServer::ConnectCallback( |
| 60 ScriptPromiseResolver* resolver, | 60 ScriptPromiseResolver* resolver, |
| 61 mojom::blink::WebBluetoothResult result) { | 61 mojom::blink::WebBluetoothResult result) { |
| 62 if (!resolver->getExecutionContext() || | 62 if (!resolver->getExecutionContext() || |
| 63 resolver->getExecutionContext()->isContextDestroyed()) | 63 resolver->getExecutionContext()->isContextDestroyed()) |
| 64 return; | 64 return; |
| 65 | 65 |
| 66 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { | 66 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { |
| 67 m_device->bluetooth()->addToConnectedDevicesMap(device()->id(), device()); |
| 67 setConnected(true); | 68 setConnected(true); |
| 68 resolver->resolve(this); | 69 resolver->resolve(this); |
| 69 } else { | 70 } else { |
| 70 resolver->reject(BluetoothError::take(resolver, result)); | 71 resolver->reject(BluetoothError::take(resolver, result)); |
| 71 } | 72 } |
| 72 } | 73 } |
| 73 | 74 |
| 74 ScriptPromise BluetoothRemoteGATTServer::connect(ScriptState* scriptState) { | 75 ScriptPromise BluetoothRemoteGATTServer::connect(ScriptState* scriptState) { |
| 75 m_device->bluetooth()->addDevice(device()->id(), device()); | |
| 76 | |
| 77 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 76 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 78 ScriptPromise promise = resolver->promise(); | 77 ScriptPromise promise = resolver->promise(); |
| 79 | 78 |
| 80 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); | 79 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); |
| 81 service->RemoteServerConnect( | 80 service->RemoteServerConnect( |
| 82 device()->id(), convertToBaseCallback(WTF::bind( | 81 device()->id(), convertToBaseCallback(WTF::bind( |
| 83 &BluetoothRemoteGATTServer::ConnectCallback, | 82 &BluetoothRemoteGATTServer::ConnectCallback, |
| 84 wrapPersistent(this), wrapPersistent(resolver)))); | 83 wrapPersistent(this), wrapPersistent(resolver)))); |
| 85 | 84 |
| 86 return promise; | 85 return promise; |
| 87 } | 86 } |
| 88 | 87 |
| 89 void BluetoothRemoteGATTServer::disconnect(ScriptState* scriptState) { | 88 void BluetoothRemoteGATTServer::disconnect(ScriptState* scriptState) { |
| 90 if (!m_connected) | 89 if (!m_connected) |
| 91 return; | 90 return; |
| 92 device()->cleanupDisconnectedDeviceAndFireEvent(); | 91 device()->cleanupDisconnectedDeviceAndFireEvent(); |
| 93 m_device->bluetooth()->removeDevice(device()->id()); | 92 m_device->bluetooth()->removeFromConnectedDevicesMap(device()->id()); |
| 94 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); | 93 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); |
| 95 service->RemoteServerDisconnect(device()->id()); | 94 service->RemoteServerDisconnect(device()->id()); |
| 96 } | 95 } |
| 97 | 96 |
| 98 // Callback that allows us to resolve the promise with a single service or | 97 // Callback that allows us to resolve the promise with a single service or |
| 99 // with a vector owning the services. | 98 // with a vector owning the services. |
| 100 void BluetoothRemoteGATTServer::GetPrimaryServicesCallback( | 99 void BluetoothRemoteGATTServer::GetPrimaryServicesCallback( |
| 101 mojom::blink::WebBluetoothGATTQueryQuantity quantity, | 100 mojom::blink::WebBluetoothGATTQueryQuantity quantity, |
| 102 ScriptPromiseResolver* resolver, | 101 ScriptPromiseResolver* resolver, |
| 103 mojom::blink::WebBluetoothResult result, | 102 mojom::blink::WebBluetoothResult result, |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 192 |
| 194 service->RemoteServerGetPrimaryServices( | 193 service->RemoteServerGetPrimaryServices( |
| 195 device()->id(), quantity, uuid, | 194 device()->id(), quantity, uuid, |
| 196 convertToBaseCallback( | 195 convertToBaseCallback( |
| 197 WTF::bind(&BluetoothRemoteGATTServer::GetPrimaryServicesCallback, | 196 WTF::bind(&BluetoothRemoteGATTServer::GetPrimaryServicesCallback, |
| 198 wrapPersistent(this), quantity, wrapPersistent(resolver)))); | 197 wrapPersistent(this), quantity, wrapPersistent(resolver)))); |
| 199 return promise; | 198 return promise; |
| 200 } | 199 } |
| 201 | 200 |
| 202 } // namespace blink | 201 } // namespace blink |
| OLD | NEW |