summaryrefslogtreecommitdiffstats
path: root/device
diff options
context:
space:
mode:
Diffstat (limited to 'device')
-rw-r--r--device/bluetooth/bluetooth_task_manager_win.cc42
-rw-r--r--device/bluetooth/bluetooth_task_manager_win.h8
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,