| OLD | NEW |
| 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/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 if (name_it == device_id_to_name_map_.end()) | 232 if (name_it == device_id_to_name_map_.end()) |
| 233 return; | 233 return; |
| 234 | 234 |
| 235 auto device_it = | 235 auto device_it = |
| 236 std::find_if(devices_.begin(), devices_.end(), | 236 std::find_if(devices_.begin(), devices_.end(), |
| 237 [&device_id](const BluetoothDeviceInfo& device) { | 237 [&device_id](const BluetoothDeviceInfo& device) { |
| 238 return device.id == device_id; | 238 return device.id == device_id; |
| 239 }); | 239 }); |
| 240 | 240 |
| 241 if (device_it != devices_.end()) { | 241 if (device_it != devices_.end()) { |
| 242 size_t index = device_it - devices_.begin(); |
| 242 devices_.erase(device_it); | 243 devices_.erase(device_it); |
| 243 | 244 |
| 244 const auto& it = device_name_counts_.find(name_it->second); | 245 const auto& it = device_name_counts_.find(name_it->second); |
| 245 DCHECK(it != device_name_counts_.end()); | 246 DCHECK(it != device_name_counts_.end()); |
| 246 DCHECK_GT(it->second, 0); | 247 DCHECK_GT(it->second, 0); |
| 247 | 248 |
| 248 if (--(it->second) == 0) | 249 if (--(it->second) == 0) |
| 249 device_name_counts_.erase(it); | 250 device_name_counts_.erase(it); |
| 250 | 251 |
| 251 device_id_to_name_map_.erase(name_it); | 252 device_id_to_name_map_.erase(name_it); |
| 252 | 253 |
| 253 if (view()) | 254 if (view()) |
| 254 view()->OnOptionRemoved(device_it - devices_.begin()); | 255 view()->OnOptionRemoved(index); |
| 255 } | 256 } |
| 256 } | 257 } |
| 257 | 258 |
| 258 void BluetoothChooserController::ResetEventHandler() { | 259 void BluetoothChooserController::ResetEventHandler() { |
| 259 event_handler_.Reset(); | 260 event_handler_.Reset(); |
| 260 } | 261 } |
| 261 | 262 |
| 262 void BluetoothChooserController::ClearAllDevices() { | 263 void BluetoothChooserController::ClearAllDevices() { |
| 263 devices_.clear(); | 264 devices_.clear(); |
| 264 device_id_to_name_map_.clear(); | 265 device_id_to_name_map_.clear(); |
| 265 device_name_counts_.clear(); | 266 device_name_counts_.clear(); |
| 266 } | 267 } |
| OLD | NEW |