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/BluetoothRemoteGATTService.h" | 5 #include "modules/bluetooth/BluetoothRemoteGATTService.h" |
6 | 6 |
| 7 #include <utility> |
7 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
9 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
10 #include "core/dom/ExceptionCode.h" | 11 #include "core/dom/ExceptionCode.h" |
11 #include "core/inspector/ConsoleMessage.h" | 12 #include "core/inspector/ConsoleMessage.h" |
12 #include "modules/bluetooth/Bluetooth.h" | 13 #include "modules/bluetooth/Bluetooth.h" |
13 #include "modules/bluetooth/BluetoothError.h" | 14 #include "modules/bluetooth/BluetoothError.h" |
| 15 #include "modules/bluetooth/BluetoothMetrics.h" |
14 #include "modules/bluetooth/BluetoothRemoteGATTCharacteristic.h" | 16 #include "modules/bluetooth/BluetoothRemoteGATTCharacteristic.h" |
15 #include "modules/bluetooth/BluetoothUUID.h" | 17 #include "modules/bluetooth/BluetoothUUID.h" |
16 #include "wtf/PtrUtil.h" | 18 #include "wtf/PtrUtil.h" |
17 #include <utility> | |
18 | 19 |
19 namespace blink { | 20 namespace blink { |
20 | 21 |
21 BluetoothRemoteGATTService::BluetoothRemoteGATTService( | 22 BluetoothRemoteGATTService::BluetoothRemoteGATTService( |
22 mojom::blink::WebBluetoothRemoteGATTServicePtr service, | 23 mojom::blink::WebBluetoothRemoteGATTServicePtr service, |
23 bool isPrimary, | 24 bool isPrimary, |
24 const String& deviceInstanceId, | 25 const String& deviceInstanceId, |
25 BluetoothDevice* device) | 26 BluetoothDevice* device) |
26 : m_service(std::move(service)), | 27 : m_service(std::move(service)), |
27 m_isPrimary(isPrimary), | 28 m_isPrimary(isPrimary), |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 } else { | 83 } else { |
83 resolver->reject(BluetoothError::CreateDOMException(result)); | 84 resolver->reject(BluetoothError::CreateDOMException(result)); |
84 } | 85 } |
85 } | 86 } |
86 } | 87 } |
87 | 88 |
88 ScriptPromise BluetoothRemoteGATTService::getCharacteristic( | 89 ScriptPromise BluetoothRemoteGATTService::getCharacteristic( |
89 ScriptState* scriptState, | 90 ScriptState* scriptState, |
90 const StringOrUnsignedLong& characteristic, | 91 const StringOrUnsignedLong& characteristic, |
91 ExceptionState& exceptionState) { | 92 ExceptionState& exceptionState) { |
| 93 RecordWebBluetoothFunctionCall( |
| 94 UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTIC); |
| 95 |
92 String characteristicUUID = | 96 String characteristicUUID = |
93 BluetoothUUID::getCharacteristic(characteristic, exceptionState); | 97 BluetoothUUID::getCharacteristic(characteristic, exceptionState); |
94 if (exceptionState.hadException()) | 98 if (exceptionState.hadException()) |
95 return exceptionState.reject(scriptState); | 99 return exceptionState.reject(scriptState); |
96 | 100 |
97 return GetCharacteristicsImpl( | 101 return GetCharacteristicsImpl( |
98 scriptState, mojom::blink::WebBluetoothGATTQueryQuantity::SINGLE, | 102 scriptState, mojom::blink::WebBluetoothGATTQueryQuantity::SINGLE, |
99 characteristicUUID); | 103 characteristicUUID); |
100 } | 104 } |
101 | 105 |
102 ScriptPromise BluetoothRemoteGATTService::getCharacteristics( | 106 ScriptPromise BluetoothRemoteGATTService::getCharacteristics( |
103 ScriptState* scriptState, | 107 ScriptState* scriptState, |
104 const StringOrUnsignedLong& characteristic, | 108 const StringOrUnsignedLong& characteristic, |
105 ExceptionState& exceptionState) { | 109 ExceptionState& exceptionState) { |
| 110 RecordWebBluetoothFunctionCall( |
| 111 UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTICS); |
| 112 |
106 String characteristicUUID = | 113 String characteristicUUID = |
107 BluetoothUUID::getCharacteristic(characteristic, exceptionState); | 114 BluetoothUUID::getCharacteristic(characteristic, exceptionState); |
108 if (exceptionState.hadException()) | 115 if (exceptionState.hadException()) |
109 return exceptionState.reject(scriptState); | 116 return exceptionState.reject(scriptState); |
110 | 117 |
111 return GetCharacteristicsImpl( | 118 return GetCharacteristicsImpl( |
112 scriptState, mojom::blink::WebBluetoothGATTQueryQuantity::MULTIPLE, | 119 scriptState, mojom::blink::WebBluetoothGATTQueryQuantity::MULTIPLE, |
113 characteristicUUID); | 120 characteristicUUID); |
114 } | 121 } |
115 | 122 |
116 ScriptPromise BluetoothRemoteGATTService::getCharacteristics( | 123 ScriptPromise BluetoothRemoteGATTService::getCharacteristics( |
117 ScriptState* scriptState, | 124 ScriptState* scriptState, |
118 ExceptionState&) { | 125 ExceptionState&) { |
| 126 RecordWebBluetoothFunctionCall( |
| 127 UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTICS); |
| 128 |
119 return GetCharacteristicsImpl( | 129 return GetCharacteristicsImpl( |
120 scriptState, mojom::blink::WebBluetoothGATTQueryQuantity::MULTIPLE); | 130 scriptState, mojom::blink::WebBluetoothGATTQueryQuantity::MULTIPLE); |
121 } | 131 } |
122 | 132 |
123 ScriptPromise BluetoothRemoteGATTService::GetCharacteristicsImpl( | 133 ScriptPromise BluetoothRemoteGATTService::GetCharacteristicsImpl( |
124 ScriptState* scriptState, | 134 ScriptState* scriptState, |
125 mojom::blink::WebBluetoothGATTQueryQuantity quantity, | 135 mojom::blink::WebBluetoothGATTQueryQuantity quantity, |
126 const String& characteristicsUUID) { | 136 const String& characteristicsUUID) { |
127 if (!m_device->gatt()->connected()) { | 137 if (!m_device->gatt()->connected()) { |
128 return ScriptPromise::rejectWithDOMException( | 138 return ScriptPromise::rejectWithDOMException( |
(...skipping 19 matching lines...) Expand all Loading... |
148 m_service->instance_id, quantity, characteristicsUUID, | 158 m_service->instance_id, quantity, characteristicsUUID, |
149 convertToBaseCallback( | 159 convertToBaseCallback( |
150 WTF::bind(&BluetoothRemoteGATTService::GetCharacteristicsCallback, | 160 WTF::bind(&BluetoothRemoteGATTService::GetCharacteristicsCallback, |
151 wrapPersistent(this), m_service->instance_id, | 161 wrapPersistent(this), m_service->instance_id, |
152 characteristicsUUID, quantity, wrapPersistent(resolver)))); | 162 characteristicsUUID, quantity, wrapPersistent(resolver)))); |
153 | 163 |
154 return promise; | 164 return promise; |
155 } | 165 } |
156 | 166 |
157 } // namespace blink | 167 } // namespace blink |
OLD | NEW |