Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(387)

Unified Diff: device/bluetooth/bluetooth_task_manager_win.cc

Issue 180163009: chrome.bluetooth API improvements. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix threading ownership related to ApiResourceManager<BluetoothApiSocket> and BluetoothSocketEventD… Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 3347f0f17534fd3e501a4addf56b0cbfca2453fc..74b81fba6d1d88e700f190400c08972bc068735d 100644
--- a/device/bluetooth/bluetooth_task_manager_win.cc
+++ b/device/bluetooth/bluetooth_task_manager_win.cc
@@ -30,6 +30,8 @@ const int kMaxNumDeviceAddressChar = 127;
const int kServiceDiscoveryResultBufferSize = 5000;
const int kMaxDeviceDiscoveryTimeout = 48;
+typedef device::BluetoothTaskManagerWin::ServiceRecordState ServiceRecordState;
+
// Populates bluetooth adapter state using adapter_handle.
void GetAdapterState(HANDLE adapter_handle,
device::BluetoothTaskManagerWin::AdapterState* state) {
@@ -71,6 +73,46 @@ void GetDeviceState(const BLUETOOTH_DEVICE_INFO& device_info,
state->authenticated = !!device_info.fAuthenticated;
}
+void DiscoverDeviceServices(
+ const std::string& device_address,
+ const GUID& protocol_uuid,
+ 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));
+ sdp_query.dwSize = sizeof(sdp_query);
+ GUID protocol = protocol_uuid;
+ sdp_query.lpServiceClassId = &protocol;
+ sdp_query.dwNameSpace = NS_BTH;
+ wchar_t device_address_context[kMaxNumDeviceAddressChar];
+ std::size_t length = base::SysUTF8ToWide("(" + device_address + ")").copy(
+ device_address_context, kMaxNumDeviceAddressChar);
+ device_address_context[length] = NULL;
+ sdp_query.lpszContext = device_address_context;
+ HANDLE sdp_handle;
+ if (ERROR_SUCCESS !=
+ WSALookupServiceBegin(&sdp_query, LUP_RETURN_ALL, &sdp_handle)) {
+ return;
+ }
+ char sdp_buffer[kServiceDiscoveryResultBufferSize];
+ LPWSAQUERYSET sdp_result_data = reinterpret_cast<LPWSAQUERYSET>(sdp_buffer);
+ DWORD sdp_buffer_size = sizeof(sdp_buffer);
+ while (ERROR_SUCCESS ==
+ WSALookupServiceNext(
+ sdp_handle, LUP_RETURN_ALL, &sdp_buffer_size, sdp_result_data)) {
+ ServiceRecordState* service_record_state = new ServiceRecordState();
+ service_record_state->name =
+ base::SysWideToUTF8(sdp_result_data->lpszServiceInstanceName);
+ service_record_state->address = device_address;
+ for (uint64 i = 0; i < sdp_result_data->lpBlob->cbSize; i++) {
+ service_record_state->sdp_bytes.push_back(
+ sdp_result_data->lpBlob->pBlobData[i]);
+ }
+ service_record_states->push_back(service_record_state);
+ }
+ WSALookupServiceEnd(sdp_handle);
+}
+
} // namespace
namespace device {
@@ -375,41 +417,56 @@ void BluetoothTaskManagerWin::DiscoverServices(
const std::string device_address = (*iter)->address;
ScopedVector<ServiceRecordState>* service_record_states =
&(*iter)->service_record_states;
- WSAQUERYSET sdp_query;
- ZeroMemory(&sdp_query, sizeof(sdp_query));
- sdp_query.dwSize = sizeof(sdp_query);
- GUID protocol = L2CAP_PROTOCOL_UUID;
- sdp_query.lpServiceClassId = &protocol;
- sdp_query.dwNameSpace = NS_BTH;
- wchar_t device_address_context[kMaxNumDeviceAddressChar];
- std::size_t length =
- base::SysUTF8ToWide("(" + device_address + ")").copy(
- device_address_context, kMaxNumDeviceAddressChar);
- device_address_context[length] = NULL;
- sdp_query.lpszContext = device_address_context;
- HANDLE sdp_handle;
- if (ERROR_SUCCESS !=
- WSALookupServiceBegin(&sdp_query, LUP_RETURN_ALL, &sdp_handle)) {
- return;
- }
- char sdp_buffer[kServiceDiscoveryResultBufferSize];
- LPWSAQUERYSET sdp_result_data = reinterpret_cast<LPWSAQUERYSET>(sdp_buffer);
- DWORD sdp_buffer_size = sizeof(sdp_buffer);
- while (ERROR_SUCCESS == WSALookupServiceNext(sdp_handle,
- LUP_RETURN_ALL,
- &sdp_buffer_size,
- sdp_result_data)) {
- ServiceRecordState* service_record_state = new ServiceRecordState();
- service_record_state->name =
- base::SysWideToUTF8(sdp_result_data->lpszServiceInstanceName);
- service_record_state->address = device_address;
- for (uint64 i = 0; i < sdp_result_data->lpBlob->cbSize; i++) {
- service_record_state->sdp_bytes.push_back(
- sdp_result_data->lpBlob->pBlobData[i]);
- }
- service_record_states->push_back(service_record_state);
- }
- WSALookupServiceEnd(sdp_handle);
+
+ // TODO(rpaquay): Find a better way to enumerate registered protocols.
+ DiscoverDeviceServices(
+ device_address, SDP_PROTOCOL_UUID, service_record_states);
+ DiscoverDeviceServices(
+ device_address, UDP_PROTOCOL_UUID, service_record_states);
+ DiscoverDeviceServices(
+ device_address, RFCOMM_PROTOCOL_UUID, service_record_states);
+ DiscoverDeviceServices(
+ device_address, TCP_PROTOCOL_UUID, service_record_states);
+ DiscoverDeviceServices(
+ device_address, TCSBIN_PROTOCOL_UUID, service_record_states);
+ DiscoverDeviceServices(
+ device_address, TCSAT_PROTOCOL_UUID, service_record_states);
+ DiscoverDeviceServices(
+ device_address, OBEX_PROTOCOL_UUID, service_record_states);
+ DiscoverDeviceServices(
+ device_address, IP_PROTOCOL_UUID, service_record_states);
+ DiscoverDeviceServices(
+ device_address, FTP_PROTOCOL_UUID, service_record_states);
+ DiscoverDeviceServices(
+ device_address, HTTP_PROTOCOL_UUID, service_record_states);
+ DiscoverDeviceServices(
+ device_address, WSP_PROTOCOL_UUID, service_record_states);
+ DiscoverDeviceServices(
+ device_address, BNEP_PROTOCOL_UUID, service_record_states);
+ DiscoverDeviceServices(
+ device_address, UPNP_PROTOCOL_UUID, service_record_states);
+ DiscoverDeviceServices(
+ device_address, HID_PROTOCOL_UUID, service_record_states);
+ DiscoverDeviceServices(
+ device_address, HCCC_PROTOCOL_UUID, service_record_states);
+ DiscoverDeviceServices(
+ device_address, HCDC_PROTOCOL_UUID, service_record_states);
+ DiscoverDeviceServices(
+ device_address, HN_PROTOCOL_UUID, service_record_states);
+ DiscoverDeviceServices(
+ device_address, AVCTP_PROTOCOL_UUID, service_record_states);
+ DiscoverDeviceServices(
+ device_address, AVDTP_PROTOCOL_UUID, service_record_states);
+ DiscoverDeviceServices(
+ device_address, CMPT_PROTOCOL_UUID, service_record_states);
+ DiscoverDeviceServices(
+ device_address, UDI_C_PLANE_PROTOCOL_UUID, service_record_states);
+ DiscoverDeviceServices(
+ device_address, L2CAP_PROTOCOL_UUID, service_record_states);
xiyuan 2014/03/17 22:55:11 It seems we only need enumerate L2CAP_PROTOCOL_UUI
rpaquay 2014/03/20 00:48:18 Done.
+
+ // TODO(rpaquay): Workaround issue where this profile is not discovered.
+ DiscoverDeviceServices(
+ device_address, OBEXObjectPushServiceClass_UUID, service_record_states);
}
}

Powered by Google App Engine
This is Rietveld 408576698