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/location.h" | 9 #include "base/location.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 } | 277 } |
278 | 278 |
279 void NetworkStateHandler::GetNetworkListByType(const NetworkTypePattern& type, | 279 void NetworkStateHandler::GetNetworkListByType(const NetworkTypePattern& type, |
280 NetworkStateList* list) const { | 280 NetworkStateList* list) const { |
281 DCHECK(list); | 281 DCHECK(list); |
282 list->clear(); | 282 list->clear(); |
283 for (ManagedStateList::const_iterator iter = network_list_.begin(); | 283 for (ManagedStateList::const_iterator iter = network_list_.begin(); |
284 iter != network_list_.end(); ++iter) { | 284 iter != network_list_.end(); ++iter) { |
285 const NetworkState* network = (*iter)->AsNetworkState(); | 285 const NetworkState* network = (*iter)->AsNetworkState(); |
286 DCHECK(network); | 286 DCHECK(network); |
287 if (!network->update_received()) | 287 if (network->update_received() && network->Matches(type)) |
288 continue; | |
289 if (network->Matches(type)) | |
290 list->push_back(network); | 288 list->push_back(network); |
291 } | 289 } |
292 } | 290 } |
293 | 291 |
294 void NetworkStateHandler::GetDeviceList(DeviceStateList* list) const { | 292 void NetworkStateHandler::GetDeviceList(DeviceStateList* list) const { |
295 DCHECK(list); | 293 DCHECK(list); |
296 list->clear(); | 294 list->clear(); |
297 for (ManagedStateList::const_iterator iter = device_list_.begin(); | 295 for (ManagedStateList::const_iterator iter = device_list_.begin(); |
298 iter != device_list_.end(); ++iter) { | 296 iter != device_list_.end(); ++iter) { |
299 const DeviceState* device = (*iter)->AsDeviceState(); | 297 const DeviceState* device = (*iter)->AsDeviceState(); |
300 DCHECK(device); | 298 DCHECK(device); |
301 if (!device->update_received()) | 299 if (device->update_received()) |
302 continue; | 300 list->push_back(device); |
303 list->push_back(device); | |
304 } | 301 } |
305 } | 302 } |
306 | 303 |
307 void NetworkStateHandler::GetFavoriteList(FavoriteStateList* list) const { | 304 void NetworkStateHandler::GetFavoriteList(FavoriteStateList* list) const { |
| 305 GetFavoriteListByType(NetworkTypePattern::Default(), list); |
| 306 } |
| 307 |
| 308 void NetworkStateHandler::GetFavoriteListByType(const NetworkTypePattern& type, |
| 309 FavoriteStateList* list) const { |
308 DCHECK(list); | 310 DCHECK(list); |
309 FavoriteStateList result; | 311 FavoriteStateList result; |
310 list->clear(); | 312 list->clear(); |
311 for (ManagedStateList::const_iterator iter = favorite_list_.begin(); | 313 for (ManagedStateList::const_iterator iter = favorite_list_.begin(); |
312 iter != favorite_list_.end(); ++iter) { | 314 iter != favorite_list_.end(); ++iter) { |
313 const FavoriteState* favorite = (*iter)->AsFavoriteState(); | 315 const FavoriteState* favorite = (*iter)->AsFavoriteState(); |
314 DCHECK(favorite); | 316 DCHECK(favorite); |
315 if (!favorite->update_received()) | 317 if (favorite->update_received() && favorite->is_favorite() && |
316 continue; | 318 favorite->Matches(type)) { |
317 if (favorite->is_favorite()) | |
318 list->push_back(favorite); | 319 list->push_back(favorite); |
| 320 } |
319 } | 321 } |
320 } | 322 } |
321 | 323 |
322 const FavoriteState* NetworkStateHandler::GetFavoriteState( | 324 const FavoriteState* NetworkStateHandler::GetFavoriteState( |
323 const std::string& service_path) const { | 325 const std::string& service_path) const { |
324 ManagedState* managed = | 326 ManagedState* managed = |
325 GetModifiableManagedState(&favorite_list_, service_path); | 327 GetModifiableManagedState(&favorite_list_, service_path); |
326 if (!managed) | 328 if (!managed) |
327 return NULL; | 329 return NULL; |
328 if (managed && !managed->update_received()) | 330 if (managed && !managed->update_received()) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 ManagedState::MANAGED_TYPE_NETWORK, network->path()); | 371 ManagedState::MANAGED_TYPE_NETWORK, network->path()); |
370 } | 372 } |
371 } | 373 } |
372 | 374 |
373 void NetworkStateHandler::SetCheckPortalList( | 375 void NetworkStateHandler::SetCheckPortalList( |
374 const std::string& check_portal_list) { | 376 const std::string& check_portal_list) { |
375 NET_LOG_EVENT("SetCheckPortalList", check_portal_list); | 377 NET_LOG_EVENT("SetCheckPortalList", check_portal_list); |
376 shill_property_handler_->SetCheckPortalList(check_portal_list); | 378 shill_property_handler_->SetCheckPortalList(check_portal_list); |
377 } | 379 } |
378 | 380 |
| 381 const FavoriteState* NetworkStateHandler::GetEAPForEthernet( |
| 382 const std::string& service_path) const { |
| 383 const NetworkState* network = GetNetworkState(service_path); |
| 384 if (!network) { |
| 385 NET_LOG_ERROR("GetEAPForEthernet", "Unknown service path " + service_path); |
| 386 return NULL; |
| 387 } |
| 388 if (network->type() != shill::kTypeEthernet) { |
| 389 NET_LOG_ERROR("GetEAPForEthernet", "Not of type Ethernet: " + service_path); |
| 390 return NULL; |
| 391 } |
| 392 if (!network->IsConnectedState()) |
| 393 return NULL; |
| 394 |
| 395 // The same EAP service is shared for all ethernet services/devices. |
| 396 // However EAP is used/enabled per device and only if the connection was |
| 397 // successfully established. |
| 398 const DeviceState* device = GetDeviceState(network->device_path()); |
| 399 if (!device) { |
| 400 NET_LOG_ERROR( |
| 401 "GetEAPForEthernet", |
| 402 base::StringPrintf("Unknown device %s of connected ethernet service %s", |
| 403 service_path.c_str(), |
| 404 network->device_path().c_str())); |
| 405 return NULL; |
| 406 } |
| 407 if (!device->eap_authentication_completed()) |
| 408 return NULL; |
| 409 |
| 410 FavoriteStateList list; |
| 411 GetFavoriteListByType(NetworkTypePattern::Primitive(shill::kTypeEthernetEap), |
| 412 &list); |
| 413 if (list.empty()) { |
| 414 NET_LOG_ERROR("GetEAPForEthernet", |
| 415 base::StringPrintf( |
| 416 "Ethernet service %s connected using EAP, but no " |
| 417 "EAP service found.", |
| 418 service_path.c_str())); |
| 419 return NULL; |
| 420 } |
| 421 DCHECK(list.size() == 1); |
| 422 return list.front(); |
| 423 } |
| 424 |
379 void NetworkStateHandler::GetNetworkStatePropertiesForTest( | 425 void NetworkStateHandler::GetNetworkStatePropertiesForTest( |
380 base::DictionaryValue* dictionary) const { | 426 base::DictionaryValue* dictionary) const { |
381 for (ManagedStateList::const_iterator iter = network_list_.begin(); | 427 for (ManagedStateList::const_iterator iter = network_list_.begin(); |
382 iter != network_list_.end(); ++iter) { | 428 iter != network_list_.end(); ++iter) { |
383 base::DictionaryValue* network_dict = new base::DictionaryValue; | 429 base::DictionaryValue* network_dict = new base::DictionaryValue; |
384 (*iter)->AsNetworkState()->GetProperties(network_dict); | 430 (*iter)->AsNetworkState()->GetProperties(network_dict); |
385 dictionary->SetWithoutPathExpansion((*iter)->path(), network_dict); | 431 dictionary->SetWithoutPathExpansion((*iter)->path(), network_dict); |
386 } | 432 } |
387 } | 433 } |
388 | 434 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 return; | 615 return; |
570 | 616 |
571 std::string detail = device->name() + "." + key; | 617 std::string detail = device->name() + "." + key; |
572 detail += " = " + network_event_log::ValueAsString(value); | 618 detail += " = " + network_event_log::ValueAsString(value); |
573 NET_LOG_EVENT("DevicePropertyUpdated", detail); | 619 NET_LOG_EVENT("DevicePropertyUpdated", detail); |
574 | 620 |
575 NotifyDeviceListChanged(); | 621 NotifyDeviceListChanged(); |
576 | 622 |
577 if (key == shill::kScanningProperty && device->scanning() == false) | 623 if (key == shill::kScanningProperty && device->scanning() == false) |
578 ScanCompleted(device->type()); | 624 ScanCompleted(device->type()); |
| 625 if (key == shill::kEapAuthenticationCompletedProperty) { |
| 626 // Notify a change for each Ethernet service using this device. |
| 627 NetworkStateList ethernet_services; |
| 628 GetNetworkListByType(NetworkTypePattern::Ethernet(), ðernet_services); |
| 629 for (NetworkStateList::const_iterator it = ethernet_services.begin(); |
| 630 it != ethernet_services.end(); ++it) { |
| 631 const NetworkState* ethernet_service = *it; |
| 632 if (ethernet_service->update_received() || |
| 633 ethernet_service->device_path() != device->path()) { |
| 634 continue; |
| 635 } |
| 636 RequestUpdateForNetwork(ethernet_service->path()); |
| 637 } |
| 638 } |
579 } | 639 } |
580 | 640 |
581 void NetworkStateHandler::CheckPortalListChanged( | 641 void NetworkStateHandler::CheckPortalListChanged( |
582 const std::string& check_portal_list) { | 642 const std::string& check_portal_list) { |
583 check_portal_list_ = check_portal_list; | 643 check_portal_list_ = check_portal_list; |
584 } | 644 } |
585 | 645 |
586 void NetworkStateHandler::TechnologyListChanged() { | 646 void NetworkStateHandler::TechnologyListChanged() { |
587 // Eventually we would like to replace Technology state with Device state. | 647 // Eventually we would like to replace Technology state with Device state. |
588 // For now, treat technology state changes as device list changes. | 648 // For now, treat technology state changes as device list changes. |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 } | 811 } |
752 | 812 |
753 if (type.MatchesType(shill::kTypeCellular)) | 813 if (type.MatchesType(shill::kTypeCellular)) |
754 return shill::kTypeCellular; | 814 return shill::kTypeCellular; |
755 | 815 |
756 NOTREACHED(); | 816 NOTREACHED(); |
757 return std::string(); | 817 return std::string(); |
758 } | 818 } |
759 | 819 |
760 } // namespace chromeos | 820 } // namespace chromeos |
OLD | NEW |