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

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 Created 4 years, 4 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
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/optional.h" 12 #include "base/optional.h"
13 #include "content/child/mojo/type_converters.h" 13 #include "content/child/mojo/type_converters.h"
14 #include "content/child/thread_safe_sender.h" 14 #include "content/child/thread_safe_sender.h"
15 #include "content/common/bluetooth/web_bluetooth_device_id.h"
15 #include "content/renderer/bluetooth/bluetooth_type_converters.h" 16 #include "content/renderer/bluetooth/bluetooth_type_converters.h"
16 #include "ipc/ipc_message.h" 17 #include "ipc/ipc_message.h"
17 #include "mojo/public/cpp/bindings/array.h" 18 #include "mojo/public/cpp/bindings/array.h"
18 #include "services/shell/public/cpp/interface_provider.h" 19 #include "services/shell/public/cpp/interface_provider.h"
19 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic e.h" 20 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic e.h"
20 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic eInit.h" 21 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic eInit.h"
21 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTCharacteristic.h" 22 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTCharacteristic.h"
22 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTCharacteristicInit.h" 23 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTCharacteristicInit.h"
23 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTService.h" 24 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTService.h"
24 #include "third_party/WebKit/public/platform/modules/bluetooth/WebRequestDeviceO ptions.h" 25 #include "third_party/WebKit/public/platform/modules/bluetooth/WebRequestDeviceO ptions.h"
(...skipping 25 matching lines...) Expand all
50 base::Unretained(this), 51 base::Unretained(this),
51 base::Passed(base::WrapUnique(callbacks)))); 52 base::Passed(base::WrapUnique(callbacks))));
52 } 53 }
53 54
54 void WebBluetoothImpl::connect( 55 void WebBluetoothImpl::connect(
55 const blink::WebString& device_id, 56 const blink::WebString& device_id,
56 blink::WebBluetoothDevice* device, 57 blink::WebBluetoothDevice* device,
57 blink::WebBluetoothRemoteGATTServerConnectCallbacks* callbacks) { 58 blink::WebBluetoothRemoteGATTServerConnectCallbacks* callbacks) {
58 // TODO(crbug.com/495270): After the Bluetooth Tree is implemented, there will 59 // 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. 60 // only be one object per device. But for now we replace the previous object.
60 connected_devices_[device_id.utf8()] = device; 61 WebBluetoothDeviceId device_id_obj = WebBluetoothDeviceId(device_id.utf8());
62 connected_devices_[device_id_obj] = device;
61 63
62 GetWebBluetoothService().RemoteServerConnect( 64 GetWebBluetoothService().RemoteServerConnect(
63 mojo::String::From(device_id), 65 std::move(device_id_obj),
64 base::Bind(&WebBluetoothImpl::OnConnectComplete, base::Unretained(this), 66 base::Bind(&WebBluetoothImpl::OnConnectComplete, base::Unretained(this),
65 base::Passed(base::WrapUnique(callbacks)))); 67 base::Passed(base::WrapUnique(callbacks))));
66 } 68 }
67 69
68 void WebBluetoothImpl::disconnect(const blink::WebString& device_id) { 70 void WebBluetoothImpl::disconnect(const blink::WebString& device_id) {
69 connected_devices_.erase(device_id.utf8()); 71 WebBluetoothDeviceId device_id_obj = WebBluetoothDeviceId(device_id.utf8());
72 connected_devices_.erase(device_id_obj);
70 73
71 GetWebBluetoothService().RemoteServerDisconnect( 74 GetWebBluetoothService().RemoteServerDisconnect(std::move(device_id_obj));
72 mojo::String::From(device_id));
73 } 75 }
74 76
75 void WebBluetoothImpl::getPrimaryServices( 77 void WebBluetoothImpl::getPrimaryServices(
76 const blink::WebString& device_id, 78 const blink::WebString& device_id,
77 int32_t quantity, 79 int32_t quantity,
78 const blink::WebString& services_uuid, 80 const blink::WebString& services_uuid,
79 blink::WebBluetoothGetPrimaryServicesCallbacks* callbacks) { 81 blink::WebBluetoothGetPrimaryServicesCallbacks* callbacks) {
80 DCHECK(blink::mojom::IsKnownEnumValue( 82 DCHECK(blink::mojom::IsKnownEnumValue(
81 static_cast<blink::mojom::WebBluetoothGATTQueryQuantity>(quantity))); 83 static_cast<blink::mojom::WebBluetoothGATTQueryQuantity>(quantity)));
82 GetWebBluetoothService().RemoteServerGetPrimaryServices( 84 GetWebBluetoothService().RemoteServerGetPrimaryServices(
83 mojo::String::From(device_id), 85 WebBluetoothDeviceId(device_id.utf8()),
84 static_cast<blink::mojom::WebBluetoothGATTQueryQuantity>(quantity), 86 static_cast<blink::mojom::WebBluetoothGATTQueryQuantity>(quantity),
85 services_uuid.isEmpty() 87 services_uuid.isEmpty()
86 ? base::nullopt 88 ? base::nullopt
87 : base::make_optional(device::BluetoothUUID(services_uuid.utf8())), 89 : base::make_optional(device::BluetoothUUID(services_uuid.utf8())),
88 base::Bind(&WebBluetoothImpl::OnGetPrimaryServicesComplete, 90 base::Bind(&WebBluetoothImpl::OnGetPrimaryServicesComplete,
89 base::Unretained(this), device_id, 91 base::Unretained(this), device_id,
90 base::Passed(base::WrapUnique(callbacks)))); 92 base::Passed(base::WrapUnique(callbacks))));
91 } 93 }
92 94
93 void WebBluetoothImpl::getCharacteristics( 95 void WebBluetoothImpl::getCharacteristics(
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 void WebBluetoothImpl::OnRequestDeviceComplete( 183 void WebBluetoothImpl::OnRequestDeviceComplete(
182 std::unique_ptr<blink::WebBluetoothRequestDeviceCallbacks> callbacks, 184 std::unique_ptr<blink::WebBluetoothRequestDeviceCallbacks> callbacks,
183 const blink::mojom::WebBluetoothError error, 185 const blink::mojom::WebBluetoothError error,
184 blink::mojom::WebBluetoothDevicePtr device) { 186 blink::mojom::WebBluetoothDevicePtr device) {
185 if (error == blink::mojom::WebBluetoothError::SUCCESS) { 187 if (error == blink::mojom::WebBluetoothError::SUCCESS) {
186 blink::WebVector<blink::WebString> uuids(device->uuids.size()); 188 blink::WebVector<blink::WebString> uuids(device->uuids.size());
187 for (size_t i = 0; i < device->uuids.size(); ++i) 189 for (size_t i = 0; i < device->uuids.size(); ++i)
188 uuids[i] = blink::WebString::fromUTF8(device->uuids[i]); 190 uuids[i] = blink::WebString::fromUTF8(device->uuids[i]);
189 191
190 callbacks->onSuccess(base::WrapUnique(new blink::WebBluetoothDeviceInit( 192 callbacks->onSuccess(base::WrapUnique(new blink::WebBluetoothDeviceInit(
191 blink::WebString::fromUTF8(device->id), 193 blink::WebString::fromUTF8(device->id.str()),
192 device->name.is_null() ? blink::WebString() 194 device->name.is_null() ? blink::WebString()
193 : blink::WebString::fromUTF8(device->name), 195 : blink::WebString::fromUTF8(device->name),
194 uuids))); 196 uuids)));
195 } else { 197 } else {
196 callbacks->onError(ToInt32(error)); 198 callbacks->onError(ToInt32(error));
197 } 199 }
198 } 200 }
199 201
200 void WebBluetoothImpl::GattServerDisconnected(const mojo::String& device_id) { 202 void WebBluetoothImpl::GattServerDisconnected(
203 const WebBluetoothDeviceId& device_id) {
201 auto device_iter = connected_devices_.find(device_id); 204 auto device_iter = connected_devices_.find(device_id);
202 if (device_iter != connected_devices_.end()) { 205 if (device_iter != connected_devices_.end()) {
203 // Remove device from the map before calling dispatchGattServerDisconnected 206 // Remove device from the map before calling dispatchGattServerDisconnected
204 // to avoid removing a device the gattserverdisconnected event handler might 207 // to avoid removing a device the gattserverdisconnected event handler might
205 // have re-connected. 208 // have re-connected.
206 blink::WebBluetoothDevice* device = device_iter->second; 209 blink::WebBluetoothDevice* device = device_iter->second;
207 connected_devices_.erase(device_iter); 210 connected_devices_.erase(device_iter);
208 device->dispatchGattServerDisconnected(); 211 device->dispatchGattServerDisconnected();
209 } 212 }
210 } 213 }
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 // Create an associated interface ptr and pass it to the WebBluetoothService 322 // Create an associated interface ptr and pass it to the WebBluetoothService
320 // so that it can send us events without us prompting. 323 // so that it can send us events without us prompting.
321 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info; 324 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info;
322 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group()); 325 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group());
323 web_bluetooth_service_->SetClient(std::move(ptr_info)); 326 web_bluetooth_service_->SetClient(std::move(ptr_info));
324 } 327 }
325 return *web_bluetooth_service_; 328 return *web_bluetooth_service_;
326 } 329 }
327 330
328 } // namespace content 331 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/bluetooth/web_bluetooth_impl.h ('k') | mojo/public/tools/bindings/chromium_bindings_configuration.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698