diff options
author | rpaquay@chromium.org <rpaquay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-16 00:08:35 +0000 |
---|---|---|
committer | rpaquay@chromium.org <rpaquay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-16 00:09:23 +0000 |
commit | 2977264ca3368b288192faebeec409cac3b22c27 (patch) | |
tree | 2373c886eb7fa0333c587571803a2a76cd2744d0 /device | |
parent | 703d04a41fae2e16686d3b4a136403a6ecc30119 (diff) | |
download | chromium_src-2977264ca3368b288192faebeec409cac3b22c27.zip chromium_src-2977264ca3368b288192faebeec409cac3b22c27.tar.gz chromium_src-2977264ca3368b288192faebeec409cac3b22c27.tar.bz2 |
Fix Bluetooth Classic device polling issue.
With the recent device polling changes
(https://codereview.chromium.org/424093004/), any failure in enumerating
devices/services prevents the background polling task from reporting
changes (to avoid reporting inconsistent configuration). However, when
devices are offline and polling is done in "discovery" mode,
enumerating services fails because the underlying SDP request fails.
The workaround if to ask for cached services only instead, so that at
least the services already previously known are returned and the
polling operation can succeed.
BUG=396337
Review URL: https://codereview.chromium.org/476823003
Cr-Commit-Position: refs/heads/master@{#290061}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@290061 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'device')
-rw-r--r-- | device/bluetooth/bluetooth_task_manager_win.cc | 42 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_task_manager_win.h | 8 |
2 files changed, 44 insertions, 6 deletions
diff --git a/device/bluetooth/bluetooth_task_manager_win.cc b/device/bluetooth/bluetooth_task_manager_win.cc index db2540b..d89c1a0 100644 --- a/device/bluetooth/bluetooth_task_manager_win.cc +++ b/device/bluetooth/bluetooth_task_manager_win.cc @@ -537,6 +537,28 @@ bool BluetoothTaskManagerWin::DiscoverClassicDeviceServices( const GUID& protocol_uuid, bool search_cached_services_only, ScopedVector<ServiceRecordState>* service_record_states) { + int error_code = + DiscoverClassicDeviceServicesWorker(device_address, + protocol_uuid, + search_cached_services_only, + service_record_states); + // If the device is "offline", no services are returned when specifying + // "LUP_FLUSHCACHE". Try again without flushing the cache so that the list + // of previously known services is returned. + if (!search_cached_services_only && + (error_code == WSASERVICE_NOT_FOUND || error_code == WSANO_DATA)) { + error_code = DiscoverClassicDeviceServicesWorker( + device_address, protocol_uuid, true, service_record_states); + } + + return (error_code == ERROR_SUCCESS); +} + +int BluetoothTaskManagerWin::DiscoverClassicDeviceServicesWorker( + const std::string& device_address, + const GUID& protocol_uuid, + bool search_cached_services_only, + ScopedVector<ServiceRecordState>* service_record_states) { // Bluetooth and WSAQUERYSET for Service Inquiry. See http://goo.gl/2v9pyt. WSAQUERYSET sdp_query; ZeroMemory(&sdp_query, sizeof(sdp_query)); @@ -562,8 +584,15 @@ bool BluetoothTaskManagerWin::DiscoverClassicDeviceServices( HANDLE sdp_handle; if (ERROR_SUCCESS != WSALookupServiceBegin(&sdp_query, control_flags, &sdp_handle)) { - LogPollingError("Error calling WSALookupServiceBegin", WSAGetLastError()); - return false; + int last_error = WSAGetLastError(); + // If the device is "offline", no services are returned when specifying + // "LUP_FLUSHCACHE". Don't log error in that case. + if (!search_cached_services_only && + (last_error == WSASERVICE_NOT_FOUND || last_error == WSANO_DATA)) { + return last_error; + } + LogPollingError("Error calling WSALookupServiceBegin", last_error); + return last_error; } char sdp_buffer[kServiceDiscoveryResultBufferSize]; LPWSAQUERYSET sdp_result_data = reinterpret_cast<LPWSAQUERYSET>(sdp_buffer); @@ -578,7 +607,7 @@ bool BluetoothTaskManagerWin::DiscoverClassicDeviceServices( } LogPollingError("Error calling WSALookupServiceNext", last_error); WSALookupServiceEnd(sdp_handle); - return false; + return last_error; } ServiceRecordState* service_record_state = new ServiceRecordState(); service_record_state->name = @@ -590,11 +619,12 @@ bool BluetoothTaskManagerWin::DiscoverClassicDeviceServices( service_record_states->push_back(service_record_state); } if (ERROR_SUCCESS != WSALookupServiceEnd(sdp_handle)) { - LogPollingError("Error calling WSALookupServiceEnd", WSAGetLastError()); - return false; + int last_error = WSAGetLastError(); + LogPollingError("Error calling WSALookupServiceEnd", last_error); + return last_error; } - return true; + return ERROR_SUCCESS; } bool BluetoothTaskManagerWin::DiscoverLowEnergyDeviceServices( diff --git a/device/bluetooth/bluetooth_task_manager_win.h b/device/bluetooth/bluetooth_task_manager_win.h index be8b90c..20024c8 100644 --- a/device/bluetooth/bluetooth_task_manager_win.h +++ b/device/bluetooth/bluetooth_task_manager_win.h @@ -179,6 +179,14 @@ class BluetoothTaskManagerWin bool search_cached_services_only, ScopedVector<ServiceRecordState>* service_record_states); + // Discover Bluetooth Classic services for the given |device_address|. + // Returns a Win32 error code. + int DiscoverClassicDeviceServicesWorker( + 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, |