Chromium Code Reviews| 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" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 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, |
| 120 base::StringPrintf("NetworkStateHandler::RemoveObserver: 0x%p", | 120 base::StringPrintf("NetworkStateHandler::RemoveObserver: 0x%p", |
| 121 observer)); | 121 observer)); |
| 122 } | 122 } |
| 123 | 123 |
| 124 NetworkStateHandler::TechnologyState NetworkStateHandler::GetTechnologyState( | 124 NetworkStateHandler::TechnologyState NetworkStateHandler::GetTechnologyState( |
| 125 const NetworkTypePattern& type) const { | 125 const NetworkTypePattern& type) const { |
| 126 std::string technology = GetTechnologyForType(type); | 126 std::string technology = GetTechnologyForType(type); |
| 127 | 127 |
| 128 if (technology == kTypeTether) { | 128 if (technology == kTypeTether) { |
| 129 bool is_tether_enabled = base::CommandLine::ForCurrentProcess()->HasSwitch( | 129 return tether_technology_state_; |
| 130 chromeos::switches::kEnableTether); | |
| 131 return is_tether_enabled ? TECHNOLOGY_ENABLED : TECHNOLOGY_UNAVAILABLE; | |
| 132 } | 130 } |
| 133 | 131 |
| 134 TechnologyState state; | 132 TechnologyState state; |
| 135 if (shill_property_handler_->IsTechnologyEnabled(technology)) | 133 if (shill_property_handler_->IsTechnologyEnabled(technology)) |
| 136 state = TECHNOLOGY_ENABLED; | 134 state = TECHNOLOGY_ENABLED; |
| 137 else if (shill_property_handler_->IsTechnologyEnabling(technology)) | 135 else if (shill_property_handler_->IsTechnologyEnabling(technology)) |
| 138 state = TECHNOLOGY_ENABLING; | 136 state = TECHNOLOGY_ENABLING; |
| 139 else if (shill_property_handler_->IsTechnologyProhibited(technology)) | 137 else if (shill_property_handler_->IsTechnologyProhibited(technology)) |
| 140 state = TECHNOLOGY_PROHIBITED; | 138 state = TECHNOLOGY_PROHIBITED; |
| 141 else if (shill_property_handler_->IsTechnologyUninitialized(technology)) | 139 else if (shill_property_handler_->IsTechnologyUninitialized(technology)) |
| 142 state = TECHNOLOGY_UNINITIALIZED; | 140 state = TECHNOLOGY_UNINITIALIZED; |
| 143 else if (shill_property_handler_->IsTechnologyAvailable(technology)) | 141 else if (shill_property_handler_->IsTechnologyAvailable(technology)) |
| 144 state = TECHNOLOGY_AVAILABLE; | 142 state = TECHNOLOGY_AVAILABLE; |
| 145 else | 143 else |
| 146 state = TECHNOLOGY_UNAVAILABLE; | 144 state = TECHNOLOGY_UNAVAILABLE; |
| 147 VLOG(2) << "GetTechnologyState: " << type.ToDebugString() << " = " << state; | 145 VLOG(2) << "GetTechnologyState: " << type.ToDebugString() << " = " << state; |
| 148 return state; | 146 return state; |
| 149 } | 147 } |
| 150 | 148 |
| 151 void NetworkStateHandler::SetTechnologyEnabled( | 149 void NetworkStateHandler::SetTechnologyEnabled( |
| 152 const NetworkTypePattern& type, | 150 const NetworkTypePattern& type, |
| 153 bool enabled, | 151 bool enabled, |
| 154 const network_handler::ErrorCallback& error_callback) { | 152 const network_handler::ErrorCallback& error_callback) { |
| 155 std::vector<std::string> technologies = GetTechnologiesForType(type); | 153 std::vector<std::string> technologies = GetTechnologiesForType(type); |
| 156 for (const std::string& technology : technologies) { | 154 for (const std::string& technology : technologies) { |
| 155 if (technology == kTypeTether) { | |
| 156 // Tether does not exist in Shill, so set |tether_technology_state_| and | |
| 157 // skip the below interactions with |shill_property_handler_|. | |
| 158 tether_technology_state_ = | |
| 159 enabled ? TECHNOLOGY_ENABLED : TECHNOLOGY_AVAILABLE; | |
|
stevenjb
2017/04/20 16:49:41
We need to ensure that this transition is valid:
i
Kyle Horimoto
2017/04/20 19:38:46
Done.
| |
| 160 continue; | |
| 161 } | |
| 162 | |
| 157 if (!shill_property_handler_->IsTechnologyAvailable(technology)) | 163 if (!shill_property_handler_->IsTechnologyAvailable(technology)) |
| 158 continue; | 164 continue; |
| 159 NET_LOG_USER("SetTechnologyEnabled", | 165 NET_LOG_USER("SetTechnologyEnabled", |
| 160 base::StringPrintf("%s:%d", technology.c_str(), enabled)); | 166 base::StringPrintf("%s:%d", technology.c_str(), enabled)); |
| 161 shill_property_handler_->SetTechnologyEnabled(technology, enabled, | 167 shill_property_handler_->SetTechnologyEnabled(technology, enabled, |
| 162 error_callback); | 168 error_callback); |
| 163 } | 169 } |
| 164 // Signal Device/Technology state changed. | 170 // Signal Device/Technology state changed. |
| 165 NotifyDeviceListChanged(); | 171 NotifyDeviceListChanged(); |
| 166 } | 172 } |
| 167 | 173 |
| 174 void NetworkStateHandler::SetTetherTechnologyState( | |
| 175 TechnologyState technology_state) { | |
| 176 if (tether_technology_state_ == technology_state) | |
| 177 return; | |
| 178 | |
| 179 tether_technology_state_ = technology_state; | |
|
stevenjb
2017/04/20 18:13:45
So, to go with my comments in UpdateManagedList(),
Kyle Horimoto
2017/04/20 19:38:46
Done.
| |
| 180 | |
| 181 // Signal Device/Technology state changed. | |
| 182 NotifyDeviceListChanged(); | |
| 183 } | |
| 184 | |
| 185 void NetworkStateHandler::SetTetherScanState(bool is_scanning) { | |
| 186 DeviceState* tether_device_state = | |
| 187 GetModifiableDeviceState(kTetherDevicePath); | |
| 188 DCHECK(tether_device_state); | |
| 189 | |
| 190 bool was_scanning = tether_device_state->scanning(); | |
| 191 tether_device_state->set_scanning(is_scanning); | |
| 192 | |
| 193 if (was_scanning && !is_scanning) { | |
| 194 // If a scan was in progress but has completed, notify observers. | |
| 195 NotifyScanCompleted(tether_device_state); | |
| 196 } | |
| 197 } | |
| 198 | |
| 168 void NetworkStateHandler::SetProhibitedTechnologies( | 199 void NetworkStateHandler::SetProhibitedTechnologies( |
| 169 const std::vector<std::string>& prohibited_technologies, | 200 const std::vector<std::string>& prohibited_technologies, |
| 170 const network_handler::ErrorCallback& error_callback) { | 201 const network_handler::ErrorCallback& error_callback) { |
| 171 shill_property_handler_->SetProhibitedTechnologies(prohibited_technologies, | 202 // Make a copy of |prohibited_technologies| since the list may be edited |
| 172 error_callback); | 203 // within this function. |
| 204 std::vector<std::string> prohibited_technologies_copy = | |
| 205 prohibited_technologies; | |
| 206 | |
| 207 for (auto it = prohibited_technologies_copy.begin(); | |
| 208 it < prohibited_technologies_copy.end(); ++it) { | |
| 209 if (*it == kTypeTether) { | |
| 210 // If Tether networks are prohibited, set |tether_technology_state_| and | |
| 211 // remove |kTypeTether| from the list before passing it to | |
| 212 // |shill_property_handler_| below. Shill does not have a concept of | |
| 213 // Tether networks, so it cannot prohibit that technology type. | |
| 214 tether_technology_state_ = TECHNOLOGY_PROHIBITED; | |
| 215 it = prohibited_technologies_copy.erase(it); | |
| 216 } | |
| 217 } | |
| 218 | |
| 219 shill_property_handler_->SetProhibitedTechnologies( | |
| 220 prohibited_technologies_copy, error_callback); | |
| 173 // Signal Device/Technology state changed. | 221 // Signal Device/Technology state changed. |
| 174 NotifyDeviceListChanged(); | 222 NotifyDeviceListChanged(); |
| 175 } | 223 } |
| 176 | 224 |
| 177 const DeviceState* NetworkStateHandler::GetDeviceState( | 225 const DeviceState* NetworkStateHandler::GetDeviceState( |
| 178 const std::string& device_path) const { | 226 const std::string& device_path) const { |
| 179 const DeviceState* device = GetModifiableDeviceState(device_path); | 227 const DeviceState* device = GetModifiableDeviceState(device_path); |
| 180 if (device && !device->update_received()) | 228 if (device && !device->update_received()) |
| 181 return nullptr; | 229 return nullptr; |
| 182 return device; | 230 return device; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 } | 341 } |
| 294 | 342 |
| 295 return connecting_network; | 343 return connecting_network; |
| 296 } | 344 } |
| 297 | 345 |
| 298 const NetworkState* NetworkStateHandler::FirstNetworkByType( | 346 const NetworkState* NetworkStateHandler::FirstNetworkByType( |
| 299 const NetworkTypePattern& type) { | 347 const NetworkTypePattern& type) { |
| 300 if (!network_list_sorted_) | 348 if (!network_list_sorted_) |
| 301 SortNetworkList(); // Sort to ensure visible networks are listed first. | 349 SortNetworkList(); // Sort to ensure visible networks are listed first. |
| 302 | 350 |
| 303 // If |type| matches tether networks and at least one tether network is | 351 // If |type| matches Tether networks and at least one Tether network is |
| 304 // present, return the first network (since it has been sorted already). | 352 // present, return the first network (since it has been sorted already). |
| 305 if (type.MatchesPattern(NetworkTypePattern::Tether()) && | 353 if (type.MatchesPattern(NetworkTypePattern::Tether()) && |
| 306 !tether_network_list_.empty()) { | 354 !tether_network_list_.empty()) { |
| 307 return tether_network_list_[0]->AsNetworkState(); | 355 return tether_network_list_[0]->AsNetworkState(); |
| 308 } | 356 } |
| 309 | 357 |
| 310 for (auto iter = network_list_.begin(); iter != network_list_.end(); ++iter) { | 358 for (auto iter = network_list_.begin(); iter != network_list_.end(); ++iter) { |
| 311 const NetworkState* network = (*iter)->AsNetworkState(); | 359 const NetworkState* network = (*iter)->AsNetworkState(); |
| 312 DCHECK(network); | 360 DCHECK(network); |
| 313 if (!network->update_received()) | 361 if (!network->update_received()) |
| 314 continue; | 362 continue; |
| 315 if (!network->visible()) | 363 if (!network->visible()) |
| 316 break; | 364 break; |
| 317 if (network->Matches(type)) | 365 if (network->Matches(type)) |
| 318 return network; | 366 return network; |
| 319 } | 367 } |
| 320 return nullptr; | 368 return nullptr; |
| 321 } | 369 } |
| 322 | 370 |
| 323 std::string NetworkStateHandler::FormattedHardwareAddressForType( | 371 std::string NetworkStateHandler::FormattedHardwareAddressForType( |
| 324 const NetworkTypePattern& type) const { | 372 const NetworkTypePattern& type) const { |
| 325 const NetworkState* network = ConnectedNetworkByType(type); | 373 const NetworkState* network = ConnectedNetworkByType(type); |
| 374 if (network && network->type() == kTypeTether) { | |
| 375 // If this is a Tether network, get the MAC address corresponding to that | |
| 376 // network instead. | |
| 377 network = GetNetworkStateFromGuid(network->tether_guid()); | |
| 378 } | |
| 326 const DeviceState* device = network ? GetDeviceState(network->device_path()) | 379 const DeviceState* device = network ? GetDeviceState(network->device_path()) |
| 327 : GetDeviceStateByType(type); | 380 : GetDeviceStateByType(type); |
| 328 if (!device) | 381 if (!device || device->mac_address().empty()) |
| 329 return std::string(); | 382 return std::string(); |
| 330 return network_util::FormattedMacAddress(device->mac_address()); | 383 return network_util::FormattedMacAddress(device->mac_address()); |
| 331 } | 384 } |
| 332 | 385 |
| 333 void NetworkStateHandler::GetVisibleNetworkListByType( | 386 void NetworkStateHandler::GetVisibleNetworkListByType( |
| 334 const NetworkTypePattern& type, | 387 const NetworkTypePattern& type, |
| 335 NetworkStateList* list) { | 388 NetworkStateList* list) { |
| 336 GetNetworkListByType(type, false /* configured_only */, | 389 GetNetworkListByType(type, false /* configured_only */, |
| 337 true /* visible_only */, 0 /* no limit */, list); | 390 true /* visible_only */, 0 /* no limit */, list); |
| 338 } | 391 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 354 SortNetworkList(); | 407 SortNetworkList(); |
| 355 | 408 |
| 356 if (type.MatchesPattern(NetworkTypePattern::Tether())) { | 409 if (type.MatchesPattern(NetworkTypePattern::Tether())) { |
| 357 GetTetherNetworkList(limit, list); | 410 GetTetherNetworkList(limit, list); |
| 358 } | 411 } |
| 359 | 412 |
| 360 int count = list->size(); | 413 int count = list->size(); |
| 361 | 414 |
| 362 if (type.Equals(NetworkTypePattern::Tether()) || | 415 if (type.Equals(NetworkTypePattern::Tether()) || |
| 363 (limit != 0 && count >= limit)) { | 416 (limit != 0 && count >= limit)) { |
| 364 // If only searching for tether networks, there is no need to continue | 417 // If only searching for Tether networks, there is no need to continue |
| 365 // searching through other network types; likewise, if the limit has already | 418 // searching through other network types; likewise, if the limit has already |
| 366 // been reached, there is no need to continue searching. | 419 // been reached, there is no need to continue searching. |
| 367 return; | 420 return; |
| 368 } | 421 } |
| 369 | 422 |
| 370 for (auto iter = network_list_.begin(); iter != network_list_.end(); ++iter) { | 423 for (auto iter = network_list_.begin(); iter != network_list_.end(); ++iter) { |
| 371 const NetworkState* network = (*iter)->AsNetworkState(); | 424 const NetworkState* network = (*iter)->AsNetworkState(); |
| 372 DCHECK(network); | 425 DCHECK(network); |
| 373 if (!network->update_received() || !network->Matches(type)) | 426 if (!network->update_received() || !network->Matches(type)) |
| 374 continue; | 427 continue; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 424 } | 477 } |
| 425 | 478 |
| 426 void NetworkStateHandler::AddTetherNetworkState(const std::string& guid, | 479 void NetworkStateHandler::AddTetherNetworkState(const std::string& guid, |
| 427 const std::string& name, | 480 const std::string& name, |
| 428 const std::string& carrier, | 481 const std::string& carrier, |
| 429 int battery_percentage, | 482 int battery_percentage, |
| 430 int signal_strength) { | 483 int signal_strength) { |
| 431 DCHECK(!guid.empty()); | 484 DCHECK(!guid.empty()); |
| 432 DCHECK(battery_percentage >= 0 && battery_percentage <= 100); | 485 DCHECK(battery_percentage >= 0 && battery_percentage <= 100); |
| 433 DCHECK(signal_strength >= 0 && signal_strength <= 100); | 486 DCHECK(signal_strength >= 0 && signal_strength <= 100); |
| 487 DCHECK(tether_technology_state_ == TECHNOLOGY_ENABLED); | |
|
stevenjb
2017/04/20 16:49:41
This probably shouldn't be a DCHECK. I can imagine
Kyle Horimoto
2017/04/20 19:38:46
Done.
| |
| 434 | 488 |
| 435 // If the network already exists, do nothing. | 489 // If the network already exists, do nothing. |
| 436 if (GetNetworkStateFromGuid(guid)) { | 490 if (GetNetworkStateFromGuid(guid)) { |
| 437 NET_LOG(ERROR) << "AddTetherNetworkState: " << name | 491 NET_LOG(ERROR) << "AddTetherNetworkState: " << name |
| 438 << " called with existing guid:" << guid; | 492 << " called with existing guid:" << guid; |
| 439 return; | 493 return; |
| 440 } | 494 } |
| 441 | 495 |
| 442 // Use the GUID as the network's service path. | 496 // Use the GUID as the network's service path. |
| 443 std::unique_ptr<NetworkState> tether_network_state = | 497 std::unique_ptr<NetworkState> tether_network_state = |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 456 | 510 |
| 457 tether_network_list_.push_back(std::move(tether_network_state)); | 511 tether_network_list_.push_back(std::move(tether_network_state)); |
| 458 NotifyNetworkListChanged(); | 512 NotifyNetworkListChanged(); |
| 459 } | 513 } |
| 460 | 514 |
| 461 bool NetworkStateHandler::UpdateTetherNetworkProperties( | 515 bool NetworkStateHandler::UpdateTetherNetworkProperties( |
| 462 const std::string& guid, | 516 const std::string& guid, |
| 463 const std::string& carrier, | 517 const std::string& carrier, |
| 464 int battery_percentage, | 518 int battery_percentage, |
| 465 int signal_strength) { | 519 int signal_strength) { |
| 520 DCHECK(tether_technology_state_ == TECHNOLOGY_ENABLED); | |
|
stevenjb
2017/04/20 16:49:41
ditto
Kyle Horimoto
2017/04/20 19:38:46
Done.
| |
| 521 | |
| 466 NetworkState* tether_network_state = GetModifiableNetworkStateFromGuid(guid); | 522 NetworkState* tether_network_state = GetModifiableNetworkStateFromGuid(guid); |
| 467 if (!tether_network_state) | 523 if (!tether_network_state) |
| 468 return false; | 524 return false; |
| 469 | 525 |
| 470 tether_network_state->set_carrier(carrier); | 526 tether_network_state->set_carrier(carrier); |
| 471 tether_network_state->set_battery_percentage(battery_percentage); | 527 tether_network_state->set_battery_percentage(battery_percentage); |
| 472 tether_network_state->set_signal_strength(signal_strength); | 528 tether_network_state->set_signal_strength(signal_strength); |
| 473 | 529 |
| 474 NotifyNetworkListChanged(); | 530 NotifyNetworkListChanged(); |
| 475 return true; | 531 return true; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 487 tether_network_list_.erase(iter); | 543 tether_network_list_.erase(iter); |
| 488 NotifyNetworkListChanged(); | 544 NotifyNetworkListChanged(); |
| 489 return; | 545 return; |
| 490 } | 546 } |
| 491 } | 547 } |
| 492 } | 548 } |
| 493 | 549 |
| 494 bool NetworkStateHandler::AssociateTetherNetworkStateWithWifiNetwork( | 550 bool NetworkStateHandler::AssociateTetherNetworkStateWithWifiNetwork( |
| 495 const std::string& tether_network_guid, | 551 const std::string& tether_network_guid, |
| 496 const std::string& wifi_network_guid) { | 552 const std::string& wifi_network_guid) { |
| 553 DCHECK(tether_technology_state_ == TECHNOLOGY_ENABLED); | |
|
stevenjb
2017/04/20 16:49:41
ditto
Kyle Horimoto
2017/04/20 19:38:46
Done.
| |
| 554 | |
| 497 NetworkState* tether_network = | 555 NetworkState* tether_network = |
| 498 GetModifiableNetworkStateFromGuid(tether_network_guid); | 556 GetModifiableNetworkStateFromGuid(tether_network_guid); |
| 499 if (!tether_network) { | 557 if (!tether_network) { |
| 500 NET_LOG(ERROR) << "Tether network does not exist: " << tether_network_guid; | 558 NET_LOG(ERROR) << "Tether network does not exist: " << tether_network_guid; |
| 501 return false; | 559 return false; |
| 502 } | 560 } |
| 503 if (!NetworkTypePattern::Tether().MatchesType(tether_network->type())) { | 561 if (!NetworkTypePattern::Tether().MatchesType(tether_network->type())) { |
| 504 NET_LOG(ERROR) << "Network is not a Tether network: " | 562 NET_LOG(ERROR) << "Network is not a Tether network: " |
| 505 << tether_network_guid; | 563 << tether_network_guid; |
| 506 return false; | 564 return false; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 518 } | 576 } |
| 519 | 577 |
| 520 tether_network->set_tether_guid(wifi_network_guid); | 578 tether_network->set_tether_guid(wifi_network_guid); |
| 521 wifi_network->set_tether_guid(tether_network_guid); | 579 wifi_network->set_tether_guid(tether_network_guid); |
| 522 NotifyNetworkListChanged(); | 580 NotifyNetworkListChanged(); |
| 523 return true; | 581 return true; |
| 524 } | 582 } |
| 525 | 583 |
| 526 void NetworkStateHandler::SetTetherNetworkStateDisconnected( | 584 void NetworkStateHandler::SetTetherNetworkStateDisconnected( |
| 527 const std::string& guid) { | 585 const std::string& guid) { |
| 528 // TODO(khorimoto): Remove the tether network as the default network, and | 586 // TODO(khorimoto): Remove the Tether network as the default network, and |
| 529 // send a connection status change. | 587 // send a connection status change. |
| 530 SetTetherNetworkStateConnectionState(guid, shill::kStateDisconnect); | 588 SetTetherNetworkStateConnectionState(guid, shill::kStateDisconnect); |
| 531 } | 589 } |
| 532 | 590 |
| 533 void NetworkStateHandler::SetTetherNetworkStateConnecting( | 591 void NetworkStateHandler::SetTetherNetworkStateConnecting( |
| 534 const std::string& guid) { | 592 const std::string& guid) { |
| 535 // TODO(khorimoto): Set the tether network as the default network, and send | 593 // TODO(khorimoto): Set the Tether network as the default network, and send |
| 536 // a connection status change. | 594 // a connection status change. |
| 537 SetTetherNetworkStateConnectionState(guid, shill::kStateConfiguration); | 595 SetTetherNetworkStateConnectionState(guid, shill::kStateConfiguration); |
| 538 } | 596 } |
| 539 | 597 |
| 540 void NetworkStateHandler::SetTetherNetworkStateConnected( | 598 void NetworkStateHandler::SetTetherNetworkStateConnected( |
| 541 const std::string& guid) { | 599 const std::string& guid) { |
| 542 // Being connected implies that AssociateTetherNetworkStateWithWifiNetwork() | 600 // Being connected implies that AssociateTetherNetworkStateWithWifiNetwork() |
| 543 // was already called, so ensure that the association is still intact. | 601 // was already called, so ensure that the association is still intact. |
| 544 DCHECK(GetNetworkStateFromGuid(GetNetworkStateFromGuid(guid)->tether_guid()) | 602 DCHECK(GetNetworkStateFromGuid(GetNetworkStateFromGuid(guid)->tether_guid()) |
| 545 ->tether_guid() == guid); | 603 ->tether_guid() == guid); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 686 } | 744 } |
| 687 | 745 |
| 688 //------------------------------------------------------------------------------ | 746 //------------------------------------------------------------------------------ |
| 689 // ShillPropertyHandler::Delegate overrides | 747 // ShillPropertyHandler::Delegate overrides |
| 690 | 748 |
| 691 void NetworkStateHandler::UpdateManagedList(ManagedState::ManagedType type, | 749 void NetworkStateHandler::UpdateManagedList(ManagedState::ManagedType type, |
| 692 const base::ListValue& entries) { | 750 const base::ListValue& entries) { |
| 693 ManagedStateList* managed_list = GetManagedList(type); | 751 ManagedStateList* managed_list = GetManagedList(type); |
| 694 NET_LOG_DEBUG("UpdateManagedList: " + ManagedState::TypeToString(type), | 752 NET_LOG_DEBUG("UpdateManagedList: " + ManagedState::TypeToString(type), |
| 695 base::StringPrintf("%" PRIuS, entries.GetSize())); | 753 base::StringPrintf("%" PRIuS, entries.GetSize())); |
| 754 | |
| 755 // Create a copy of |entries| since it may be edited below. | |
| 756 base::ListValue entries_copy(entries); | |
| 757 if (type == ManagedState::ManagedType::MANAGED_TYPE_DEVICE) { | |
| 758 // If a device list update is received from Shill, the list supplied will | |
| 759 // never contain an entry for Tether networks since Shill does not recognize | |
| 760 // Tether networks as a device type. Before processing the list, add an | |
| 761 // entry for the tether device type with the constant tether device path. | |
| 762 entries_copy.Append(base::MakeUnique<base::Value>(kTetherDevicePath)); | |
| 763 } | |
|
stevenjb
2017/04/20 16:49:41
This seems unnecessary, and placing the code at 79
Kyle Horimoto
2017/04/20 19:38:46
Done.
| |
| 764 | |
| 696 // Create a map of existing entries. Assumes all entries in |managed_list| | 765 // Create a map of existing entries. Assumes all entries in |managed_list| |
| 697 // are unique. | 766 // are unique. |
| 698 std::map<std::string, std::unique_ptr<ManagedState>> managed_map; | 767 std::map<std::string, std::unique_ptr<ManagedState>> managed_map; |
| 699 for (auto& item : *managed_list) { | 768 for (auto& item : *managed_list) { |
| 700 std::string path = item->path(); | 769 std::string path = item->path(); |
| 701 DCHECK(!base::ContainsKey(managed_map, path)); | 770 DCHECK(!base::ContainsKey(managed_map, path)); |
| 702 managed_map[path] = std::move(item); | 771 managed_map[path] = std::move(item); |
| 703 } | 772 } |
| 704 // Clear the list (objects are temporarily owned by managed_map). | 773 // Clear the list (objects are temporarily owned by managed_map). |
| 705 managed_list->clear(); | 774 managed_list->clear(); |
| 706 // Updates managed_list and request updates for new entries. | 775 // Updates managed_list and request updates for new entries. |
| 707 std::set<std::string> list_entries; | 776 std::set<std::string> list_entries; |
| 708 for (auto& iter : entries) { | 777 for (auto& iter : entries_copy) { |
| 709 std::string path; | 778 std::string path; |
| 710 iter.GetAsString(&path); | 779 iter.GetAsString(&path); |
| 711 if (path.empty() || path == shill::kFlimflamServicePath) { | 780 if (path.empty() || path == shill::kFlimflamServicePath) { |
| 712 NET_LOG_ERROR(base::StringPrintf("Bad path in list:%d", type), path); | 781 NET_LOG_ERROR(base::StringPrintf("Bad path in list:%d", type), path); |
| 713 continue; | 782 continue; |
| 714 } | 783 } |
| 715 auto found = managed_map.find(path); | 784 auto found = managed_map.find(path); |
| 716 if (found == managed_map.end()) { | 785 if (found == managed_map.end()) { |
| 717 if (list_entries.count(path) != 0) { | 786 if (list_entries.count(path) != 0) { |
| 718 NET_LOG_ERROR("Duplicate entry in list", path); | 787 NET_LOG_ERROR("Duplicate entry in list", path); |
| 719 continue; | 788 continue; |
| 720 } | 789 } |
| 721 managed_list->push_back(ManagedState::Create(type, path)); | 790 std::unique_ptr<ManagedState> state = ManagedState::Create(type, path); |
| 791 if (type == ManagedState::ManagedType::MANAGED_TYPE_DEVICE && | |
| 792 path == kTetherDevicePath) { | |
| 793 // If adding the tether DeviceState, set appropriate properties since | |
| 794 // it will never receive a properties update from Shill. | |
| 795 state->set_update_received(); | |
| 796 state->set_update_requested(false); | |
| 797 state->set_name(kTetherDeviceName); | |
| 798 state->set_type(kTypeTether); | |
| 799 } | |
| 800 managed_list->push_back(std::move(state)); | |
| 722 } else { | 801 } else { |
| 723 managed_list->push_back(std::move(found->second)); | 802 managed_list->push_back(std::move(found->second)); |
| 724 managed_map.erase(found); | 803 managed_map.erase(found); |
| 725 } | 804 } |
| 726 list_entries.insert(path); | 805 list_entries.insert(path); |
| 727 } | 806 } |
| 728 | 807 |
| 729 if (type != ManagedState::ManagedType::MANAGED_TYPE_NETWORK) | 808 if (type != ManagedState::ManagedType::MANAGED_TYPE_NETWORK) |
| 730 return; | 809 return; |
| 731 | 810 |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 964 devices += ", "; | 1043 devices += ", "; |
| 965 devices += (*iter)->name(); | 1044 devices += (*iter)->name(); |
| 966 } | 1045 } |
| 967 NET_LOG_EVENT("DeviceList", devices); | 1046 NET_LOG_EVENT("DeviceList", devices); |
| 968 NotifyDeviceListChanged(); | 1047 NotifyDeviceListChanged(); |
| 969 } else { | 1048 } else { |
| 970 NOTREACHED(); | 1049 NOTREACHED(); |
| 971 } | 1050 } |
| 972 } | 1051 } |
| 973 | 1052 |
| 974 // TODO(khorimoto): Add sorting for the tether network list as well. | 1053 // TODO(khorimoto): Add sorting for the Tether network list as well. |
| 975 void NetworkStateHandler::SortNetworkList() { | 1054 void NetworkStateHandler::SortNetworkList() { |
| 976 // Note: usually active networks will precede inactive networks, however | 1055 // Note: usually active networks will precede inactive networks, however |
| 977 // this may briefly be untrue during state transitions (e.g. a network may | 1056 // this may briefly be untrue during state transitions (e.g. a network may |
| 978 // transition to idle before the list is updated). | 1057 // transition to idle before the list is updated). |
| 979 ManagedStateList active, non_wifi_visible, wifi_visible, hidden, new_networks; | 1058 ManagedStateList active, non_wifi_visible, wifi_visible, hidden, new_networks; |
| 980 for (ManagedStateList::iterator iter = network_list_.begin(); | 1059 for (ManagedStateList::iterator iter = network_list_.begin(); |
| 981 iter != network_list_.end(); ++iter) { | 1060 iter != network_list_.end(); ++iter) { |
| 982 NetworkState* network = (*iter)->AsNetworkState(); | 1061 NetworkState* network = (*iter)->AsNetworkState(); |
| 983 if (!network->update_received()) { | 1062 if (!network->update_received()) { |
| 984 new_networks.push_back(std::move(*iter)); | 1063 new_networks.push_back(std::move(*iter)); |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1268 if (type.MatchesType(shill::kTypeWifi)) | 1347 if (type.MatchesType(shill::kTypeWifi)) |
| 1269 technologies.emplace_back(shill::kTypeWifi); | 1348 technologies.emplace_back(shill::kTypeWifi); |
| 1270 if (type.MatchesType(shill::kTypeWimax)) | 1349 if (type.MatchesType(shill::kTypeWimax)) |
| 1271 technologies.emplace_back(shill::kTypeWimax); | 1350 technologies.emplace_back(shill::kTypeWimax); |
| 1272 if (type.MatchesType(shill::kTypeCellular)) | 1351 if (type.MatchesType(shill::kTypeCellular)) |
| 1273 technologies.emplace_back(shill::kTypeCellular); | 1352 technologies.emplace_back(shill::kTypeCellular); |
| 1274 if (type.MatchesType(shill::kTypeBluetooth)) | 1353 if (type.MatchesType(shill::kTypeBluetooth)) |
| 1275 technologies.emplace_back(shill::kTypeBluetooth); | 1354 technologies.emplace_back(shill::kTypeBluetooth); |
| 1276 if (type.MatchesType(shill::kTypeVPN)) | 1355 if (type.MatchesType(shill::kTypeVPN)) |
| 1277 technologies.emplace_back(shill::kTypeVPN); | 1356 technologies.emplace_back(shill::kTypeVPN); |
| 1357 if (type.MatchesType(kTypeTether)) | |
| 1358 technologies.emplace_back(kTypeTether); | |
| 1278 | 1359 |
| 1279 CHECK_GT(technologies.size(), 0ul); | 1360 CHECK_GT(technologies.size(), 0ul); |
| 1280 return technologies; | 1361 return technologies; |
| 1281 } | 1362 } |
| 1282 | 1363 |
| 1283 } // namespace chromeos | 1364 } // namespace chromeos |
| OLD | NEW |