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

Unified Diff: chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.cc

Issue 1984723006: Add implementation for parsing device info in read/write attribute calls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@devices_dbus_readwrite
Patch Set: Created 4 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
« no previous file with comments | « no previous file | device/bluetooth/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.cc
diff --git a/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.cc b/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.cc
index 8cbe640939cd07196a261343d6fb3f27af4eab84..9159c5c2daf43ec588341d2ee1ff707e2c721848 100644
--- a/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.cc
+++ b/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.h"
+#include <algorithm>
#include <iterator>
#include <utility>
@@ -12,6 +13,8 @@
#include "base/containers/hash_tables.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
+#include "base/strings/utf_string_conversions.h"
+#include "base/values.h"
#include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_connection.h"
#include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_notify_session.h"
#include "chrome/browser/extensions/api/bluetooth_low_energy/utils.h"
@@ -27,6 +30,7 @@
#include "extensions/browser/api/api_resource_manager.h"
#include "extensions/browser/event_listener_map.h"
#include "extensions/browser/event_router.h"
+#include "extensions/browser/extension_registry.h"
#include "extensions/common/api/bluetooth/bluetooth_manifest_data.h"
#include "extensions/common/extension.h"
@@ -139,6 +143,16 @@ void PopulateDescriptor(const BluetoothRemoteGattDescriptor* descriptor,
out->value.reset(new std::vector<char>(value.begin(), value.end()));
}
+void PopulateDevice(const device::BluetoothDevice* device,
+ apibtle::Request* request) {
+ if (!device)
+ return;
+ request->device.address = device->GetAddress();
+ request->device.name.reset(
+ new std::string(base::UTF16ToUTF8(device->GetName())));
+ request->device.device_class.reset(new int(device->GetBluetoothClass()));
+}
+
typedef extensions::ApiResourceManager<extensions::BluetoothLowEnergyConnection>
ConnectionResourceManager;
ConnectionResourceManager* GetConnectionResourceManager(
@@ -1109,6 +1123,7 @@ void BluetoothLowEnergyEventRouter::OnCharacteristicReadRequest(
request.request_id =
StoreSentRequest(extension_id, base::WrapUnique(new AttributeValueRequest(
value_callback, error_callback)));
+ PopulateDevice(device, &request);
DispatchEventToExtension(
extension_id, events::BLUETOOTH_LOW_ENERGY_ON_CHARACTERISTIC_READ_REQUEST,
apibtle::OnCharacteristicReadRequest::kEventName,
@@ -1139,6 +1154,7 @@ void BluetoothLowEnergyEventRouter::OnCharacteristicWriteRequest(
base::WrapUnique(new AttributeValueRequest(callback, error_callback)));
request.value =
base::WrapUnique(new std::vector<char>(value.begin(), value.end()));
+ PopulateDevice(device, &request);
DispatchEventToExtension(
extension_id,
events::BLUETOOTH_LOW_ENERGY_ON_CHARACTERISTIC_WRITE_REQUEST,
@@ -1168,6 +1184,7 @@ void BluetoothLowEnergyEventRouter::OnDescriptorReadRequest(
request.request_id =
StoreSentRequest(extension_id, base::WrapUnique(new AttributeValueRequest(
value_callback, error_callback)));
+ PopulateDevice(device, &request);
DispatchEventToExtension(
extension_id,
events::BLUETOOTH_LOW_ENERGY_ON_CHARACTERISTIC_WRITE_REQUEST,
@@ -1200,6 +1217,7 @@ void BluetoothLowEnergyEventRouter::OnDescriptorWriteRequest(
base::WrapUnique(new AttributeValueRequest(callback, error_callback)));
request.value =
base::WrapUnique(new std::vector<char>(value.begin(), value.end()));
+ PopulateDevice(device, &request);
DispatchEventToExtension(
extension_id,
events::BLUETOOTH_LOW_ENERGY_ON_CHARACTERISTIC_WRITE_REQUEST,
« no previous file with comments | « no previous file | device/bluetooth/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698