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

Unified Diff: device/bluetooth/device.cc

Issue 2401193002: bluetooth: Add Device service for chrome://bluetooth-internals. (Closed)
Patch Set: Fully qualify mojom import 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
« no previous file with comments | « device/bluetooth/device.h ('k') | device/bluetooth/public/interfaces/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/device.cc
diff --git a/device/bluetooth/device.cc b/device/bluetooth/device.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6ebc34cc6b496be69a284ca730ee03d399590dcd
--- /dev/null
+++ b/device/bluetooth/device.cc
@@ -0,0 +1,42 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <utility>
+
+#include "base/strings/utf_string_conversions.h"
+#include "device/bluetooth/device.h"
+#include "mojo/public/cpp/bindings/strong_binding.h"
+
+namespace bluetooth {
+
+Device::Device(const std::string& address,
+ scoped_refptr<device::BluetoothAdapter> adapter)
+ : address_(address), adapter_(std::move(adapter)) {}
+
+Device::~Device() {}
+
+// static
+mojom::DeviceInfoPtr Device::ConstructDeviceInfoStruct(
+ const device::BluetoothDevice* device) {
+ mojom::DeviceInfoPtr device_info = mojom::DeviceInfo::New();
+
+ device_info->name = device->GetName();
+ device_info->name_for_display =
+ base::UTF16ToUTF8(device->GetNameForDisplay());
+ device_info->address = device->GetAddress();
+
+ return device_info;
+}
+
+void Device::GetInfo(const GetInfoCallback& callback) {
+ device::BluetoothDevice* device = adapter_->GetDevice(address_);
+ if (device) {
+ mojom::DeviceInfoPtr device_info = ConstructDeviceInfoStruct(device);
+ callback.Run(std::move(device_info));
+ } else {
+ callback.Run(nullptr);
+ }
+}
+
+} // namespace bluetooth
« no previous file with comments | « device/bluetooth/device.h ('k') | device/bluetooth/public/interfaces/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698