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

Side by Side Diff: chromeos/network/network_state_handler.cc

Issue 2701463003: Create a Tether section in the system tray network list. (Closed)
Patch Set: Use NetworkStateHandler::GetTechnologyState and explicitly fetch the Tether networks in NetworkList… Created 3 years, 10 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
« no previous file with comments | « chromeos/network/network_state_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chromeos/network/network_state_handler.h" 5 #include "chromeos/network/network_state_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h"
10 #include "base/format_macros.h" 11 #include "base/format_macros.h"
11 #include "base/guid.h" 12 #include "base/guid.h"
12 #include "base/json/json_string_value_serializer.h" 13 #include "base/json/json_string_value_serializer.h"
13 #include "base/json/json_writer.h" 14 #include "base/json/json_writer.h"
14 #include "base/location.h" 15 #include "base/location.h"
15 #include "base/logging.h" 16 #include "base/logging.h"
16 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
17 #include "base/metrics/histogram_macros.h" 18 #include "base/metrics/histogram_macros.h"
18 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
20 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
21 #include "base/values.h" 22 #include "base/values.h"
23 #include "chromeos/chromeos_switches.h"
22 #include "chromeos/network/device_state.h" 24 #include "chromeos/network/device_state.h"
23 #include "chromeos/network/network_event_log.h" 25 #include "chromeos/network/network_event_log.h"
24 #include "chromeos/network/network_state.h" 26 #include "chromeos/network/network_state.h"
25 #include "chromeos/network/network_state_handler_observer.h" 27 #include "chromeos/network/network_state_handler_observer.h"
26 #include "third_party/cros_system_api/dbus/service_constants.h" 28 #include "third_party/cros_system_api/dbus/service_constants.h"
27 29
28 namespace chromeos { 30 namespace chromeos {
29 31
30 namespace { 32 namespace {
31 33
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 if (shill_property_handler_->IsTechnologyEnabled(technology)) 128 if (shill_property_handler_->IsTechnologyEnabled(technology))
127 state = TECHNOLOGY_ENABLED; 129 state = TECHNOLOGY_ENABLED;
128 else if (shill_property_handler_->IsTechnologyEnabling(technology)) 130 else if (shill_property_handler_->IsTechnologyEnabling(technology))
129 state = TECHNOLOGY_ENABLING; 131 state = TECHNOLOGY_ENABLING;
130 else if (shill_property_handler_->IsTechnologyProhibited(technology)) 132 else if (shill_property_handler_->IsTechnologyProhibited(technology))
131 state = TECHNOLOGY_PROHIBITED; 133 state = TECHNOLOGY_PROHIBITED;
132 else if (shill_property_handler_->IsTechnologyUninitialized(technology)) 134 else if (shill_property_handler_->IsTechnologyUninitialized(technology))
133 state = TECHNOLOGY_UNINITIALIZED; 135 state = TECHNOLOGY_UNINITIALIZED;
134 else if (shill_property_handler_->IsTechnologyAvailable(technology)) 136 else if (shill_property_handler_->IsTechnologyAvailable(technology))
135 state = TECHNOLOGY_AVAILABLE; 137 state = TECHNOLOGY_AVAILABLE;
136 else 138 else if (technology == kTypeTether) {
Ryan Hansberry 2017/02/16 22:42:20 (holding off on writing a test until I get the cle
139 bool isTetherAvailable = base::CommandLine::ForCurrentProcess()->HasSwitch(
140 chromeos::switches::kEnableTether);
141 if (isTetherAvailable) {
142 // TODO (hansberry): Figure this one out.
143 bool isTetherEnabled = true;
144 if (isTetherEnabled) {
145 return TECHNOLOGY_ENABLED;
146 }
147 return TECHNOLOGY_AVAILABLE;
148 }
149 } else
137 state = TECHNOLOGY_UNAVAILABLE; 150 state = TECHNOLOGY_UNAVAILABLE;
138 VLOG(2) << "GetTechnologyState: " << type.ToDebugString() << " = " << state; 151 VLOG(2) << "GetTechnologyState: " << type.ToDebugString() << " = " << state;
139 return state; 152 return state;
140 } 153 }
141 154
142 void NetworkStateHandler::SetTechnologyEnabled( 155 void NetworkStateHandler::SetTechnologyEnabled(
143 const NetworkTypePattern& type, 156 const NetworkTypePattern& type,
144 bool enabled, 157 bool enabled,
145 const network_handler::ErrorCallback& error_callback) { 158 const network_handler::ErrorCallback& error_callback) {
146 std::vector<std::string> technologies = GetTechnologiesForType(type); 159 std::vector<std::string> technologies = GetTechnologiesForType(type);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 continue; 206 continue;
194 if (device->Matches(type) && device->scanning()) 207 if (device->Matches(type) && device->scanning())
195 return true; 208 return true;
196 } 209 }
197 return false; 210 return false;
198 } 211 }
199 212
200 const NetworkState* NetworkStateHandler::GetNetworkState( 213 const NetworkState* NetworkStateHandler::GetNetworkState(
201 const std::string& service_path) const { 214 const std::string& service_path) const {
202 const NetworkState* network = GetModifiableNetworkState(service_path); 215 const NetworkState* network = GetModifiableNetworkState(service_path);
216 // This is a hack that I don't intend to keep here.
217 if (!network) {
218 return GetNetworkStateFromGuid(service_path);
219 }
203 if (network && !network->update_received()) 220 if (network && !network->update_received())
204 return nullptr; 221 return nullptr;
205 return network; 222 return network;
206 } 223 }
207 224
208 const NetworkState* NetworkStateHandler::DefaultNetwork() const { 225 const NetworkState* NetworkStateHandler::DefaultNetwork() const {
209 if (default_network_path_.empty()) 226 if (default_network_path_.empty())
210 return nullptr; 227 return nullptr;
211 return GetNetworkState(default_network_path_); 228 return GetNetworkState(default_network_path_);
212 } 229 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 } 299 }
283 300
284 void NetworkStateHandler::GetNetworkListByType(const NetworkTypePattern& type, 301 void NetworkStateHandler::GetNetworkListByType(const NetworkTypePattern& type,
285 bool configured_only, 302 bool configured_only,
286 bool visible_only, 303 bool visible_only,
287 int limit, 304 int limit,
288 NetworkStateList* list) { 305 NetworkStateList* list) {
289 DCHECK(list); 306 DCHECK(list);
290 list->clear(); 307 list->clear();
291 int count = 0; 308 int count = 0;
309
310 if (NetworkTypePattern::Tether().MatchesPattern(type)) {
Ryan Hansberry 2017/02/16 22:42:20 Should there actually just be a GetTetherNetworkLi
Ryan Hansberry 2017/02/17 19:29:42 Ping.
stevenjb 2017/02/17 20:11:10 That seems fine also, although this would allow us
Ryan Hansberry 2017/02/17 23:28:13 Done.
311 for (auto iter = tether_network_list_.begin();
312 iter != tether_network_list_.end(); ++iter) {
313 list->push_back((*iter)->AsNetworkState());
314 if (limit > 0 && ++count >= limit)
315 return;
316 }
317 }
318
292 // Sort the network list if necessary. 319 // Sort the network list if necessary.
293 if (!network_list_sorted_) 320 if (!network_list_sorted_)
294 SortNetworkList(); 321 SortNetworkList();
295 for (auto iter = network_list_.begin(); iter != network_list_.end(); ++iter) { 322 for (auto iter = network_list_.begin(); iter != network_list_.end(); ++iter) {
296 const NetworkState* network = (*iter)->AsNetworkState(); 323 const NetworkState* network = (*iter)->AsNetworkState();
297 DCHECK(network); 324 DCHECK(network);
298 if (!network->update_received() || !network->Matches(type)) 325 if (!network->update_received() || !network->Matches(type))
299 continue; 326 continue;
300 if (configured_only && !network->IsInProfile()) 327 if (configured_only && !network->IsInProfile())
301 continue; 328 continue;
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 1048
1022 // Prefer Wimax over Cellular only if it's available. 1049 // Prefer Wimax over Cellular only if it's available.
1023 if (type.MatchesType(shill::kTypeWimax) && 1050 if (type.MatchesType(shill::kTypeWimax) &&
1024 shill_property_handler_->IsTechnologyAvailable(shill::kTypeWimax)) { 1051 shill_property_handler_->IsTechnologyAvailable(shill::kTypeWimax)) {
1025 return shill::kTypeWimax; 1052 return shill::kTypeWimax;
1026 } 1053 }
1027 1054
1028 if (type.MatchesType(shill::kTypeCellular)) 1055 if (type.MatchesType(shill::kTypeCellular))
1029 return shill::kTypeCellular; 1056 return shill::kTypeCellular;
1030 1057
1058 if (type.MatchesType(kTypeTether))
1059 return kTypeTether;
1060
1031 NOTREACHED(); 1061 NOTREACHED();
1032 return std::string(); 1062 return std::string();
1033 } 1063 }
1034 1064
1035 std::vector<std::string> NetworkStateHandler::GetTechnologiesForType( 1065 std::vector<std::string> NetworkStateHandler::GetTechnologiesForType(
1036 const NetworkTypePattern& type) const { 1066 const NetworkTypePattern& type) const {
1037 std::vector<std::string> technologies; 1067 std::vector<std::string> technologies;
1038 if (type.MatchesType(shill::kTypeEthernet)) 1068 if (type.MatchesType(shill::kTypeEthernet))
1039 technologies.emplace_back(shill::kTypeEthernet); 1069 technologies.emplace_back(shill::kTypeEthernet);
1040 if (type.MatchesType(shill::kTypeWifi)) 1070 if (type.MatchesType(shill::kTypeWifi))
1041 technologies.emplace_back(shill::kTypeWifi); 1071 technologies.emplace_back(shill::kTypeWifi);
1042 if (type.MatchesType(shill::kTypeWimax)) 1072 if (type.MatchesType(shill::kTypeWimax))
1043 technologies.emplace_back(shill::kTypeWimax); 1073 technologies.emplace_back(shill::kTypeWimax);
1044 if (type.MatchesType(shill::kTypeCellular)) 1074 if (type.MatchesType(shill::kTypeCellular))
1045 technologies.emplace_back(shill::kTypeCellular); 1075 technologies.emplace_back(shill::kTypeCellular);
1046 if (type.MatchesType(shill::kTypeBluetooth)) 1076 if (type.MatchesType(shill::kTypeBluetooth))
1047 technologies.emplace_back(shill::kTypeBluetooth); 1077 technologies.emplace_back(shill::kTypeBluetooth);
1048 if (type.MatchesType(shill::kTypeVPN)) 1078 if (type.MatchesType(shill::kTypeVPN))
1049 technologies.emplace_back(shill::kTypeVPN); 1079 technologies.emplace_back(shill::kTypeVPN);
1050 1080
1051 CHECK_GT(technologies.size(), 0ul); 1081 CHECK_GT(technologies.size(), 0ul);
1052 return technologies; 1082 return technologies;
1053 } 1083 }
1054 1084
1055 } // namespace chromeos 1085 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/network_state_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698