| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/browser/bluetooth/bluetooth_device_chooser_controller.h" | 5 #include "content/browser/bluetooth/bluetooth_device_chooser_controller.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <unordered_set> | 9 #include <unordered_set> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "content/browser/bluetooth/bluetooth_blacklist.h" | 15 #include "content/browser/bluetooth/bluetooth_blacklist.h" |
| 16 #include "content/browser/bluetooth/bluetooth_metrics.h" | 16 #include "content/browser/bluetooth/bluetooth_metrics.h" |
| 17 #include "content/browser/bluetooth/first_device_bluetooth_chooser.h" | 17 #include "content/browser/bluetooth/first_device_bluetooth_chooser.h" |
| 18 #include "content/browser/bluetooth/web_bluetooth_service_impl.h" | 18 #include "content/browser/bluetooth/web_bluetooth_service_impl.h" |
| 19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/content_browser_client.h" | 20 #include "content/public/browser/content_browser_client.h" |
| 21 #include "content/public/browser/render_frame_host.h" | 21 #include "content/public/browser/render_frame_host.h" |
| 22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 23 #include "content/public/browser/web_contents_delegate.h" | 23 #include "content/public/browser/web_contents_delegate.h" |
| 24 #include "device/bluetooth/bluetooth_adapter.h" | 24 #include "device/bluetooth/bluetooth_adapter.h" |
| 25 #include "device/bluetooth/bluetooth_common.h" |
| 25 #include "device/bluetooth/bluetooth_discovery_session.h" | 26 #include "device/bluetooth/bluetooth_discovery_session.h" |
| 26 | 27 |
| 27 using device::BluetoothUUID; | 28 using device::BluetoothUUID; |
| 28 | 29 |
| 29 namespace content { | 30 namespace content { |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 constexpr size_t kMaxLengthForDeviceName = | 33 constexpr size_t kMaxLengthForDeviceName = |
| 33 29; // max length of device name in filter. | 34 29; // max length of device name in filter. |
| 34 | 35 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 126 |
| 126 std::unique_ptr<device::BluetoothDiscoveryFilter> ComputeScanFilter( | 127 std::unique_ptr<device::BluetoothDiscoveryFilter> ComputeScanFilter( |
| 127 const mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>& filters) { | 128 const mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>& filters) { |
| 128 std::unordered_set<BluetoothUUID, device::BluetoothUUIDHash> services; | 129 std::unordered_set<BluetoothUUID, device::BluetoothUUIDHash> services; |
| 129 for (const auto& filter : filters) { | 130 for (const auto& filter : filters) { |
| 130 for (const base::Optional<BluetoothUUID>& service : filter->services) { | 131 for (const base::Optional<BluetoothUUID>& service : filter->services) { |
| 131 services.insert(service.value()); | 132 services.insert(service.value()); |
| 132 } | 133 } |
| 133 } | 134 } |
| 134 auto discovery_filter = base::MakeUnique<device::BluetoothDiscoveryFilter>( | 135 auto discovery_filter = base::MakeUnique<device::BluetoothDiscoveryFilter>( |
| 135 device::BluetoothDiscoveryFilter::TRANSPORT_DUAL); | 136 device::BLUETOOTH_TRANSPORT_DUAL); |
| 136 for (const BluetoothUUID& service : services) { | 137 for (const BluetoothUUID& service : services) { |
| 137 discovery_filter->AddUUID(service); | 138 discovery_filter->AddUUID(service); |
| 138 } | 139 } |
| 139 return discovery_filter; | 140 return discovery_filter; |
| 140 } | 141 } |
| 141 | 142 |
| 142 void StopDiscoverySession( | 143 void StopDiscoverySession( |
| 143 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session) { | 144 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session) { |
| 144 // Nothing goes wrong if the discovery session fails to stop, and we don't | 145 // Nothing goes wrong if the discovery session fails to stop, and we don't |
| 145 // need to wait for it before letting the user's script proceed, so we ignore | 146 // need to wait for it before letting the user's script proceed, so we ignore |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 | 467 |
| 467 void BluetoothDeviceChooserController::PostErrorCallback( | 468 void BluetoothDeviceChooserController::PostErrorCallback( |
| 468 blink::mojom::WebBluetoothError error) { | 469 blink::mojom::WebBluetoothError error) { |
| 469 if (!base::ThreadTaskRunnerHandle::Get()->PostTask( | 470 if (!base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 470 FROM_HERE, base::Bind(error_callback_, error))) { | 471 FROM_HERE, base::Bind(error_callback_, error))) { |
| 471 LOG(WARNING) << "No TaskRunner."; | 472 LOG(WARNING) << "No TaskRunner."; |
| 472 } | 473 } |
| 473 } | 474 } |
| 474 | 475 |
| 475 } // namespace content | 476 } // namespace content |
| OLD | NEW |