OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/renderer/bluetooth/web_bluetooth_impl.h" | 5 #include "content/renderer/bluetooth/web_bluetooth_impl.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 } | 94 } |
95 | 95 |
96 void WebBluetoothImpl::getCharacteristics( | 96 void WebBluetoothImpl::getCharacteristics( |
97 const blink::WebString& service_instance_id, | 97 const blink::WebString& service_instance_id, |
98 int32_t quantity, | 98 int32_t quantity, |
99 const blink::WebString& characteristics_uuid, | 99 const blink::WebString& characteristics_uuid, |
100 blink::WebBluetoothGetCharacteristicsCallbacks* callbacks) { | 100 blink::WebBluetoothGetCharacteristicsCallbacks* callbacks) { |
101 DCHECK(blink::mojom::IsKnownEnumValue( | 101 DCHECK(blink::mojom::IsKnownEnumValue( |
102 static_cast<blink::mojom::WebBluetoothGATTQueryQuantity>(quantity))); | 102 static_cast<blink::mojom::WebBluetoothGATTQueryQuantity>(quantity))); |
103 GetWebBluetoothService().RemoteServiceGetCharacteristics( | 103 GetWebBluetoothService().RemoteServiceGetCharacteristics( |
104 mojo::String::From(service_instance_id), | 104 service_instance_id.utf8(), |
105 static_cast<blink::mojom::WebBluetoothGATTQueryQuantity>(quantity), | 105 static_cast<blink::mojom::WebBluetoothGATTQueryQuantity>(quantity), |
106 characteristics_uuid.isEmpty() | 106 characteristics_uuid.isEmpty() |
107 ? base::nullopt | 107 ? base::nullopt |
108 : base::make_optional( | 108 : base::make_optional( |
109 device::BluetoothUUID(characteristics_uuid.utf8())), | 109 device::BluetoothUUID(characteristics_uuid.utf8())), |
110 base::Bind(&WebBluetoothImpl::OnGetCharacteristicsComplete, | 110 base::Bind(&WebBluetoothImpl::OnGetCharacteristicsComplete, |
111 base::Unretained(this), service_instance_id, | 111 base::Unretained(this), service_instance_id, |
112 base::Passed(base::WrapUnique(callbacks)))); | 112 base::Passed(base::WrapUnique(callbacks)))); |
113 } | 113 } |
114 | 114 |
115 void WebBluetoothImpl::readValue( | 115 void WebBluetoothImpl::readValue( |
116 const blink::WebString& characteristic_instance_id, | 116 const blink::WebString& characteristic_instance_id, |
117 blink::WebBluetoothReadValueCallbacks* callbacks) { | 117 blink::WebBluetoothReadValueCallbacks* callbacks) { |
118 GetWebBluetoothService().RemoteCharacteristicReadValue( | 118 GetWebBluetoothService().RemoteCharacteristicReadValue( |
119 mojo::String::From(characteristic_instance_id), | 119 characteristic_instance_id.utf8(), |
120 base::Bind(&WebBluetoothImpl::OnReadValueComplete, base::Unretained(this), | 120 base::Bind(&WebBluetoothImpl::OnReadValueComplete, base::Unretained(this), |
121 base::Passed(base::WrapUnique(callbacks)))); | 121 base::Passed(base::WrapUnique(callbacks)))); |
122 } | 122 } |
123 | 123 |
124 void WebBluetoothImpl::writeValue( | 124 void WebBluetoothImpl::writeValue( |
125 const blink::WebString& characteristic_instance_id, | 125 const blink::WebString& characteristic_instance_id, |
126 const blink::WebVector<uint8_t>& value, | 126 const blink::WebVector<uint8_t>& value, |
127 blink::WebBluetoothWriteValueCallbacks* callbacks) { | 127 blink::WebBluetoothWriteValueCallbacks* callbacks) { |
128 GetWebBluetoothService().RemoteCharacteristicWriteValue( | 128 GetWebBluetoothService().RemoteCharacteristicWriteValue( |
129 mojo::String::From(characteristic_instance_id), | 129 characteristic_instance_id.utf8(), mojo::Array<uint8_t>::From(value), |
130 mojo::Array<uint8_t>::From(value), | |
131 base::Bind(&WebBluetoothImpl::OnWriteValueComplete, | 130 base::Bind(&WebBluetoothImpl::OnWriteValueComplete, |
132 base::Unretained(this), value, | 131 base::Unretained(this), value, |
133 base::Passed(base::WrapUnique(callbacks)))); | 132 base::Passed(base::WrapUnique(callbacks)))); |
134 } | 133 } |
135 | 134 |
136 void WebBluetoothImpl::startNotifications( | 135 void WebBluetoothImpl::startNotifications( |
137 const blink::WebString& characteristic_instance_id, | 136 const blink::WebString& characteristic_instance_id, |
138 blink::WebBluetoothNotificationsCallbacks* callbacks) { | 137 blink::WebBluetoothNotificationsCallbacks* callbacks) { |
139 GetWebBluetoothService().RemoteCharacteristicStartNotifications( | 138 GetWebBluetoothService().RemoteCharacteristicStartNotifications( |
140 mojo::String::From(characteristic_instance_id), | 139 characteristic_instance_id.utf8(), |
141 base::Bind(&WebBluetoothImpl::OnStartNotificationsComplete, | 140 base::Bind(&WebBluetoothImpl::OnStartNotificationsComplete, |
142 base::Unretained(this), | 141 base::Unretained(this), |
143 base::Passed(base::WrapUnique(callbacks)))); | 142 base::Passed(base::WrapUnique(callbacks)))); |
144 } | 143 } |
145 | 144 |
146 void WebBluetoothImpl::stopNotifications( | 145 void WebBluetoothImpl::stopNotifications( |
147 const blink::WebString& characteristic_instance_id, | 146 const blink::WebString& characteristic_instance_id, |
148 blink::WebBluetoothNotificationsCallbacks* callbacks) { | 147 blink::WebBluetoothNotificationsCallbacks* callbacks) { |
149 GetWebBluetoothService().RemoteCharacteristicStopNotifications( | 148 GetWebBluetoothService().RemoteCharacteristicStopNotifications( |
150 mojo::String::From(characteristic_instance_id), | 149 characteristic_instance_id.utf8(), |
151 base::Bind(&WebBluetoothImpl::OnStopNotificationsComplete, | 150 base::Bind(&WebBluetoothImpl::OnStopNotificationsComplete, |
152 base::Unretained(this), | 151 base::Unretained(this), |
153 base::Passed(base::WrapUnique(callbacks)))); | 152 base::Passed(base::WrapUnique(callbacks)))); |
154 } | 153 } |
155 | 154 |
156 void WebBluetoothImpl::characteristicObjectRemoved( | 155 void WebBluetoothImpl::characteristicObjectRemoved( |
157 const blink::WebString& characteristic_instance_id, | 156 const blink::WebString& characteristic_instance_id, |
158 blink::WebBluetoothRemoteGATTCharacteristic* characteristic) { | 157 blink::WebBluetoothRemoteGATTCharacteristic* characteristic) { |
159 active_characteristics_.erase(characteristic_instance_id.utf8()); | 158 active_characteristics_.erase(characteristic_instance_id.utf8()); |
160 } | 159 } |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 // Create an associated interface ptr and pass it to the WebBluetoothService | 320 // Create an associated interface ptr and pass it to the WebBluetoothService |
322 // so that it can send us events without us prompting. | 321 // so that it can send us events without us prompting. |
323 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info; | 322 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info; |
324 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group()); | 323 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group()); |
325 web_bluetooth_service_->SetClient(std::move(ptr_info)); | 324 web_bluetooth_service_->SetClient(std::move(ptr_info)); |
326 } | 325 } |
327 return *web_bluetooth_service_; | 326 return *web_bluetooth_service_; |
328 } | 327 } |
329 | 328 |
330 } // namespace content | 329 } // namespace content |
OLD | NEW |