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

Side by Side Diff: device/bluetooth/bluetooth_remote_gatt_service_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 4 years 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 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"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 128
129 device::BluetoothDevice* BluetoothRemoteGattServiceAndroid::GetDevice() const { 129 device::BluetoothDevice* BluetoothRemoteGattServiceAndroid::GetDevice() const {
130 return device_; 130 return device_;
131 } 131 }
132 132
133 std::vector<device::BluetoothRemoteGattCharacteristic*> 133 std::vector<device::BluetoothRemoteGattCharacteristic*>
134 BluetoothRemoteGattServiceAndroid::GetCharacteristics() const { 134 BluetoothRemoteGattServiceAndroid::GetCharacteristics() const {
135 EnsureCharacteristicsCreated(); 135 EnsureCharacteristicsCreated();
136 std::vector<device::BluetoothRemoteGattCharacteristic*> characteristics; 136 std::vector<device::BluetoothRemoteGattCharacteristic*> characteristics;
137 for (const auto& map_iter : characteristics_) 137 for (const auto& map_iter : characteristics_)
138 characteristics.push_back(map_iter.second); 138 characteristics.push_back(map_iter.second.get());
139 return characteristics; 139 return characteristics;
140 } 140 }
141 141
142 std::vector<device::BluetoothRemoteGattService*> 142 std::vector<device::BluetoothRemoteGattService*>
143 BluetoothRemoteGattServiceAndroid::GetIncludedServices() const { 143 BluetoothRemoteGattServiceAndroid::GetIncludedServices() const {
144 NOTIMPLEMENTED(); 144 NOTIMPLEMENTED();
145 return std::vector<device::BluetoothRemoteGattService*>(); 145 return std::vector<device::BluetoothRemoteGattService*>();
146 } 146 }
147 147
148 device::BluetoothRemoteGattCharacteristic* 148 device::BluetoothRemoteGattCharacteristic*
149 BluetoothRemoteGattServiceAndroid::GetCharacteristic( 149 BluetoothRemoteGattServiceAndroid::GetCharacteristic(
150 const std::string& identifier) const { 150 const std::string& identifier) const {
151 EnsureCharacteristicsCreated(); 151 EnsureCharacteristicsCreated();
152 const auto& iter = characteristics_.find(identifier); 152 const auto& iter = characteristics_.find(identifier);
153 if (iter == characteristics_.end()) 153 if (iter == characteristics_.end()) {
154 return nullptr; 154 return nullptr;
155 return iter->second; 155 }
156
157 return iter->second.get();
156 } 158 }
157 159
158 void BluetoothRemoteGattServiceAndroid::CreateGattRemoteCharacteristic( 160 void BluetoothRemoteGattServiceAndroid::CreateGattRemoteCharacteristic(
159 JNIEnv* env, 161 JNIEnv* env,
160 const JavaParamRef<jobject>& caller, 162 const JavaParamRef<jobject>& caller,
161 const JavaParamRef<jstring>& instance_id, 163 const JavaParamRef<jstring>& instance_id,
162 const JavaParamRef<jobject>& /* BluetoothGattCharacteristicWrapper */ 164 const JavaParamRef<jobject>& /* BluetoothGattCharacteristicWrapper */
163 bluetooth_gatt_characteristic_wrapper, 165 bluetooth_gatt_characteristic_wrapper,
164 const JavaParamRef< 166 const JavaParamRef<
165 jobject>& /* ChromeBluetoothDevice */ chrome_bluetooth_device) { 167 jobject>& /* ChromeBluetoothDevice */ chrome_bluetooth_device) {
166 std::string instance_id_string = 168 std::string instance_id_string =
167 base::android::ConvertJavaStringToUTF8(env, instance_id); 169 base::android::ConvertJavaStringToUTF8(env, instance_id);
168 170
169 DCHECK(!characteristics_.contains(instance_id_string)); 171 // DCHECK(characteristics_.find(instance_id_string) != nullptr);
Reilly Grant (use Gerrit) 2016/12/21 22:25:15 Same comment as previous.
dougt 2016/12/22 01:18:03 Done.
170 172
171 characteristics_.set( 173 auto characteristic = BluetoothRemoteGattCharacteristicAndroid::Create(
172 instance_id_string, 174 adapter_, this, instance_id_string, bluetooth_gatt_characteristic_wrapper,
173 BluetoothRemoteGattCharacteristicAndroid::Create( 175 chrome_bluetooth_device);
174 adapter_, this, instance_id_string, 176
175 bluetooth_gatt_characteristic_wrapper, chrome_bluetooth_device)); 177 characteristics_.insert(
178 std::make_pair(instance_id_string, std::move(characteristic)));
176 } 179 }
177 180
178 BluetoothRemoteGattServiceAndroid::BluetoothRemoteGattServiceAndroid( 181 BluetoothRemoteGattServiceAndroid::BluetoothRemoteGattServiceAndroid(
179 BluetoothAdapterAndroid* adapter, 182 BluetoothAdapterAndroid* adapter,
180 BluetoothDeviceAndroid* device, 183 BluetoothDeviceAndroid* device,
181 const std::string& instance_id) 184 const std::string& instance_id)
182 : adapter_(adapter), device_(device), instance_id_(instance_id) {} 185 : adapter_(adapter), device_(device), instance_id_(instance_id) {}
183 186
184 void BluetoothRemoteGattServiceAndroid::EnsureCharacteristicsCreated() const { 187 void BluetoothRemoteGattServiceAndroid::EnsureCharacteristicsCreated() const {
185 if (!characteristics_.empty()) 188 if (!characteristics_.empty())
186 return; 189 return;
187 190
188 // Java call 191 // Java call
189 Java_ChromeBluetoothRemoteGattService_createCharacteristics( 192 Java_ChromeBluetoothRemoteGattService_createCharacteristics(
190 AttachCurrentThread(), j_service_); 193 AttachCurrentThread(), j_service_);
191 } 194 }
192 195
193 } // namespace device 196 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698