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

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

Issue 2606823002: Remove base::ScopedPtrHashMap from device/. (Closed)
Patch Set: one last fix 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
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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 void BluetoothAdapterAndroid::CreateOrUpdateDeviceOnScan( 176 void BluetoothAdapterAndroid::CreateOrUpdateDeviceOnScan(
177 JNIEnv* env, 177 JNIEnv* env,
178 const JavaParamRef<jobject>& caller, 178 const JavaParamRef<jobject>& caller,
179 const JavaParamRef<jstring>& address, 179 const JavaParamRef<jstring>& address,
180 const JavaParamRef<jobject>& 180 const JavaParamRef<jobject>&
181 bluetooth_device_wrapper, // Java Type: bluetoothDeviceWrapper 181 bluetooth_device_wrapper, // Java Type: bluetoothDeviceWrapper
182 int32_t rssi, 182 int32_t rssi,
183 const JavaParamRef<jobjectArray>& advertised_uuids, // Java Type: String[] 183 const JavaParamRef<jobjectArray>& advertised_uuids, // Java Type: String[]
184 int32_t tx_power) { 184 int32_t tx_power) {
185 std::string device_address = ConvertJavaStringToUTF8(env, address); 185 std::string device_address = ConvertJavaStringToUTF8(env, address);
186 DevicesMap::const_iterator iter = devices_.find(device_address); 186 auto iter = devices_.find(device_address);
187 187
188 bool is_new_device = false; 188 bool is_new_device = false;
189 std::unique_ptr<BluetoothDeviceAndroid> device_android_owner; 189 std::unique_ptr<BluetoothDeviceAndroid> device_android_owner;
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 devices_[device_address] = std::move(device_android_owner);
223 for (auto& observer : observers_) 223 for (auto& observer : observers_)
224 observer.DeviceAdded(this, device_android); 224 observer.DeviceAdded(this, device_android);
225 } else { 225 } else {
226 for (auto& observer : observers_) 226 for (auto& observer : observers_)
227 observer.DeviceChanged(this, device_android); 227 observer.DeviceChanged(this, device_android);
228 } 228 }
229 } 229 }
230 230
231 BluetoothAdapterAndroid::BluetoothAdapterAndroid() : weak_ptr_factory_(this) { 231 BluetoothAdapterAndroid::BluetoothAdapterAndroid() : weak_ptr_factory_(this) {
232 } 232 }
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 // TODO(scheib): Support filters crbug.com/490401 325 // TODO(scheib): Support filters crbug.com/490401
326 NOTIMPLEMENTED(); 326 NOTIMPLEMENTED();
327 error_callback.Run(UMABluetoothDiscoverySessionOutcome::NOT_IMPLEMENTED); 327 error_callback.Run(UMABluetoothDiscoverySessionOutcome::NOT_IMPLEMENTED);
328 } 328 }
329 329
330 void BluetoothAdapterAndroid::RemovePairingDelegateInternal( 330 void BluetoothAdapterAndroid::RemovePairingDelegateInternal(
331 device::BluetoothDevice::PairingDelegate* pairing_delegate) { 331 device::BluetoothDevice::PairingDelegate* pairing_delegate) {
332 } 332 }
333 333
334 } // namespace device 334 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698