diff options
author | rpaquay@chromium.org <rpaquay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-31 12:17:25 +0000 |
---|---|---|
committer | rpaquay@chromium.org <rpaquay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-31 12:17:25 +0000 |
commit | f1ef22779257ffc38e326c89b227016b837de8c2 (patch) | |
tree | 148b5f74cb2471203c47c1c9b8b4954bc1e8197a /device/bluetooth/bluetooth_task_manager_win.h | |
parent | 9a391ca240057108941495db69c9c55d0613d167 (diff) | |
download | chromium_src-f1ef22779257ffc38e326c89b227016b837de8c2.zip chromium_src-f1ef22779257ffc38e326c89b227016b837de8c2.tar.gz chromium_src-f1ef22779257ffc38e326c89b227016b837de8c2.tar.bz2 |
Improve processing of Bluetooth device discovery on Windows.
* Merge all events into DevicesPolled event, as this
better reflects how the underlying discovery work in Windows.
* Process the list of devices from DevicesPolled event with
more granularity so we can detect adding, removing and
updating single devices, and raise the appropriate events
to the Chrome App. Add unit tests.
* Don't emit "DevicesPolled" events when the worker thread
encounters issues enumerating devices and services. Instead,
log warnings and ignore the result of the enumeration. This
is required to avoid a Chrome App being notified of
inconsistent events if the worker thread can't successfully
enumerate all devices/services.
* Fix call to BluetoothFindDeviceOpen to use LUP_FLUSHCACHE
when in "discovery" mode, ensuring services are discovered
using a active SDP request.
BUG=396337
Review URL: https://codereview.chromium.org/424093004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@286755 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'device/bluetooth/bluetooth_task_manager_win.h')
-rw-r--r-- | device/bluetooth/bluetooth_task_manager_win.h | 74 |
1 files changed, 57 insertions, 17 deletions
diff --git a/device/bluetooth/bluetooth_task_manager_win.h b/device/bluetooth/bluetooth_task_manager_win.h index 7f6c988..be8b90c 100644 --- a/device/bluetooth/bluetooth_task_manager_win.h +++ b/device/bluetooth/bluetooth_task_manager_win.h @@ -46,9 +46,9 @@ class BluetoothTaskManagerWin struct ServiceRecordState { ServiceRecordState(); ~ServiceRecordState(); - // Properties common to Bluetooth Radio and LE devices. + // Properties common to Bluetooth Classic and LE devices. std::string name; - // Properties specific to Bluetooth Radio devices. + // Properties specific to Bluetooth Classic devices. std::vector<uint8> sdp_bytes; // Properties specific to Bluetooth LE devices. BluetoothUUID gatt_uuid; @@ -57,14 +57,17 @@ class BluetoothTaskManagerWin struct DeviceState { DeviceState(); ~DeviceState(); - // Properties common to Bluetooth Radio and LE devices. - std::string name; - std::string address; + + bool is_bluetooth_classic() const { return path.empty(); } + + // Properties common to Bluetooth Classic and LE devices. + std::string address; // This uniquely identifies the device. + std::string name; // Friendly name bool visible; bool connected; bool authenticated; ScopedVector<ServiceRecordState> service_record_states; - // Properties specific to Bluetooth Radio devices. + // Properties specific to Bluetooth Classic devices. uint32 bluetooth_class; // Properties specific to Bluetooth LE devices. base::FilePath path; @@ -77,8 +80,14 @@ class BluetoothTaskManagerWin virtual void AdapterStateChanged(const AdapterState& state) {} virtual void DiscoveryStarted(bool success) {} virtual void DiscoveryStopped() {} - virtual void DevicesUpdated(const ScopedVector<DeviceState>& devices) {} - virtual void DevicesDiscovered(const ScopedVector<DeviceState>& devices) {} + // Called when the adapter has just been polled for the list of *all* known + // devices. This includes devices previously paired, devices paired using + // the underlying Operating System UI, and devices discovered recently due + // to an active discovery session. Note that for a given device (address), + // the associated state can change over time. For example, during a + // discovery session, the "friendly" name may initially be "unknown" before + // the actual name is retrieved in subsequent poll events. + virtual void DevicesPolled(const ScopedVector<DeviceState>& devices) {} }; explicit BluetoothTaskManagerWin( @@ -107,13 +116,16 @@ class BluetoothTaskManagerWin virtual ~BluetoothTaskManagerWin(); + // Logs Win32 errors occuring during polling on the worker thread. The method + // may discards messages to avoid logging being too verbose. + void LogPollingError(const char* message, int win32_error); + // Notify all Observers of updated AdapterState. Should only be called on the // UI thread. void OnAdapterStateChanged(const AdapterState* state); void OnDiscoveryStarted(bool success); void OnDiscoveryStopped(); - void OnDevicesUpdated(const ScopedVector<DeviceState>* devices); - void OnDevicesDiscovered(const ScopedVector<DeviceState>* devices); + void OnDevicesPolled(const ScopedVector<DeviceState>* devices); // Called on BluetoothTaskRunner. void StartPolling(); @@ -130,23 +142,47 @@ class BluetoothTaskManagerWin void StartDiscovery(); void StopDiscovery(); - // Issues a device inquiry that runs for |timeout| * 1.28 seconds. - // This posts itself again with |timeout| + 1 until |timeout| reaches the - // maximum value or stop discovery call is received. - void DiscoverDevices(int timeout); + // Issues a device inquiry that runs for |timeout_multiplier| * 1.28 seconds. + // This posts itself again with |timeout_multiplier| + 1 until + // |timeout_multiplier| reaches the maximum value or stop discovery call is + // received. + void DiscoverDevices(int timeout_multiplier); // Fetch already known device information. Similar to |StartDiscovery|, except // this function does not issue a discovery inquiry. Instead it gets the // device info cached in the adapter. void GetKnownDevices(); - // Sends a device search API call to the adapter. - void SearchDevices(int timeout, + // Looks for Bluetooth Classic and Low Energy devices, as well as the services + // exposed by those devices. + bool SearchDevices(int timeout_multiplier, bool search_cached_devices_only, ScopedVector<DeviceState>* device_list); + // Sends a device search API call to the adapter to look for Bluetooth Classic + // devices. + bool SearchClassicDevices(int timeout_multiplier, + bool search_cached_devices_only, + ScopedVector<DeviceState>* device_list); + + // Enumerate Bluetooth Low Energy devices. + bool SearchLowEnergyDevices(ScopedVector<DeviceState>* device_list); + // Discover services for the devices in |device_list|. - void DiscoverServices(ScopedVector<DeviceState>* device_list); + bool DiscoverServices(ScopedVector<DeviceState>* device_list, + bool search_cached_services_only); + + // Discover Bluetooth Classic services for the given |device_address|. + bool DiscoverClassicDeviceServices( + const std::string& device_address, + const GUID& protocol_uuid, + bool search_cached_services_only, + ScopedVector<ServiceRecordState>* service_record_states); + + // Discover Bluetooth Low Energy services for the given |device_path|. + bool DiscoverLowEnergyDeviceServices( + const base::FilePath& device_path, + ScopedVector<ServiceRecordState>* service_record_states); // UI task runner reference. scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; @@ -163,6 +199,10 @@ class BluetoothTaskManagerWin // indicates whether the adapter is in discovery mode or not. bool discovering_; + // Use for discarding too many log messages. + base::TimeTicks current_logging_batch_ticks_; + int current_logging_batch_count_; + DISALLOW_COPY_AND_ASSIGN(BluetoothTaskManagerWin); }; |