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

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: Mac bustage 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);
170 DCHECK(!base::ContainsKey(characteristics_, instance_id_string));
171 auto characteristic = BluetoothRemoteGattCharacteristicAndroid::Create(
172 adapter_, this, instance_id_string, bluetooth_gatt_characteristic_wrapper,
173 chrome_bluetooth_device);
168 174
169 DCHECK(!characteristics_.contains(instance_id_string)); 175 characteristics_.insert(
170 176 std::make_pair(instance_id_string, std::move(characteristic)));
171 characteristics_.set(
172 instance_id_string,
173 BluetoothRemoteGattCharacteristicAndroid::Create(
174 adapter_, this, instance_id_string,
175 bluetooth_gatt_characteristic_wrapper, chrome_bluetooth_device));
176 } 177 }
177 178
178 BluetoothRemoteGattServiceAndroid::BluetoothRemoteGattServiceAndroid( 179 BluetoothRemoteGattServiceAndroid::BluetoothRemoteGattServiceAndroid(
179 BluetoothAdapterAndroid* adapter, 180 BluetoothAdapterAndroid* adapter,
180 BluetoothDeviceAndroid* device, 181 BluetoothDeviceAndroid* device,
181 const std::string& instance_id) 182 const std::string& instance_id)
182 : adapter_(adapter), device_(device), instance_id_(instance_id) {} 183 : adapter_(adapter), device_(device), instance_id_(instance_id) {}
183 184
184 void BluetoothRemoteGattServiceAndroid::EnsureCharacteristicsCreated() const { 185 void BluetoothRemoteGattServiceAndroid::EnsureCharacteristicsCreated() const {
185 if (!characteristics_.empty()) 186 if (!characteristics_.empty())
186 return; 187 return;
187 188
188 // Java call 189 // Java call
189 Java_ChromeBluetoothRemoteGattService_createCharacteristics( 190 Java_ChromeBluetoothRemoteGattService_createCharacteristics(
190 AttachCurrentThread(), j_service_); 191 AttachCurrentThread(), j_service_);
191 } 192 }
192 193
193 } // namespace device 194 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698