OLD | NEW |
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_device_android.h" | 5 #include "device/bluetooth/bluetooth_device_android.h" |
6 | 6 |
7 #include "base/android/context_utils.h" | 7 #include "base/android/context_utils.h" |
8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/stl_util.h" |
11 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
12 #include "device/bluetooth/bluetooth_adapter_android.h" | 13 #include "device/bluetooth/bluetooth_adapter_android.h" |
13 #include "device/bluetooth/bluetooth_remote_gatt_service_android.h" | 14 #include "device/bluetooth/bluetooth_remote_gatt_service_android.h" |
14 #include "jni/ChromeBluetoothDevice_jni.h" | 15 #include "jni/ChromeBluetoothDevice_jni.h" |
15 | 16 |
16 using base::android::AttachCurrentThread; | 17 using base::android::AttachCurrentThread; |
17 using base::android::JavaParamRef; | 18 using base::android::JavaParamRef; |
18 using base::android::JavaRef; | 19 using base::android::JavaRef; |
19 | 20 |
20 namespace device { | 21 namespace device { |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 | 240 |
240 void BluetoothDeviceAndroid::CreateGattRemoteService( | 241 void BluetoothDeviceAndroid::CreateGattRemoteService( |
241 JNIEnv* env, | 242 JNIEnv* env, |
242 const JavaParamRef<jobject>& caller, | 243 const JavaParamRef<jobject>& caller, |
243 const JavaParamRef<jstring>& instance_id, | 244 const JavaParamRef<jstring>& instance_id, |
244 const JavaParamRef<jobject>& | 245 const JavaParamRef<jobject>& |
245 bluetooth_gatt_service_wrapper) { // BluetoothGattServiceWrapper | 246 bluetooth_gatt_service_wrapper) { // BluetoothGattServiceWrapper |
246 std::string instance_id_string = | 247 std::string instance_id_string = |
247 base::android::ConvertJavaStringToUTF8(env, instance_id); | 248 base::android::ConvertJavaStringToUTF8(env, instance_id); |
248 | 249 |
249 if (gatt_services_.find(instance_id_string) != gatt_services_.end()) | 250 if (base::ContainsKey(gatt_services_, instance_id_string)) |
250 return; | 251 return; |
251 | 252 |
252 std::unique_ptr<BluetoothRemoteGattServiceAndroid> service = | 253 std::unique_ptr<BluetoothRemoteGattServiceAndroid> service = |
253 BluetoothRemoteGattServiceAndroid::Create(GetAndroidAdapter(), this, | 254 BluetoothRemoteGattServiceAndroid::Create(GetAndroidAdapter(), this, |
254 bluetooth_gatt_service_wrapper, | 255 bluetooth_gatt_service_wrapper, |
255 instance_id_string, j_device_); | 256 instance_id_string, j_device_); |
256 BluetoothRemoteGattServiceAndroid* service_ptr = service.get(); | 257 BluetoothRemoteGattServiceAndroid* service_ptr = service.get(); |
257 gatt_services_[instance_id_string] = std::move(service); | 258 gatt_services_[instance_id_string] = std::move(service); |
258 | 259 |
259 adapter_->NotifyGattServiceAdded(service_ptr); | 260 adapter_->NotifyGattServiceAdded(service_ptr); |
260 } | 261 } |
261 | 262 |
262 BluetoothDeviceAndroid::BluetoothDeviceAndroid(BluetoothAdapterAndroid* adapter) | 263 BluetoothDeviceAndroid::BluetoothDeviceAndroid(BluetoothAdapterAndroid* adapter) |
263 : BluetoothDevice(adapter) {} | 264 : BluetoothDevice(adapter) {} |
264 | 265 |
265 void BluetoothDeviceAndroid::CreateGattConnectionImpl() { | 266 void BluetoothDeviceAndroid::CreateGattConnectionImpl() { |
266 Java_ChromeBluetoothDevice_createGattConnectionImpl( | 267 Java_ChromeBluetoothDevice_createGattConnectionImpl( |
267 AttachCurrentThread(), j_device_, base::android::GetApplicationContext()); | 268 AttachCurrentThread(), j_device_, base::android::GetApplicationContext()); |
268 } | 269 } |
269 | 270 |
270 void BluetoothDeviceAndroid::DisconnectGatt() { | 271 void BluetoothDeviceAndroid::DisconnectGatt() { |
271 Java_ChromeBluetoothDevice_disconnectGatt(AttachCurrentThread(), j_device_); | 272 Java_ChromeBluetoothDevice_disconnectGatt(AttachCurrentThread(), j_device_); |
272 } | 273 } |
273 | 274 |
274 } // namespace device | 275 } // namespace device |
OLD | NEW |