Chromium Code Reviews| Index: device/bluetooth/bluetooth_remote_gatt_characteristic_android.cc |
| diff --git a/device/bluetooth/bluetooth_remote_gatt_characteristic_android.cc b/device/bluetooth/bluetooth_remote_gatt_characteristic_android.cc |
| index 152764465978a3d05075cbbf02857a63c463c299..483f37c6782f051c16db469078686c7e756820a5 100644 |
| --- a/device/bluetooth/bluetooth_remote_gatt_characteristic_android.cc |
| +++ b/device/bluetooth/bluetooth_remote_gatt_characteristic_android.cc |
| @@ -10,7 +10,9 @@ |
| #include "base/bind.h" |
| #include "base/logging.h" |
| #include "base/message_loop/message_loop.h" |
| +#include "device/bluetooth/bluetooth_adapter_android.h" |
| #include "device/bluetooth/bluetooth_gatt_notify_session_android.h" |
| +#include "device/bluetooth/bluetooth_remote_gatt_descriptor_android.h" |
| #include "device/bluetooth/bluetooth_remote_gatt_service_android.h" |
| #include "jni/ChromeBluetoothRemoteGattCharacteristic_jni.h" |
| @@ -21,18 +23,21 @@ namespace device { |
| // static |
| scoped_ptr<BluetoothRemoteGattCharacteristicAndroid> |
| BluetoothRemoteGattCharacteristicAndroid::Create( |
| + BluetoothAdapterAndroid* adapter, |
| const std::string& instance_id, |
| jobject /* BluetoothGattCharacteristicWrapper */ |
| bluetooth_gatt_characteristic_wrapper, |
| jobject /* ChromeBluetoothDevice */ chrome_bluetooth_device) { |
| scoped_ptr<BluetoothRemoteGattCharacteristicAndroid> characteristic( |
| - new BluetoothRemoteGattCharacteristicAndroid(instance_id)); |
| + new BluetoothRemoteGattCharacteristicAndroid(adapter, instance_id)); |
| + JNIEnv* env = AttachCurrentThread(); |
| characteristic->j_characteristic_.Reset( |
| Java_ChromeBluetoothRemoteGattCharacteristic_create( |
| - AttachCurrentThread(), |
| - reinterpret_cast<intptr_t>(characteristic.get()), |
| - bluetooth_gatt_characteristic_wrapper, chrome_bluetooth_device)); |
| + env, reinterpret_cast<intptr_t>(characteristic.get()), |
| + bluetooth_gatt_characteristic_wrapper, |
| + base::android::ConvertUTF8ToJavaString(env, instance_id).obj(), |
| + chrome_bluetooth_device)); |
| return characteristic; |
| } |
| @@ -98,15 +103,21 @@ bool BluetoothRemoteGattCharacteristicAndroid::IsNotifying() const { |
| std::vector<BluetoothGattDescriptor*> |
| BluetoothRemoteGattCharacteristicAndroid::GetDescriptors() const { |
| - NOTIMPLEMENTED(); |
| - return std::vector<BluetoothGattDescriptor*>(); |
| + EnsureDescriptorsCreated(); |
| + std::vector<BluetoothGattDescriptor*> descriptors; |
| + for (const auto& map_iter : descriptors_) |
| + descriptors.push_back(map_iter.second); |
| + return descriptors; |
| } |
| BluetoothGattDescriptor* |
| BluetoothRemoteGattCharacteristicAndroid::GetDescriptor( |
| const std::string& identifier) const { |
| - NOTIMPLEMENTED(); |
| - return nullptr; |
| + EnsureDescriptorsCreated(); |
| + const auto& iter = descriptors_.find(identifier); |
| + if (iter == descriptors_.end()) |
| + return nullptr; |
| + return iter->second; |
| } |
| bool BluetoothRemoteGattCharacteristicAndroid::AddDescriptor( |
| @@ -235,8 +246,38 @@ void BluetoothRemoteGattCharacteristicAndroid::OnWrite( |
| } |
| } |
| +void BluetoothRemoteGattCharacteristicAndroid::CreateGattRemoteDescriptor( |
| + JNIEnv* env, |
| + const JavaParamRef<jobject>& caller, |
| + const JavaParamRef<jstring>& instanceId, |
| + const JavaParamRef<jobject>& /* BluetoothGattDescriptorWrapper */ |
| + bluetooth_gatt_descriptor_wrapper, |
| + const JavaParamRef< |
| + jobject>& /* chromeBluetoothDevice */ chrome_bluetooth_device) { |
|
Jeffrey Yasskin
2016/01/12 21:53:54
Should 'chrome' be capitalized too? It's a type na
scheib
2016/01/12 23:16:55
Done.
|
| + std::string instanceIdString = |
| + base::android::ConvertJavaStringToUTF8(env, instanceId); |
| + |
| + DCHECK(!descriptors_.contains(instanceIdString)); |
| + |
| + descriptors_.set( |
| + instanceIdString, |
| + BluetoothRemoteGattDescriptorAndroid::Create( |
| + adapter_, instanceIdString, bluetooth_gatt_descriptor_wrapper, |
| + chrome_bluetooth_device)); |
| +} |
| + |
| BluetoothRemoteGattCharacteristicAndroid:: |
| - BluetoothRemoteGattCharacteristicAndroid(const std::string& instance_id) |
| - : instance_id_(instance_id) {} |
| + BluetoothRemoteGattCharacteristicAndroid(BluetoothAdapterAndroid* adapter, |
| + const std::string& instance_id) |
| + : adapter_(adapter), instance_id_(instance_id) {} |
| + |
| +void BluetoothRemoteGattCharacteristicAndroid::EnsureDescriptorsCreated() |
| + const { |
| + if (!descriptors_.empty()) |
|
Jeffrey Yasskin
2016/01/12 21:53:54
Are we going to need to do something else here to
scheib
2016/01/12 23:16:55
Yes, created issue http://crbug.com/576906 for thi
|
| + return; |
| + |
| + Java_ChromeBluetoothRemoteGattCharacteristic_ensureDescriptorsCreated( |
| + AttachCurrentThread(), j_characteristic_.obj()); |
| +} |
| } // namespace device |