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

Side by Side Diff: chrome/browser/ui/bluetooth/bluetooth_chooser_controller.cc

Issue 2275173002: Add unit test for BluetoothChooserController (Closed)
Patch Set: added unit test for BluetoothChooserController Created 4 years, 3 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 "chrome/browser/ui/bluetooth/bluetooth_chooser_controller.h" 5 #include "chrome/browser/ui/bluetooth/bluetooth_chooser_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 if (name_it == device_id_to_name_map_.end()) 227 if (name_it == device_id_to_name_map_.end())
228 return; 228 return;
229 229
230 auto device_it = 230 auto device_it =
231 std::find_if(devices_.begin(), devices_.end(), 231 std::find_if(devices_.begin(), devices_.end(),
232 [&device_id](const BluetoothDeviceInfo& device) { 232 [&device_id](const BluetoothDeviceInfo& device) {
233 return device.id == device_id; 233 return device.id == device_id;
234 }); 234 });
235 235
236 if (device_it != devices_.end()) { 236 if (device_it != devices_.end()) {
237 size_t index = device_it - devices_.begin();
Jeffrey Yasskin 2016/08/26 21:46:12 Why did this move back?
juncai 2016/08/27 00:21:30 The previous one works in release code, but debug
Jeffrey Yasskin 2016/08/27 00:35:45 Oops, you're totally right. The .erase() invalidat
juncai 2016/08/27 02:15:56 Acknowledged.
237 devices_.erase(device_it); 238 devices_.erase(device_it);
238 239
239 const auto& it = device_name_counts_.find(name_it->second); 240 const auto& it = device_name_counts_.find(name_it->second);
240 DCHECK(it != device_name_counts_.end()); 241 DCHECK(it != device_name_counts_.end());
241 DCHECK_GT(it->second, 0); 242 DCHECK_GT(it->second, 0);
242 243
243 if (--(it->second) == 0) 244 if (--(it->second) == 0)
244 device_name_counts_.erase(it); 245 device_name_counts_.erase(it);
245 246
246 device_id_to_name_map_.erase(name_it); 247 device_id_to_name_map_.erase(name_it);
247 248
248 if (view()) 249 if (view())
249 view()->OnOptionRemoved(device_it - devices_.begin()); 250 view()->OnOptionRemoved(index);
250 } 251 }
251 } 252 }
252 253
253 void BluetoothChooserController::ResetEventHandler() { 254 void BluetoothChooserController::ResetEventHandler() {
254 event_handler_.Reset(); 255 event_handler_.Reset();
255 } 256 }
256 257
257 void BluetoothChooserController::ClearAllDevices() { 258 void BluetoothChooserController::ClearAllDevices() {
258 devices_.clear(); 259 devices_.clear();
259 device_id_to_name_map_.clear(); 260 device_id_to_name_map_.clear();
260 device_name_counts_.clear(); 261 device_name_counts_.clear();
261 } 262 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698