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..a3855c60f97cd260b5a56451024366b5928131ce 100644 |
--- a/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
+++ b/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
@@ -10,20 +10,25 @@ |
#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 |
+// TODO(ortuno): Once we have a chooser for scanning and the right |
+// callback for discovered services we should delete these constants. |
+// https://crbug.com/436280 and https://crbug.com/484504 |
+const int kDelayTime = 5; // 5 seconds for scanning and discovering |
+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 +53,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 +62,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 +129,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 |
scheib
2015/05/28 23:09:16
TODO: Check if device_instance_id is in "allowed d
ortuno
2015/05/29 17:53:54
Done.
|
+ // 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. |
scheib
2015/05/28 23:09:16
s/wait two seconds/wait a fixed time/. The constan
ortuno
2015/05/29 17:53:54
Done.
|
+ // 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 +159,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 +238,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)); |
scheib
2015/05/28 23:09:16
We should get the error messages returning error s
ortuno
2015/05/29 17:53:54
Ack.
|
+ 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->GetIdentifier(), |
+ service->GetUUID().canonical_value())); |
+ return; |
+ } |
+ } |
+ Send(new BluetoothMsg_GetPrimaryServiceError(thread_id, request_id, |
+ BluetoothError::NOT_FOUND)); |
+} |
+ |
} // namespace content |