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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
| 9 #include "base/guid.h" | 9 #include "base/guid.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 return "None"; | 49 return "None"; |
| 50 return base::StringPrintf("%s (%s)", state->name().c_str(), | 50 return base::StringPrintf("%s (%s)", state->name().c_str(), |
| 51 state->path().c_str()); | 51 state->path().c_str()); |
| 52 } | 52 } |
| 53 | 53 |
| 54 } // namespace | 54 } // namespace |
| 55 | 55 |
| 56 const char NetworkStateHandler::kDefaultCheckPortalList[] = | 56 const char NetworkStateHandler::kDefaultCheckPortalList[] = |
| 57 "ethernet,wifi,cellular"; | 57 "ethernet,wifi,cellular"; |
| 58 | 58 |
| 59 NetworkStateHandler::NetworkStateHandler() { | 59 NetworkStateHandler::NetworkStateHandler() |
| 60 : network_list_sorted_(false) { | |
| 60 } | 61 } |
| 61 | 62 |
| 62 NetworkStateHandler::~NetworkStateHandler() { | 63 NetworkStateHandler::~NetworkStateHandler() { |
| 63 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, IsShuttingDown()); | 64 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, IsShuttingDown()); |
| 64 STLDeleteContainerPointers(network_list_.begin(), network_list_.end()); | 65 STLDeleteContainerPointers(network_list_.begin(), network_list_.end()); |
| 65 STLDeleteContainerPointers(device_list_.begin(), device_list_.end()); | 66 STLDeleteContainerPointers(device_list_.begin(), device_list_.end()); |
| 66 } | 67 } |
| 67 | 68 |
| 68 void NetworkStateHandler::InitShillPropertyHandler() { | 69 void NetworkStateHandler::InitShillPropertyHandler() { |
| 69 shill_property_handler_.reset(new internal::ShillPropertyHandler(this)); | 70 shill_property_handler_.reset(new internal::ShillPropertyHandler(this)); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 } | 180 } |
| 180 | 181 |
| 181 const NetworkState* NetworkStateHandler::DefaultNetwork() const { | 182 const NetworkState* NetworkStateHandler::DefaultNetwork() const { |
| 182 if (default_network_path_.empty()) | 183 if (default_network_path_.empty()) |
| 183 return NULL; | 184 return NULL; |
| 184 return GetNetworkState(default_network_path_); | 185 return GetNetworkState(default_network_path_); |
| 185 } | 186 } |
| 186 | 187 |
| 187 const NetworkState* NetworkStateHandler::ConnectedNetworkByType( | 188 const NetworkState* NetworkStateHandler::ConnectedNetworkByType( |
| 188 const NetworkTypePattern& type) const { | 189 const NetworkTypePattern& type) const { |
| 190 // Active networks are always listed first by Shill so no need to sort. | |
| 189 for (ManagedStateList::const_iterator iter = network_list_.begin(); | 191 for (ManagedStateList::const_iterator iter = network_list_.begin(); |
| 190 iter != network_list_.end(); ++iter) { | 192 iter != network_list_.end(); ++iter) { |
| 191 const NetworkState* network = (*iter)->AsNetworkState(); | 193 const NetworkState* network = (*iter)->AsNetworkState(); |
| 192 DCHECK(network); | 194 DCHECK(network); |
| 193 if (!network->update_received()) | 195 if (!network->update_received()) |
| 194 continue; | 196 continue; |
| 195 if (!network->IsConnectedState()) | 197 if (!network->IsConnectedState()) |
| 196 break; // Connected networks are listed first. | 198 break; // Connected networks are listed first. |
| 197 if (network->Matches(type)) | 199 if (network->Matches(type)) |
| 198 return network; | 200 return network; |
| 199 } | 201 } |
| 200 return NULL; | 202 return NULL; |
| 201 } | 203 } |
| 202 | 204 |
| 203 const NetworkState* NetworkStateHandler::ConnectingNetworkByType( | 205 const NetworkState* NetworkStateHandler::ConnectingNetworkByType( |
| 204 const NetworkTypePattern& type) const { | 206 const NetworkTypePattern& type) const { |
| 207 // Active networks are always listed first by Shill so no need to sort. | |
| 205 for (ManagedStateList::const_iterator iter = network_list_.begin(); | 208 for (ManagedStateList::const_iterator iter = network_list_.begin(); |
| 206 iter != network_list_.end(); ++iter) { | 209 iter != network_list_.end(); ++iter) { |
| 207 const NetworkState* network = (*iter)->AsNetworkState(); | 210 const NetworkState* network = (*iter)->AsNetworkState(); |
| 208 DCHECK(network); | 211 DCHECK(network); |
| 209 if (!network->update_received() || network->IsConnectedState()) | 212 if (!network->update_received() || network->IsConnectedState()) |
| 210 continue; | 213 continue; |
| 211 if (!network->IsConnectingState()) | 214 if (!network->IsConnectingState()) |
| 212 break; // Connected and connecting networks are listed first. | 215 break; // Connected and connecting networks are listed first. |
| 213 if (network->Matches(type)) | 216 if (network->Matches(type)) |
| 214 return network; | 217 return network; |
| 215 } | 218 } |
| 216 return NULL; | 219 return NULL; |
| 217 } | 220 } |
| 218 | 221 |
| 219 const NetworkState* NetworkStateHandler::FirstNetworkByType( | 222 const NetworkState* NetworkStateHandler::FirstNetworkByType( |
| 220 const NetworkTypePattern& type) const { | 223 const NetworkTypePattern& type) { |
| 224 if (!network_list_sorted_) | |
|
pneubeck (no reviews)
2014/06/18 09:45:48
optional nit:
you could move network_list_sorted_
stevenjb
2014/06/18 22:33:26
Yeah, I considered that, but I kind of want to for
pneubeck (no reviews)
2014/06/18 22:35:29
I see. that's fine.
| |
| 225 SortNetworkList(); // Sort to ensure visible networks are listed fist. | |
|
pneubeck (no reviews)
2014/06/18 09:45:49
fist -> first
stevenjb
2014/06/18 22:33:26
Done.
| |
| 221 for (ManagedStateList::const_iterator iter = network_list_.begin(); | 226 for (ManagedStateList::const_iterator iter = network_list_.begin(); |
| 222 iter != network_list_.end(); ++iter) { | 227 iter != network_list_.end(); ++iter) { |
| 223 const NetworkState* network = (*iter)->AsNetworkState(); | 228 const NetworkState* network = (*iter)->AsNetworkState(); |
| 224 DCHECK(network); | 229 DCHECK(network); |
| 225 if (!network->update_received()) | 230 if (!network->update_received()) |
| 226 continue; | 231 continue; |
| 227 if (!network->visible()) | 232 if (!network->visible()) |
| 228 continue; | 233 break; |
| 229 if (network->Matches(type)) | 234 if (network->Matches(type)) |
| 230 return network; | 235 return network; |
| 231 } | 236 } |
| 232 return NULL; | 237 return NULL; |
| 233 } | 238 } |
| 234 | 239 |
| 235 std::string NetworkStateHandler::FormattedHardwareAddressForType( | 240 std::string NetworkStateHandler::FormattedHardwareAddressForType( |
| 236 const NetworkTypePattern& type) const { | 241 const NetworkTypePattern& type) const { |
| 237 const DeviceState* device = NULL; | 242 const DeviceState* device = NULL; |
| 238 const NetworkState* network = ConnectedNetworkByType(type); | 243 const NetworkState* network = ConnectedNetworkByType(type); |
| 239 if (network) | 244 if (network) |
| 240 device = GetDeviceState(network->device_path()); | 245 device = GetDeviceState(network->device_path()); |
| 241 else | 246 else |
| 242 device = GetDeviceStateByType(type); | 247 device = GetDeviceStateByType(type); |
| 243 if (!device) | 248 if (!device) |
| 244 return std::string(); | 249 return std::string(); |
| 245 return network_util::FormattedMacAddress(device->mac_address()); | 250 return network_util::FormattedMacAddress(device->mac_address()); |
| 246 } | 251 } |
| 247 | 252 |
| 248 void NetworkStateHandler::GetVisibleNetworkListByType( | 253 void NetworkStateHandler::GetVisibleNetworkListByType( |
| 249 const NetworkTypePattern& type, | 254 const NetworkTypePattern& type, |
| 250 NetworkStateList* list) const { | 255 NetworkStateList* list) { |
| 251 GetNetworkListByType(type, | 256 GetNetworkListByType(type, |
| 252 false /* configured_only */, | 257 false /* configured_only */, |
| 253 true /* visible_only */, | 258 true /* visible_only */, |
| 254 0 /* no limit */, | 259 0 /* no limit */, |
| 255 list); | 260 list); |
| 256 } | 261 } |
| 257 | 262 |
| 258 void NetworkStateHandler::GetVisibleNetworkList(NetworkStateList* list) const { | 263 void NetworkStateHandler::GetVisibleNetworkList(NetworkStateList* list) { |
| 259 GetVisibleNetworkListByType(NetworkTypePattern::Default(), list); | 264 GetVisibleNetworkListByType(NetworkTypePattern::Default(), list); |
| 260 } | 265 } |
| 261 | 266 |
| 262 void NetworkStateHandler::GetNetworkListByType(const NetworkTypePattern& type, | 267 void NetworkStateHandler::GetNetworkListByType(const NetworkTypePattern& type, |
| 263 bool configured_only, | 268 bool configured_only, |
| 264 bool visible_only, | 269 bool visible_only, |
| 265 int limit, | 270 int limit, |
| 266 NetworkStateList* list) const { | 271 NetworkStateList* list) { |
| 267 DCHECK(list); | 272 DCHECK(list); |
| 268 list->clear(); | 273 list->clear(); |
| 269 int count = 0; | 274 int count = 0; |
| 275 // Sort the network list if necessary. | |
| 276 if (!network_list_sorted_) | |
| 277 SortNetworkList(); | |
| 270 for (ManagedStateList::const_iterator iter = network_list_.begin(); | 278 for (ManagedStateList::const_iterator iter = network_list_.begin(); |
| 271 iter != network_list_.end(); ++iter) { | 279 iter != network_list_.end(); ++iter) { |
| 272 const NetworkState* network = (*iter)->AsNetworkState(); | 280 const NetworkState* network = (*iter)->AsNetworkState(); |
| 273 DCHECK(network); | 281 DCHECK(network); |
| 274 if (!network->update_received() || !network->Matches(type)) | 282 if (!network->update_received() || !network->Matches(type)) |
| 275 continue; | 283 continue; |
| 276 if (configured_only && !network->IsInProfile()) | 284 if (configured_only && !network->IsInProfile()) |
| 277 continue; | 285 continue; |
| 278 if (visible_only && !network->visible()) | 286 if (visible_only && !network->visible()) |
| 279 continue; | 287 continue; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 network->clear_last_error(); | 372 network->clear_last_error(); |
| 365 } | 373 } |
| 366 | 374 |
| 367 void NetworkStateHandler::SetCheckPortalList( | 375 void NetworkStateHandler::SetCheckPortalList( |
| 368 const std::string& check_portal_list) { | 376 const std::string& check_portal_list) { |
| 369 NET_LOG_EVENT("SetCheckPortalList", check_portal_list); | 377 NET_LOG_EVENT("SetCheckPortalList", check_portal_list); |
| 370 shill_property_handler_->SetCheckPortalList(check_portal_list); | 378 shill_property_handler_->SetCheckPortalList(check_portal_list); |
| 371 } | 379 } |
| 372 | 380 |
| 373 const NetworkState* NetworkStateHandler::GetEAPForEthernet( | 381 const NetworkState* NetworkStateHandler::GetEAPForEthernet( |
| 374 const std::string& service_path) const { | 382 const std::string& service_path) { |
| 375 const NetworkState* network = GetNetworkState(service_path); | 383 const NetworkState* network = GetNetworkState(service_path); |
| 376 if (!network) { | 384 if (!network) { |
| 377 NET_LOG_ERROR("GetEAPForEthernet", "Unknown service path " + service_path); | 385 NET_LOG_ERROR("GetEAPForEthernet", "Unknown service path " + service_path); |
| 378 return NULL; | 386 return NULL; |
| 379 } | 387 } |
| 380 if (network->type() != shill::kTypeEthernet) { | 388 if (network->type() != shill::kTypeEthernet) { |
| 381 NET_LOG_ERROR("GetEAPForEthernet", "Not of type Ethernet: " + service_path); | 389 NET_LOG_ERROR("GetEAPForEthernet", "Not of type Ethernet: " + service_path); |
| 382 return NULL; | 390 return NULL; |
| 383 } | 391 } |
| 384 if (!network->IsConnectedState()) | 392 if (!network->IsConnectedState()) |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 457 } else { | 465 } else { |
| 458 managed_list->push_back(found->second); | 466 managed_list->push_back(found->second); |
| 459 managed_map.erase(found); | 467 managed_map.erase(found); |
| 460 } | 468 } |
| 461 list_entries.insert(path); | 469 list_entries.insert(path); |
| 462 } | 470 } |
| 463 // Delete any remaining entries in managed_map. | 471 // Delete any remaining entries in managed_map. |
| 464 STLDeleteContainerPairSecondPointers(managed_map.begin(), managed_map.end()); | 472 STLDeleteContainerPairSecondPointers(managed_map.begin(), managed_map.end()); |
| 465 } | 473 } |
| 466 | 474 |
| 467 void NetworkStateHandler::UpdateVisibleNetworks( | |
| 468 const base::ListValue& entries) { | |
| 469 NET_LOG_DEBUG(base::StringPrintf("UpdateVisibleNetworks"), | |
| 470 base::StringPrintf("%" PRIuS, entries.GetSize())); | |
| 471 // Create a map of all networks and clear the visible state. | |
| 472 ManagedStateList* network_list = | |
| 473 GetManagedList(ManagedState::MANAGED_TYPE_NETWORK); | |
| 474 typedef std::map<std::string, NetworkState*> NetworkMap; | |
| 475 NetworkMap network_map; | |
| 476 for (ManagedStateList::iterator iter = network_list->begin(); | |
| 477 iter != network_list->end(); ++iter) { | |
| 478 NetworkState* network = (*iter)->AsNetworkState(); | |
| 479 network_map[network->path()] = network; | |
| 480 network->set_visible(false); | |
| 481 } | |
| 482 // Look up each entry and set the associated network to visible. | |
| 483 for (base::ListValue::const_iterator iter = entries.begin(); | |
| 484 iter != entries.end(); ++iter) { | |
| 485 std::string path; | |
| 486 (*iter)->GetAsString(&path); | |
| 487 NetworkMap::iterator found = network_map.find(path); | |
| 488 if (found != network_map.end()) | |
| 489 found->second->set_visible(true); | |
| 490 else | |
| 491 NET_LOG_DEBUG("Visible network not in list", path); | |
| 492 } | |
| 493 } | |
| 494 | |
| 495 void NetworkStateHandler::ProfileListChanged() { | 475 void NetworkStateHandler::ProfileListChanged() { |
| 496 NET_LOG_EVENT("ProfileListChanged", "Re-Requesting Network Properties"); | 476 NET_LOG_EVENT("ProfileListChanged", "Re-Requesting Network Properties"); |
| 497 for (ManagedStateList::iterator iter = network_list_.begin(); | 477 for (ManagedStateList::iterator iter = network_list_.begin(); |
| 498 iter != network_list_.end(); ++iter) { | 478 iter != network_list_.end(); ++iter) { |
| 499 NetworkState* network = (*iter)->AsNetworkState(); | 479 NetworkState* network = (*iter)->AsNetworkState(); |
| 500 DCHECK(network); | 480 DCHECK(network); |
| 501 shill_property_handler_->RequestProperties( | 481 shill_property_handler_->RequestProperties( |
| 502 ManagedState::MANAGED_TYPE_NETWORK, network->path()); | 482 ManagedState::MANAGED_TYPE_NETWORK, network->path()); |
| 503 } | 483 } |
| 504 } | 484 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 537 const base::DictionaryValue& properties) { | 517 const base::DictionaryValue& properties) { |
| 538 DCHECK(network); | 518 DCHECK(network); |
| 539 bool network_property_updated = false; | 519 bool network_property_updated = false; |
| 540 std::string prev_connection_state = network->connection_state(); | 520 std::string prev_connection_state = network->connection_state(); |
| 541 for (base::DictionaryValue::Iterator iter(properties); | 521 for (base::DictionaryValue::Iterator iter(properties); |
| 542 !iter.IsAtEnd(); iter.Advance()) { | 522 !iter.IsAtEnd(); iter.Advance()) { |
| 543 if (network->PropertyChanged(iter.key(), iter.value())) | 523 if (network->PropertyChanged(iter.key(), iter.value())) |
| 544 network_property_updated = true; | 524 network_property_updated = true; |
| 545 } | 525 } |
| 546 network_property_updated |= network->InitialPropertiesReceived(properties); | 526 network_property_updated |= network->InitialPropertiesReceived(properties); |
| 527 UpdateGuid(network); | |
| 528 network_list_sorted_ = false; | |
| 529 | |
| 547 // Notify observers of NetworkState changes. | 530 // Notify observers of NetworkState changes. |
| 548 if (network_property_updated || network->update_requested()) { | 531 if (network_property_updated || network->update_requested()) { |
| 549 // Signal connection state changed after all properties have been updated. | 532 // Signal connection state changed after all properties have been updated. |
| 550 if (ConnectionStateChanged(network, prev_connection_state)) | 533 if (ConnectionStateChanged(network, prev_connection_state)) |
| 551 OnNetworkConnectionStateChanged(network); | 534 OnNetworkConnectionStateChanged(network); |
| 552 NET_LOG_EVENT("NetworkPropertiesUpdated", GetLogName(network)); | 535 NET_LOG_EVENT("NetworkPropertiesUpdated", GetLogName(network)); |
| 553 NotifyNetworkPropertiesUpdated(network); | 536 NotifyNetworkPropertiesUpdated(network); |
| 554 } | 537 } |
| 555 UpdateGuid(network); | |
| 556 } | 538 } |
| 557 | 539 |
| 558 void NetworkStateHandler::UpdateNetworkServiceProperty( | 540 void NetworkStateHandler::UpdateNetworkServiceProperty( |
| 559 const std::string& service_path, | 541 const std::string& service_path, |
| 560 const std::string& key, | 542 const std::string& key, |
| 561 const base::Value& value) { | 543 const base::Value& value) { |
| 562 bool changed = false; | 544 bool changed = false; |
| 563 NetworkState* network = GetModifiableNetworkState(service_path); | 545 NetworkState* network = GetModifiableNetworkState(service_path); |
| 564 if (!network) | 546 if (!network) |
| 565 return; | 547 return; |
| 566 std::string prev_connection_state = network->connection_state(); | 548 std::string prev_connection_state = network->connection_state(); |
| 567 std::string prev_profile_path = network->profile_path(); | 549 std::string prev_profile_path = network->profile_path(); |
| 568 changed |= network->PropertyChanged(key, value); | 550 changed |= network->PropertyChanged(key, value); |
| 569 if (!changed) | 551 if (!changed) |
| 570 return; | 552 return; |
| 571 | 553 |
| 572 if (key == shill::kStateProperty) { | 554 if (key == shill::kStateProperty || key == shill::kVisibleProperty) { |
| 555 network_list_sorted_ = false; | |
| 573 if (ConnectionStateChanged(network, prev_connection_state)) { | 556 if (ConnectionStateChanged(network, prev_connection_state)) { |
| 574 OnNetworkConnectionStateChanged(network); | 557 OnNetworkConnectionStateChanged(network); |
| 575 // If the connection state changes, other properties such as IPConfig | 558 // If the connection state changes, other properties such as IPConfig |
| 576 // may have changed, so request a full update. | 559 // may have changed, so request a full update. |
| 577 RequestUpdateForNetwork(service_path); | 560 RequestUpdateForNetwork(service_path); |
| 578 } | 561 } |
| 579 } else { | 562 } else { |
| 580 std::string value_str; | 563 std::string value_str; |
| 581 value.GetAsString(&value_str); | 564 value.GetAsString(&value_str); |
| 582 // Some property changes are noisy and not interesting: | 565 // Some property changes are noisy and not interesting: |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 684 | 667 |
| 685 void NetworkStateHandler::TechnologyListChanged() { | 668 void NetworkStateHandler::TechnologyListChanged() { |
| 686 // Eventually we would like to replace Technology state with Device state. | 669 // Eventually we would like to replace Technology state with Device state. |
| 687 // For now, treat technology state changes as device list changes. | 670 // For now, treat technology state changes as device list changes. |
| 688 NotifyDeviceListChanged(); | 671 NotifyDeviceListChanged(); |
| 689 } | 672 } |
| 690 | 673 |
| 691 void NetworkStateHandler::ManagedStateListChanged( | 674 void NetworkStateHandler::ManagedStateListChanged( |
| 692 ManagedState::ManagedType type) { | 675 ManagedState::ManagedType type) { |
| 693 if (type == ManagedState::MANAGED_TYPE_NETWORK) { | 676 if (type == ManagedState::MANAGED_TYPE_NETWORK) { |
| 677 SortNetworkList(); | |
| 678 UpdateNetworkStats(); | |
| 694 // Notify observers that the list of networks has changed. | 679 // Notify observers that the list of networks has changed. |
| 695 NET_LOG_EVENT("NOTIFY:NetworkListChanged", | 680 NET_LOG_EVENT("NOTIFY:NetworkListChanged", |
| 696 base::StringPrintf("Size:%" PRIuS, network_list_.size())); | 681 base::StringPrintf("Size:%" PRIuS, network_list_.size())); |
| 697 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 682 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
| 698 NetworkListChanged()); | 683 NetworkListChanged()); |
| 699 // Update UMA stats. | |
| 700 size_t shared = 0, unshared = 0, visible = 0; | |
| 701 for (ManagedStateList::iterator iter = network_list_.begin(); | |
| 702 iter != network_list_.end(); ++iter) { | |
| 703 NetworkState* network = (*iter)->AsNetworkState(); | |
| 704 if (network->visible()) | |
| 705 ++visible; | |
| 706 if (network->IsInProfile()) { | |
| 707 if (network->IsPrivate()) | |
| 708 ++unshared; | |
| 709 else | |
| 710 ++shared; | |
| 711 } | |
| 712 } | |
| 713 UMA_HISTOGRAM_COUNTS_100("Networks.Visible", visible); | |
| 714 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedShared", shared); | |
| 715 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedUnshared", unshared); | |
| 716 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { | 684 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { |
| 717 std::string devices; | 685 std::string devices; |
| 718 for (ManagedStateList::const_iterator iter = device_list_.begin(); | 686 for (ManagedStateList::const_iterator iter = device_list_.begin(); |
| 719 iter != device_list_.end(); ++iter) { | 687 iter != device_list_.end(); ++iter) { |
| 720 if (iter != device_list_.begin()) | 688 if (iter != device_list_.begin()) |
| 721 devices += ", "; | 689 devices += ", "; |
| 722 devices += (*iter)->name(); | 690 devices += (*iter)->name(); |
| 723 } | 691 } |
| 724 NET_LOG_EVENT("DeviceList", devices); | 692 NET_LOG_EVENT("DeviceList", devices); |
| 725 NotifyDeviceListChanged(); | 693 NotifyDeviceListChanged(); |
| 726 } else { | 694 } else { |
| 727 NOTREACHED(); | 695 NOTREACHED(); |
| 728 } | 696 } |
| 729 } | 697 } |
| 730 | 698 |
| 699 void NetworkStateHandler::SortNetworkList() { | |
| 700 bool listing_active_networks = true; | |
| 701 ManagedStateList active, non_wifi_visible, wifi_visible, hidden; | |
| 702 for (ManagedStateList::iterator iter = network_list_.begin(); | |
| 703 iter != network_list_.end(); ++iter) { | |
| 704 NetworkState* network = (*iter)->AsNetworkState(); | |
| 705 if (network->IsConnectedState() || network->IsConnectingState()) { | |
| 706 active.push_back(network); | |
| 707 if (!listing_active_networks) { | |
| 708 NET_LOG_ERROR("Active network follows inactive network", | |
| 709 GetLogName(network)); | |
| 710 } | |
| 711 } else { | |
| 712 listing_active_networks = false; | |
| 713 if (network->visible()) { | |
| 714 if (NetworkTypePattern::WiFi().MatchesType(network->type())) | |
| 715 wifi_visible.push_back(network); | |
| 716 else | |
| 717 non_wifi_visible.push_back(network); | |
| 718 } else { | |
| 719 hidden.push_back(network); | |
|
pneubeck (no reviews)
2014/06/18 09:45:48
do networks with !update_received() always end up
stevenjb
2014/06/18 22:33:26
They would be treated as "hidden", which would be
| |
| 720 } | |
| 721 } | |
| 722 } | |
| 723 network_list_.clear(); | |
| 724 network_list_.insert(network_list_.end(), active.begin(), active.end()); | |
| 725 network_list_.insert( | |
| 726 network_list_.end(), non_wifi_visible.begin(), non_wifi_visible.end()); | |
| 727 network_list_.insert( | |
| 728 network_list_.end(), wifi_visible.begin(), wifi_visible.end()); | |
| 729 network_list_.insert(network_list_.end(), hidden.begin(), hidden.end()); | |
| 730 network_list_sorted_ = true; | |
| 731 } | |
| 732 | |
| 733 void NetworkStateHandler::UpdateNetworkStats() { | |
| 734 size_t shared = 0, unshared = 0, visible = 0; | |
| 735 for (ManagedStateList::iterator iter = network_list_.begin(); | |
| 736 iter != network_list_.end(); ++iter) { | |
| 737 NetworkState* network = (*iter)->AsNetworkState(); | |
| 738 if (network->visible()) | |
| 739 ++visible; | |
| 740 if (network->IsInProfile()) { | |
| 741 if (network->IsPrivate()) | |
| 742 ++unshared; | |
| 743 else | |
| 744 ++shared; | |
| 745 } | |
| 746 } | |
| 747 UMA_HISTOGRAM_COUNTS_100("Networks.Visible", visible); | |
| 748 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedShared", shared); | |
| 749 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedUnshared", unshared); | |
| 750 } | |
| 751 | |
| 731 void NetworkStateHandler::DefaultNetworkServiceChanged( | 752 void NetworkStateHandler::DefaultNetworkServiceChanged( |
| 732 const std::string& service_path) { | 753 const std::string& service_path) { |
| 733 // Shill uses '/' for empty service path values; check explicitly for that. | 754 // Shill uses '/' for empty service path values; check explicitly for that. |
| 734 const char* kEmptyServicePath = "/"; | 755 const char* kEmptyServicePath = "/"; |
| 735 std::string new_service_path = | 756 std::string new_service_path = |
| 736 (service_path != kEmptyServicePath) ? service_path : ""; | 757 (service_path != kEmptyServicePath) ? service_path : ""; |
| 737 if (new_service_path == default_network_path_) | 758 if (new_service_path == default_network_path_) |
| 738 return; | 759 return; |
| 739 | 760 |
| 740 default_network_path_ = service_path; | 761 default_network_path_ = service_path; |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 921 if (type.MatchesType(shill::kTypeBluetooth)) | 942 if (type.MatchesType(shill::kTypeBluetooth)) |
| 922 technologies.push_back(new std::string(shill::kTypeBluetooth)); | 943 technologies.push_back(new std::string(shill::kTypeBluetooth)); |
| 923 if (type.MatchesType(shill::kTypeVPN)) | 944 if (type.MatchesType(shill::kTypeVPN)) |
| 924 technologies.push_back(new std::string(shill::kTypeVPN)); | 945 technologies.push_back(new std::string(shill::kTypeVPN)); |
| 925 | 946 |
| 926 CHECK_GT(technologies.size(), 0ul); | 947 CHECK_GT(technologies.size(), 0ul); |
| 927 return technologies.Pass(); | 948 return technologies.Pass(); |
| 928 } | 949 } |
| 929 | 950 |
| 930 } // namespace chromeos | 951 } // namespace chromeos |
| OLD | NEW |