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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 blink::WebString::fromUTF8(device->id), | 176 blink::WebString::fromUTF8(device->id), |
177 blink::WebString::fromUTF8(device->name), uuids))); | 177 blink::WebString::fromUTF8(device->name), uuids))); |
178 } else { | 178 } else { |
179 callbacks->onError(error); | 179 callbacks->onError(error); |
180 } | 180 } |
181 } | 181 } |
182 | 182 |
183 void WebBluetoothImpl::GattServerDisconnected(const mojo::String& device_id) { | 183 void WebBluetoothImpl::GattServerDisconnected(const mojo::String& device_id) { |
184 auto device_iter = connected_devices_.find(device_id); | 184 auto device_iter = connected_devices_.find(device_id); |
185 if (device_iter != connected_devices_.end()) { | 185 if (device_iter != connected_devices_.end()) { |
186 device_iter->second->dispatchGattServerDisconnected(); | 186 // Remove device from the map before calling dispatchGattServerDisconnected |
| 187 // to avoid removing a device the gattserverdisconnected event handler might |
| 188 // have re-connected. |
| 189 blink::WebBluetoothDevice* device = device_iter->second; |
187 connected_devices_.erase(device_iter); | 190 connected_devices_.erase(device_iter); |
| 191 device->dispatchGattServerDisconnected(); |
188 } | 192 } |
189 } | 193 } |
190 | 194 |
191 void WebBluetoothImpl::OnConnectComplete( | 195 void WebBluetoothImpl::OnConnectComplete( |
192 std::unique_ptr<blink::WebBluetoothRemoteGATTServerConnectCallbacks> | 196 std::unique_ptr<blink::WebBluetoothRemoteGATTServerConnectCallbacks> |
193 callbacks, | 197 callbacks, |
194 blink::mojom::WebBluetoothError error) { | 198 blink::mojom::WebBluetoothError error) { |
195 if (error == blink::mojom::WebBluetoothError::SUCCESS) { | 199 if (error == blink::mojom::WebBluetoothError::SUCCESS) { |
196 callbacks->onSuccess(); | 200 callbacks->onSuccess(); |
197 } else { | 201 } else { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 // Create an associated interface ptr and pass it to the WebBluetoothService | 303 // Create an associated interface ptr and pass it to the WebBluetoothService |
300 // so that it can send us events without us prompting. | 304 // so that it can send us events without us prompting. |
301 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info; | 305 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info; |
302 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group()); | 306 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group()); |
303 web_bluetooth_service_->SetClient(std::move(ptr_info)); | 307 web_bluetooth_service_->SetClient(std::move(ptr_info)); |
304 } | 308 } |
305 return *web_bluetooth_service_; | 309 return *web_bluetooth_service_; |
306 } | 310 } |
307 | 311 |
308 } // namespace content | 312 } // namespace content |
OLD | NEW |