| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/net/referrer.h" | 9 #include "chrome/browser/net/referrer.h" |
| 10 #include "chrome/browser/profiles/profile_manager.h" | 10 #include "chrome/browser/profiles/profile_manager.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 false /* Refreshing options is complete */); | 145 false /* Refreshing options is complete */); |
| 146 } | 146 } |
| 147 break; | 147 break; |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 | 150 |
| 151 void BluetoothChooserController::AddDevice(const std::string& device_id, | 151 void BluetoothChooserController::AddDevice(const std::string& device_id, |
| 152 const base::string16& device_name) { | 152 const base::string16& device_name) { |
| 153 device_names_and_ids_.push_back(std::make_pair(device_name, device_id)); | 153 device_names_and_ids_.push_back(std::make_pair(device_name, device_id)); |
| 154 ++device_name_map_[device_name]; | 154 ++device_name_map_[device_name]; |
| 155 if (view()) | 155 if (view()) { |
| 156 view()->OnOptionAdded(device_names_and_ids_.size() - 1); | 156 view()->OnOptionAdded(device_names_and_ids_.size() - 1); |
| 157 if (device_names_and_ids_.size() == 1) |
| 158 view()->OnOptionAvailableDuringRefresh(); |
| 159 } |
| 157 } | 160 } |
| 158 | 161 |
| 159 void BluetoothChooserController::RemoveDevice(const std::string& device_id) { | 162 void BluetoothChooserController::RemoveDevice(const std::string& device_id) { |
| 160 for (auto it = device_names_and_ids_.begin(); | 163 for (auto it = device_names_and_ids_.begin(); |
| 161 it != device_names_and_ids_.end(); ++it) { | 164 it != device_names_and_ids_.end(); ++it) { |
| 162 if (it->second == device_id) { | 165 if (it->second == device_id) { |
| 163 size_t index = it - device_names_and_ids_.begin(); | 166 size_t index = it - device_names_and_ids_.begin(); |
| 164 DCHECK_GT(device_name_map_[it->first], 0); | 167 DCHECK_GT(device_name_map_[it->first], 0); |
| 165 if (--device_name_map_[it->first] == 0) | 168 if (--device_name_map_[it->first] == 0) |
| 166 device_name_map_.erase(it->first); | 169 device_name_map_.erase(it->first); |
| 167 device_names_and_ids_.erase(it); | 170 device_names_and_ids_.erase(it); |
| 168 if (view()) | 171 if (view()) |
| 169 view()->OnOptionRemoved(index); | 172 view()->OnOptionRemoved(index); |
| 170 return; | 173 return; |
| 171 } | 174 } |
| 172 } | 175 } |
| 173 } | 176 } |
| 174 | 177 |
| 175 void BluetoothChooserController::ClearAllDevices() { | 178 void BluetoothChooserController::ClearAllDevices() { |
| 176 device_names_and_ids_.clear(); | 179 device_names_and_ids_.clear(); |
| 177 device_name_map_.clear(); | 180 device_name_map_.clear(); |
| 178 } | 181 } |
| OLD | NEW |