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

Unified Diff: device/bluetooth/adapter.cc

Issue 2401193002: bluetooth: Add Device service for chrome://bluetooth-internals. (Closed)
Patch Set: Add log function comment 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/adapter.cc
diff --git a/device/bluetooth/adapter.cc b/device/bluetooth/adapter.cc
index 1d0a25aaa3e9c025fbe734d88e760ba4c073152e..8737115803cd97bb68d8e80a79c8bb896ca7bd21 100644
--- a/device/bluetooth/adapter.cc
+++ b/device/bluetooth/adapter.cc
@@ -6,16 +6,15 @@
#include <utility>
#include <vector>
-#include "base/memory/ptr_util.h"
-#include "base/strings/utf_string_conversions.h"
#include "device/bluetooth/adapter.h"
-#include "mojo/public/cpp/bindings/string.h"
+#include "device/bluetooth/bluetooth_adapter_factory.h"
+#include "device/bluetooth/le_device.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
namespace bluetooth {
Adapter::Adapter(scoped_refptr<device::BluetoothAdapter> adapter)
- : adapter_(adapter), client_(nullptr), weak_ptr_factory_(this) {
+ : adapter_(std::move(adapter)), client_(nullptr), weak_ptr_factory_(this) {
adapter_->AddObserver(this);
}
@@ -36,11 +35,21 @@ void Adapter::GetInfo(const GetInfoCallback& callback) {
callback.Run(std::move(adapter_info));
}
+void Adapter::GetDeviceService(const std::string& address,
+ const GetDeviceServiceCallback& callback) {
+ mojom::LEDevicePtr device_ptr;
+ mojo::MakeStrongBinding(
+ base::MakeUnique<LEDevice>(address, std::move(adapter_)),
ortuno 2016/10/10 00:11:20 Any reason why you are using std::move here? std::
mbrunson 2016/10/10 19:21:28 You are right. This shouldn't be here.
+ mojo::GetProxy(&device_ptr));
+ callback.Run(std::move(device_ptr));
+}
+
void Adapter::GetDevices(const GetDevicesCallback& callback) {
- std::vector<mojom::DeviceInfoPtr> devices;
+ std::vector<mojom::LEDeviceInfoPtr> devices;
for (const device::BluetoothDevice* device : adapter_->GetDevices()) {
- mojom::DeviceInfoPtr device_info = ConstructDeviceInfoStruct(device);
+ mojom::LEDeviceInfoPtr device_info =
+ LEDevice::ConstructLEDeviceInfoStruct(device);
devices.push_back(std::move(device_info));
}
@@ -54,7 +63,7 @@ void Adapter::SetClient(mojom::AdapterClientPtr client) {
void Adapter::DeviceAdded(device::BluetoothAdapter* adapter,
device::BluetoothDevice* device) {
if (client_) {
- auto device_info = ConstructDeviceInfoStruct(device);
+ auto device_info = LEDevice::ConstructLEDeviceInfoStruct(device);
client_->DeviceAdded(std::move(device_info));
}
}
@@ -62,23 +71,9 @@ void Adapter::DeviceAdded(device::BluetoothAdapter* adapter,
void Adapter::DeviceRemoved(device::BluetoothAdapter* adapter,
device::BluetoothDevice* device) {
if (client_) {
- auto device_info = ConstructDeviceInfoStruct(device);
+ auto device_info = LEDevice::ConstructLEDeviceInfoStruct(device);
client_->DeviceRemoved(std::move(device_info));
}
}
-// static
-mojom::DeviceInfoPtr Adapter::ConstructDeviceInfoStruct(
- const device::BluetoothDevice* const device) {
- mojom::DeviceInfoPtr device_info = mojom::DeviceInfo::New();
-
- device_info->name = device->GetName();
- device_info->name_for_display =
- base::UTF16ToUTF8(device->GetNameForDisplay());
- device_info->id = device->GetIdentifier();
- device_info->address = device->GetAddress();
-
- return device_info;
-}
-
} // namespace bluetooth

Powered by Google App Engine
This is Rietveld 408576698