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

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

Issue 2567903004: Replace ScopedVector/ScopedPtrHashMap with std::vector and std::unordered_map (Closed)
Patch Set: Replace ScopedVector/ScopedPtrHashMap with std::vector and std::unordered_map Created 3 years, 12 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_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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 BluetoothRemoteGattCharacteristicAndroid::GetPermissions() const { 106 BluetoothRemoteGattCharacteristicAndroid::GetPermissions() const {
107 NOTIMPLEMENTED(); 107 NOTIMPLEMENTED();
108 return 0; 108 return 0;
109 } 109 }
110 110
111 std::vector<BluetoothRemoteGattDescriptor*> 111 std::vector<BluetoothRemoteGattDescriptor*>
112 BluetoothRemoteGattCharacteristicAndroid::GetDescriptors() const { 112 BluetoothRemoteGattCharacteristicAndroid::GetDescriptors() const {
113 EnsureDescriptorsCreated(); 113 EnsureDescriptorsCreated();
114 std::vector<BluetoothRemoteGattDescriptor*> descriptors; 114 std::vector<BluetoothRemoteGattDescriptor*> descriptors;
115 for (const auto& map_iter : descriptors_) 115 for (const auto& map_iter : descriptors_)
116 descriptors.push_back(map_iter.second); 116 descriptors.push_back(map_iter.second.get());
117 return descriptors; 117 return descriptors;
118 } 118 }
119 119
120 BluetoothRemoteGattDescriptor* 120 BluetoothRemoteGattDescriptor*
121 BluetoothRemoteGattCharacteristicAndroid::GetDescriptor( 121 BluetoothRemoteGattCharacteristicAndroid::GetDescriptor(
122 const std::string& identifier) const { 122 const std::string& identifier) const {
123 EnsureDescriptorsCreated(); 123 EnsureDescriptorsCreated();
124 const auto& iter = descriptors_.find(identifier); 124 const auto& iter = descriptors_.find(identifier);
125 if (iter == descriptors_.end()) 125 if (iter == descriptors_.end())
126 return nullptr; 126 return nullptr;
127 return iter->second; 127 return iter->second.get();
128 } 128 }
129 129
130 void BluetoothRemoteGattCharacteristicAndroid::ReadRemoteCharacteristic( 130 void BluetoothRemoteGattCharacteristicAndroid::ReadRemoteCharacteristic(
131 const ValueCallback& callback, 131 const ValueCallback& callback,
132 const ErrorCallback& error_callback) { 132 const ErrorCallback& error_callback) {
133 if (read_pending_ || write_pending_) { 133 if (read_pending_ || write_pending_) {
134 base::ThreadTaskRunnerHandle::Get()->PostTask( 134 base::ThreadTaskRunnerHandle::Get()->PostTask(
135 FROM_HERE, 135 FROM_HERE,
136 base::Bind(error_callback, 136 base::Bind(error_callback,
137 BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS)); 137 BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS));
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 JNIEnv* env, 234 JNIEnv* env,
235 const JavaParamRef<jobject>& caller, 235 const JavaParamRef<jobject>& caller,
236 const JavaParamRef<jstring>& instanceId, 236 const JavaParamRef<jstring>& instanceId,
237 const JavaParamRef<jobject>& /* BluetoothGattDescriptorWrapper */ 237 const JavaParamRef<jobject>& /* BluetoothGattDescriptorWrapper */
238 bluetooth_gatt_descriptor_wrapper, 238 bluetooth_gatt_descriptor_wrapper,
239 const JavaParamRef<jobject>& /* ChromeBluetoothDevice */ 239 const JavaParamRef<jobject>& /* ChromeBluetoothDevice */
240 chrome_bluetooth_device) { 240 chrome_bluetooth_device) {
241 std::string instanceIdString = 241 std::string instanceIdString =
242 base::android::ConvertJavaStringToUTF8(env, instanceId); 242 base::android::ConvertJavaStringToUTF8(env, instanceId);
243 243
244 DCHECK(!descriptors_.contains(instanceIdString)); 244 auto dup = descriptors_.find(instanceIdString);
245 CHECK(!dup.second)
Reilly Grant (use Gerrit) 2016/12/21 22:25:14 DCHECK(!base::ContainsKey(descriptors_, instanceId
dougt 2016/12/22 01:18:03 Done.
246 auto descriptor = BluetoothRemoteGattDescriptorAndroid::Create(
247 instanceIdString, bluetooth_gatt_descriptor_wrapper,
248 chrome_bluetooth_device);
245 249
246 descriptors_.set(instanceIdString, 250 descriptors_.insert(std::make_pair(instanceIdString, std::move(descriptor)));
247 BluetoothRemoteGattDescriptorAndroid::Create(
248 instanceIdString, bluetooth_gatt_descriptor_wrapper,
249 chrome_bluetooth_device));
250 } 251 }
251 252
252 void BluetoothRemoteGattCharacteristicAndroid::SubscribeToNotifications( 253 void BluetoothRemoteGattCharacteristicAndroid::SubscribeToNotifications(
253 BluetoothRemoteGattDescriptor* ccc_descriptor, 254 BluetoothRemoteGattDescriptor* ccc_descriptor,
254 const base::Closure& callback, 255 const base::Closure& callback,
255 const ErrorCallback& error_callback) { 256 const ErrorCallback& error_callback) {
256 if (!Java_ChromeBluetoothRemoteGattCharacteristic_setCharacteristicNotificatio n( 257 if (!Java_ChromeBluetoothRemoteGattCharacteristic_setCharacteristicNotificatio n(
257 AttachCurrentThread(), j_characteristic_, true)) { 258 AttachCurrentThread(), j_characteristic_, true)) {
258 LOG(ERROR) << "Error enabling characteristic notification"; 259 LOG(ERROR) << "Error enabling characteristic notification";
259 base::ThreadTaskRunnerHandle::Get()->PostTask( 260 base::ThreadTaskRunnerHandle::Get()->PostTask(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 void BluetoothRemoteGattCharacteristicAndroid::EnsureDescriptorsCreated() 300 void BluetoothRemoteGattCharacteristicAndroid::EnsureDescriptorsCreated()
300 const { 301 const {
301 if (!descriptors_.empty()) 302 if (!descriptors_.empty())
302 return; 303 return;
303 304
304 Java_ChromeBluetoothRemoteGattCharacteristic_createDescriptors( 305 Java_ChromeBluetoothRemoteGattCharacteristic_createDescriptors(
305 AttachCurrentThread(), j_characteristic_); 306 AttachCurrentThread(), j_characteristic_);
306 } 307 }
307 308
308 } // namespace device 309 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698