OLD | NEW |
---|---|
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 Loading... | |
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 && |
139 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
140 chromeos::switches::kEnableTether)) { | |
141 // TODO (hansberry): Provide Tether a way to enable and disable the | |
142 // technology. | |
143 state = TECHNOLOGY_ENABLED; | |
stevenjb
2017/02/21 22:43:56
If we but {} around one if clause, we should put i
Ryan Hansberry
2017/02/21 23:26:37
Done. Decided to not add a VLOG.
| |
144 } else | |
137 state = TECHNOLOGY_UNAVAILABLE; | 145 state = TECHNOLOGY_UNAVAILABLE; |
138 VLOG(2) << "GetTechnologyState: " << type.ToDebugString() << " = " << state; | 146 VLOG(2) << "GetTechnologyState: " << type.ToDebugString() << " = " << state; |
139 return state; | 147 return state; |
140 } | 148 } |
141 | 149 |
142 void NetworkStateHandler::SetTechnologyEnabled( | 150 void NetworkStateHandler::SetTechnologyEnabled( |
143 const NetworkTypePattern& type, | 151 const NetworkTypePattern& type, |
144 bool enabled, | 152 bool enabled, |
145 const network_handler::ErrorCallback& error_callback) { | 153 const network_handler::ErrorCallback& error_callback) { |
146 std::vector<std::string> technologies = GetTechnologiesForType(type); | 154 std::vector<std::string> technologies = GetTechnologiesForType(type); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 if (configured_only && !network->IsInProfile()) | 308 if (configured_only && !network->IsInProfile()) |
301 continue; | 309 continue; |
302 if (visible_only && !network->visible()) | 310 if (visible_only && !network->visible()) |
303 continue; | 311 continue; |
304 list->push_back(network); | 312 list->push_back(network); |
305 if (limit > 0 && ++count >= limit) | 313 if (limit > 0 && ++count >= limit) |
306 break; | 314 break; |
307 } | 315 } |
308 } | 316 } |
309 | 317 |
318 void NetworkStateHandler::GetTetherNetworkList(int limit, | |
319 NetworkStateList* list) { | |
320 DCHECK(list); | |
321 list->clear(); | |
322 int count = 0; | |
323 | |
324 for (auto iter = tether_network_list_.begin(); | |
325 iter != tether_network_list_.end(); ++iter) { | |
326 list->push_back((*iter)->AsNetworkState()); | |
327 if (limit > 0 && ++count >= limit) | |
328 return; | |
329 } | |
330 } | |
331 | |
310 const NetworkState* NetworkStateHandler::GetNetworkStateFromServicePath( | 332 const NetworkState* NetworkStateHandler::GetNetworkStateFromServicePath( |
311 const std::string& service_path, | 333 const std::string& service_path, |
312 bool configured_only) const { | 334 bool configured_only) const { |
313 ManagedState* managed = | 335 ManagedState* managed = |
314 GetModifiableManagedState(&network_list_, service_path); | 336 GetModifiableManagedState(&network_list_, service_path); |
315 if (!managed) | 337 if (!managed) |
316 return nullptr; | 338 return nullptr; |
317 const NetworkState* network = managed->AsNetworkState(); | 339 const NetworkState* network = managed->AsNetworkState(); |
318 DCHECK(network); | 340 DCHECK(network); |
319 if (!network->update_received() || | 341 if (!network->update_received() || |
(...skipping 16 matching lines...) Expand all Loading... | |
336 for (auto iter = tether_network_list_.begin(); | 358 for (auto iter = tether_network_list_.begin(); |
337 iter != tether_network_list_.end(); ++iter) { | 359 iter != tether_network_list_.end(); ++iter) { |
338 const NetworkState* network = (*iter)->AsNetworkState(); | 360 const NetworkState* network = (*iter)->AsNetworkState(); |
339 if (network->guid() == guid) | 361 if (network->guid() == guid) |
340 return network; | 362 return network; |
341 } | 363 } |
342 | 364 |
343 return nullptr; | 365 return nullptr; |
344 } | 366 } |
345 | 367 |
346 const std::string NetworkStateHandler::CreateTetherNetworkState( | 368 void NetworkStateHandler::AddTetherNetworkState(const std::string& guid, |
347 const std::string& name) { | 369 const std::string& name) { |
348 const std::string& guid = base::GenerateGUID(); | 370 #if DCHECK_IS_ON() |
stevenjb
2017/02/21 22:43:56
This #if is only needed if there is logic other th
Ryan Hansberry
2017/02/21 23:26:37
Done.
| |
371 DCHECK(!guid.empty()); | |
372 #endif | |
373 | |
374 // If the network already exists, do nothing. | |
375 for (auto iter = tether_network_list_.begin(); | |
376 iter != tether_network_list_.end(); ++iter) { | |
377 if (iter->get()->AsNetworkState()->guid() == guid) { | |
stevenjb
2017/02/21 22:43:56
I would add:
NET_LOG(ERROR) << "Add tether network
Ryan Hansberry
2017/02/21 23:26:37
Done.
| |
378 return; | |
379 } | |
380 } | |
349 | 381 |
350 std::unique_ptr<NetworkState> tether_managed_state = | 382 std::unique_ptr<NetworkState> tether_managed_state = |
351 base::MakeUnique<NetworkState>(base::GenerateGUID()); | 383 base::MakeUnique<NetworkState>(base::GenerateGUID()); |
352 | 384 |
353 tether_managed_state->set_name(name); | 385 tether_managed_state->set_name(name); |
354 tether_managed_state->set_type(kTypeTether); | 386 tether_managed_state->set_type(kTypeTether); |
355 tether_managed_state->SetGuid(guid); | 387 tether_managed_state->SetGuid(guid); |
356 tether_managed_state->set_update_received(); | 388 tether_managed_state->set_update_received(); |
357 | 389 |
358 tether_network_list_.push_back(std::move(tether_managed_state)); | 390 tether_network_list_.push_back(std::move(tether_managed_state)); |
359 NotifyNetworkListChanged(); | 391 NotifyNetworkListChanged(); |
360 | |
361 return guid; | |
362 } | 392 } |
363 | 393 |
364 void NetworkStateHandler::RemoveTetherNetworkState(const std::string& guid) { | 394 void NetworkStateHandler::RemoveTetherNetworkState(const std::string& guid) { |
365 for (auto iter = tether_network_list_.begin(); | 395 for (auto iter = tether_network_list_.begin(); |
366 iter != tether_network_list_.end(); ++iter) { | 396 iter != tether_network_list_.end(); ++iter) { |
367 if (iter->get()->AsNetworkState()->guid() == guid) { | 397 if (iter->get()->AsNetworkState()->guid() == guid) { |
368 tether_network_list_.erase(iter); | 398 tether_network_list_.erase(iter); |
369 NotifyNetworkListChanged(); | 399 NotifyNetworkListChanged(); |
370 return; | 400 return; |
371 } | 401 } |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1021 | 1051 |
1022 // Prefer Wimax over Cellular only if it's available. | 1052 // Prefer Wimax over Cellular only if it's available. |
1023 if (type.MatchesType(shill::kTypeWimax) && | 1053 if (type.MatchesType(shill::kTypeWimax) && |
1024 shill_property_handler_->IsTechnologyAvailable(shill::kTypeWimax)) { | 1054 shill_property_handler_->IsTechnologyAvailable(shill::kTypeWimax)) { |
1025 return shill::kTypeWimax; | 1055 return shill::kTypeWimax; |
1026 } | 1056 } |
1027 | 1057 |
1028 if (type.MatchesType(shill::kTypeCellular)) | 1058 if (type.MatchesType(shill::kTypeCellular)) |
1029 return shill::kTypeCellular; | 1059 return shill::kTypeCellular; |
1030 | 1060 |
1061 if (type.MatchesType(kTypeTether)) | |
1062 return kTypeTether; | |
1063 | |
1031 NOTREACHED(); | 1064 NOTREACHED(); |
1032 return std::string(); | 1065 return std::string(); |
1033 } | 1066 } |
1034 | 1067 |
1035 std::vector<std::string> NetworkStateHandler::GetTechnologiesForType( | 1068 std::vector<std::string> NetworkStateHandler::GetTechnologiesForType( |
1036 const NetworkTypePattern& type) const { | 1069 const NetworkTypePattern& type) const { |
1037 std::vector<std::string> technologies; | 1070 std::vector<std::string> technologies; |
1038 if (type.MatchesType(shill::kTypeEthernet)) | 1071 if (type.MatchesType(shill::kTypeEthernet)) |
1039 technologies.emplace_back(shill::kTypeEthernet); | 1072 technologies.emplace_back(shill::kTypeEthernet); |
1040 if (type.MatchesType(shill::kTypeWifi)) | 1073 if (type.MatchesType(shill::kTypeWifi)) |
1041 technologies.emplace_back(shill::kTypeWifi); | 1074 technologies.emplace_back(shill::kTypeWifi); |
1042 if (type.MatchesType(shill::kTypeWimax)) | 1075 if (type.MatchesType(shill::kTypeWimax)) |
1043 technologies.emplace_back(shill::kTypeWimax); | 1076 technologies.emplace_back(shill::kTypeWimax); |
1044 if (type.MatchesType(shill::kTypeCellular)) | 1077 if (type.MatchesType(shill::kTypeCellular)) |
1045 technologies.emplace_back(shill::kTypeCellular); | 1078 technologies.emplace_back(shill::kTypeCellular); |
1046 if (type.MatchesType(shill::kTypeBluetooth)) | 1079 if (type.MatchesType(shill::kTypeBluetooth)) |
1047 technologies.emplace_back(shill::kTypeBluetooth); | 1080 technologies.emplace_back(shill::kTypeBluetooth); |
1048 if (type.MatchesType(shill::kTypeVPN)) | 1081 if (type.MatchesType(shill::kTypeVPN)) |
1049 technologies.emplace_back(shill::kTypeVPN); | 1082 technologies.emplace_back(shill::kTypeVPN); |
1050 | 1083 |
1051 CHECK_GT(technologies.size(), 0ul); | 1084 CHECK_GT(technologies.size(), 0ul); |
1052 return technologies; | 1085 return technologies; |
1053 } | 1086 } |
1054 | 1087 |
1055 } // namespace chromeos | 1088 } // namespace chromeos |
OLD | NEW |