diff options
Diffstat (limited to 'chromium/content/browser/bluetooth')
11 files changed, 43 insertions, 36 deletions
diff --git a/chromium/content/browser/bluetooth/README.md b/chromium/content/browser/bluetooth/README.md index 87c06ffa87f..e39aac5da16 100644 --- a/chromium/content/browser/bluetooth/README.md +++ b/chromium/content/browser/bluetooth/README.md @@ -7,7 +7,7 @@ This service is exposed to the web in the [blink bluetooth module]. [Web Bluetooth specification]: https://webbluetoothcg.github.io/web-bluetooth/ [/device/bluetooth]: /device/bluetooth -[blink bluetooth module]: /third_party/WebKit/Source/modules/bluetooth/ +[blink bluetooth module]: /third_party/blink/renderer/modules/bluetooth/ ## Testing diff --git a/chromium/content/browser/bluetooth/bluetooth_allowed_devices.h b/chromium/content/browser/bluetooth/bluetooth_allowed_devices.h index 32e871f5ee8..dc5223c254d 100644 --- a/chromium/content/browser/bluetooth/bluetooth_allowed_devices.h +++ b/chromium/content/browser/bluetooth/bluetooth_allowed_devices.h @@ -14,7 +14,7 @@ #include "base/optional.h" #include "content/common/bluetooth/web_bluetooth_device_id.h" #include "content/common/content_export.h" -#include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.mojom.h" +#include "third_party/blink/public/platform/modules/bluetooth/web_bluetooth.mojom.h" namespace device { class BluetoothUUID; diff --git a/chromium/content/browser/bluetooth/bluetooth_blocklist.h b/chromium/content/browser/bluetooth/bluetooth_blocklist.h index c719b571fae..103e8c2da42 100644 --- a/chromium/content/browser/bluetooth/bluetooth_blocklist.h +++ b/chromium/content/browser/bluetooth/bluetooth_blocklist.h @@ -13,7 +13,7 @@ #include "base/strings/string_piece.h" #include "content/common/content_export.h" #include "device/bluetooth/bluetooth_uuid.h" -#include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.mojom.h" +#include "third_party/blink/public/platform/modules/bluetooth/web_bluetooth.mojom.h" namespace content { diff --git a/chromium/content/browser/bluetooth/bluetooth_device_chooser_controller.cc b/chromium/content/browser/bluetooth/bluetooth_device_chooser_controller.cc index 1b12e6638d5..4d08d443e55 100644 --- a/chromium/content/browser/bluetooth/bluetooth_device_chooser_controller.cc +++ b/chromium/content/browser/bluetooth/bluetooth_device_chooser_controller.cc @@ -10,7 +10,6 @@ #include "base/bind.h" #include "base/bind_helpers.h" -#include "base/memory/ptr_util.h" #include "base/metrics/histogram_macros.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" @@ -81,17 +80,14 @@ const int k80thPercentileRSSI = -52; namespace content { -bool BluetoothDeviceChooserController::use_test_scan_duration_ = false; +// Sets the default duration for a Bluetooth scan to 60 seconds. +int64_t BluetoothDeviceChooserController::scan_duration_ = 60; namespace { // Max length of device name in filter. Bluetooth 5.0 3.C.3.2.2.3 states that // the maximum device name length is 248 bytes (UTF-8 encoded). constexpr size_t kMaxLengthForDeviceName = 248; -// The duration of a Bluetooth Scan in seconds. -constexpr int kScanDuration = 60; -constexpr int kTestScanDuration = 0; - void LogRequestDeviceOptions( const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options) { DVLOG(1) << "requestDevice called with the following filters: "; @@ -281,10 +277,7 @@ BluetoothDeviceChooserController::BluetoothDeviceChooserController( web_contents_(WebContents::FromRenderFrameHost(render_frame_host_)), discovery_session_timer_( FROM_HERE, - // TODO(jyasskin): Add a way for tests to control the dialog - // directly, and change this to a reasonable discovery timeout. - base::TimeDelta::FromSeconds( - use_test_scan_duration_ ? kTestScanDuration : kScanDuration), + base::TimeDelta::FromSeconds(scan_duration_), base::Bind(&BluetoothDeviceChooserController::StopDeviceDiscovery, // base::Timer guarantees it won't call back after its // destructor starts. @@ -397,7 +390,7 @@ void BluetoothDeviceChooserController::GetDevice( if (WebContentsDelegate* delegate = web_contents_->GetDelegate()) { chooser_ = delegate->RunBluetoothChooser(render_frame_host_, - chooser_event_handler); + std::move(chooser_event_handler)); } if (!chooser_.get()) { @@ -490,8 +483,16 @@ int BluetoothDeviceChooserController::CalculateSignalStrengthLevel( } } -void BluetoothDeviceChooserController::SetTestScanDurationForTesting() { - BluetoothDeviceChooserController::use_test_scan_duration_ = true; +void BluetoothDeviceChooserController::SetTestScanDurationForTesting( + TestScanDurationSetting setting) { + switch (setting) { + case TestScanDurationSetting::IMMEDIATE_TIMEOUT: + scan_duration_ = 0; + break; + case TestScanDurationSetting::NEVER_TIMEOUT: + scan_duration_ = base::TimeDelta::Max().InSeconds(); + break; + } } void BluetoothDeviceChooserController::PopulateConnectedDevices() { diff --git a/chromium/content/browser/bluetooth/bluetooth_device_chooser_controller.h b/chromium/content/browser/bluetooth/bluetooth_device_chooser_controller.h index a054d6bf705..54eb7a113e2 100644 --- a/chromium/content/browser/bluetooth/bluetooth_device_chooser_controller.h +++ b/chromium/content/browser/bluetooth/bluetooth_device_chooser_controller.h @@ -14,7 +14,7 @@ #include "base/timer/timer.h" #include "content/common/content_export.h" #include "content/public/browser/bluetooth_chooser.h" -#include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.mojom.h" +#include "third_party/blink/public/platform/modules/bluetooth/web_bluetooth.mojom.h" namespace device { class BluetoothAdapter; @@ -39,6 +39,8 @@ class CONTENT_EXPORT BluetoothDeviceChooserController final { typedef base::Callback<void(blink::mojom::WebBluetoothResult result)> ErrorCallback; + enum class TestScanDurationSetting { IMMEDIATE_TIMEOUT, NEVER_TIMEOUT }; + // |web_bluetooth_service_| service that owns this class. // |render_frame_host| should be the RenderFrameHost that owns the // |web_bluetooth_service_|. @@ -83,9 +85,14 @@ class CONTENT_EXPORT BluetoothDeviceChooserController final { // present in a received radio signal. static int CalculateSignalStrengthLevel(int8_t rssi); - // After this method is called any new instance of - // BluetoothDeviceChooserController will have a scan duration of 0. - static void SetTestScanDurationForTesting(); + // After this method is called, any new instance of + // BluetoothDeviceChooserController will have a scan duration determined by + // the |setting| enum. The possible enumerations are described below: + // IMMEDIATE_TIMEOUT: Sets the scan duration to 0 seconds. + // NEVER_TIMEOUT: Sets the scan duration to INT_MAX seconds. + static void SetTestScanDurationForTesting( + TestScanDurationSetting setting = + TestScanDurationSetting::IMMEDIATE_TIMEOUT); private: // Populates the chooser with the GATT connected devices. @@ -115,8 +122,9 @@ class CONTENT_EXPORT BluetoothDeviceChooserController final { // Helper function to asynchronously run error_callback_. void PostErrorCallback(blink::mojom::WebBluetoothResult result); - // If true all new instances of this class will have a scan duration of 0. - static bool use_test_scan_duration_; + // Stores the scan duration to use for the discovery session timer. + // The default value is 60 seconds. + static int64_t scan_duration_; // The adapter used to get existing devices and start a discovery session. device::BluetoothAdapter* adapter_; diff --git a/chromium/content/browser/bluetooth/bluetooth_metrics.h b/chromium/content/browser/bluetooth/bluetooth_metrics.h index 4a7d761c63c..2b7ec33ec91 100644 --- a/chromium/content/browser/bluetooth/bluetooth_metrics.h +++ b/chromium/content/browser/bluetooth/bluetooth_metrics.h @@ -8,7 +8,7 @@ #include <string> #include <vector> -#include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.mojom.h" +#include "third_party/blink/public/platform/modules/bluetooth/web_bluetooth.mojom.h" namespace base { class TimeDelta; diff --git a/chromium/content/browser/bluetooth/frame_connected_bluetooth_devices.cc b/chromium/content/browser/bluetooth/frame_connected_bluetooth_devices.cc index e64676e7745..1b4b07030db 100644 --- a/chromium/content/browser/bluetooth/frame_connected_bluetooth_devices.cc +++ b/chromium/content/browser/bluetooth/frame_connected_bluetooth_devices.cc @@ -4,7 +4,6 @@ #include "content/browser/bluetooth/frame_connected_bluetooth_devices.h" -#include "base/memory/ptr_util.h" #include "base/optional.h" #include "base/strings/string_util.h" #include "content/browser/web_contents/web_contents_impl.h" diff --git a/chromium/content/browser/bluetooth/frame_connected_bluetooth_devices.h b/chromium/content/browser/bluetooth/frame_connected_bluetooth_devices.h index 3c4dcf0ce30..d8adcbd5953 100644 --- a/chromium/content/browser/bluetooth/frame_connected_bluetooth_devices.h +++ b/chromium/content/browser/bluetooth/frame_connected_bluetooth_devices.h @@ -12,7 +12,7 @@ #include "base/optional.h" #include "content/common/bluetooth/web_bluetooth_device_id.h" #include "content/common/content_export.h" -#include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.mojom.h" +#include "third_party/blink/public/platform/modules/bluetooth/web_bluetooth.mojom.h" #include "url/origin.h" namespace device { diff --git a/chromium/content/browser/bluetooth/frame_connected_bluetooth_devices_unittest.cc b/chromium/content/browser/bluetooth/frame_connected_bluetooth_devices_unittest.cc index 1cf49611197..22f2e06d0e8 100644 --- a/chromium/content/browser/bluetooth/frame_connected_bluetooth_devices_unittest.cc +++ b/chromium/content/browser/bluetooth/frame_connected_bluetooth_devices_unittest.cc @@ -4,7 +4,6 @@ #include "content/browser/bluetooth/frame_connected_bluetooth_devices.h" -#include "base/memory/ptr_util.h" #include "base/memory/ref_counted.h" #include "content/browser/bluetooth/web_bluetooth_service_impl.h" #include "content/test/test_render_view_host.h" diff --git a/chromium/content/browser/bluetooth/web_bluetooth_service_impl.cc b/chromium/content/browser/bluetooth/web_bluetooth_service_impl.cc index e5c7291dcc8..cda94e43e86 100644 --- a/chromium/content/browser/bluetooth/web_bluetooth_service_impl.cc +++ b/chromium/content/browser/bluetooth/web_bluetooth_service_impl.cc @@ -12,7 +12,6 @@ #include <algorithm> -#include "base/memory/ptr_util.h" #include "base/strings/utf_string_conversions.h" #include "base/threading/thread_task_runner_handle.h" #include "content/browser/bluetooth/bluetooth_blocklist.h" @@ -178,8 +177,8 @@ WebBluetoothServiceImpl::~WebBluetoothServiceImpl() { } void WebBluetoothServiceImpl::SetClientConnectionErrorHandler( - base::Closure closure) { - binding_.set_connection_error_handler(closure); + base::OnceClosure closure) { + binding_.set_connection_error_handler(std::move(closure)); } bool WebBluetoothServiceImpl::IsDevicePaired( @@ -823,11 +822,12 @@ void WebBluetoothServiceImpl::RequestDeviceImpl( blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, RequestDeviceCallback callback, device::BluetoothAdapter* adapter) { - // requestDevice() can only be called when processing a user-gesture and any - // user gesture outside of a chooser should close the chooser. This does - // not happen on all platforms so we don't DCHECK that the old one is closed. - // We destroy the old chooser before constructing the new one to make sure - // they can't conflict. + // Calls to requestDevice() require user activation (user gestures). We + // should close any opened chooser when a duplicate requestDevice call is made + // with the same user activation or when any gesture occurs outside of the + // opened chooser. This does not happen on all platforms so we don't DCHECK + // that the old one is closed. We destroy the old chooser before constructing + // the new one to make sure they can't conflict. device_chooser_controller_.reset(); device_chooser_controller_.reset( diff --git a/chromium/content/browser/bluetooth/web_bluetooth_service_impl.h b/chromium/content/browser/bluetooth/web_bluetooth_service_impl.h index 5ecd3e0b7e9..55b409a3525 100644 --- a/chromium/content/browser/bluetooth/web_bluetooth_service_impl.h +++ b/chromium/content/browser/bluetooth/web_bluetooth_service_impl.h @@ -21,7 +21,7 @@ #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" #include "device/bluetooth/bluetooth_remote_gatt_service.h" #include "mojo/public/cpp/bindings/binding.h" -#include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.mojom.h" +#include "third_party/blink/public/platform/modules/bluetooth/web_bluetooth.mojom.h" namespace url { class Origin; @@ -60,7 +60,7 @@ class CONTENT_EXPORT WebBluetoothServiceImpl void CrashRendererAndClosePipe(bad_message::BadMessageReason reason); // Sets the connection error handler for WebBluetoothServiceImpl's Binding. - void SetClientConnectionErrorHandler(base::Closure closure); + void SetClientConnectionErrorHandler(base::OnceClosure closure); // Returns whether the device is paired with the |render_frame_host_|'s // GetLastCommittedOrigin(). |