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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 device_event_log::AddEntry( | 117 device_event_log::AddEntry( |
116 from_here.file_name(), from_here.line_number(), | 118 from_here.file_name(), from_here.line_number(), |
117 device_event_log::LOG_TYPE_NETWORK, device_event_log::LOG_LEVEL_DEBUG, | 119 device_event_log::LOG_TYPE_NETWORK, device_event_log::LOG_LEVEL_DEBUG, |
118 base::StringPrintf("NetworkStateHandler::RemoveObserver: 0x%p", | 120 base::StringPrintf("NetworkStateHandler::RemoveObserver: 0x%p", |
119 observer)); | 121 observer)); |
120 } | 122 } |
121 | 123 |
122 NetworkStateHandler::TechnologyState NetworkStateHandler::GetTechnologyState( | 124 NetworkStateHandler::TechnologyState NetworkStateHandler::GetTechnologyState( |
123 const NetworkTypePattern& type) const { | 125 const NetworkTypePattern& type) const { |
124 std::string technology = GetTechnologyForType(type); | 126 std::string technology = GetTechnologyForType(type); |
| 127 |
| 128 if (technology == kTypeTether) { |
| 129 bool is_tether_enabled = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 130 chromeos::switches::kEnableTether); |
| 131 return is_tether_enabled ? TECHNOLOGY_ENABLED : TECHNOLOGY_UNAVAILABLE; |
| 132 } |
| 133 |
125 TechnologyState state; | 134 TechnologyState state; |
126 if (shill_property_handler_->IsTechnologyEnabled(technology)) | 135 if (shill_property_handler_->IsTechnologyEnabled(technology)) |
127 state = TECHNOLOGY_ENABLED; | 136 state = TECHNOLOGY_ENABLED; |
128 else if (shill_property_handler_->IsTechnologyEnabling(technology)) | 137 else if (shill_property_handler_->IsTechnologyEnabling(technology)) |
129 state = TECHNOLOGY_ENABLING; | 138 state = TECHNOLOGY_ENABLING; |
130 else if (shill_property_handler_->IsTechnologyProhibited(technology)) | 139 else if (shill_property_handler_->IsTechnologyProhibited(technology)) |
131 state = TECHNOLOGY_PROHIBITED; | 140 state = TECHNOLOGY_PROHIBITED; |
132 else if (shill_property_handler_->IsTechnologyUninitialized(technology)) | 141 else if (shill_property_handler_->IsTechnologyUninitialized(technology)) |
133 state = TECHNOLOGY_UNINITIALIZED; | 142 state = TECHNOLOGY_UNINITIALIZED; |
134 else if (shill_property_handler_->IsTechnologyAvailable(technology)) | 143 else if (shill_property_handler_->IsTechnologyAvailable(technology)) |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 if (configured_only && !network->IsInProfile()) | 309 if (configured_only && !network->IsInProfile()) |
301 continue; | 310 continue; |
302 if (visible_only && !network->visible()) | 311 if (visible_only && !network->visible()) |
303 continue; | 312 continue; |
304 list->push_back(network); | 313 list->push_back(network); |
305 if (limit > 0 && ++count >= limit) | 314 if (limit > 0 && ++count >= limit) |
306 break; | 315 break; |
307 } | 316 } |
308 } | 317 } |
309 | 318 |
| 319 void NetworkStateHandler::GetTetherNetworkList(int limit, |
| 320 NetworkStateList* list) { |
| 321 DCHECK(list); |
| 322 list->clear(); |
| 323 int count = 0; |
| 324 |
| 325 for (auto iter = tether_network_list_.begin(); |
| 326 iter != tether_network_list_.end(); ++iter) { |
| 327 list->push_back((*iter)->AsNetworkState()); |
| 328 if (limit > 0 && ++count >= limit) |
| 329 return; |
| 330 } |
| 331 } |
| 332 |
310 const NetworkState* NetworkStateHandler::GetNetworkStateFromServicePath( | 333 const NetworkState* NetworkStateHandler::GetNetworkStateFromServicePath( |
311 const std::string& service_path, | 334 const std::string& service_path, |
312 bool configured_only) const { | 335 bool configured_only) const { |
313 ManagedState* managed = | 336 ManagedState* managed = |
314 GetModifiableManagedState(&network_list_, service_path); | 337 GetModifiableManagedState(&network_list_, service_path); |
315 if (!managed) | 338 if (!managed) |
316 return nullptr; | 339 return nullptr; |
317 const NetworkState* network = managed->AsNetworkState(); | 340 const NetworkState* network = managed->AsNetworkState(); |
318 DCHECK(network); | 341 DCHECK(network); |
319 if (!network->update_received() || | 342 if (!network->update_received() || |
(...skipping 16 matching lines...) Expand all Loading... |
336 for (auto iter = tether_network_list_.begin(); | 359 for (auto iter = tether_network_list_.begin(); |
337 iter != tether_network_list_.end(); ++iter) { | 360 iter != tether_network_list_.end(); ++iter) { |
338 const NetworkState* network = (*iter)->AsNetworkState(); | 361 const NetworkState* network = (*iter)->AsNetworkState(); |
339 if (network->guid() == guid) | 362 if (network->guid() == guid) |
340 return network; | 363 return network; |
341 } | 364 } |
342 | 365 |
343 return nullptr; | 366 return nullptr; |
344 } | 367 } |
345 | 368 |
346 const std::string NetworkStateHandler::CreateTetherNetworkState( | 369 void NetworkStateHandler::AddTetherNetworkState(const std::string& guid, |
347 const std::string& name) { | 370 const std::string& name) { |
348 const std::string& guid = base::GenerateGUID(); | 371 DCHECK(!guid.empty()); |
| 372 |
| 373 // If the network already exists, do nothing. |
| 374 for (auto iter = tether_network_list_.begin(); |
| 375 iter != tether_network_list_.end(); ++iter) { |
| 376 if (iter->get()->AsNetworkState()->guid() == guid) { |
| 377 NET_LOG(ERROR) << "AddTetherNetworkState: " << name |
| 378 << " called with existing guid:" << guid; |
| 379 return; |
| 380 } |
| 381 } |
349 | 382 |
350 std::unique_ptr<NetworkState> tether_managed_state = | 383 std::unique_ptr<NetworkState> tether_managed_state = |
351 base::MakeUnique<NetworkState>(base::GenerateGUID()); | 384 base::MakeUnique<NetworkState>(base::GenerateGUID()); |
352 | 385 |
353 tether_managed_state->set_name(name); | 386 tether_managed_state->set_name(name); |
354 tether_managed_state->set_type(kTypeTether); | 387 tether_managed_state->set_type(kTypeTether); |
355 tether_managed_state->SetGuid(guid); | 388 tether_managed_state->SetGuid(guid); |
356 tether_managed_state->set_update_received(); | 389 tether_managed_state->set_update_received(); |
357 | 390 |
358 tether_network_list_.push_back(std::move(tether_managed_state)); | 391 tether_network_list_.push_back(std::move(tether_managed_state)); |
359 NotifyNetworkListChanged(); | 392 NotifyNetworkListChanged(); |
360 | |
361 return guid; | |
362 } | 393 } |
363 | 394 |
364 void NetworkStateHandler::RemoveTetherNetworkState(const std::string& guid) { | 395 void NetworkStateHandler::RemoveTetherNetworkState(const std::string& guid) { |
365 for (auto iter = tether_network_list_.begin(); | 396 for (auto iter = tether_network_list_.begin(); |
366 iter != tether_network_list_.end(); ++iter) { | 397 iter != tether_network_list_.end(); ++iter) { |
367 if (iter->get()->AsNetworkState()->guid() == guid) { | 398 if (iter->get()->AsNetworkState()->guid() == guid) { |
368 tether_network_list_.erase(iter); | 399 tether_network_list_.erase(iter); |
369 NotifyNetworkListChanged(); | 400 NotifyNetworkListChanged(); |
370 return; | 401 return; |
371 } | 402 } |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 | 1052 |
1022 // Prefer Wimax over Cellular only if it's available. | 1053 // Prefer Wimax over Cellular only if it's available. |
1023 if (type.MatchesType(shill::kTypeWimax) && | 1054 if (type.MatchesType(shill::kTypeWimax) && |
1024 shill_property_handler_->IsTechnologyAvailable(shill::kTypeWimax)) { | 1055 shill_property_handler_->IsTechnologyAvailable(shill::kTypeWimax)) { |
1025 return shill::kTypeWimax; | 1056 return shill::kTypeWimax; |
1026 } | 1057 } |
1027 | 1058 |
1028 if (type.MatchesType(shill::kTypeCellular)) | 1059 if (type.MatchesType(shill::kTypeCellular)) |
1029 return shill::kTypeCellular; | 1060 return shill::kTypeCellular; |
1030 | 1061 |
| 1062 if (type.MatchesType(kTypeTether)) |
| 1063 return kTypeTether; |
| 1064 |
1031 NOTREACHED(); | 1065 NOTREACHED(); |
1032 return std::string(); | 1066 return std::string(); |
1033 } | 1067 } |
1034 | 1068 |
1035 std::vector<std::string> NetworkStateHandler::GetTechnologiesForType( | 1069 std::vector<std::string> NetworkStateHandler::GetTechnologiesForType( |
1036 const NetworkTypePattern& type) const { | 1070 const NetworkTypePattern& type) const { |
1037 std::vector<std::string> technologies; | 1071 std::vector<std::string> technologies; |
1038 if (type.MatchesType(shill::kTypeEthernet)) | 1072 if (type.MatchesType(shill::kTypeEthernet)) |
1039 technologies.emplace_back(shill::kTypeEthernet); | 1073 technologies.emplace_back(shill::kTypeEthernet); |
1040 if (type.MatchesType(shill::kTypeWifi)) | 1074 if (type.MatchesType(shill::kTypeWifi)) |
1041 technologies.emplace_back(shill::kTypeWifi); | 1075 technologies.emplace_back(shill::kTypeWifi); |
1042 if (type.MatchesType(shill::kTypeWimax)) | 1076 if (type.MatchesType(shill::kTypeWimax)) |
1043 technologies.emplace_back(shill::kTypeWimax); | 1077 technologies.emplace_back(shill::kTypeWimax); |
1044 if (type.MatchesType(shill::kTypeCellular)) | 1078 if (type.MatchesType(shill::kTypeCellular)) |
1045 technologies.emplace_back(shill::kTypeCellular); | 1079 technologies.emplace_back(shill::kTypeCellular); |
1046 if (type.MatchesType(shill::kTypeBluetooth)) | 1080 if (type.MatchesType(shill::kTypeBluetooth)) |
1047 technologies.emplace_back(shill::kTypeBluetooth); | 1081 technologies.emplace_back(shill::kTypeBluetooth); |
1048 if (type.MatchesType(shill::kTypeVPN)) | 1082 if (type.MatchesType(shill::kTypeVPN)) |
1049 technologies.emplace_back(shill::kTypeVPN); | 1083 technologies.emplace_back(shill::kTypeVPN); |
1050 | 1084 |
1051 CHECK_GT(technologies.size(), 0ul); | 1085 CHECK_GT(technologies.size(), 0ul); |
1052 return technologies; | 1086 return technologies; |
1053 } | 1087 } |
1054 | 1088 |
1055 } // namespace chromeos | 1089 } // namespace chromeos |
OLD | NEW |