Chromium Code Reviews| Index: content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| diff --git a/content/browser/bluetooth/bluetooth_dispatcher_host.cc b/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| index fe067a12ca1103e3e113291942bc1737f8b5f9ad..af06cecbabf48d7310be204310787d0eb5557a7e 100644 |
| --- a/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| +++ b/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| @@ -10,20 +10,22 @@ |
| #include "device/bluetooth/bluetooth_adapter_factory.h" |
| #include "device/bluetooth/bluetooth_device.h" |
| #include "device/bluetooth/bluetooth_discovery_session.h" |
| +#include "device/bluetooth/bluetooth_gatt_service.h" |
| using device::BluetoothAdapter; |
| using device::BluetoothAdapterFactory; |
| +using device::BluetoothGattService; |
| namespace content { |
| -const int kScanTime = 5; // 5 seconds of scan time |
| -const int kTestingScanTime = 0; // No need to scan for tests |
| +const int kDelayTime = 5; // 5 seconds for scanning and discovering |
|
Jeffrey Yasskin
2015/05/27 18:36:59
Maybe add a TODO here that this is supposed to ent
ortuno
2015/05/27 21:07:45
Done.
|
| +const int kTestingDelayTime = 0; // No need to wait during tests |
| BluetoothDispatcherHost::BluetoothDispatcherHost() |
| : BrowserMessageFilter(BluetoothMsgStart), |
| weak_ptr_factory_(this) { |
| DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| - current_scan_time_ = kScanTime; |
| + current_delay_time_ = kDelayTime; |
| if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) |
| BluetoothAdapterFactory::GetAdapter( |
| base::Bind(&BluetoothDispatcherHost::set_adapter, |
| @@ -48,6 +50,7 @@ bool BluetoothDispatcherHost::OnMessageReceived(const IPC::Message& message) { |
| IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcherHost, message) |
| IPC_MESSAGE_HANDLER(BluetoothHostMsg_RequestDevice, OnRequestDevice) |
| IPC_MESSAGE_HANDLER(BluetoothHostMsg_ConnectGATT, OnConnectGATT) |
| + IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetPrimaryService, OnGetPrimaryService) |
| IPC_MESSAGE_UNHANDLED(handled = false) |
| IPC_END_MESSAGE_MAP() |
| return handled; |
| @@ -56,7 +59,7 @@ bool BluetoothDispatcherHost::OnMessageReceived(const IPC::Message& message) { |
| void BluetoothDispatcherHost::SetBluetoothAdapterForTesting( |
| scoped_refptr<device::BluetoothAdapter> mock_adapter) { |
| DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| - current_scan_time_ = kTestingScanTime; |
| + current_delay_time_ = kTestingDelayTime; |
| set_adapter(mock_adapter.Pass()); |
| } |
| @@ -123,6 +126,26 @@ void BluetoothDispatcherHost::OnConnectGATT( |
| device_instance_id)); |
| } |
| +void BluetoothDispatcherHost::OnGetPrimaryService( |
| + int thread_id, |
| + int request_id, |
| + const std::string& device_instance_id, |
| + const std::string& service_uuid) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + // TODO(ortuno): Right now it's pointless to check if the domain has access to |
| + // the device, because any domain can connect to any device. But once |
| + // permissions are implemented we should check that the domain has access to |
| + // the device. https://crbug.com/484745 |
| + // For now just wait two seconds and call OnServiceDiscovered. |
| + // TODO(ortuno): Use callback once it's implemented http://crbug.com/484504 |
| + BrowserThread::PostDelayedTask( |
| + BrowserThread::UI, FROM_HERE, |
| + base::Bind(&BluetoothDispatcherHost::OnServicesDiscovered, |
| + weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, |
| + device_instance_id, service_uuid), |
| + base::TimeDelta::FromSeconds(current_delay_time_)); |
| +} |
| + |
| void BluetoothDispatcherHost::OnDiscoverySessionStarted( |
| int thread_id, |
| int request_id, |
| @@ -133,7 +156,7 @@ void BluetoothDispatcherHost::OnDiscoverySessionStarted( |
| base::Bind(&BluetoothDispatcherHost::StopDiscoverySession, |
| weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, |
| base::Passed(&discovery_session)), |
| - base::TimeDelta::FromSeconds(current_scan_time_)); |
| + base::TimeDelta::FromSeconds(current_delay_time_)); |
| } |
| void BluetoothDispatcherHost::OnDiscoverySessionStartedError(int thread_id, |
| @@ -212,4 +235,29 @@ void BluetoothDispatcherHost::OnCreateGATTConnectionError( |
| BluetoothError::NETWORK_ERROR)); |
| } |
| +void BluetoothDispatcherHost::OnServicesDiscovered( |
| + int thread_id, |
| + int request_id, |
| + const std::string& device_instance_id, |
| + const std::string& service_uuid) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + |
| + device::BluetoothDevice* device = adapter_->GetDevice(device_instance_id); |
| + if (device == NULL) { |
| + Send(new BluetoothMsg_GetPrimaryServiceError( |
| + thread_id, request_id, BluetoothError::NETWORK_ERROR)); |
| + return; |
| + } |
| + for (BluetoothGattService* service : device->GetGattServices()) { |
| + if (service->GetUUID().canonical_value() == service_uuid) { |
| + Send(new BluetoothMsg_GetPrimaryServiceSuccess( |
| + thread_id, request_id, device_instance_id, |
| + service->GetUUID().canonical_value())); |
|
Jeffrey Yasskin
2015/05/27 18:36:59
There can be multiple services in a device with th
ortuno
2015/05/27 21:07:45
Ah. Good point. Done.
|
| + return; |
| + } |
| + } |
| + Send(new BluetoothMsg_GetPrimaryServiceError(thread_id, request_id, |
| + BluetoothError::NOT_FOUND)); |
| +} |
| + |
| } // namespace content |