| 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/command_line.h" |
| 11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
| 12 #include "base/guid.h" | 12 #include "base/guid.h" |
| 13 #include "base/json/json_string_value_serializer.h" | 13 #include "base/json/json_string_value_serializer.h" |
| 14 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
| 15 #include "base/location.h" | 15 #include "base/location.h" |
| 16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 17 #include "base/metrics/histogram_macros.h" | 17 #include "base/metrics/histogram_macros.h" |
| 18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 21 #include "base/values.h" | 21 #include "base/values.h" |
| 22 #include "chromeos/chromeos_switches.h" | 22 #include "chromeos/chromeos_switches.h" |
| 23 #include "chromeos/network/device_state.h" | 23 #include "chromeos/network/device_state.h" |
| 24 #include "chromeos/network/network_connection_handler.h" | |
| 25 #include "chromeos/network/network_event_log.h" | 24 #include "chromeos/network/network_event_log.h" |
| 26 #include "chromeos/network/network_handler_callbacks.h" | |
| 27 #include "chromeos/network/network_state.h" | 25 #include "chromeos/network/network_state.h" |
| 28 #include "chromeos/network/network_state_handler_observer.h" | 26 #include "chromeos/network/network_state_handler_observer.h" |
| 29 #include "chromeos/network/tether_constants.h" | 27 #include "chromeos/network/tether_constants.h" |
| 30 #include "third_party/cros_system_api/dbus/service_constants.h" | 28 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 31 | 29 |
| 32 namespace chromeos { | 30 namespace chromeos { |
| 33 | 31 |
| 34 namespace { | 32 namespace { |
| 35 | 33 |
| 36 bool ConnectionStateChanged(NetworkState* network, | 34 bool ConnectionStateChanged(NetworkState* network, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 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, |
| 122 base::StringPrintf("NetworkStateHandler::RemoveObserver: 0x%p", | 120 base::StringPrintf("NetworkStateHandler::RemoveObserver: 0x%p", |
| 123 observer)); | 121 observer)); |
| 124 } | 122 } |
| 125 | 123 |
| 126 NetworkStateHandler::TechnologyState NetworkStateHandler::GetTechnologyState( | 124 NetworkStateHandler::TechnologyState NetworkStateHandler::GetTechnologyState( |
| 127 const NetworkTypePattern& type) const { | 125 const NetworkTypePattern& type) const { |
| 128 std::string technology = GetTechnologyForType(type); | 126 std::string technology = GetTechnologyForType(type); |
| 129 | 127 |
| 130 if (technology == kTypeTether) { | 128 if (technology == kTypeTether) { |
| 131 return tether_technology_state_; | 129 bool is_tether_enabled = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 130 chromeos::switches::kEnableTether); |
| 131 return is_tether_enabled ? TECHNOLOGY_ENABLED : TECHNOLOGY_UNAVAILABLE; |
| 132 } | 132 } |
| 133 | 133 |
| 134 TechnologyState state; | 134 TechnologyState state; |
| 135 if (shill_property_handler_->IsTechnologyEnabled(technology)) | 135 if (shill_property_handler_->IsTechnologyEnabled(technology)) |
| 136 state = TECHNOLOGY_ENABLED; | 136 state = TECHNOLOGY_ENABLED; |
| 137 else if (shill_property_handler_->IsTechnologyEnabling(technology)) | 137 else if (shill_property_handler_->IsTechnologyEnabling(technology)) |
| 138 state = TECHNOLOGY_ENABLING; | 138 state = TECHNOLOGY_ENABLING; |
| 139 else if (shill_property_handler_->IsTechnologyProhibited(technology)) | 139 else if (shill_property_handler_->IsTechnologyProhibited(technology)) |
| 140 state = TECHNOLOGY_PROHIBITED; | 140 state = TECHNOLOGY_PROHIBITED; |
| 141 else if (shill_property_handler_->IsTechnologyUninitialized(technology)) | 141 else if (shill_property_handler_->IsTechnologyUninitialized(technology)) |
| 142 state = TECHNOLOGY_UNINITIALIZED; | 142 state = TECHNOLOGY_UNINITIALIZED; |
| 143 else if (shill_property_handler_->IsTechnologyAvailable(technology)) | 143 else if (shill_property_handler_->IsTechnologyAvailable(technology)) |
| 144 state = TECHNOLOGY_AVAILABLE; | 144 state = TECHNOLOGY_AVAILABLE; |
| 145 else | 145 else |
| 146 state = TECHNOLOGY_UNAVAILABLE; | 146 state = TECHNOLOGY_UNAVAILABLE; |
| 147 VLOG(2) << "GetTechnologyState: " << type.ToDebugString() << " = " << state; | 147 VLOG(2) << "GetTechnologyState: " << type.ToDebugString() << " = " << state; |
| 148 return state; | 148 return state; |
| 149 } | 149 } |
| 150 | 150 |
| 151 void NetworkStateHandler::SetTechnologyEnabled( | 151 void NetworkStateHandler::SetTechnologyEnabled( |
| 152 const NetworkTypePattern& type, | 152 const NetworkTypePattern& type, |
| 153 bool enabled, | 153 bool enabled, |
| 154 const network_handler::ErrorCallback& error_callback) { | 154 const network_handler::ErrorCallback& error_callback) { |
| 155 std::vector<std::string> technologies = GetTechnologiesForType(type); | 155 std::vector<std::string> technologies = GetTechnologiesForType(type); |
| 156 for (const std::string& technology : technologies) { | 156 for (const std::string& technology : technologies) { |
| 157 if (technology == kTypeTether) { | |
| 158 if (tether_technology_state_ != TECHNOLOGY_ENABLED && | |
| 159 tether_technology_state_ != TECHNOLOGY_AVAILABLE) { | |
| 160 NET_LOG(ERROR) << "SetTechnologyEnabled() called for the Tether " | |
| 161 << "DeviceState, but the current state was not " | |
| 162 << "TECHNOLOGY_ENABLED or TECHNOLOGY_AVAILABLE."; | |
| 163 network_handler::RunErrorCallback( | |
| 164 error_callback, kTetherDevicePath, | |
| 165 NetworkConnectionHandler::kEnabledOrDisabledWhenNotAvailable, ""); | |
| 166 continue; | |
| 167 } | |
| 168 | |
| 169 // Tether does not exist in Shill, so set |tether_technology_state_| and | |
| 170 // skip the below interactions with |shill_property_handler_|. | |
| 171 tether_technology_state_ = | |
| 172 enabled ? TECHNOLOGY_ENABLED : TECHNOLOGY_AVAILABLE; | |
| 173 continue; | |
| 174 } | |
| 175 | |
| 176 if (!shill_property_handler_->IsTechnologyAvailable(technology)) | 157 if (!shill_property_handler_->IsTechnologyAvailable(technology)) |
| 177 continue; | 158 continue; |
| 178 NET_LOG_USER("SetTechnologyEnabled", | 159 NET_LOG_USER("SetTechnologyEnabled", |
| 179 base::StringPrintf("%s:%d", technology.c_str(), enabled)); | 160 base::StringPrintf("%s:%d", technology.c_str(), enabled)); |
| 180 shill_property_handler_->SetTechnologyEnabled(technology, enabled, | 161 shill_property_handler_->SetTechnologyEnabled(technology, enabled, |
| 181 error_callback); | 162 error_callback); |
| 182 } | 163 } |
| 183 // Signal Device/Technology state changed. | 164 // Signal Device/Technology state changed. |
| 184 NotifyDeviceListChanged(); | 165 NotifyDeviceListChanged(); |
| 185 } | 166 } |
| 186 | 167 |
| 187 void NetworkStateHandler::SetTetherTechnologyState( | |
| 188 TechnologyState technology_state) { | |
| 189 if (tether_technology_state_ == technology_state) | |
| 190 return; | |
| 191 | |
| 192 tether_technology_state_ = technology_state; | |
| 193 EnsureTetherDeviceState(); | |
| 194 | |
| 195 // Signal Device/Technology state changed. | |
| 196 NotifyDeviceListChanged(); | |
| 197 } | |
| 198 | |
| 199 void NetworkStateHandler::SetTetherScanState(bool is_scanning) { | |
| 200 DeviceState* tether_device_state = | |
| 201 GetModifiableDeviceState(kTetherDevicePath); | |
| 202 DCHECK(tether_device_state); | |
| 203 | |
| 204 bool was_scanning = tether_device_state->scanning(); | |
| 205 tether_device_state->set_scanning(is_scanning); | |
| 206 | |
| 207 if (was_scanning && !is_scanning) { | |
| 208 // If a scan was in progress but has completed, notify observers. | |
| 209 NotifyScanCompleted(tether_device_state); | |
| 210 } | |
| 211 } | |
| 212 | |
| 213 void NetworkStateHandler::SetProhibitedTechnologies( | 168 void NetworkStateHandler::SetProhibitedTechnologies( |
| 214 const std::vector<std::string>& prohibited_technologies, | 169 const std::vector<std::string>& prohibited_technologies, |
| 215 const network_handler::ErrorCallback& error_callback) { | 170 const network_handler::ErrorCallback& error_callback) { |
| 216 // Make a copy of |prohibited_technologies| since the list may be edited | 171 shill_property_handler_->SetProhibitedTechnologies(prohibited_technologies, |
| 217 // within this function. | 172 error_callback); |
| 218 std::vector<std::string> prohibited_technologies_copy = | |
| 219 prohibited_technologies; | |
| 220 | |
| 221 for (auto it = prohibited_technologies_copy.begin(); | |
| 222 it < prohibited_technologies_copy.end(); ++it) { | |
| 223 if (*it == kTypeTether) { | |
| 224 // If Tether networks are prohibited, set |tether_technology_state_| and | |
| 225 // remove |kTypeTether| from the list before passing it to | |
| 226 // |shill_property_handler_| below. Shill does not have a concept of | |
| 227 // Tether networks, so it cannot prohibit that technology type. | |
| 228 tether_technology_state_ = TECHNOLOGY_PROHIBITED; | |
| 229 it = prohibited_technologies_copy.erase(it); | |
| 230 } | |
| 231 } | |
| 232 | |
| 233 shill_property_handler_->SetProhibitedTechnologies( | |
| 234 prohibited_technologies_copy, error_callback); | |
| 235 // Signal Device/Technology state changed. | 173 // Signal Device/Technology state changed. |
| 236 NotifyDeviceListChanged(); | 174 NotifyDeviceListChanged(); |
| 237 } | 175 } |
| 238 | 176 |
| 239 const DeviceState* NetworkStateHandler::GetDeviceState( | 177 const DeviceState* NetworkStateHandler::GetDeviceState( |
| 240 const std::string& device_path) const { | 178 const std::string& device_path) const { |
| 241 const DeviceState* device = GetModifiableDeviceState(device_path); | 179 const DeviceState* device = GetModifiableDeviceState(device_path); |
| 242 if (device && !device->update_received()) | 180 if (device && !device->update_received()) |
| 243 return nullptr; | 181 return nullptr; |
| 244 return device; | 182 return device; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 } | 293 } |
| 356 | 294 |
| 357 return connecting_network; | 295 return connecting_network; |
| 358 } | 296 } |
| 359 | 297 |
| 360 const NetworkState* NetworkStateHandler::FirstNetworkByType( | 298 const NetworkState* NetworkStateHandler::FirstNetworkByType( |
| 361 const NetworkTypePattern& type) { | 299 const NetworkTypePattern& type) { |
| 362 if (!network_list_sorted_) | 300 if (!network_list_sorted_) |
| 363 SortNetworkList(); // Sort to ensure visible networks are listed first. | 301 SortNetworkList(); // Sort to ensure visible networks are listed first. |
| 364 | 302 |
| 365 // If |type| matches Tether networks and at least one Tether network is | 303 // If |type| matches tether networks and at least one tether network is |
| 366 // present, return the first network (since it has been sorted already). | 304 // present, return the first network (since it has been sorted already). |
| 367 if (type.MatchesPattern(NetworkTypePattern::Tether()) && | 305 if (type.MatchesPattern(NetworkTypePattern::Tether()) && |
| 368 !tether_network_list_.empty()) { | 306 !tether_network_list_.empty()) { |
| 369 return tether_network_list_[0]->AsNetworkState(); | 307 return tether_network_list_[0]->AsNetworkState(); |
| 370 } | 308 } |
| 371 | 309 |
| 372 for (auto iter = network_list_.begin(); iter != network_list_.end(); ++iter) { | 310 for (auto iter = network_list_.begin(); iter != network_list_.end(); ++iter) { |
| 373 const NetworkState* network = (*iter)->AsNetworkState(); | 311 const NetworkState* network = (*iter)->AsNetworkState(); |
| 374 DCHECK(network); | 312 DCHECK(network); |
| 375 if (!network->update_received()) | 313 if (!network->update_received()) |
| 376 continue; | 314 continue; |
| 377 if (!network->visible()) | 315 if (!network->visible()) |
| 378 break; | 316 break; |
| 379 if (network->Matches(type)) | 317 if (network->Matches(type)) |
| 380 return network; | 318 return network; |
| 381 } | 319 } |
| 382 return nullptr; | 320 return nullptr; |
| 383 } | 321 } |
| 384 | 322 |
| 385 std::string NetworkStateHandler::FormattedHardwareAddressForType( | 323 std::string NetworkStateHandler::FormattedHardwareAddressForType( |
| 386 const NetworkTypePattern& type) const { | 324 const NetworkTypePattern& type) const { |
| 387 const NetworkState* network = ConnectedNetworkByType(type); | 325 const NetworkState* network = ConnectedNetworkByType(type); |
| 388 if (network && network->type() == kTypeTether) { | |
| 389 // If this is a Tether network, get the MAC address corresponding to that | |
| 390 // network instead. | |
| 391 network = GetNetworkStateFromGuid(network->tether_guid()); | |
| 392 } | |
| 393 const DeviceState* device = network ? GetDeviceState(network->device_path()) | 326 const DeviceState* device = network ? GetDeviceState(network->device_path()) |
| 394 : GetDeviceStateByType(type); | 327 : GetDeviceStateByType(type); |
| 395 if (!device || device->mac_address().empty()) | 328 if (!device) |
| 396 return std::string(); | 329 return std::string(); |
| 397 return network_util::FormattedMacAddress(device->mac_address()); | 330 return network_util::FormattedMacAddress(device->mac_address()); |
| 398 } | 331 } |
| 399 | 332 |
| 400 void NetworkStateHandler::GetVisibleNetworkListByType( | 333 void NetworkStateHandler::GetVisibleNetworkListByType( |
| 401 const NetworkTypePattern& type, | 334 const NetworkTypePattern& type, |
| 402 NetworkStateList* list) { | 335 NetworkStateList* list) { |
| 403 GetNetworkListByType(type, false /* configured_only */, | 336 GetNetworkListByType(type, false /* configured_only */, |
| 404 true /* visible_only */, 0 /* no limit */, list); | 337 true /* visible_only */, 0 /* no limit */, list); |
| 405 } | 338 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 421 SortNetworkList(); | 354 SortNetworkList(); |
| 422 | 355 |
| 423 if (type.MatchesPattern(NetworkTypePattern::Tether())) { | 356 if (type.MatchesPattern(NetworkTypePattern::Tether())) { |
| 424 GetTetherNetworkList(limit, list); | 357 GetTetherNetworkList(limit, list); |
| 425 } | 358 } |
| 426 | 359 |
| 427 int count = list->size(); | 360 int count = list->size(); |
| 428 | 361 |
| 429 if (type.Equals(NetworkTypePattern::Tether()) || | 362 if (type.Equals(NetworkTypePattern::Tether()) || |
| 430 (limit != 0 && count >= limit)) { | 363 (limit != 0 && count >= limit)) { |
| 431 // If only searching for Tether networks, there is no need to continue | 364 // If only searching for tether networks, there is no need to continue |
| 432 // searching through other network types; likewise, if the limit has already | 365 // searching through other network types; likewise, if the limit has already |
| 433 // been reached, there is no need to continue searching. | 366 // been reached, there is no need to continue searching. |
| 434 return; | 367 return; |
| 435 } | 368 } |
| 436 | 369 |
| 437 for (auto iter = network_list_.begin(); iter != network_list_.end(); ++iter) { | 370 for (auto iter = network_list_.begin(); iter != network_list_.end(); ++iter) { |
| 438 const NetworkState* network = (*iter)->AsNetworkState(); | 371 const NetworkState* network = (*iter)->AsNetworkState(); |
| 439 DCHECK(network); | 372 DCHECK(network); |
| 440 if (!network->update_received() || !network->Matches(type)) | 373 if (!network->update_received() || !network->Matches(type)) |
| 441 continue; | 374 continue; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 | 425 |
| 493 void NetworkStateHandler::AddTetherNetworkState(const std::string& guid, | 426 void NetworkStateHandler::AddTetherNetworkState(const std::string& guid, |
| 494 const std::string& name, | 427 const std::string& name, |
| 495 const std::string& carrier, | 428 const std::string& carrier, |
| 496 int battery_percentage, | 429 int battery_percentage, |
| 497 int signal_strength) { | 430 int signal_strength) { |
| 498 DCHECK(!guid.empty()); | 431 DCHECK(!guid.empty()); |
| 499 DCHECK(battery_percentage >= 0 && battery_percentage <= 100); | 432 DCHECK(battery_percentage >= 0 && battery_percentage <= 100); |
| 500 DCHECK(signal_strength >= 0 && signal_strength <= 100); | 433 DCHECK(signal_strength >= 0 && signal_strength <= 100); |
| 501 | 434 |
| 502 if (tether_technology_state_ != TECHNOLOGY_ENABLED) { | |
| 503 NET_LOG(ERROR) << "AddTetherNetworkState() called when Tether networks " | |
| 504 << "are not enabled. Cannot add NetworkState."; | |
| 505 return; | |
| 506 } | |
| 507 | |
| 508 // If the network already exists, do nothing. | 435 // If the network already exists, do nothing. |
| 509 if (GetNetworkStateFromGuid(guid)) { | 436 if (GetNetworkStateFromGuid(guid)) { |
| 510 NET_LOG(ERROR) << "AddTetherNetworkState: " << name | 437 NET_LOG(ERROR) << "AddTetherNetworkState: " << name |
| 511 << " called with existing guid:" << guid; | 438 << " called with existing guid:" << guid; |
| 512 return; | 439 return; |
| 513 } | 440 } |
| 514 | 441 |
| 515 // Use the GUID as the network's service path. | 442 // Use the GUID as the network's service path. |
| 516 std::unique_ptr<NetworkState> tether_network_state = | 443 std::unique_ptr<NetworkState> tether_network_state = |
| 517 base::MakeUnique<NetworkState>(guid /* path */); | 444 base::MakeUnique<NetworkState>(guid /* path */); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 529 | 456 |
| 530 tether_network_list_.push_back(std::move(tether_network_state)); | 457 tether_network_list_.push_back(std::move(tether_network_state)); |
| 531 NotifyNetworkListChanged(); | 458 NotifyNetworkListChanged(); |
| 532 } | 459 } |
| 533 | 460 |
| 534 bool NetworkStateHandler::UpdateTetherNetworkProperties( | 461 bool NetworkStateHandler::UpdateTetherNetworkProperties( |
| 535 const std::string& guid, | 462 const std::string& guid, |
| 536 const std::string& carrier, | 463 const std::string& carrier, |
| 537 int battery_percentage, | 464 int battery_percentage, |
| 538 int signal_strength) { | 465 int signal_strength) { |
| 539 if (tether_technology_state_ != TECHNOLOGY_ENABLED) { | |
| 540 NET_LOG(ERROR) << "UpdateTetherNetworkProperties() called when Tether " | |
| 541 << "networks are not enabled. Cannot update."; | |
| 542 return false; | |
| 543 } | |
| 544 | |
| 545 NetworkState* tether_network_state = GetModifiableNetworkStateFromGuid(guid); | 466 NetworkState* tether_network_state = GetModifiableNetworkStateFromGuid(guid); |
| 546 if (!tether_network_state) | 467 if (!tether_network_state) |
| 547 return false; | 468 return false; |
| 548 | 469 |
| 549 tether_network_state->set_carrier(carrier); | 470 tether_network_state->set_carrier(carrier); |
| 550 tether_network_state->set_battery_percentage(battery_percentage); | 471 tether_network_state->set_battery_percentage(battery_percentage); |
| 551 tether_network_state->set_signal_strength(signal_strength); | 472 tether_network_state->set_signal_strength(signal_strength); |
| 552 | 473 |
| 553 NotifyNetworkListChanged(); | 474 NotifyNetworkListChanged(); |
| 554 return true; | 475 return true; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 566 tether_network_list_.erase(iter); | 487 tether_network_list_.erase(iter); |
| 567 NotifyNetworkListChanged(); | 488 NotifyNetworkListChanged(); |
| 568 return; | 489 return; |
| 569 } | 490 } |
| 570 } | 491 } |
| 571 } | 492 } |
| 572 | 493 |
| 573 bool NetworkStateHandler::AssociateTetherNetworkStateWithWifiNetwork( | 494 bool NetworkStateHandler::AssociateTetherNetworkStateWithWifiNetwork( |
| 574 const std::string& tether_network_guid, | 495 const std::string& tether_network_guid, |
| 575 const std::string& wifi_network_guid) { | 496 const std::string& wifi_network_guid) { |
| 576 if (tether_technology_state_ != TECHNOLOGY_ENABLED) { | |
| 577 NET_LOG(ERROR) << "AssociateTetherNetworkStateWithWifiNetwork() called " | |
| 578 << "when Tether networks are not enabled. Cannot " | |
| 579 << "associate."; | |
| 580 return false; | |
| 581 } | |
| 582 | |
| 583 NetworkState* tether_network = | 497 NetworkState* tether_network = |
| 584 GetModifiableNetworkStateFromGuid(tether_network_guid); | 498 GetModifiableNetworkStateFromGuid(tether_network_guid); |
| 585 if (!tether_network) { | 499 if (!tether_network) { |
| 586 NET_LOG(ERROR) << "Tether network does not exist: " << tether_network_guid; | 500 NET_LOG(ERROR) << "Tether network does not exist: " << tether_network_guid; |
| 587 return false; | 501 return false; |
| 588 } | 502 } |
| 589 if (!NetworkTypePattern::Tether().MatchesType(tether_network->type())) { | 503 if (!NetworkTypePattern::Tether().MatchesType(tether_network->type())) { |
| 590 NET_LOG(ERROR) << "Network is not a Tether network: " | 504 NET_LOG(ERROR) << "Network is not a Tether network: " |
| 591 << tether_network_guid; | 505 << tether_network_guid; |
| 592 return false; | 506 return false; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 604 } | 518 } |
| 605 | 519 |
| 606 tether_network->set_tether_guid(wifi_network_guid); | 520 tether_network->set_tether_guid(wifi_network_guid); |
| 607 wifi_network->set_tether_guid(tether_network_guid); | 521 wifi_network->set_tether_guid(tether_network_guid); |
| 608 NotifyNetworkListChanged(); | 522 NotifyNetworkListChanged(); |
| 609 return true; | 523 return true; |
| 610 } | 524 } |
| 611 | 525 |
| 612 void NetworkStateHandler::SetTetherNetworkStateDisconnected( | 526 void NetworkStateHandler::SetTetherNetworkStateDisconnected( |
| 613 const std::string& guid) { | 527 const std::string& guid) { |
| 614 // TODO(khorimoto): Remove the Tether network as the default network, and | 528 // TODO(khorimoto): Remove the tether network as the default network, and |
| 615 // send a connection status change. | 529 // send a connection status change. |
| 616 SetTetherNetworkStateConnectionState(guid, shill::kStateDisconnect); | 530 SetTetherNetworkStateConnectionState(guid, shill::kStateDisconnect); |
| 617 } | 531 } |
| 618 | 532 |
| 619 void NetworkStateHandler::SetTetherNetworkStateConnecting( | 533 void NetworkStateHandler::SetTetherNetworkStateConnecting( |
| 620 const std::string& guid) { | 534 const std::string& guid) { |
| 621 // TODO(khorimoto): Set the Tether network as the default network, and send | 535 // TODO(khorimoto): Set the tether network as the default network, and send |
| 622 // a connection status change. | 536 // a connection status change. |
| 623 SetTetherNetworkStateConnectionState(guid, shill::kStateConfiguration); | 537 SetTetherNetworkStateConnectionState(guid, shill::kStateConfiguration); |
| 624 } | 538 } |
| 625 | 539 |
| 626 void NetworkStateHandler::SetTetherNetworkStateConnected( | 540 void NetworkStateHandler::SetTetherNetworkStateConnected( |
| 627 const std::string& guid) { | 541 const std::string& guid) { |
| 628 // Being connected implies that AssociateTetherNetworkStateWithWifiNetwork() | 542 // Being connected implies that AssociateTetherNetworkStateWithWifiNetwork() |
| 629 // was already called, so ensure that the association is still intact. | 543 // was already called, so ensure that the association is still intact. |
| 630 DCHECK(GetNetworkStateFromGuid(GetNetworkStateFromGuid(guid)->tether_guid()) | 544 DCHECK(GetNetworkStateFromGuid(GetNetworkStateFromGuid(guid)->tether_guid()) |
| 631 ->tether_guid() == guid); | 545 ->tether_guid() == guid); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 643 << "not found: " << guid; | 557 << "not found: " << guid; |
| 644 return; | 558 return; |
| 645 } | 559 } |
| 646 | 560 |
| 647 DCHECK(NetworkTypePattern::Tether().MatchesType(tether_network->type())); | 561 DCHECK(NetworkTypePattern::Tether().MatchesType(tether_network->type())); |
| 648 | 562 |
| 649 tether_network->set_connection_state(connection_state); | 563 tether_network->set_connection_state(connection_state); |
| 650 NotifyNetworkListChanged(); | 564 NotifyNetworkListChanged(); |
| 651 } | 565 } |
| 652 | 566 |
| 653 void NetworkStateHandler::EnsureTetherDeviceState() { | |
| 654 bool should_be_present = | |
| 655 tether_technology_state_ != TechnologyState::TECHNOLOGY_UNAVAILABLE; | |
| 656 | |
| 657 for (auto it = device_list_.begin(); it < device_list_.end(); ++it) { | |
| 658 std::string path = (*it)->path(); | |
| 659 if (path == kTetherDevicePath) { | |
| 660 // If the Tether DeviceState is in the list and it should not be, remove | |
| 661 // it and return. If it is in the list and it should be, the list is | |
| 662 // already valid, so return without removing it. | |
| 663 if (!should_be_present) | |
| 664 device_list_.erase(it); | |
| 665 return; | |
| 666 } | |
| 667 } | |
| 668 | |
| 669 if (!should_be_present) { | |
| 670 // If the Tether DeviceState was not in the list and it should not be, the | |
| 671 // list is already valid, so return. | |
| 672 return; | |
| 673 } | |
| 674 | |
| 675 // The Tether DeviceState is not present in the list, but it should be. Since | |
| 676 // Tether networks are not recognized by Shill, they will never receive an | |
| 677 // update, so set properties on the state here. | |
| 678 std::unique_ptr<ManagedState> tether_device_state = ManagedState::Create( | |
| 679 ManagedState::ManagedType::MANAGED_TYPE_DEVICE, kTetherDevicePath); | |
| 680 tether_device_state->set_update_received(); | |
| 681 tether_device_state->set_update_requested(false); | |
| 682 tether_device_state->set_name(kTetherDeviceName); | |
| 683 tether_device_state->set_type(kTypeTether); | |
| 684 | |
| 685 device_list_.push_back(std::move(tether_device_state)); | |
| 686 } | |
| 687 | |
| 688 void NetworkStateHandler::GetDeviceList(DeviceStateList* list) const { | 567 void NetworkStateHandler::GetDeviceList(DeviceStateList* list) const { |
| 689 GetDeviceListByType(NetworkTypePattern::Default(), list); | 568 GetDeviceListByType(NetworkTypePattern::Default(), list); |
| 690 } | 569 } |
| 691 | 570 |
| 692 void NetworkStateHandler::GetDeviceListByType(const NetworkTypePattern& type, | 571 void NetworkStateHandler::GetDeviceListByType(const NetworkTypePattern& type, |
| 693 DeviceStateList* list) const { | 572 DeviceStateList* list) const { |
| 694 DCHECK(list); | 573 DCHECK(list); |
| 695 list->clear(); | 574 list->clear(); |
| 696 | |
| 697 for (auto iter = device_list_.begin(); iter != device_list_.end(); ++iter) { | 575 for (auto iter = device_list_.begin(); iter != device_list_.end(); ++iter) { |
| 698 const DeviceState* device = (*iter)->AsDeviceState(); | 576 const DeviceState* device = (*iter)->AsDeviceState(); |
| 699 DCHECK(device); | 577 DCHECK(device); |
| 700 if (device->update_received() && device->Matches(type)) | 578 if (device->update_received() && device->Matches(type)) |
| 701 list->push_back(device); | 579 list->push_back(device); |
| 702 } | 580 } |
| 703 } | 581 } |
| 704 | 582 |
| 705 void NetworkStateHandler::RequestScan() const { | 583 void NetworkStateHandler::RequestScan() const { |
| 706 NET_LOG_USER("RequestScan", ""); | 584 NET_LOG_USER("RequestScan", ""); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 continue; | 719 continue; |
| 842 } | 720 } |
| 843 managed_list->push_back(ManagedState::Create(type, path)); | 721 managed_list->push_back(ManagedState::Create(type, path)); |
| 844 } else { | 722 } else { |
| 845 managed_list->push_back(std::move(found->second)); | 723 managed_list->push_back(std::move(found->second)); |
| 846 managed_map.erase(found); | 724 managed_map.erase(found); |
| 847 } | 725 } |
| 848 list_entries.insert(path); | 726 list_entries.insert(path); |
| 849 } | 727 } |
| 850 | 728 |
| 851 if (type == ManagedState::ManagedType::MANAGED_TYPE_DEVICE) { | |
| 852 // Also move the Tether DeviceState if it exists. This will not happen as | |
| 853 // part of the loop above since |entries| will never contain the Tether | |
| 854 // path. | |
| 855 auto iter = managed_map.find(kTetherDevicePath); | |
| 856 if (iter != managed_map.end()) { | |
| 857 managed_list->push_back(std::move(iter->second)); | |
| 858 managed_map.erase(iter); | |
| 859 } | |
| 860 } | |
| 861 | |
| 862 if (type != ManagedState::ManagedType::MANAGED_TYPE_NETWORK) | 729 if (type != ManagedState::ManagedType::MANAGED_TYPE_NETWORK) |
| 863 return; | 730 return; |
| 864 | 731 |
| 865 // Remove associations Tether NetworkStates had with now removed Wi-Fi | 732 // Remove associations Tether NetworkStates had with now removed Wi-Fi |
| 866 // NetworkStates. | 733 // NetworkStates. |
| 867 for (auto& iter : managed_map) { | 734 for (auto& iter : managed_map) { |
| 868 if (!iter.second->Matches(NetworkTypePattern::WiFi())) | 735 if (!iter.second->Matches(NetworkTypePattern::WiFi())) |
| 869 continue; | 736 continue; |
| 870 | 737 |
| 871 NetworkState* tether_network = GetModifiableNetworkStateFromGuid( | 738 NetworkState* tether_network = GetModifiableNetworkStateFromGuid( |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1097 devices += ", "; | 964 devices += ", "; |
| 1098 devices += (*iter)->name(); | 965 devices += (*iter)->name(); |
| 1099 } | 966 } |
| 1100 NET_LOG_EVENT("DeviceList", devices); | 967 NET_LOG_EVENT("DeviceList", devices); |
| 1101 NotifyDeviceListChanged(); | 968 NotifyDeviceListChanged(); |
| 1102 } else { | 969 } else { |
| 1103 NOTREACHED(); | 970 NOTREACHED(); |
| 1104 } | 971 } |
| 1105 } | 972 } |
| 1106 | 973 |
| 1107 // TODO(khorimoto): Add sorting for the Tether network list as well. | 974 // TODO(khorimoto): Add sorting for the tether network list as well. |
| 1108 void NetworkStateHandler::SortNetworkList() { | 975 void NetworkStateHandler::SortNetworkList() { |
| 1109 // Note: usually active networks will precede inactive networks, however | 976 // Note: usually active networks will precede inactive networks, however |
| 1110 // this may briefly be untrue during state transitions (e.g. a network may | 977 // this may briefly be untrue during state transitions (e.g. a network may |
| 1111 // transition to idle before the list is updated). | 978 // transition to idle before the list is updated). |
| 1112 ManagedStateList active, non_wifi_visible, wifi_visible, hidden, new_networks; | 979 ManagedStateList active, non_wifi_visible, wifi_visible, hidden, new_networks; |
| 1113 for (ManagedStateList::iterator iter = network_list_.begin(); | 980 for (ManagedStateList::iterator iter = network_list_.begin(); |
| 1114 iter != network_list_.end(); ++iter) { | 981 iter != network_list_.end(); ++iter) { |
| 1115 NetworkState* network = (*iter)->AsNetworkState(); | 982 NetworkState* network = (*iter)->AsNetworkState(); |
| 1116 if (!network->update_received()) { | 983 if (!network->update_received()) { |
| 1117 new_networks.push_back(std::move(*iter)); | 984 new_networks.push_back(std::move(*iter)); |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1401 if (type.MatchesType(shill::kTypeWifi)) | 1268 if (type.MatchesType(shill::kTypeWifi)) |
| 1402 technologies.emplace_back(shill::kTypeWifi); | 1269 technologies.emplace_back(shill::kTypeWifi); |
| 1403 if (type.MatchesType(shill::kTypeWimax)) | 1270 if (type.MatchesType(shill::kTypeWimax)) |
| 1404 technologies.emplace_back(shill::kTypeWimax); | 1271 technologies.emplace_back(shill::kTypeWimax); |
| 1405 if (type.MatchesType(shill::kTypeCellular)) | 1272 if (type.MatchesType(shill::kTypeCellular)) |
| 1406 technologies.emplace_back(shill::kTypeCellular); | 1273 technologies.emplace_back(shill::kTypeCellular); |
| 1407 if (type.MatchesType(shill::kTypeBluetooth)) | 1274 if (type.MatchesType(shill::kTypeBluetooth)) |
| 1408 technologies.emplace_back(shill::kTypeBluetooth); | 1275 technologies.emplace_back(shill::kTypeBluetooth); |
| 1409 if (type.MatchesType(shill::kTypeVPN)) | 1276 if (type.MatchesType(shill::kTypeVPN)) |
| 1410 technologies.emplace_back(shill::kTypeVPN); | 1277 technologies.emplace_back(shill::kTypeVPN); |
| 1411 if (type.MatchesType(kTypeTether)) | |
| 1412 technologies.emplace_back(kTypeTether); | |
| 1413 | 1278 |
| 1414 CHECK_GT(technologies.size(), 0ul); | 1279 CHECK_GT(technologies.size(), 0ul); |
| 1415 return technologies; | 1280 return technologies; |
| 1416 } | 1281 } |
| 1417 | 1282 |
| 1418 } // namespace chromeos | 1283 } // namespace chromeos |
| OLD | NEW |