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

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

Issue 2567903004: Replace ScopedVector/ScopedPtrHashMap with std::vector and std::unordered_map (Closed)
Patch Set: Replace ScopedVector/ScopedPtrHashMap with std::vector and std::unordered_map Created 4 years 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "device/bluetooth/bluetooth_adapter_android.h" 5 #include "device/bluetooth/bluetooth_adapter_android.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_array.h" 10 #include "base/android/jni_array.h"
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 BluetoothDeviceAndroid* device_android; 190 BluetoothDeviceAndroid* device_android;
191 191
192 if (iter == devices_.end()) { 192 if (iter == devices_.end()) {
193 // New device. 193 // New device.
194 is_new_device = true; 194 is_new_device = true;
195 device_android_owner.reset( 195 device_android_owner.reset(
196 BluetoothDeviceAndroid::Create(this, bluetooth_device_wrapper)); 196 BluetoothDeviceAndroid::Create(this, bluetooth_device_wrapper));
197 device_android = device_android_owner.get(); 197 device_android = device_android_owner.get();
198 } else { 198 } else {
199 // Existing device. 199 // Existing device.
200 device_android = static_cast<BluetoothDeviceAndroid*>(iter->second); 200 device_android = static_cast<BluetoothDeviceAndroid*>(iter->second.get());
201 } 201 }
202 DCHECK(device_android); 202 DCHECK(device_android);
203 203
204 std::vector<std::string> advertised_uuids_strings; 204 std::vector<std::string> advertised_uuids_strings;
205 AppendJavaStringArrayToStringVector(env, advertised_uuids, 205 AppendJavaStringArrayToStringVector(env, advertised_uuids,
206 &advertised_uuids_strings); 206 &advertised_uuids_strings);
207 BluetoothDevice::UUIDList advertised_bluetooth_uuids; 207 BluetoothDevice::UUIDList advertised_bluetooth_uuids;
208 for (std::string& uuid : advertised_uuids_strings) { 208 for (std::string& uuid : advertised_uuids_strings) {
209 advertised_bluetooth_uuids.push_back(BluetoothUUID(std::move(uuid))); 209 advertised_bluetooth_uuids.push_back(BluetoothUUID(std::move(uuid)));
210 } 210 }
211 211
212 int8_t clamped_tx_power = BluetoothDevice::ClampPower(tx_power); 212 int8_t clamped_tx_power = BluetoothDevice::ClampPower(tx_power);
213 213
214 device_android->UpdateAdvertisementData( 214 device_android->UpdateAdvertisementData(
215 BluetoothDevice::ClampPower(rssi), std::move(advertised_bluetooth_uuids), 215 BluetoothDevice::ClampPower(rssi), std::move(advertised_bluetooth_uuids),
216 {} /* service_data */, 216 {} /* service_data */,
217 // Android uses INT32_MIN to indicate no Advertised Tx Power. 217 // Android uses INT32_MIN to indicate no Advertised Tx Power.
218 // https://developer.android.com/reference/android/bluetooth/le/ScanRecord .html#getTxPowerLevel() 218 // https://developer.android.com/reference/android/bluetooth/le/ScanRecord .html#getTxPowerLevel()
219 tx_power == INT32_MIN ? nullptr : &clamped_tx_power); 219 tx_power == INT32_MIN ? nullptr : &clamped_tx_power);
220 220
221 if (is_new_device) { 221 if (is_new_device) {
222 devices_.add(device_address, std::move(device_android_owner)); 222 auto insertion = devices_.insert(
223 std::make_pair(device_address, std::move(device_android_owner)));
224 if (!insertion.second) {
225 VLOG(1) << "Insertion of device failed.";
226 }
Reilly Grant (use Gerrit) 2016/12/21 22:25:13 I would make the loop below contingent on insertio
dougt 2016/12/22 01:18:02 Done.
223 for (auto& observer : observers_) 227 for (auto& observer : observers_)
224 observer.DeviceAdded(this, device_android); 228 observer.DeviceAdded(this, insertion.first->second.get());
225 } else { 229 } else {
226 for (auto& observer : observers_) 230 for (auto& observer : observers_)
227 observer.DeviceChanged(this, device_android); 231 observer.DeviceChanged(this, device_android);
228 } 232 }
229 } 233 }
230 234
231 BluetoothAdapterAndroid::BluetoothAdapterAndroid() : weak_ptr_factory_(this) { 235 BluetoothAdapterAndroid::BluetoothAdapterAndroid() : weak_ptr_factory_(this) {
232 } 236 }
233 237
234 BluetoothAdapterAndroid::~BluetoothAdapterAndroid() { 238 BluetoothAdapterAndroid::~BluetoothAdapterAndroid() {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 // TODO(scheib): Support filters crbug.com/490401 329 // TODO(scheib): Support filters crbug.com/490401
326 NOTIMPLEMENTED(); 330 NOTIMPLEMENTED();
327 error_callback.Run(UMABluetoothDiscoverySessionOutcome::NOT_IMPLEMENTED); 331 error_callback.Run(UMABluetoothDiscoverySessionOutcome::NOT_IMPLEMENTED);
328 } 332 }
329 333
330 void BluetoothAdapterAndroid::RemovePairingDelegateInternal( 334 void BluetoothAdapterAndroid::RemovePairingDelegateInternal(
331 device::BluetoothDevice::PairingDelegate* pairing_delegate) { 335 device::BluetoothDevice::PairingDelegate* pairing_delegate) {
332 } 336 }
333 337
334 } // namespace device 338 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698