Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: content/renderer/bluetooth/web_bluetooth_impl.cc

Issue 2506813003: Use new wrapper types for web_bluetooth.mojom (Closed)
Patch Set: merge master and resolve conflicts Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 const blink::WebString& characteristic_instance_id, 163 const blink::WebString& characteristic_instance_id,
164 blink::WebBluetoothRemoteGATTCharacteristic* characteristic) { 164 blink::WebBluetoothRemoteGATTCharacteristic* characteristic) {
165 // TODO(ortuno): After the Bluetooth Tree is implemented, there will 165 // TODO(ortuno): After the Bluetooth Tree is implemented, there will
166 // only be one object per characteristic. But for now we replace 166 // only be one object per characteristic. But for now we replace
167 // the previous object. 167 // the previous object.
168 // https://crbug.com/495270 168 // https://crbug.com/495270
169 active_characteristics_[characteristic_instance_id.utf8()] = characteristic; 169 active_characteristics_[characteristic_instance_id.utf8()] = characteristic;
170 } 170 }
171 171
172 void WebBluetoothImpl::RemoteCharacteristicValueChanged( 172 void WebBluetoothImpl::RemoteCharacteristicValueChanged(
173 const mojo::String& characteristic_instance_id, 173 const std::string& characteristic_instance_id,
174 mojo::Array<uint8_t> value) { 174 const std::vector<uint8_t>& value) {
175 // We post a task so that the event is fired after any pending promises have 175 // We post a task so that the event is fired after any pending promises have
176 // resolved. 176 // resolved.
177 base::ThreadTaskRunnerHandle::Get()->PostTask( 177 base::ThreadTaskRunnerHandle::Get()->PostTask(
178 FROM_HERE, 178 FROM_HERE,
179 base::Bind(&WebBluetoothImpl::DispatchCharacteristicValueChanged, 179 base::Bind(&WebBluetoothImpl::DispatchCharacteristicValueChanged,
180 base::Unretained(this), characteristic_instance_id, 180 base::Unretained(this), characteristic_instance_id, value));
181 value.PassStorage()));
182 } 181 }
183 182
184 void WebBluetoothImpl::OnRequestDeviceComplete( 183 void WebBluetoothImpl::OnRequestDeviceComplete(
185 std::unique_ptr<blink::WebBluetoothRequestDeviceCallbacks> callbacks, 184 std::unique_ptr<blink::WebBluetoothRequestDeviceCallbacks> callbacks,
186 const blink::mojom::WebBluetoothResult result, 185 const blink::mojom::WebBluetoothResult result,
187 blink::mojom::WebBluetoothDevicePtr device) { 186 blink::mojom::WebBluetoothDevicePtr device) {
188 if (result == blink::mojom::WebBluetoothResult::SUCCESS) { 187 if (result == blink::mojom::WebBluetoothResult::SUCCESS) {
189 callbacks->onSuccess(base::MakeUnique<blink::WebBluetoothDeviceInit>( 188 callbacks->onSuccess(base::MakeUnique<blink::WebBluetoothDeviceInit>(
190 blink::WebString::fromUTF8(device->id.str()), 189 blink::WebString::fromUTF8(device->id.str()),
191 device->name.is_null() ? blink::WebString() 190 device->name ? blink::WebString::fromUTF8(device->name.value().c_str())
dcheng 2016/11/24 04:56:49 Nit: no c_str() here
juncai 2016/11/28 22:25:21 Done.
192 : blink::WebString::fromUTF8(device->name))); 191 : blink::WebString()));
193 } else { 192 } else {
194 callbacks->onError(ToInt32(result)); 193 callbacks->onError(ToInt32(result));
195 } 194 }
196 } 195 }
197 196
198 void WebBluetoothImpl::GattServerDisconnected( 197 void WebBluetoothImpl::GattServerDisconnected(
199 const WebBluetoothDeviceId& device_id) { 198 const WebBluetoothDeviceId& device_id) {
200 auto device_iter = connected_devices_.find(device_id); 199 auto device_iter = connected_devices_.find(device_id);
201 if (device_iter != connected_devices_.end()) { 200 if (device_iter != connected_devices_.end()) {
202 // Remove device from the map before calling dispatchGattServerDisconnected 201 // Remove device from the map before calling dispatchGattServerDisconnected
(...skipping 13 matching lines...) Expand all
216 callbacks->onSuccess(); 215 callbacks->onSuccess();
217 } else { 216 } else {
218 callbacks->onError(ToInt32(result)); 217 callbacks->onError(ToInt32(result));
219 } 218 }
220 } 219 }
221 220
222 void WebBluetoothImpl::OnGetPrimaryServicesComplete( 221 void WebBluetoothImpl::OnGetPrimaryServicesComplete(
223 const blink::WebString& device_id, 222 const blink::WebString& device_id,
224 std::unique_ptr<blink::WebBluetoothGetPrimaryServicesCallbacks> callbacks, 223 std::unique_ptr<blink::WebBluetoothGetPrimaryServicesCallbacks> callbacks,
225 blink::mojom::WebBluetoothResult result, 224 blink::mojom::WebBluetoothResult result,
226 mojo::Array<blink::mojom::WebBluetoothRemoteGATTServicePtr> services) { 225 base::Optional<std::vector<blink::mojom::WebBluetoothRemoteGATTServicePtr>>
226 services) {
227 if (result == blink::mojom::WebBluetoothResult::SUCCESS) { 227 if (result == blink::mojom::WebBluetoothResult::SUCCESS) {
228 DCHECK(services);
228 // TODO(dcheng): This WebVector should use smart pointers. 229 // TODO(dcheng): This WebVector should use smart pointers.
229 blink::WebVector<blink::WebBluetoothRemoteGATTService*> promise_services( 230 blink::WebVector<blink::WebBluetoothRemoteGATTService*> promise_services(
230 services.size()); 231 services->size());
231 232 for (size_t i = 0; i < services->size(); i++) {
232 for (size_t i = 0; i < services.size(); i++) {
233 promise_services[i] = new blink::WebBluetoothRemoteGATTService( 233 promise_services[i] = new blink::WebBluetoothRemoteGATTService(
234 blink::WebString::fromUTF8(services[i]->instance_id), 234 blink::WebString::fromUTF8(services.value()[i]->instance_id),
235 blink::WebString::fromUTF8(services[i]->uuid), true /* isPrimary */, 235 blink::WebString::fromUTF8(services.value()[i]->uuid),
236 device_id); 236 true /* isPrimary */, device_id);
237 } 237 }
238 callbacks->onSuccess(promise_services); 238 callbacks->onSuccess(promise_services);
239 } else { 239 } else {
240 callbacks->onError(ToInt32(result)); 240 callbacks->onError(ToInt32(result));
241 } 241 }
242 } 242 }
243 243
244 void WebBluetoothImpl::OnGetCharacteristicsComplete( 244 void WebBluetoothImpl::OnGetCharacteristicsComplete(
245 const blink::WebString& service_instance_id, 245 const blink::WebString& service_instance_id,
246 std::unique_ptr<blink::WebBluetoothGetCharacteristicsCallbacks> callbacks, 246 std::unique_ptr<blink::WebBluetoothGetCharacteristicsCallbacks> callbacks,
247 blink::mojom::WebBluetoothResult result, 247 blink::mojom::WebBluetoothResult result,
248 mojo::Array<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr> 248 base::Optional<
249 std::vector<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr>>
249 characteristics) { 250 characteristics) {
250 if (result == blink::mojom::WebBluetoothResult::SUCCESS) { 251 if (result == blink::mojom::WebBluetoothResult::SUCCESS) {
252 DCHECK(characteristics);
251 // TODO(dcheng): This WebVector should use smart pointers. 253 // TODO(dcheng): This WebVector should use smart pointers.
252 blink::WebVector<blink::WebBluetoothRemoteGATTCharacteristicInit*> 254 blink::WebVector<blink::WebBluetoothRemoteGATTCharacteristicInit*>
253 promise_characteristics(characteristics.size()); 255 promise_characteristics(characteristics->size());
254 256 for (size_t i = 0; i < characteristics->size(); i++) {
255 for (size_t i = 0; i < characteristics.size(); i++) {
256 promise_characteristics[i] = 257 promise_characteristics[i] =
257 new blink::WebBluetoothRemoteGATTCharacteristicInit( 258 new blink::WebBluetoothRemoteGATTCharacteristicInit(
258 service_instance_id, 259 service_instance_id, blink::WebString::fromUTF8(
259 blink::WebString::fromUTF8(characteristics[i]->instance_id), 260 characteristics.value()[i]->instance_id),
260 blink::WebString::fromUTF8(characteristics[i]->uuid), 261 blink::WebString::fromUTF8(characteristics.value()[i]->uuid),
261 characteristics[i]->properties); 262 characteristics.value()[i]->properties);
262 } 263 }
263 callbacks->onSuccess(promise_characteristics); 264 callbacks->onSuccess(promise_characteristics);
264 } else { 265 } else {
265 callbacks->onError(ToInt32(result)); 266 callbacks->onError(ToInt32(result));
266 } 267 }
267 } 268 }
268 269
269 void WebBluetoothImpl::OnReadValueComplete( 270 void WebBluetoothImpl::OnReadValueComplete(
270 std::unique_ptr<blink::WebBluetoothReadValueCallbacks> callbacks, 271 std::unique_ptr<blink::WebBluetoothReadValueCallbacks> callbacks,
271 blink::mojom::WebBluetoothResult result, 272 blink::mojom::WebBluetoothResult result,
272 mojo::Array<uint8_t> value) { 273 const base::Optional<std::vector<uint8_t>>& value) {
273 if (result == blink::mojom::WebBluetoothResult::SUCCESS) { 274 if (result == blink::mojom::WebBluetoothResult::SUCCESS) {
274 callbacks->onSuccess(value.PassStorage()); 275 DCHECK(value);
276 callbacks->onSuccess(std::move(value.value()));
dcheng 2016/11/24 04:56:49 Nit: this std::move() has no effect, as |value| is
juncai 2016/11/28 22:25:21 Done.
275 } else { 277 } else {
276 callbacks->onError(ToInt32(result)); 278 callbacks->onError(ToInt32(result));
277 } 279 }
278 } 280 }
279 281
280 void WebBluetoothImpl::OnWriteValueComplete( 282 void WebBluetoothImpl::OnWriteValueComplete(
281 const blink::WebVector<uint8_t>& value, 283 const blink::WebVector<uint8_t>& value,
282 std::unique_ptr<blink::WebBluetoothWriteValueCallbacks> callbacks, 284 std::unique_ptr<blink::WebBluetoothWriteValueCallbacks> callbacks,
283 blink::mojom::WebBluetoothResult result) { 285 blink::mojom::WebBluetoothResult result) {
284 if (result == blink::mojom::WebBluetoothResult::SUCCESS) { 286 if (result == blink::mojom::WebBluetoothResult::SUCCESS) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 // Create an associated interface ptr and pass it to the WebBluetoothService 320 // Create an associated interface ptr and pass it to the WebBluetoothService
319 // so that it can send us events without us prompting. 321 // so that it can send us events without us prompting.
320 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info; 322 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info;
321 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group()); 323 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group());
322 web_bluetooth_service_->SetClient(std::move(ptr_info)); 324 web_bluetooth_service_->SetClient(std::move(ptr_info));
323 } 325 }
324 return *web_bluetooth_service_; 326 return *web_bluetooth_service_;
325 } 327 }
326 328
327 } // namespace content 329 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698