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 // TODO(ortuno): Update device's information. |
|
msw
2016/08/12 22:19:33
q: can you remove this TODO now that we're updatin
juncai
2016/08/15 18:11:19
Done.
| |
| 176 // https://crbug.com/634366 Update name | 178 if (should_update_name) { |
| 179 base::string16 previous_device_name = name_it->second; | |
| 180 name_it->second = device_name; | |
| 181 | |
| 182 const auto& it = device_name_map_.find(previous_device_name); | |
| 183 DCHECK(it != device_name_map_.end()); | |
| 184 DCHECK_GT(it->second, 0); | |
| 185 | |
| 186 if (--(it->second) == 0) | |
| 187 device_name_map_.erase(it); | |
| 188 | |
| 189 ++device_name_map_[device_name]; | |
| 190 } | |
| 191 | |
| 192 size_t index = std::distance( | |
| 193 device_ids_.begin(), | |
| 194 std::find(device_ids_.begin(), device_ids_.end(), device_id)); | |
| 195 DCHECK_NE(device_ids_.size(), index); | |
| 177 // http://crbug.com/543466 Update connection and paired status | 196 // http://crbug.com/543466 Update connection and paired status |
| 178 // http://crbug.com/629689 Update RSSI. | 197 // http://crbug.com/629689 Update RSSI. |
| 198 if (view()) | |
| 199 view()->OnOptionUpdated(index); | |
|
msw
2016/08/12 22:19:33
Do we want to report that the option was updated i
juncai
2016/08/15 18:11:19
Regarding the first question, if the |device_name|
msw
2016/08/15 19:04:58
Okay, good to know; thanks.
juncai
2016/08/15 23:53:33
Done.
| |
| 179 return; | 200 return; |
| 180 } | 201 } |
| 181 | 202 |
| 182 device_ids_.push_back(device_id); | 203 device_ids_.push_back(device_id); |
| 204 device_id_to_name_map_.insert({device_id, device_name}); | |
| 183 ++device_name_map_[device_name]; | 205 ++device_name_map_[device_name]; |
| 184 if (view()) | 206 if (view()) |
| 185 view()->OnOptionAdded(device_ids_.size() - 1); | 207 view()->OnOptionAdded(device_ids_.size() - 1); |
| 186 } | 208 } |
| 187 | 209 |
| 188 void BluetoothChooserController::RemoveDevice(const std::string& device_id) { | 210 void BluetoothChooserController::RemoveDevice(const std::string& device_id) { |
| 189 const auto& name_it = device_id_to_name_map_.find(device_id); | 211 const auto& name_it = device_id_to_name_map_.find(device_id); |
| 190 if (name_it == device_id_to_name_map_.end()) | 212 if (name_it == device_id_to_name_map_.end()) |
| 191 return; | 213 return; |
| 192 | 214 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 216 | 238 |
| 217 void BluetoothChooserController::ResetEventHandler() { | 239 void BluetoothChooserController::ResetEventHandler() { |
| 218 event_handler_.Reset(); | 240 event_handler_.Reset(); |
| 219 } | 241 } |
| 220 | 242 |
| 221 void BluetoothChooserController::ClearAllDevices() { | 243 void BluetoothChooserController::ClearAllDevices() { |
| 222 device_ids_.clear(); | 244 device_ids_.clear(); |
| 223 device_id_to_name_map_.clear(); | 245 device_id_to_name_map_.clear(); |
| 224 device_name_map_.clear(); | 246 device_name_map_.clear(); |
| 225 } | 247 } |
| OLD | NEW |