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

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

Issue 2019853002: bluetooth: Use WebBluetoothDeviceId instead of string (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-uuid-typemap
Patch Set: Rebase on top of another patch Created 4 years, 5 months 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 base::Unretained(this), 50 base::Unretained(this),
51 base::Passed(base::WrapUnique(callbacks)))); 51 base::Passed(base::WrapUnique(callbacks))));
52 } 52 }
53 53
54 void WebBluetoothImpl::connect( 54 void WebBluetoothImpl::connect(
55 const blink::WebString& device_id, 55 const blink::WebString& device_id,
56 blink::WebBluetoothDevice* device, 56 blink::WebBluetoothDevice* device,
57 blink::WebBluetoothRemoteGATTServerConnectCallbacks* callbacks) { 57 blink::WebBluetoothRemoteGATTServerConnectCallbacks* callbacks) {
58 // TODO(crbug.com/495270): After the Bluetooth Tree is implemented, there will 58 // TODO(crbug.com/495270): After the Bluetooth Tree is implemented, there will
59 // only be one object per device. But for now we replace the previous object. 59 // only be one object per device. But for now we replace the previous object.
60 connected_devices_[device_id.utf8()] = device; 60 WebBluetoothDeviceId device_id_obj = WebBluetoothDeviceId(device_id.utf8());
61 connected_devices_[device_id_obj] = device;
61 62
62 GetWebBluetoothService().RemoteServerConnect( 63 GetWebBluetoothService().RemoteServerConnect(
63 mojo::String::From(device_id), 64 std::move(device_id_obj),
64 base::Bind(&WebBluetoothImpl::OnConnectComplete, base::Unretained(this), 65 base::Bind(&WebBluetoothImpl::OnConnectComplete, base::Unretained(this),
65 base::Passed(base::WrapUnique(callbacks)))); 66 base::Passed(base::WrapUnique(callbacks))));
66 } 67 }
67 68
68 void WebBluetoothImpl::disconnect(const blink::WebString& device_id) { 69 void WebBluetoothImpl::disconnect(const blink::WebString& device_id) {
69 connected_devices_.erase(device_id.utf8()); 70 WebBluetoothDeviceId device_id_obj = WebBluetoothDeviceId(device_id.utf8());
71 connected_devices_.erase(device_id_obj);
70 72
71 GetWebBluetoothService().RemoteServerDisconnect( 73 GetWebBluetoothService().RemoteServerDisconnect(std::move(device_id_obj));
72 mojo::String::From(device_id));
73 } 74 }
74 75
75 void WebBluetoothImpl::getPrimaryServices( 76 void WebBluetoothImpl::getPrimaryServices(
76 const blink::WebString& device_id, 77 const blink::WebString& device_id,
77 int32_t quantity, 78 int32_t quantity,
78 const blink::WebString& services_uuid, 79 const blink::WebString& services_uuid,
79 blink::WebBluetoothGetPrimaryServicesCallbacks* callbacks) { 80 blink::WebBluetoothGetPrimaryServicesCallbacks* callbacks) {
80 GetWebBluetoothService().RemoteServerGetPrimaryServices( 81 GetWebBluetoothService().RemoteServerGetPrimaryServices(
81 mojo::String::From(device_id), 82 WebBluetoothDeviceId(device_id.utf8()),
82 static_cast<blink::mojom::WebBluetoothGATTQueryQuantity>(quantity), 83 static_cast<blink::mojom::WebBluetoothGATTQueryQuantity>(quantity),
83 services_uuid.isEmpty() 84 services_uuid.isEmpty()
84 ? base::nullopt 85 ? base::nullopt
85 : base::make_optional(device::BluetoothUUID(services_uuid.utf8())), 86 : base::make_optional(device::BluetoothUUID(services_uuid.utf8())),
86 base::Bind(&WebBluetoothImpl::OnGetPrimaryServicesComplete, 87 base::Bind(&WebBluetoothImpl::OnGetPrimaryServicesComplete,
87 base::Unretained(this), device_id, 88 base::Unretained(this), device_id,
88 base::Passed(base::WrapUnique(callbacks)))); 89 base::Passed(base::WrapUnique(callbacks))));
89 } 90 }
90 91
91 void WebBluetoothImpl::getCharacteristics( 92 void WebBluetoothImpl::getCharacteristics(
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 void WebBluetoothImpl::OnRequestDeviceComplete( 178 void WebBluetoothImpl::OnRequestDeviceComplete(
178 std::unique_ptr<blink::WebBluetoothRequestDeviceCallbacks> callbacks, 179 std::unique_ptr<blink::WebBluetoothRequestDeviceCallbacks> callbacks,
179 const blink::mojom::WebBluetoothError error, 180 const blink::mojom::WebBluetoothError error,
180 blink::mojom::WebBluetoothDevicePtr device) { 181 blink::mojom::WebBluetoothDevicePtr device) {
181 if (error == blink::mojom::WebBluetoothError::SUCCESS) { 182 if (error == blink::mojom::WebBluetoothError::SUCCESS) {
182 blink::WebVector<blink::WebString> uuids(device->uuids.size()); 183 blink::WebVector<blink::WebString> uuids(device->uuids.size());
183 for (size_t i = 0; i < device->uuids.size(); ++i) 184 for (size_t i = 0; i < device->uuids.size(); ++i)
184 uuids[i] = blink::WebString::fromUTF8(device->uuids[i]); 185 uuids[i] = blink::WebString::fromUTF8(device->uuids[i]);
185 186
186 callbacks->onSuccess(base::WrapUnique(new blink::WebBluetoothDeviceInit( 187 callbacks->onSuccess(base::WrapUnique(new blink::WebBluetoothDeviceInit(
187 blink::WebString::fromUTF8(device->id), 188 blink::WebString::fromUTF8(device->id.str()),
188 blink::WebString::fromUTF8(device->name), uuids))); 189 blink::WebString::fromUTF8(device->name), uuids)));
189 } else { 190 } else {
190 callbacks->onError(ToInt32(error)); 191 callbacks->onError(ToInt32(error));
191 } 192 }
192 } 193 }
193 194
194 void WebBluetoothImpl::GattServerDisconnected(const mojo::String& device_id) { 195 void WebBluetoothImpl::GattServerDisconnected(
196 const WebBluetoothDeviceId& device_id) {
195 auto device_iter = connected_devices_.find(device_id); 197 auto device_iter = connected_devices_.find(device_id);
196 if (device_iter != connected_devices_.end()) { 198 if (device_iter != connected_devices_.end()) {
197 // Remove device from the map before calling dispatchGattServerDisconnected 199 // Remove device from the map before calling dispatchGattServerDisconnected
198 // to avoid removing a device the gattserverdisconnected event handler might 200 // to avoid removing a device the gattserverdisconnected event handler might
199 // have re-connected. 201 // have re-connected.
200 blink::WebBluetoothDevice* device = device_iter->second; 202 blink::WebBluetoothDevice* device = device_iter->second;
201 connected_devices_.erase(device_iter); 203 connected_devices_.erase(device_iter);
202 device->dispatchGattServerDisconnected(); 204 device->dispatchGattServerDisconnected();
203 } 205 }
204 } 206 }
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 // Create an associated interface ptr and pass it to the WebBluetoothService 315 // Create an associated interface ptr and pass it to the WebBluetoothService
314 // so that it can send us events without us prompting. 316 // so that it can send us events without us prompting.
315 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info; 317 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info;
316 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group()); 318 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group());
317 web_bluetooth_service_->SetClient(std::move(ptr_info)); 319 web_bluetooth_service_->SetClient(std::move(ptr_info));
318 } 320 }
319 return *web_bluetooth_service_; 321 return *web_bluetooth_service_;
320 } 322 }
321 323
322 } // namespace content 324 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698