OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 #include <utility> | 6 #include <utility> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "device/bluetooth/adapter.h" | 11 #include "device/bluetooth/adapter.h" |
12 #include "mojo/public/cpp/bindings/string.h" | 12 #include "mojo/public/cpp/bindings/string.h" |
13 #include "mojo/public/cpp/bindings/strong_binding.h" | 13 #include "mojo/public/cpp/bindings/strong_binding.h" |
14 | 14 |
15 namespace bluetooth { | 15 namespace bluetooth { |
16 | 16 |
17 Adapter::Adapter(scoped_refptr<device::BluetoothAdapter> adapter) | 17 Adapter::Adapter(scoped_refptr<device::BluetoothAdapter> adapter) |
18 : adapter_(std::move(adapter)), client_(nullptr), weak_ptr_factory_(this) { | 18 : adapter_(std::move(adapter)), client_(nullptr), weak_ptr_factory_(this) { |
19 adapter_->AddObserver(this); | 19 adapter_->AddObserver(this); |
20 } | 20 } |
21 | 21 |
22 Adapter::~Adapter() { | 22 Adapter::~Adapter() { |
23 adapter_->RemoveObserver(this); | 23 adapter_->RemoveObserver(this); |
24 adapter_ = nullptr; | 24 adapter_ = nullptr; |
25 } | 25 } |
26 | 26 |
| 27 void Adapter::GetInfo(const GetInfoCallback& callback) { |
| 28 mojom::AdapterInfoPtr adapter_info = mojom::AdapterInfo::New(); |
| 29 adapter_info->address = adapter_->GetAddress(); |
| 30 adapter_info->name = adapter_->GetName(); |
| 31 adapter_info->initialized = adapter_->IsInitialized(); |
| 32 adapter_info->present = adapter_->IsPresent(); |
| 33 adapter_info->powered = adapter_->IsPowered(); |
| 34 adapter_info->discoverable = adapter_->IsDiscoverable(); |
| 35 adapter_info->discovering = adapter_->IsDiscovering(); |
| 36 callback.Run(std::move(adapter_info)); |
| 37 } |
| 38 |
27 void Adapter::GetDevices(const GetDevicesCallback& callback) { | 39 void Adapter::GetDevices(const GetDevicesCallback& callback) { |
28 std::vector<mojom::DeviceInfoPtr> devices; | 40 std::vector<mojom::DeviceInfoPtr> devices; |
29 | 41 |
30 for (const device::BluetoothDevice* device : adapter_->GetDevices()) { | 42 for (const device::BluetoothDevice* device : adapter_->GetDevices()) { |
31 mojom::DeviceInfoPtr device_info = ConstructDeviceInfoStruct(device); | 43 mojom::DeviceInfoPtr device_info = ConstructDeviceInfoStruct(device); |
32 devices.push_back(std::move(device_info)); | 44 devices.push_back(std::move(device_info)); |
33 } | 45 } |
34 | 46 |
35 callback.Run(std::move(devices)); | 47 callback.Run(std::move(devices)); |
36 } | 48 } |
(...skipping 26 matching lines...) Expand all Loading... |
63 device_info->name = device->GetName(); | 75 device_info->name = device->GetName(); |
64 device_info->name_for_display = | 76 device_info->name_for_display = |
65 base::UTF16ToUTF8(device->GetNameForDisplay()); | 77 base::UTF16ToUTF8(device->GetNameForDisplay()); |
66 device_info->id = device->GetIdentifier(); | 78 device_info->id = device->GetIdentifier(); |
67 device_info->address = device->GetAddress(); | 79 device_info->address = device->GetAddress(); |
68 | 80 |
69 return device_info; | 81 return device_info; |
70 } | 82 } |
71 | 83 |
72 } // namespace bluetooth | 84 } // namespace bluetooth |
OLD | NEW |