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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
264 } | 264 } |
265 | 265 |
266 void NetworkStateHandler::GetNetworkListByType(const NetworkTypePattern& type, | 266 void NetworkStateHandler::GetNetworkListByType(const NetworkTypePattern& type, |
267 NetworkStateList* list) const { | 267 NetworkStateList* list) const { |
268 DCHECK(list); | 268 DCHECK(list); |
269 list->clear(); | 269 list->clear(); |
270 for (ManagedStateList::const_iterator iter = network_list_.begin(); | 270 for (ManagedStateList::const_iterator iter = network_list_.begin(); |
271 iter != network_list_.end(); ++iter) { | 271 iter != network_list_.end(); ++iter) { |
272 const NetworkState* network = (*iter)->AsNetworkState(); | 272 const NetworkState* network = (*iter)->AsNetworkState(); |
273 DCHECK(network); | 273 DCHECK(network); |
274 if (!network->update_received()) | 274 if (network->update_received() && network->Matches(type)) |
275 continue; | |
276 if (network->Matches(type)) | |
277 list->push_back(network); | 275 list->push_back(network); |
278 } | 276 } |
279 } | 277 } |
280 | 278 |
281 void NetworkStateHandler::GetDeviceList(DeviceStateList* list) const { | 279 void NetworkStateHandler::GetDeviceList(DeviceStateList* list) const { |
282 DCHECK(list); | 280 DCHECK(list); |
283 list->clear(); | 281 list->clear(); |
284 for (ManagedStateList::const_iterator iter = device_list_.begin(); | 282 for (ManagedStateList::const_iterator iter = device_list_.begin(); |
285 iter != device_list_.end(); ++iter) { | 283 iter != device_list_.end(); ++iter) { |
286 const DeviceState* device = (*iter)->AsDeviceState(); | 284 const DeviceState* device = (*iter)->AsDeviceState(); |
287 DCHECK(device); | 285 DCHECK(device); |
288 if (!device->update_received()) | 286 if (device->update_received()) |
289 continue; | 287 list->push_back(device); |
290 list->push_back(device); | |
291 } | 288 } |
292 } | 289 } |
293 | 290 |
294 void NetworkStateHandler::GetFavoriteList(FavoriteStateList* list) const { | 291 void NetworkStateHandler::GetFavoriteList(FavoriteStateList* list) const { |
292 GetFavoriteListByType(NetworkTypePattern::Default(), list); | |
293 } | |
294 | |
295 void NetworkStateHandler::GetFavoriteListByType(const NetworkTypePattern& type, | |
296 FavoriteStateList* list) const { | |
295 DCHECK(list); | 297 DCHECK(list); |
296 FavoriteStateList result; | 298 FavoriteStateList result; |
297 list->clear(); | 299 list->clear(); |
298 for (ManagedStateList::const_iterator iter = favorite_list_.begin(); | 300 for (ManagedStateList::const_iterator iter = favorite_list_.begin(); |
299 iter != favorite_list_.end(); ++iter) { | 301 iter != favorite_list_.end(); ++iter) { |
300 const FavoriteState* favorite = (*iter)->AsFavoriteState(); | 302 const FavoriteState* favorite = (*iter)->AsFavoriteState(); |
301 DCHECK(favorite); | 303 DCHECK(favorite); |
302 if (!favorite->update_received()) | 304 if (favorite->update_received() && favorite->is_favorite() && |
303 continue; | 305 favorite->Matches(type)) { |
304 if (favorite->is_favorite()) | |
305 list->push_back(favorite); | 306 list->push_back(favorite); |
307 } | |
306 } | 308 } |
307 } | 309 } |
308 | 310 |
309 const FavoriteState* NetworkStateHandler::GetFavoriteState( | 311 const FavoriteState* NetworkStateHandler::GetFavoriteState( |
310 const std::string& service_path) const { | 312 const std::string& service_path) const { |
311 ManagedState* managed = | 313 ManagedState* managed = |
312 GetModifiableManagedState(&favorite_list_, service_path); | 314 GetModifiableManagedState(&favorite_list_, service_path); |
313 if (!managed) | 315 if (!managed) |
314 return NULL; | 316 return NULL; |
315 DCHECK(managed->update_received()); | 317 DCHECK(managed->update_received()); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
355 ManagedState::MANAGED_TYPE_NETWORK, network->path()); | 357 ManagedState::MANAGED_TYPE_NETWORK, network->path()); |
356 } | 358 } |
357 } | 359 } |
358 | 360 |
359 void NetworkStateHandler::SetCheckPortalList( | 361 void NetworkStateHandler::SetCheckPortalList( |
360 const std::string& check_portal_list) { | 362 const std::string& check_portal_list) { |
361 NET_LOG_EVENT("SetCheckPortalList", check_portal_list); | 363 NET_LOG_EVENT("SetCheckPortalList", check_portal_list); |
362 shill_property_handler_->SetCheckPortalList(check_portal_list); | 364 shill_property_handler_->SetCheckPortalList(check_portal_list); |
363 } | 365 } |
364 | 366 |
367 const FavoriteState* NetworkStateHandler::GetEAPForEthernet( | |
368 const std::string& service_path) const { | |
369 const NetworkState* network = GetNetworkState(service_path); | |
370 if (!network) { | |
371 NET_LOG_ERROR( | |
372 "GetEAPForEthernet", | |
373 base::StringPrintf("Unknown service path %s", service_path.c_str())); | |
stevenjb
2013/09/17 16:22:59
nit: + instead of StringPrintf ("foo" + bar where
pneubeck (no reviews)
2013/09/30 20:08:31
Done.
| |
374 return NULL; | |
375 } | |
376 if (network->type() != flimflam::kTypeEthernet || | |
377 !network->IsConnectedState()) { | |
378 return NULL; | |
379 } | |
380 | |
381 // The same EAP service is shared for all ethernet services/devices. | |
382 // However EAP is used/enabled per device and only if the connection was | |
383 // successfully established. | |
384 const DeviceState* device = GetDeviceState(network->device_path()); | |
385 if (!device) { | |
386 NET_LOG_ERROR( | |
387 "GetEAPForEthernet", | |
388 base::StringPrintf("Unknown device %s of connected ethernet service %s", | |
389 service_path.c_str(), | |
390 network->device_path().c_str())); | |
391 return NULL; | |
392 } | |
393 if (!device->eap_authentication_completed()) | |
394 return NULL; | |
395 | |
396 FavoriteStateList list; | |
397 GetFavoriteListByType(NetworkTypePattern::Primitive(shill::kTypeEthernetEap), | |
398 &list); | |
399 if (list.empty()) { | |
400 NET_LOG_ERROR("GetEAPForEthernet", | |
401 base::StringPrintf( | |
402 "Ethernet service %s connected using EAP, but no " | |
403 "EAP service found.", | |
404 service_path.c_str())); | |
405 return NULL; | |
406 } | |
407 DCHECK(list.size() == 1); | |
408 return list.front(); | |
409 } | |
410 | |
365 void NetworkStateHandler::GetNetworkStatePropertiesForTest( | 411 void NetworkStateHandler::GetNetworkStatePropertiesForTest( |
366 base::DictionaryValue* dictionary) const { | 412 base::DictionaryValue* dictionary) const { |
367 for (ManagedStateList::const_iterator iter = network_list_.begin(); | 413 for (ManagedStateList::const_iterator iter = network_list_.begin(); |
368 iter != network_list_.end(); ++iter) { | 414 iter != network_list_.end(); ++iter) { |
369 base::DictionaryValue* network_dict = new base::DictionaryValue; | 415 base::DictionaryValue* network_dict = new base::DictionaryValue; |
370 (*iter)->AsNetworkState()->GetProperties(network_dict); | 416 (*iter)->AsNetworkState()->GetProperties(network_dict); |
371 dictionary->SetWithoutPathExpansion((*iter)->path(), network_dict); | 417 dictionary->SetWithoutPathExpansion((*iter)->path(), network_dict); |
372 } | 418 } |
373 } | 419 } |
374 | 420 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
555 | 601 |
556 std::string detail = device->name() + "." + key; | 602 std::string detail = device->name() + "." + key; |
557 detail += " = " + network_event_log::ValueAsString(value); | 603 detail += " = " + network_event_log::ValueAsString(value); |
558 NET_LOG_EVENT("DevicePropertyUpdated", detail); | 604 NET_LOG_EVENT("DevicePropertyUpdated", detail); |
559 | 605 |
560 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 606 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
561 DeviceListChanged()); | 607 DeviceListChanged()); |
562 | 608 |
563 if (key == flimflam::kScanningProperty && device->scanning() == false) | 609 if (key == flimflam::kScanningProperty && device->scanning() == false) |
564 ScanCompleted(device->type()); | 610 ScanCompleted(device->type()); |
611 if (key == shill::kEapAuthenticationCompletedProperty) { | |
612 // Notify a change for each Ethernet service using this device. | |
613 NetworkStateList ethernet_services; | |
614 GetNetworkListByType(NetworkTypePattern::Ethernet(), ðernet_services); | |
615 for (NetworkStateList::const_iterator it = ethernet_services.begin(); | |
616 it != ethernet_services.end(); ++it) { | |
617 const NetworkState* ethernet_service = *it; | |
618 if (ethernet_service->update_received() || | |
619 ethernet_service->device_path() != device->path()) { | |
620 continue; | |
621 } | |
622 if (ethernet_service->path() == default_network_path_) | |
623 OnDefaultNetworkChanged(); | |
624 NetworkPropertiesUpdated(ethernet_service); | |
625 } | |
626 } | |
565 } | 627 } |
566 | 628 |
567 void NetworkStateHandler::CheckPortalListChanged( | 629 void NetworkStateHandler::CheckPortalListChanged( |
568 const std::string& check_portal_list) { | 630 const std::string& check_portal_list) { |
569 check_portal_list_ = check_portal_list; | 631 check_portal_list_ = check_portal_list; |
570 } | 632 } |
571 | 633 |
572 void NetworkStateHandler::NotifyManagerPropertyChanged() { | 634 void NetworkStateHandler::NotifyManagerPropertyChanged() { |
573 NET_LOG_DEBUG("NotifyManagerPropertyChanged", ""); | 635 NET_LOG_DEBUG("NotifyManagerPropertyChanged", ""); |
574 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 636 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
733 } | 795 } |
734 | 796 |
735 if (type.MatchesType(flimflam::kTypeCellular)) | 797 if (type.MatchesType(flimflam::kTypeCellular)) |
736 return flimflam::kTypeCellular; | 798 return flimflam::kTypeCellular; |
737 | 799 |
738 NOTREACHED(); | 800 NOTREACHED(); |
739 return std::string(); | 801 return std::string(); |
740 } | 802 } |
741 | 803 |
742 } // namespace chromeos | 804 } // namespace chromeos |
OLD | NEW |