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

Unified Diff: content/browser/bluetooth/bluetooth_dispatcher_host.cc

Issue 1156573005: bluetooth: Browser-side implementation of getCharacteristic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-get-primary-service-initial
Patch Set: Add return to BadMessage Created 5 years, 7 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: 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 c11c203b13ee8b60fef83d7ab6a95605b04b30db..768ca95dde27cd7cab941aba9e992b28dc050094 100644
--- a/content/browser/bluetooth/bluetooth_dispatcher_host.cc
+++ b/content/browser/bluetooth/bluetooth_dispatcher_host.cc
@@ -10,10 +10,12 @@
#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_characteristic.h"
#include "device/bluetooth/bluetooth_gatt_service.h"
using device::BluetoothAdapter;
using device::BluetoothAdapterFactory;
+using device::BluetoothGattCharacteristic;
using device::BluetoothGattService;
namespace content {
@@ -54,6 +56,7 @@ bool BluetoothDispatcherHost::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(BluetoothHostMsg_RequestDevice, OnRequestDevice)
IPC_MESSAGE_HANDLER(BluetoothHostMsg_ConnectGATT, OnConnectGATT)
IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetPrimaryService, OnGetPrimaryService)
+ IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetCharacteristic, OnGetCharacteristic)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
@@ -149,6 +152,57 @@ void BluetoothDispatcherHost::OnGetPrimaryService(
base::TimeDelta::FromSeconds(current_delay_time_));
}
+void BluetoothDispatcherHost::OnGetCharacteristic(
+ int thread_id,
+ int request_id,
+ const std::string& service_instance_id,
+ const std::string& characteristic_uuid) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+
+ // There are no cases in which a normal renderer could pass
+ // a service_instance_id not in our map so we can assume
+ // the renderer is hostile.
+ auto device_iter = service_to_device_.find(service_instance_id);
+ if (device_iter == service_to_device_.end()) {
+ BadMessageReceived(); // Kill the renderer.
+ return;
+ }
+
+ // TODO(ortuno): Check if domain has access to device.
+ // https://crbug.com/493459
+ device::BluetoothDevice* device =
+ adapter_->GetDevice(service_to_device_[service_instance_id]);
Jeffrey Yasskin 2015/06/03 22:56:24 Since you've looked up the iterator above, just us
ortuno 2015/06/03 23:26:56 Done.
+
+ if (device == NULL) {
+ Send(new BluetoothMsg_GetCharacteristicError(
+ thread_id, request_id, BluetoothError::NETWORK_ERROR));
+ return;
+ }
+
+ // TODO(ortuno): Check if domain has access to service
+ // http://crbug.com/493460
+ device::BluetoothGattService* service =
+ device->GetGattService(service_instance_id);
+ if (!service) {
+ Send(new BluetoothMsg_GetCharacteristicError(
+ thread_id, request_id, BluetoothError::NETWORK_ERROR));
+ return;
+ }
+
+ for (BluetoothGattCharacteristic* characteristic :
+ service->GetCharacteristics()) {
+ if (characteristic->GetUUID().canonical_value() == characteristic_uuid) {
+ // TODO(ortuno): Use generated instance ID instead.
+ // https://crbug.com/495379
+ Send(new BluetoothMsg_GetCharacteristicSuccess(
+ thread_id, request_id, characteristic->GetIdentifier()));
+ return;
+ }
+ }
+ Send(new BluetoothMsg_GetCharacteristicError(thread_id, request_id,
+ BluetoothError::NOT_FOUND));
+}
+
void BluetoothDispatcherHost::OnDiscoverySessionStarted(
int thread_id,
int request_id,
@@ -253,8 +307,13 @@ void BluetoothDispatcherHost::OnServicesDiscovered(
}
for (BluetoothGattService* service : device->GetGattServices()) {
if (service->GetUUID().canonical_value() == service_uuid) {
+ // TODO(ortuno): Use generated instance ID instead.
+ // https://crbug.com/495379
+ const std::string& service_identifier = service->GetIdentifier();
+ service_to_device_.insert(
+ make_pair(service_identifier, device_instance_id));
Send(new BluetoothMsg_GetPrimaryServiceSuccess(thread_id, request_id,
- service->GetIdentifier()));
+ service_identifier));
return;
}
}
« no previous file with comments | « content/browser/bluetooth/bluetooth_dispatcher_host.h ('k') | content/child/bluetooth/bluetooth_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698