| Index: device/bluetooth/bluetooth_task_manager_win.cc
|
| diff --git a/device/bluetooth/bluetooth_task_manager_win.cc b/device/bluetooth/bluetooth_task_manager_win.cc
|
| index db2540b12e77ddf41d8132c8b1ab5a904e590c6a..d89c1a03fde3b11707bd23b2ebff4132d2fb77f4 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(
|
|
|