OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/BluetoothRemoteGATTDescriptor.h" | 5 #include "modules/bluetooth/BluetoothRemoteGATTDescriptor.h" |
6 | 6 |
| 7 #include <memory> |
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 "modules/bluetooth/BluetoothError.h" | 11 #include "modules/bluetooth/BluetoothError.h" |
| 12 #include "modules/bluetooth/BluetoothMetrics.h" |
11 #include "modules/bluetooth/BluetoothRemoteGATTService.h" | 13 #include "modules/bluetooth/BluetoothRemoteGATTService.h" |
12 #include "modules/bluetooth/BluetoothRemoteGATTUtils.h" | 14 #include "modules/bluetooth/BluetoothRemoteGATTUtils.h" |
13 #include <memory> | |
14 | 15 |
15 namespace blink { | 16 namespace blink { |
16 | 17 |
17 BluetoothRemoteGATTDescriptor::BluetoothRemoteGATTDescriptor( | 18 BluetoothRemoteGATTDescriptor::BluetoothRemoteGATTDescriptor( |
18 mojom::blink::WebBluetoothRemoteGATTDescriptorPtr descriptor, | 19 mojom::blink::WebBluetoothRemoteGATTDescriptorPtr descriptor, |
19 BluetoothRemoteGATTCharacteristic* characteristic) | 20 BluetoothRemoteGATTCharacteristic* characteristic) |
20 : m_descriptor(std::move(descriptor)), m_characteristic(characteristic) {} | 21 : m_descriptor(std::move(descriptor)), m_characteristic(characteristic) {} |
21 | 22 |
22 BluetoothRemoteGATTDescriptor* BluetoothRemoteGATTDescriptor::Create( | 23 BluetoothRemoteGATTDescriptor* BluetoothRemoteGATTDescriptor::Create( |
23 mojom::blink::WebBluetoothRemoteGATTDescriptorPtr descriptor, | 24 mojom::blink::WebBluetoothRemoteGATTDescriptorPtr descriptor, |
(...skipping 25 matching lines...) Expand all Loading... |
49 BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value.value()); | 50 BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value.value()); |
50 m_value = domDataView; | 51 m_value = domDataView; |
51 resolver->resolve(domDataView); | 52 resolver->resolve(domDataView); |
52 } else { | 53 } else { |
53 resolver->reject(BluetoothError::CreateDOMException(result)); | 54 resolver->reject(BluetoothError::CreateDOMException(result)); |
54 } | 55 } |
55 } | 56 } |
56 | 57 |
57 ScriptPromise BluetoothRemoteGATTDescriptor::readValue( | 58 ScriptPromise BluetoothRemoteGATTDescriptor::readValue( |
58 ScriptState* scriptState) { | 59 ScriptState* scriptState) { |
| 60 RecordWebBluetoothFunctionCall( |
| 61 UMAWebBluetoothFunction::DESCRIPTOR_READ_VALUE); |
| 62 |
59 if (!GetGatt()->connected()) { | 63 if (!GetGatt()->connected()) { |
60 return ScriptPromise::rejectWithDOMException( | 64 return ScriptPromise::rejectWithDOMException( |
61 scriptState, | 65 scriptState, |
62 BluetoothError::CreateNotConnectedException(BluetoothOperation::GATT)); | 66 BluetoothError::CreateNotConnectedException(BluetoothOperation::GATT)); |
63 } | 67 } |
64 | 68 |
65 if (!GetGatt()->device()->IsValidDescriptor(m_descriptor->instance_id)) { | 69 if (!GetGatt()->device()->IsValidDescriptor(m_descriptor->instance_id)) { |
66 return ScriptPromise::rejectWithDOMException( | 70 return ScriptPromise::rejectWithDOMException( |
67 scriptState, CreateInvalidDescriptorError()); | 71 scriptState, CreateInvalidDescriptorError()); |
68 } | 72 } |
(...skipping 30 matching lines...) Expand all Loading... |
99 m_value = BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value); | 103 m_value = BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value); |
100 resolver->resolve(); | 104 resolver->resolve(); |
101 } else { | 105 } else { |
102 resolver->reject(BluetoothError::CreateDOMException(result)); | 106 resolver->reject(BluetoothError::CreateDOMException(result)); |
103 } | 107 } |
104 } | 108 } |
105 | 109 |
106 ScriptPromise BluetoothRemoteGATTDescriptor::writeValue( | 110 ScriptPromise BluetoothRemoteGATTDescriptor::writeValue( |
107 ScriptState* scriptState, | 111 ScriptState* scriptState, |
108 const DOMArrayPiece& value) { | 112 const DOMArrayPiece& value) { |
| 113 RecordWebBluetoothFunctionCall( |
| 114 UMAWebBluetoothFunction::DESCRIPTOR_WRITE_VALUE); |
| 115 |
109 if (!GetGatt()->connected()) { | 116 if (!GetGatt()->connected()) { |
110 return ScriptPromise::rejectWithDOMException( | 117 return ScriptPromise::rejectWithDOMException( |
111 scriptState, | 118 scriptState, |
112 BluetoothError::CreateNotConnectedException(BluetoothOperation::GATT)); | 119 BluetoothError::CreateNotConnectedException(BluetoothOperation::GATT)); |
113 } | 120 } |
114 | 121 |
115 if (!GetGatt()->device()->IsValidDescriptor(m_descriptor->instance_id)) { | 122 if (!GetGatt()->device()->IsValidDescriptor(m_descriptor->instance_id)) { |
116 return ScriptPromise::rejectWithDOMException( | 123 return ScriptPromise::rejectWithDOMException( |
117 scriptState, CreateInvalidDescriptorError()); | 124 scriptState, CreateInvalidDescriptorError()); |
118 } | 125 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 " is no longer valid. Remember to retrieve the Descriptor again " | 159 " is no longer valid. Remember to retrieve the Descriptor again " |
153 "after reconnecting."); | 160 "after reconnecting."); |
154 } | 161 } |
155 | 162 |
156 DEFINE_TRACE(BluetoothRemoteGATTDescriptor) { | 163 DEFINE_TRACE(BluetoothRemoteGATTDescriptor) { |
157 visitor->trace(m_characteristic); | 164 visitor->trace(m_characteristic); |
158 visitor->trace(m_value); | 165 visitor->trace(m_value); |
159 } | 166 } |
160 | 167 |
161 } // namespace blink | 168 } // namespace blink |
OLD | NEW |