| 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/logging.h" | 10 #include "base/logging.h" |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 | 297 |
| 298 void NetworkStateHandler::GetFavoriteListByType(const NetworkTypePattern& type, | 298 void NetworkStateHandler::GetFavoriteListByType(const NetworkTypePattern& type, |
| 299 FavoriteStateList* list) const { | 299 FavoriteStateList* list) const { |
| 300 DCHECK(list); | 300 DCHECK(list); |
| 301 FavoriteStateList result; | 301 FavoriteStateList result; |
| 302 list->clear(); | 302 list->clear(); |
| 303 for (ManagedStateList::const_iterator iter = favorite_list_.begin(); | 303 for (ManagedStateList::const_iterator iter = favorite_list_.begin(); |
| 304 iter != favorite_list_.end(); ++iter) { | 304 iter != favorite_list_.end(); ++iter) { |
| 305 const FavoriteState* favorite = (*iter)->AsFavoriteState(); | 305 const FavoriteState* favorite = (*iter)->AsFavoriteState(); |
| 306 DCHECK(favorite); | 306 DCHECK(favorite); |
| 307 if (favorite->update_received() && favorite->is_favorite() && | 307 if (favorite->update_received() && favorite->IsFavorite() && |
| 308 favorite->Matches(type)) { | 308 favorite->Matches(type)) { |
| 309 list->push_back(favorite); | 309 list->push_back(favorite); |
| 310 } | 310 } |
| 311 } | 311 } |
| 312 } | 312 } |
| 313 | 313 |
| 314 const FavoriteState* NetworkStateHandler::GetFavoriteState( | 314 const FavoriteState* NetworkStateHandler::GetFavoriteState( |
| 315 const std::string& service_path) const { | 315 const std::string& service_path) const { |
| 316 ManagedState* managed = | 316 ManagedState* managed = |
| 317 GetModifiableManagedState(&favorite_list_, service_path); | 317 GetModifiableManagedState(&favorite_list_, service_path); |
| 318 if (!managed) | 318 if (!managed) |
| 319 return NULL; | 319 return NULL; |
| 320 const FavoriteState* favorite = managed->AsFavoriteState(); | 320 const FavoriteState* favorite = managed->AsFavoriteState(); |
| 321 DCHECK(favorite); | 321 DCHECK(favorite); |
| 322 if (!favorite->update_received() || !favorite->is_favorite()) | 322 if (!favorite->update_received() || !favorite->IsFavorite()) |
| 323 return NULL; | 323 return NULL; |
| 324 return favorite; | 324 return favorite; |
| 325 } | 325 } |
| 326 | 326 |
| 327 void NetworkStateHandler::RequestScan() const { | 327 void NetworkStateHandler::RequestScan() const { |
| 328 NET_LOG_USER("RequestScan", ""); | 328 NET_LOG_USER("RequestScan", ""); |
| 329 shill_property_handler_->RequestScan(); | 329 shill_property_handler_->RequestScan(); |
| 330 } | 330 } |
| 331 | 331 |
| 332 void NetworkStateHandler::WaitForScan(const std::string& type, | 332 void NetworkStateHandler::WaitForScan(const std::string& type, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 346 void NetworkStateHandler::RequestUpdateForNetwork( | 346 void NetworkStateHandler::RequestUpdateForNetwork( |
| 347 const std::string& service_path) { | 347 const std::string& service_path) { |
| 348 NetworkState* network = GetModifiableNetworkState(service_path); | 348 NetworkState* network = GetModifiableNetworkState(service_path); |
| 349 if (network) | 349 if (network) |
| 350 network->set_update_requested(true); | 350 network->set_update_requested(true); |
| 351 NET_LOG_EVENT("RequestUpdate", service_path); | 351 NET_LOG_EVENT("RequestUpdate", service_path); |
| 352 shill_property_handler_->RequestProperties( | 352 shill_property_handler_->RequestProperties( |
| 353 ManagedState::MANAGED_TYPE_NETWORK, service_path); | 353 ManagedState::MANAGED_TYPE_NETWORK, service_path); |
| 354 } | 354 } |
| 355 | 355 |
| 356 void NetworkStateHandler::RequestUpdateForAllNetworks() { | |
| 357 NET_LOG_EVENT("RequestUpdateForAllNetworks", ""); | |
| 358 for (ManagedStateList::iterator iter = network_list_.begin(); | |
| 359 iter != network_list_.end(); ++iter) { | |
| 360 ManagedState* network = *iter; | |
| 361 network->set_update_requested(true); | |
| 362 shill_property_handler_->RequestProperties( | |
| 363 ManagedState::MANAGED_TYPE_NETWORK, network->path()); | |
| 364 } | |
| 365 } | |
| 366 | |
| 367 void NetworkStateHandler::ClearLastErrorForNetwork( | 356 void NetworkStateHandler::ClearLastErrorForNetwork( |
| 368 const std::string& service_path) { | 357 const std::string& service_path) { |
| 369 NetworkState* network = GetModifiableNetworkState(service_path); | 358 NetworkState* network = GetModifiableNetworkState(service_path); |
| 370 if (network) | 359 if (network) |
| 371 network->clear_last_error(); | 360 network->clear_last_error(); |
| 372 } | 361 } |
| 373 | 362 |
| 374 void NetworkStateHandler::SetCheckPortalList( | 363 void NetworkStateHandler::SetCheckPortalList( |
| 375 const std::string& check_portal_list) { | 364 const std::string& check_portal_list) { |
| 376 NET_LOG_EVENT("SetCheckPortalList", check_portal_list); | 365 NET_LOG_EVENT("SetCheckPortalList", check_portal_list); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 managed_map.erase(found); | 465 managed_map.erase(found); |
| 477 } | 466 } |
| 478 list_entries.insert(path); | 467 list_entries.insert(path); |
| 479 } | 468 } |
| 480 // Delete any remaining entries in managed_map. | 469 // Delete any remaining entries in managed_map. |
| 481 STLDeleteContainerPairSecondPointers(managed_map.begin(), managed_map.end()); | 470 STLDeleteContainerPairSecondPointers(managed_map.begin(), managed_map.end()); |
| 482 } | 471 } |
| 483 | 472 |
| 484 void NetworkStateHandler::ProfileListChanged() { | 473 void NetworkStateHandler::ProfileListChanged() { |
| 485 NET_LOG_EVENT("ProfileListChanged", "Re-Requesting Network Properties"); | 474 NET_LOG_EVENT("ProfileListChanged", "Re-Requesting Network Properties"); |
| 486 for (ManagedStateList::iterator iter = network_list_.begin(); | 475 for (ManagedStateList::iterator iter = favorite_list_.begin(); |
| 487 iter != network_list_.end(); ++iter) { | 476 iter != favorite_list_.end(); ++iter) { |
| 488 shill_property_handler_->RequestProperties( | 477 shill_property_handler_->RequestProperties( |
| 489 ManagedState::MANAGED_TYPE_NETWORK, (*iter)->path()); | 478 ManagedState::MANAGED_TYPE_NETWORK, (*iter)->path()); |
| 490 } | 479 } |
| 491 } | 480 } |
| 492 | 481 |
| 493 void NetworkStateHandler::UpdateManagedStateProperties( | 482 void NetworkStateHandler::UpdateManagedStateProperties( |
| 494 ManagedState::ManagedType type, | 483 ManagedState::ManagedType type, |
| 495 const std::string& path, | 484 const std::string& path, |
| 496 const base::DictionaryValue& properties) { | 485 const base::DictionaryValue& properties) { |
| 497 ManagedStateList* managed_list = GetManagedList(type); | 486 ManagedStateList* managed_list = GetManagedList(type); |
| 498 ManagedState* managed = GetModifiableManagedState(managed_list, path); | 487 ManagedState* managed = GetModifiableManagedState(managed_list, path); |
| 499 if (!managed) { | 488 if (!managed) { |
| 500 if (type != ManagedState::MANAGED_TYPE_FAVORITE) { | 489 if (type != ManagedState::MANAGED_TYPE_FAVORITE) { |
| 501 // The network has been removed from the list of visible networks. | 490 // The network has been removed from the list of visible networks. |
| 502 NET_LOG_DEBUG("UpdateManagedStateProperties: Not found", path); | 491 NET_LOG_DEBUG("UpdateManagedStateProperties: Not found", path); |
| 503 return; | 492 return; |
| 504 } | 493 } |
| 505 // A Favorite may not have been created yet if it was added later (e.g. | 494 // A Favorite may not have been created yet if it was added later (e.g. |
| 506 // through ConfigureService) since ServiceCompleteList updates are not | 495 // through ConfigureService) since ServiceCompleteList updates are not |
| 507 // emitted. Add and update the state here. | 496 // emitted. Add and update the state here. |
| 508 managed = new FavoriteState(path); | 497 managed = new FavoriteState(path); |
| 509 managed_list->push_back(managed); | 498 managed_list->push_back(managed); |
| 510 } | 499 } |
| 511 managed->set_update_received(); | 500 managed->set_update_received(); |
| 512 | 501 |
| 513 std::string desc = GetManagedStateLogType(managed) + " PropertiesReceived"; | 502 std::string desc = GetManagedStateLogType(managed) + " Properties Received"; |
| 514 NET_LOG_DEBUG(desc, GetManagedStateLogName(managed)); | 503 NET_LOG_DEBUG(desc, GetManagedStateLogName(managed)); |
| 515 | 504 |
| 516 if (type == ManagedState::MANAGED_TYPE_NETWORK) { | 505 if (type == ManagedState::MANAGED_TYPE_NETWORK) { |
| 517 UpdateNetworkStateProperties(managed->AsNetworkState(), properties); | 506 UpdateNetworkStateProperties(managed->AsNetworkState(), properties); |
| 518 } else { | 507 } else { |
| 519 // Device, Favorite | 508 // Device, Favorite |
| 520 for (base::DictionaryValue::Iterator iter(properties); | 509 for (base::DictionaryValue::Iterator iter(properties); |
| 521 !iter.IsAtEnd(); iter.Advance()) { | 510 !iter.IsAtEnd(); iter.Advance()) { |
| 522 managed->PropertyChanged(iter.key(), iter.value()); | 511 managed->PropertyChanged(iter.key(), iter.value()); |
| 523 } | 512 } |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 NET_LOG_DEBUG("FavoriteListChanged", | 661 NET_LOG_DEBUG("FavoriteListChanged", |
| 673 base::StringPrintf("Size:%" PRIuS, favorite_list_.size())); | 662 base::StringPrintf("Size:%" PRIuS, favorite_list_.size())); |
| 674 // The FavoriteState list only changes when the NetworkState list changes, | 663 // The FavoriteState list only changes when the NetworkState list changes, |
| 675 // so no need to signal observers here again. | 664 // so no need to signal observers here again. |
| 676 | 665 |
| 677 // Update UMA stats. | 666 // Update UMA stats. |
| 678 size_t shared = 0, unshared = 0; | 667 size_t shared = 0, unshared = 0; |
| 679 for (ManagedStateList::iterator iter = favorite_list_.begin(); | 668 for (ManagedStateList::iterator iter = favorite_list_.begin(); |
| 680 iter != favorite_list_.end(); ++iter) { | 669 iter != favorite_list_.end(); ++iter) { |
| 681 FavoriteState* favorite = (*iter)->AsFavoriteState(); | 670 FavoriteState* favorite = (*iter)->AsFavoriteState(); |
| 682 if (!favorite->is_favorite()) | 671 if (!favorite->IsFavorite()) |
| 683 continue; | 672 continue; |
| 684 if (favorite->IsPrivate()) | 673 if (favorite->IsPrivate()) |
| 685 ++unshared; | 674 ++unshared; |
| 686 else | 675 else |
| 687 ++shared; | 676 ++shared; |
| 688 } | 677 } |
| 689 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedShared", shared); | 678 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedShared", shared); |
| 690 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedUnshared", unshared); | 679 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedUnshared", unshared); |
| 691 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { | 680 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { |
| 692 NotifyDeviceListChanged(); | 681 NotifyDeviceListChanged(); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 840 } | 829 } |
| 841 | 830 |
| 842 if (type.MatchesType(shill::kTypeCellular)) | 831 if (type.MatchesType(shill::kTypeCellular)) |
| 843 return shill::kTypeCellular; | 832 return shill::kTypeCellular; |
| 844 | 833 |
| 845 NOTREACHED(); | 834 NOTREACHED(); |
| 846 return std::string(); | 835 return std::string(); |
| 847 } | 836 } |
| 848 | 837 |
| 849 } // namespace chromeos | 838 } // namespace chromeos |
| OLD | NEW |