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

Side by Side Diff: device/bluetooth/device.cc

Issue 2622393002: bluetooth: Add characteristic list to DeviceDetailsPage in internals page. (Closed)
Patch Set: Simplifications Created 3 years, 11 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 unified diff | Download patch
« no previous file with comments | « device/bluetooth/device.h ('k') | device/bluetooth/device_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <utility> 5 #include <utility>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "device/bluetooth/device.h" 10 #include "device/bluetooth/device.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 GetServicesImpl(callback); 88 GetServicesImpl(callback);
89 return; 89 return;
90 } 90 }
91 91
92 // pending_services_requests_ is owned by Device, so base::Unretained is 92 // pending_services_requests_ is owned by Device, so base::Unretained is
93 // safe. 93 // safe.
94 pending_services_requests_.push_back( 94 pending_services_requests_.push_back(
95 base::Bind(&Device::GetServicesImpl, base::Unretained(this), callback)); 95 base::Bind(&Device::GetServicesImpl, base::Unretained(this), callback));
96 } 96 }
97 97
98 void Device::GetCharacteristics(const std::string& service_id,
99 const GetCharacteristicsCallback& callback) {
100 device::BluetoothDevice* device = adapter_->GetDevice(GetAddress());
101 DCHECK(device);
102
103 if (device->IsGattServicesDiscoveryComplete()) {
104 GetCharacteristicsImpl(service_id, callback);
105 return;
106 }
107
108 // pending_services_requests_ is owned by Device, so base::Unretained is
109 // safe.
110 pending_services_requests_.push_back(
111 base::Bind(&Device::GetCharacteristicsImpl, base::Unretained(this),
112 service_id, callback));
113 }
114
98 Device::Device(scoped_refptr<device::BluetoothAdapter> adapter, 115 Device::Device(scoped_refptr<device::BluetoothAdapter> adapter,
99 std::unique_ptr<device::BluetoothGattConnection> connection) 116 std::unique_ptr<device::BluetoothGattConnection> connection)
100 : adapter_(std::move(adapter)), connection_(std::move(connection)) { 117 : adapter_(std::move(adapter)), connection_(std::move(connection)) {
101 adapter_->AddObserver(this); 118 adapter_->AddObserver(this);
102 } 119 }
103 120
104 void Device::GetServicesImpl(const GetServicesCallback& callback) { 121 void Device::GetServicesImpl(const GetServicesCallback& callback) {
105 device::BluetoothDevice* device = adapter_->GetDevice(GetAddress()); 122 device::BluetoothDevice* device = adapter_->GetDevice(GetAddress());
106 DCHECK(device); 123 DCHECK(device);
107 124
(...skipping 11 matching lines...) Expand all
119 const device::BluetoothRemoteGattService& service) { 136 const device::BluetoothRemoteGattService& service) {
120 mojom::ServiceInfoPtr service_info = mojom::ServiceInfo::New(); 137 mojom::ServiceInfoPtr service_info = mojom::ServiceInfo::New();
121 138
122 service_info->id = service.GetIdentifier(); 139 service_info->id = service.GetIdentifier();
123 service_info->uuid = service.GetUUID(); 140 service_info->uuid = service.GetUUID();
124 service_info->is_primary = service.IsPrimary(); 141 service_info->is_primary = service.IsPrimary();
125 142
126 return service_info; 143 return service_info;
127 } 144 }
128 145
146 void Device::GetCharacteristicsImpl(
147 const std::string& service_id,
148 const GetCharacteristicsCallback& callback) {
149 device::BluetoothDevice* device = adapter_->GetDevice(GetAddress());
150 DCHECK(device);
151 device::BluetoothRemoteGattService* service =
152 device->GetGattService(service_id);
153 DCHECK(service);
154
155 std::vector<mojom::CharacteristicInfoPtr> characteristics;
156
157 for (const auto* characteristic : service->GetCharacteristics()) {
158 mojom::CharacteristicInfoPtr characteristic_info =
159 mojom::CharacteristicInfo::New();
160
161 characteristic_info->id = characteristic->GetIdentifier();
162 characteristic_info->uuid = characteristic->GetUUID();
163 characteristic_info->properties = characteristic->GetProperties();
164
165 characteristics.push_back(std::move(characteristic_info));
166 }
167
168 callback.Run(std::move(characteristics));
169 }
170
129 const std::string& Device::GetAddress() { 171 const std::string& Device::GetAddress() {
130 return connection_->GetDeviceAddress(); 172 return connection_->GetDeviceAddress();
131 } 173 }
132 174
133 } // namespace bluetooth 175 } // namespace bluetooth
OLDNEW
« no previous file with comments | « device/bluetooth/device.h ('k') | device/bluetooth/device_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698