Chromium Code Reviews| 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_remote_gatt_characteristic_android.h" | 5 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 base::android::ToJavaByteArray(env, new_value))) { | 158 base::android::ToJavaByteArray(env, new_value))) { |
| 159 base::ThreadTaskRunnerHandle::Get()->PostTask( | 159 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 160 FROM_HERE, base::Bind(error_callback, | 160 FROM_HERE, base::Bind(error_callback, |
| 161 BluetoothRemoteGattService::GATT_ERROR_FAILED)); | 161 BluetoothRemoteGattService::GATT_ERROR_FAILED)); |
| 162 return; | 162 return; |
| 163 } | 163 } |
| 164 | 164 |
| 165 write_pending_ = true; | 165 write_pending_ = true; |
| 166 write_callback_ = callback; | 166 write_callback_ = callback; |
| 167 write_error_callback_ = error_callback; | 167 write_error_callback_ = error_callback; |
| 168 write_value_ = new_value; | |
| 168 } | 169 } |
| 169 | 170 |
| 170 void BluetoothRemoteGattCharacteristicAndroid::OnChanged( | 171 void BluetoothRemoteGattCharacteristicAndroid::OnChanged( |
| 171 JNIEnv* env, | 172 JNIEnv* env, |
| 172 const JavaParamRef<jobject>& jcaller, | 173 const JavaParamRef<jobject>& jcaller, |
| 173 const JavaParamRef<jbyteArray>& value) { | 174 const JavaParamRef<jbyteArray>& value) { |
| 174 base::android::JavaByteArrayToByteVector(env, value, &value_); | 175 base::android::JavaByteArrayToByteVector(env, value, &value_); |
| 175 adapter_->NotifyGattCharacteristicValueChanged(this, value_); | 176 adapter_->NotifyGattCharacteristicValueChanged(this, value_); |
| 176 } | 177 } |
| 177 | 178 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 206 write_pending_ = false; | 207 write_pending_ = false; |
| 207 | 208 |
| 208 // Clear callbacks before calling to avoid reentrancy issues. | 209 // Clear callbacks before calling to avoid reentrancy issues. |
| 209 base::Closure write_callback = write_callback_; | 210 base::Closure write_callback = write_callback_; |
| 210 ErrorCallback write_error_callback = write_error_callback_; | 211 ErrorCallback write_error_callback = write_error_callback_; |
| 211 write_callback_.Reset(); | 212 write_callback_.Reset(); |
| 212 write_error_callback_.Reset(); | 213 write_error_callback_.Reset(); |
| 213 | 214 |
| 214 if (status == 0 // android.bluetooth.BluetoothGatt.GATT_SUCCESS | 215 if (status == 0 // android.bluetooth.BluetoothGatt.GATT_SUCCESS |
| 215 && !write_callback.is_null()) { | 216 && !write_callback.is_null()) { |
| 217 value_ = write_value_; | |
| 218 adapter_->NotifyGattCharacteristicValueChanged(this, value_); | |
|
ortuno
2016/08/29 16:02:53
I don't think we want to do this, see http://crbug
tommyt
2016/08/29 17:44:36
If we don't want to do this, what is the intention
ortuno
2016/08/29 18:05:23
I believe the first one is out of date. The patch
scheib
2016/08/29 22:36:39
I agree, let's not update the value cache. tommyt,
| |
| 216 write_callback.Run(); | 219 write_callback.Run(); |
| 217 // TODO(https://crbug.com/545682): Call GattCharacteristicValueChanged. | |
| 218 } else if (!write_error_callback.is_null()) { | 220 } else if (!write_error_callback.is_null()) { |
| 219 write_error_callback.Run( | 221 write_error_callback.Run( |
| 220 BluetoothRemoteGattServiceAndroid::GetGattErrorCode(status)); | 222 BluetoothRemoteGattServiceAndroid::GetGattErrorCode(status)); |
| 221 } | 223 } |
| 222 } | 224 } |
| 223 | 225 |
| 224 void BluetoothRemoteGattCharacteristicAndroid::CreateGattRemoteDescriptor( | 226 void BluetoothRemoteGattCharacteristicAndroid::CreateGattRemoteDescriptor( |
| 225 JNIEnv* env, | 227 JNIEnv* env, |
| 226 const JavaParamRef<jobject>& caller, | 228 const JavaParamRef<jobject>& caller, |
| 227 const JavaParamRef<jstring>& instanceId, | 229 const JavaParamRef<jstring>& instanceId, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 void BluetoothRemoteGattCharacteristicAndroid::EnsureDescriptorsCreated() | 292 void BluetoothRemoteGattCharacteristicAndroid::EnsureDescriptorsCreated() |
| 291 const { | 293 const { |
| 292 if (!descriptors_.empty()) | 294 if (!descriptors_.empty()) |
| 293 return; | 295 return; |
| 294 | 296 |
| 295 Java_ChromeBluetoothRemoteGattCharacteristic_createDescriptors( | 297 Java_ChromeBluetoothRemoteGattCharacteristic_createDescriptors( |
| 296 AttachCurrentThread(), j_characteristic_); | 298 AttachCurrentThread(), j_characteristic_); |
| 297 } | 299 } |
| 298 | 300 |
| 299 } // namespace device | 301 } // namespace device |
| OLD | NEW |