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

Side by Side Diff: chrome/browser/chooser_controller/mock_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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/chooser_controller/mock_chooser_controller.h" 5 #include "chrome/browser/chooser_controller/mock_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/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 26 matching lines...) Expand all
37 } 37 }
38 38
39 int MockChooserController::GetSignalStrengthLevel(size_t index) const { 39 int MockChooserController::GetSignalStrengthLevel(size_t index) const {
40 return options_[index].signal_strength_level; 40 return options_[index].signal_strength_level;
41 } 41 }
42 42
43 base::string16 MockChooserController::GetOption(size_t index) const { 43 base::string16 MockChooserController::GetOption(size_t index) const {
44 return options_[index].name; 44 return options_[index].name;
45 } 45 }
46 46
47 bool MockChooserController::IsConnected(size_t index) const {
48 return options_[index].connected_paired_status &
49 ConnectedPairedStatus::CONNECTED;
50 }
51
52 bool MockChooserController::IsPaired(size_t index) const {
53 return options_[index].connected_paired_status &
54 ConnectedPairedStatus::PAIRED;
55 }
56
47 base::string16 MockChooserController::GetStatus() const { 57 base::string16 MockChooserController::GetStatus() const {
48 return status_text_; 58 return status_text_;
49 } 59 }
50 60
51 void MockChooserController::OnAdapterPresenceChanged( 61 void MockChooserController::OnAdapterPresenceChanged(
52 content::BluetoothChooser::AdapterPresence presence) { 62 content::BluetoothChooser::AdapterPresence presence) {
53 ClearAllOptions(); 63 ClearAllOptions();
54 switch (presence) { 64 switch (presence) {
55 case content::BluetoothChooser::AdapterPresence::ABSENT: 65 case content::BluetoothChooser::AdapterPresence::ABSENT:
56 NOTREACHED(); 66 NOTREACHED();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN); 101 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN);
92 if (view()) { 102 if (view()) {
93 view()->OnRefreshStateChanged( 103 view()->OnRefreshStateChanged(
94 false /* Refreshing options is complete */); 104 false /* Refreshing options is complete */);
95 } 105 }
96 break; 106 break;
97 } 107 }
98 } 108 }
99 109
100 void MockChooserController::OptionAdded(const base::string16& option_name, 110 void MockChooserController::OptionAdded(const base::string16& option_name,
101 int signal_strength_level) { 111 int signal_strength_level,
102 options_.push_back({option_name, signal_strength_level}); 112 int connected_paired_status) {
113 options_.push_back(
114 {option_name, signal_strength_level, connected_paired_status});
103 if (view()) 115 if (view())
104 view()->OnOptionAdded(options_.size() - 1); 116 view()->OnOptionAdded(options_.size() - 1);
105 } 117 }
106 118
107 void MockChooserController::OptionRemoved(const base::string16& option_name) { 119 void MockChooserController::OptionRemoved(const base::string16& option_name) {
108 auto it = std::find_if(options_.begin(), options_.end(), 120 auto it = std::find_if(options_.begin(), options_.end(),
109 [&option_name](const OptionInfo& option) { 121 [&option_name](const OptionInfo& option) {
110 return option.name == option_name; 122 return option.name == option_name;
111 }); 123 });
112 124
113 if (it != options_.end()) { 125 if (it != options_.end()) {
114 size_t index = it - options_.begin(); 126 size_t index = it - options_.begin();
115 options_.erase(it); 127 options_.erase(it);
116 if (view()) 128 if (view())
117 view()->OnOptionRemoved(index); 129 view()->OnOptionRemoved(index);
118 } 130 }
119 } 131 }
120 132
121 void MockChooserController::OptionUpdated( 133 void MockChooserController::OptionUpdated(
122 const base::string16& previous_option_name, 134 const base::string16& previous_option_name,
123 const base::string16& new_option_name, 135 const base::string16& new_option_name,
124 int new_signal_strength_level) { 136 int new_signal_strength_level,
137 int new_connected_paired_status) {
125 auto it = std::find_if(options_.begin(), options_.end(), 138 auto it = std::find_if(options_.begin(), options_.end(),
126 [&previous_option_name](const OptionInfo& option) { 139 [&previous_option_name](const OptionInfo& option) {
127 return option.name == previous_option_name; 140 return option.name == previous_option_name;
128 }); 141 });
129 142
130 if (it != options_.end()) { 143 if (it != options_.end()) {
131 *it = {new_option_name, new_signal_strength_level}; 144 *it = {new_option_name, new_signal_strength_level,
145 new_connected_paired_status};
132 if (view()) 146 if (view())
133 view()->OnOptionUpdated(it - options_.begin()); 147 view()->OnOptionUpdated(it - options_.begin());
134 } 148 }
135 } 149 }
136 150
137 const int MockChooserController::kNoImage = -1; 151 const int MockChooserController::kNoSignalStrengthLevelImage = -1;
138 const int MockChooserController::kSignalStrengthLevel0Bar = 0; 152 const int MockChooserController::kSignalStrengthLevel0Bar = 0;
139 const int MockChooserController::kSignalStrengthLevel1Bar = 1; 153 const int MockChooserController::kSignalStrengthLevel1Bar = 1;
140 const int MockChooserController::kSignalStrengthLevel2Bar = 2; 154 const int MockChooserController::kSignalStrengthLevel2Bar = 2;
141 const int MockChooserController::kSignalStrengthLevel3Bar = 3; 155 const int MockChooserController::kSignalStrengthLevel3Bar = 3;
142 const int MockChooserController::kSignalStrengthLevel4Bar = 4; 156 const int MockChooserController::kSignalStrengthLevel4Bar = 4;
143 157
144 void MockChooserController::ClearAllOptions() { 158 void MockChooserController::ClearAllOptions() {
145 options_.clear(); 159 options_.clear();
146 } 160 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698