OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_remote_gatt_service_android.h" | 5 #include "device/bluetooth/bluetooth_remote_gatt_service_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_string.h" | 10 #include "base/android/jni_string.h" |
| 11 #include "base/stl_util.h" |
11 #include "device/bluetooth/bluetooth_adapter_android.h" | 12 #include "device/bluetooth/bluetooth_adapter_android.h" |
12 #include "device/bluetooth/bluetooth_device_android.h" | 13 #include "device/bluetooth/bluetooth_device_android.h" |
13 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_android.h" | 14 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_android.h" |
14 #include "jni/ChromeBluetoothRemoteGattService_jni.h" | 15 #include "jni/ChromeBluetoothRemoteGattService_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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 JNIEnv* env, | 160 JNIEnv* env, |
160 const JavaParamRef<jobject>& caller, | 161 const JavaParamRef<jobject>& caller, |
161 const JavaParamRef<jstring>& instance_id, | 162 const JavaParamRef<jstring>& instance_id, |
162 const JavaParamRef<jobject>& /* BluetoothGattCharacteristicWrapper */ | 163 const JavaParamRef<jobject>& /* BluetoothGattCharacteristicWrapper */ |
163 bluetooth_gatt_characteristic_wrapper, | 164 bluetooth_gatt_characteristic_wrapper, |
164 const JavaParamRef< | 165 const JavaParamRef< |
165 jobject>& /* ChromeBluetoothDevice */ chrome_bluetooth_device) { | 166 jobject>& /* ChromeBluetoothDevice */ chrome_bluetooth_device) { |
166 std::string instance_id_string = | 167 std::string instance_id_string = |
167 base::android::ConvertJavaStringToUTF8(env, instance_id); | 168 base::android::ConvertJavaStringToUTF8(env, instance_id); |
168 | 169 |
169 DCHECK(characteristics_.find(instance_id_string) == characteristics_.end()); | 170 DCHECK(!base::ContainsKey(characteristics_, instance_id_string)); |
170 | 171 |
171 characteristics_[instance_id_string] = | 172 characteristics_[instance_id_string] = |
172 BluetoothRemoteGattCharacteristicAndroid::Create( | 173 BluetoothRemoteGattCharacteristicAndroid::Create( |
173 adapter_, this, instance_id_string, | 174 adapter_, this, instance_id_string, |
174 bluetooth_gatt_characteristic_wrapper, chrome_bluetooth_device); | 175 bluetooth_gatt_characteristic_wrapper, chrome_bluetooth_device); |
175 } | 176 } |
176 | 177 |
177 BluetoothRemoteGattServiceAndroid::BluetoothRemoteGattServiceAndroid( | 178 BluetoothRemoteGattServiceAndroid::BluetoothRemoteGattServiceAndroid( |
178 BluetoothAdapterAndroid* adapter, | 179 BluetoothAdapterAndroid* adapter, |
179 BluetoothDeviceAndroid* device, | 180 BluetoothDeviceAndroid* device, |
180 const std::string& instance_id) | 181 const std::string& instance_id) |
181 : adapter_(adapter), device_(device), instance_id_(instance_id) {} | 182 : adapter_(adapter), device_(device), instance_id_(instance_id) {} |
182 | 183 |
183 void BluetoothRemoteGattServiceAndroid::EnsureCharacteristicsCreated() const { | 184 void BluetoothRemoteGattServiceAndroid::EnsureCharacteristicsCreated() const { |
184 if (!characteristics_.empty()) | 185 if (!characteristics_.empty()) |
185 return; | 186 return; |
186 | 187 |
187 // Java call | 188 // Java call |
188 Java_ChromeBluetoothRemoteGattService_createCharacteristics( | 189 Java_ChromeBluetoothRemoteGattService_createCharacteristics( |
189 AttachCurrentThread(), j_service_); | 190 AttachCurrentThread(), j_service_); |
190 } | 191 } |
191 | 192 |
192 } // namespace device | 193 } // namespace device |
OLD | NEW |