Chromium Code Reviews| 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> | |
| 8 | |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/net/referrer.h" | 11 #include "chrome/browser/net/referrer.h" |
| 10 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
| 11 #include "chrome/browser/ui/bluetooth/bluetooth_chooser_desktop.h" | 13 #include "chrome/browser/ui/bluetooth/bluetooth_chooser_desktop.h" |
| 12 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 15 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
| 14 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
| 15 #include "chrome/grit/generated_resources.h" | 17 #include "chrome/grit/generated_resources.h" |
| 16 #include "content/browser/bluetooth/bluetooth_metrics.h" | 18 #include "content/browser/bluetooth/bluetooth_metrics.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 } | 165 } |
| 164 } | 166 } |
| 165 | 167 |
| 166 void BluetoothChooserController::AddOrUpdateDevice( | 168 void BluetoothChooserController::AddOrUpdateDevice( |
| 167 const std::string& device_id, | 169 const std::string& device_id, |
| 168 bool should_update_name, | 170 bool should_update_name, |
| 169 const base::string16& device_name, | 171 const base::string16& device_name, |
| 170 bool is_gatt_connected, | 172 bool is_gatt_connected, |
| 171 bool is_paired, | 173 bool is_paired, |
| 172 const int8_t* rssi) { | 174 const int8_t* rssi) { |
| 173 auto result = device_id_to_name_map_.insert({device_id, device_name}); | 175 auto name_it = device_id_to_name_map_.find(device_id); |
| 174 if (!result.second) { | 176 if (name_it != device_id_to_name_map_.end()) { |
| 175 // TODO(ortuno): Update device's information. | 177 if (should_update_name) { |
| 176 // https://crbug.com/634366 Update name | 178 base::string16 previous_device_name = name_it->second; |
| 179 name_it->second = device_name; | |
| 180 | |
| 181 const auto& it = device_name_map_.find(previous_device_name); | |
| 182 DCHECK(it != device_name_map_.end()); | |
| 183 DCHECK_GT(it->second, 0); | |
| 184 | |
| 185 if (--(it->second) == 0) | |
| 186 device_name_map_.erase(it); | |
|
Jeffrey Yasskin
2016/08/15 21:33:53
I wish device_name_map_ had a more descriptive nam
juncai
2016/08/15 23:53:33
Yes, it is a count of devices with a given name.
| |
| 187 | |
| 188 ++device_name_map_[device_name]; | |
| 189 } | |
| 190 | |
| 191 size_t index = std::distance( | |
| 192 device_ids_.begin(), | |
| 193 std::find(device_ids_.begin(), device_ids_.end(), device_id)); | |
| 194 DCHECK_NE(device_ids_.size(), index); | |
| 177 // http://crbug.com/543466 Update connection and paired status | 195 // http://crbug.com/543466 Update connection and paired status |
| 178 // http://crbug.com/629689 Update RSSI. | 196 // http://crbug.com/629689 Update RSSI. |
| 197 if (view()) | |
| 198 view()->OnOptionUpdated(index); | |
| 179 return; | 199 return; |
| 180 } | 200 } |
| 181 | 201 |
| 182 device_ids_.push_back(device_id); | 202 device_ids_.push_back(device_id); |
| 203 device_id_to_name_map_.insert({device_id, device_name}); | |
| 183 ++device_name_map_[device_name]; | 204 ++device_name_map_[device_name]; |
| 184 if (view()) | 205 if (view()) |
| 185 view()->OnOptionAdded(device_ids_.size() - 1); | 206 view()->OnOptionAdded(device_ids_.size() - 1); |
| 186 } | 207 } |
| 187 | 208 |
| 188 void BluetoothChooserController::RemoveDevice(const std::string& device_id) { | 209 void BluetoothChooserController::RemoveDevice(const std::string& device_id) { |
| 189 const auto& name_it = device_id_to_name_map_.find(device_id); | 210 const auto& name_it = device_id_to_name_map_.find(device_id); |
| 190 if (name_it == device_id_to_name_map_.end()) | 211 if (name_it == device_id_to_name_map_.end()) |
| 191 return; | 212 return; |
| 192 | 213 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 216 | 237 |
| 217 void BluetoothChooserController::ResetEventHandler() { | 238 void BluetoothChooserController::ResetEventHandler() { |
| 218 event_handler_.Reset(); | 239 event_handler_.Reset(); |
| 219 } | 240 } |
| 220 | 241 |
| 221 void BluetoothChooserController::ClearAllDevices() { | 242 void BluetoothChooserController::ClearAllDevices() { |
| 222 device_ids_.clear(); | 243 device_ids_.clear(); |
| 223 device_id_to_name_map_.clear(); | 244 device_id_to_name_map_.clear(); |
| 224 device_name_map_.clear(); | 245 device_name_map_.clear(); |
| 225 } | 246 } |
| OLD | NEW |