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

Unified Diff: device/bluetooth/device.cc

Issue 2404623002: bluetooth: Add DeviceChanged logging in Device service. (Closed)
Patch Set: Split JS into functions Created 4 years, 2 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/device.cc
diff --git a/device/bluetooth/device.cc b/device/bluetooth/device.cc
index 6ebc34cc6b496be69a284ca730ee03d399590dcd..0fe6b686f0d45c8ea3d05528396953a1d10acd58 100644
--- a/device/bluetooth/device.cc
+++ b/device/bluetooth/device.cc
@@ -12,9 +12,14 @@ namespace bluetooth {
Device::Device(const std::string& address,
scoped_refptr<device::BluetoothAdapter> adapter)
- : address_(address), adapter_(std::move(adapter)) {}
+ : address_(address), adapter_(std::move(adapter)) {
+ adapter_->AddObserver(this);
+}
-Device::~Device() {}
+Device::~Device() {
+ adapter_->RemoveObserver(this);
+ adapter_ = nullptr;
+}
// static
mojom::DeviceInfoPtr Device::ConstructDeviceInfoStruct(
@@ -29,6 +34,17 @@ mojom::DeviceInfoPtr Device::ConstructDeviceInfoStruct(
return device_info;
}
+void Device::DeviceChanged(device::BluetoothAdapter* adapter,
+ device::BluetoothDevice* device) {
+ if (client_ && device->GetAddress() == address_) {
+ mojom::AdvertisingPacketPtr packet = mojom::AdvertisingPacket::New();
+ packet->timestamp = base::Time::Now().ToJavaTime();
+ packet->rssi = device->GetInquiryRSSI().value_or(0);
+ packet->device = ConstructDeviceInfoStruct(device);
+ client_->DeviceChanged(std::move(packet));
+ }
+}
+
void Device::GetInfo(const GetInfoCallback& callback) {
device::BluetoothDevice* device = adapter_->GetDevice(address_);
if (device) {
@@ -39,4 +55,8 @@ void Device::GetInfo(const GetInfoCallback& callback) {
}
}
+void Device::SetClient(mojom::GattClientPtr client) {
+ client_ = std::move(client);
+}
+
} // namespace bluetooth

Powered by Google App Engine
This is Rietveld 408576698