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

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

Issue 2304213002: Show device connection and paired status in chooser on Mac (Closed)
Patch Set: added comments 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/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 } 60 }
61 61
62 size_t BluetoothChooserController::NumOptions() const { 62 size_t BluetoothChooserController::NumOptions() const {
63 return devices_.size(); 63 return devices_.size();
64 } 64 }
65 65
66 int BluetoothChooserController::GetSignalStrengthLevel(size_t index) const { 66 int BluetoothChooserController::GetSignalStrengthLevel(size_t index) const {
67 return devices_[index].signal_strength_level; 67 return devices_[index].signal_strength_level;
68 } 68 }
69 69
70 bool BluetoothChooserController::IsConnected(size_t index) const {
71 return devices_[index].is_connected;
72 }
73
74 bool BluetoothChooserController::IsPaired(size_t index) const {
75 return devices_[index].is_paired;
76 }
77
70 base::string16 BluetoothChooserController::GetOption(size_t index) const { 78 base::string16 BluetoothChooserController::GetOption(size_t index) const {
71 DCHECK_LT(index, devices_.size()); 79 DCHECK_LT(index, devices_.size());
72 const std::string& device_id = devices_[index].id; 80 const std::string& device_id = devices_[index].id;
73 const auto& device_name_it = device_id_to_name_map_.find(device_id); 81 const auto& device_name_it = device_id_to_name_map_.find(device_id);
74 DCHECK(device_name_it != device_id_to_name_map_.end()); 82 DCHECK(device_name_it != device_id_to_name_map_.end());
75 const auto& it = device_name_counts_.find(device_name_it->second); 83 const auto& it = device_name_counts_.find(device_name_it->second);
76 DCHECK(it != device_name_counts_.end()); 84 DCHECK(it != device_name_counts_.end());
77 return it->second == 1 85 return it->second == 1
78 ? device_name_it->second 86 ? device_name_it->second
79 : l10n_util::GetStringFUTF16( 87 : l10n_util::GetStringFUTF16(
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 ++device_name_counts_[device_name]; 209 ++device_name_counts_[device_name];
202 } 210 }
203 211
204 auto device_it = 212 auto device_it =
205 std::find_if(devices_.begin(), devices_.end(), 213 std::find_if(devices_.begin(), devices_.end(),
206 [&device_id](const BluetoothDeviceInfo& device) { 214 [&device_id](const BluetoothDeviceInfo& device) {
207 return device.id == device_id; 215 return device.id == device_id;
208 }); 216 });
209 217
210 DCHECK(device_it != devices_.end()); 218 DCHECK(device_it != devices_.end());
211 // http://crbug.com/543466 Update connection and paired status
212
213 // When Bluetooth device scanning stops, the |signal_strength_level| 219 // When Bluetooth device scanning stops, the |signal_strength_level|
214 // is -1, and in this case, should still use the previously stored 220 // is -1, and in this case, should still use the previously stored
215 // signal strength level value. 221 // signal strength level value.
216 if (signal_strength_level != -1) 222 if (signal_strength_level != -1)
217 device_it->signal_strength_level = signal_strength_level; 223 device_it->signal_strength_level = signal_strength_level;
224 device_it->is_connected = is_gatt_connected;
225 device_it->is_paired = is_paired;
218 if (view()) 226 if (view())
219 view()->OnOptionUpdated(device_it - devices_.begin()); 227 view()->OnOptionUpdated(device_it - devices_.begin());
220 return; 228 return;
221 } 229 }
222 230
223 devices_.push_back({device_id, signal_strength_level}); 231 devices_.push_back(
232 {device_id, signal_strength_level, is_gatt_connected, is_paired});
224 device_id_to_name_map_.insert({device_id, device_name}); 233 device_id_to_name_map_.insert({device_id, device_name});
225 ++device_name_counts_[device_name]; 234 ++device_name_counts_[device_name];
226 if (view()) 235 if (view())
227 view()->OnOptionAdded(devices_.size() - 1); 236 view()->OnOptionAdded(devices_.size() - 1);
228 } 237 }
229 238
230 void BluetoothChooserController::RemoveDevice(const std::string& device_id) { 239 void BluetoothChooserController::RemoveDevice(const std::string& device_id) {
231 const auto& name_it = device_id_to_name_map_.find(device_id); 240 const auto& name_it = device_id_to_name_map_.find(device_id);
232 if (name_it == device_id_to_name_map_.end()) 241 if (name_it == device_id_to_name_map_.end())
233 return; 242 return;
(...skipping 24 matching lines...) Expand all
258 267
259 void BluetoothChooserController::ResetEventHandler() { 268 void BluetoothChooserController::ResetEventHandler() {
260 event_handler_.Reset(); 269 event_handler_.Reset();
261 } 270 }
262 271
263 void BluetoothChooserController::ClearAllDevices() { 272 void BluetoothChooserController::ClearAllDevices() {
264 devices_.clear(); 273 devices_.clear();
265 device_id_to_name_map_.clear(); 274 device_id_to_name_map_.clear();
266 device_name_counts_.clear(); 275 device_name_counts_.clear();
267 } 276 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/bluetooth/bluetooth_chooser_controller.h ('k') | chrome/browser/ui/cocoa/chooser_content_view_cocoa.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698