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

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: Address jyasskin's comments Created 4 years, 6 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 29 matching lines...) Expand all
40 base::Unretained(this), 40 base::Unretained(this),
41 base::Passed(base::WrapUnique(callbacks)))); 41 base::Passed(base::WrapUnique(callbacks))));
42 } 42 }
43 43
44 void WebBluetoothImpl::connect( 44 void WebBluetoothImpl::connect(
45 const blink::WebString& device_id, 45 const blink::WebString& device_id,
46 blink::WebBluetoothDevice* device, 46 blink::WebBluetoothDevice* device,
47 blink::WebBluetoothRemoteGATTServerConnectCallbacks* callbacks) { 47 blink::WebBluetoothRemoteGATTServerConnectCallbacks* callbacks) {
48 // TODO(crbug.com/495270): After the Bluetooth Tree is implemented, there will 48 // TODO(crbug.com/495270): After the Bluetooth Tree is implemented, there will
49 // only be one object per device. But for now we replace the previous object. 49 // only be one object per device. But for now we replace the previous object.
50 connected_devices_[device_id.utf8()] = device; 50 BluetoothDeviceId device_id_obj = BluetoothDeviceId(device_id.utf8());
51 connected_devices_[device_id_obj] = device;
51 52
52 GetWebBluetoothService().RemoteServerConnect( 53 GetWebBluetoothService().RemoteServerConnect(
53 mojo::String::From(device_id), 54 BluetoothDeviceId(std::move(device_id_obj)),
54 base::Bind(&WebBluetoothImpl::OnConnectComplete, base::Unretained(this), 55 base::Bind(&WebBluetoothImpl::OnConnectComplete, base::Unretained(this),
55 base::Passed(base::WrapUnique(callbacks)))); 56 base::Passed(base::WrapUnique(callbacks))));
56 } 57 }
57 58
58 void WebBluetoothImpl::disconnect(const blink::WebString& device_id) { 59 void WebBluetoothImpl::disconnect(const blink::WebString& device_id) {
59 connected_devices_.erase(device_id.utf8()); 60 BluetoothDeviceId device_id_obj = BluetoothDeviceId(device_id.utf8());
61 connected_devices_.erase(device_id_obj);
60 62
61 GetWebBluetoothService().RemoteServerDisconnect( 63 GetWebBluetoothService().RemoteServerDisconnect(std::move(device_id_obj));
62 mojo::String::From(device_id));
63 } 64 }
64 65
65 void WebBluetoothImpl::getPrimaryService( 66 void WebBluetoothImpl::getPrimaryService(
66 const blink::WebString& device_id, 67 const blink::WebString& device_id,
67 const blink::WebString& service_uuid, 68 const blink::WebString& service_uuid,
68 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) { 69 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) {
69 GetWebBluetoothService().RemoteServerGetPrimaryService( 70 GetWebBluetoothService().RemoteServerGetPrimaryService(
70 mojo::String::From(device_id), 71 BluetoothDeviceId(device_id.utf8()),
71 base::make_optional(device::BluetoothUUID(service_uuid.utf8())), 72 base::make_optional(device::BluetoothUUID(service_uuid.utf8())),
72 base::Bind(&WebBluetoothImpl::OnGetPrimaryServiceComplete, 73 base::Bind(&WebBluetoothImpl::OnGetPrimaryServiceComplete,
73 base::Unretained(this), device_id, 74 base::Unretained(this), device_id,
74 base::Passed(base::WrapUnique(callbacks)))); 75 base::Passed(base::WrapUnique(callbacks))));
75 } 76 }
76 77
77 void WebBluetoothImpl::getCharacteristics( 78 void WebBluetoothImpl::getCharacteristics(
78 const blink::WebString& service_instance_id, 79 const blink::WebString& service_instance_id,
79 blink::mojom::WebBluetoothGATTQueryQuantity quantity, 80 blink::mojom::WebBluetoothGATTQueryQuantity quantity,
80 const blink::WebString& characteristics_uuid, 81 const blink::WebString& characteristics_uuid,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 void WebBluetoothImpl::OnRequestDeviceComplete( 163 void WebBluetoothImpl::OnRequestDeviceComplete(
163 std::unique_ptr<blink::WebBluetoothRequestDeviceCallbacks> callbacks, 164 std::unique_ptr<blink::WebBluetoothRequestDeviceCallbacks> callbacks,
164 const blink::mojom::WebBluetoothError error, 165 const blink::mojom::WebBluetoothError error,
165 blink::mojom::WebBluetoothDevicePtr device) { 166 blink::mojom::WebBluetoothDevicePtr device) {
166 if (error == blink::mojom::WebBluetoothError::SUCCESS) { 167 if (error == blink::mojom::WebBluetoothError::SUCCESS) {
167 blink::WebVector<blink::WebString> uuids(device->uuids.size()); 168 blink::WebVector<blink::WebString> uuids(device->uuids.size());
168 for (size_t i = 0; i < device->uuids.size(); ++i) 169 for (size_t i = 0; i < device->uuids.size(); ++i)
169 uuids[i] = blink::WebString::fromUTF8(device->uuids[i]); 170 uuids[i] = blink::WebString::fromUTF8(device->uuids[i]);
170 171
171 callbacks->onSuccess(base::WrapUnique(new blink::WebBluetoothDeviceInit( 172 callbacks->onSuccess(base::WrapUnique(new blink::WebBluetoothDeviceInit(
172 blink::WebString::fromUTF8(device->id), 173 blink::WebString::fromUTF8(device->id.str()),
173 blink::WebString::fromUTF8(device->name), uuids))); 174 blink::WebString::fromUTF8(device->name), uuids)));
174 } else { 175 } else {
175 callbacks->onError(error); 176 callbacks->onError(error);
176 } 177 }
177 } 178 }
178 179
179 void WebBluetoothImpl::GattServerDisconnected(const mojo::String& device_id) { 180 void WebBluetoothImpl::GattServerDisconnected(
181 const BluetoothDeviceId& device_id) {
180 auto device_iter = connected_devices_.find(device_id); 182 auto device_iter = connected_devices_.find(device_id);
181 if (device_iter != connected_devices_.end()) { 183 if (device_iter != connected_devices_.end()) {
182 device_iter->second->dispatchGattServerDisconnected(); 184 device_iter->second->dispatchGattServerDisconnected();
183 connected_devices_.erase(device_iter); 185 connected_devices_.erase(device_iter);
184 } 186 }
185 } 187 }
186 188
187 void WebBluetoothImpl::OnConnectComplete( 189 void WebBluetoothImpl::OnConnectComplete(
188 std::unique_ptr<blink::WebBluetoothRemoteGATTServerConnectCallbacks> 190 std::unique_ptr<blink::WebBluetoothRemoteGATTServerConnectCallbacks>
189 callbacks, 191 callbacks,
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 // Create an associated interface ptr and pass it to the WebBluetoothService 291 // Create an associated interface ptr and pass it to the WebBluetoothService
290 // so that it can send us events without us prompting. 292 // so that it can send us events without us prompting.
291 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info; 293 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info;
292 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group()); 294 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group());
293 web_bluetooth_service_->SetClient(std::move(ptr_info)); 295 web_bluetooth_service_->SetClient(std::move(ptr_info));
294 } 296 }
295 return *web_bluetooth_service_; 297 return *web_bluetooth_service_;
296 } 298 }
297 299
298 } // namespace content 300 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698