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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 } | 172 } |
173 | 173 |
174 const NetworkState* NetworkStateHandler::GetNetworkState( | 174 const NetworkState* NetworkStateHandler::GetNetworkState( |
175 const std::string& service_path) const { | 175 const std::string& service_path) const { |
176 const NetworkState* network = GetModifiableNetworkState(service_path); | 176 const NetworkState* network = GetModifiableNetworkState(service_path); |
177 if (network && !network->update_received()) | 177 if (network && !network->update_received()) |
178 return NULL; | 178 return NULL; |
179 return network; | 179 return network; |
180 } | 180 } |
181 | 181 |
182 const NetworkState* NetworkStateHandler::DefaultNetwork() const { | 182 const NetworkState* NetworkStateHandler::DefaultNetwork() const { |
pneubeck (no reviews)
2014/02/24 09:22:58
you dropped the check for IsConnectedState.
Consid
stevenjb
2014/02/24 23:59:42
So, this is kind of tricky. I want to keep the ret
| |
183 if (network_list_.empty()) | 183 return GetNetworkState(default_network_path_); |
pneubeck (no reviews)
2014/02/24 09:22:58
should early return on default_network_path_.empty
stevenjb
2014/02/24 23:59:42
Done.
| |
184 return NULL; | |
185 const NetworkState* network = network_list_.front()->AsNetworkState(); | |
186 DCHECK(network); | |
187 if (!network->update_received() || !network->IsConnectedState()) | |
188 return NULL; | |
189 return network; | |
190 } | 184 } |
191 | 185 |
192 const FavoriteState* NetworkStateHandler::DefaultFavoriteNetwork() const { | 186 const FavoriteState* NetworkStateHandler::DefaultFavoriteNetwork() const { |
193 const NetworkState* default_network = DefaultNetwork(); | 187 const NetworkState* default_network = DefaultNetwork(); |
194 if (!default_network) | 188 if (!default_network) |
195 return NULL; | 189 return NULL; |
196 const FavoriteState* default_favorite = | 190 const FavoriteState* default_favorite = |
197 GetFavoriteState(default_network->path()); | 191 GetFavoriteState(default_network->path()); |
198 DCHECK(default_favorite); | 192 DCHECK(default_favorite); |
199 DCHECK(default_favorite->update_received()); | 193 DCHECK(default_favorite->update_received()); |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
531 !iter.IsAtEnd(); iter.Advance()) { | 525 !iter.IsAtEnd(); iter.Advance()) { |
532 if (network->PropertyChanged(iter.key(), iter.value())) | 526 if (network->PropertyChanged(iter.key(), iter.value())) |
533 network_property_updated = true; | 527 network_property_updated = true; |
534 } | 528 } |
535 network_property_updated |= network->InitialPropertiesReceived(properties); | 529 network_property_updated |= network->InitialPropertiesReceived(properties); |
536 // Notify observers of NetworkState changes. | 530 // Notify observers of NetworkState changes. |
537 if (network_property_updated || network->update_requested()) { | 531 if (network_property_updated || network->update_requested()) { |
538 // Signal connection state changed after all properties have been updated. | 532 // Signal connection state changed after all properties have been updated. |
539 if (ConnectionStateChanged(network, prev_connection_state)) | 533 if (ConnectionStateChanged(network, prev_connection_state)) |
540 OnNetworkConnectionStateChanged(network); | 534 OnNetworkConnectionStateChanged(network); |
541 NetworkPropertiesUpdated(network); | 535 NET_LOG_EVENT("NetworkPropertiesUpdated", GetManagedStateLogName(network)); |
536 NotifyNetworkPropertiesUpdated(network); | |
542 } | 537 } |
543 } | 538 } |
544 | 539 |
545 void NetworkStateHandler::UpdateNetworkServiceProperty( | 540 void NetworkStateHandler::UpdateNetworkServiceProperty( |
546 const std::string& service_path, | 541 const std::string& service_path, |
547 const std::string& key, | 542 const std::string& key, |
548 const base::Value& value) { | 543 const base::Value& value) { |
549 // Update any associated FavoriteState. | 544 // Update any associated FavoriteState. |
550 ManagedState* favorite = | 545 ManagedState* favorite = |
551 GetModifiableManagedState(&favorite_list_, service_path); | 546 GetModifiableManagedState(&favorite_list_, service_path); |
(...skipping 21 matching lines...) Expand all Loading... | |
573 } else { | 568 } else { |
574 std::string value_str; | 569 std::string value_str; |
575 value.GetAsString(&value_str); | 570 value.GetAsString(&value_str); |
576 // Some property changes are noisy and not interesting: | 571 // Some property changes are noisy and not interesting: |
577 // * Wifi SignalStrength | 572 // * Wifi SignalStrength |
578 // * WifiFrequencyList updates | 573 // * WifiFrequencyList updates |
579 // * Device property changes to "/" (occurs before a service is removed) | 574 // * Device property changes to "/" (occurs before a service is removed) |
580 if (key != shill::kSignalStrengthProperty && | 575 if (key != shill::kSignalStrengthProperty && |
581 key != shill::kWifiFrequencyListProperty && | 576 key != shill::kWifiFrequencyListProperty && |
582 (key != shill::kDeviceProperty || value_str != "/")) { | 577 (key != shill::kDeviceProperty || value_str != "/")) { |
578 std::string log_event = "NetworkPropertyUpdated"; | |
583 // Trigger a default network update for interesting changes only. | 579 // Trigger a default network update for interesting changes only. |
584 if (network->path() == default_network_path_) | 580 if (network->path() == default_network_path_) { |
585 OnDefaultNetworkChanged(); | 581 NotifyDefaultNetworkChanged(network); |
586 // Log interesting event. | 582 log_event = "Default" + log_event; |
583 } | |
584 // Log event. | |
587 std::string detail = network->name() + "." + key; | 585 std::string detail = network->name() + "." + key; |
588 detail += " = " + network_event_log::ValueAsString(value); | 586 detail += " = " + network_event_log::ValueAsString(value); |
589 network_event_log::LogLevel log_level; | 587 network_event_log::LogLevel log_level; |
590 if (key == shill::kErrorProperty || key == shill::kErrorDetailsProperty) { | 588 if (key == shill::kErrorProperty || key == shill::kErrorDetailsProperty) { |
591 log_level = network_event_log::LOG_LEVEL_ERROR; | 589 log_level = network_event_log::LOG_LEVEL_ERROR; |
592 } else { | 590 } else { |
593 log_level = network_event_log::LOG_LEVEL_EVENT; | 591 log_level = network_event_log::LOG_LEVEL_EVENT; |
594 } | 592 } |
595 NET_LOG_LEVEL(log_level, "NetworkPropertyUpdated", detail); | 593 NET_LOG_LEVEL(log_level, log_event, detail); |
596 } | 594 } |
597 } | 595 } |
598 | 596 |
599 // All property updates signal 'NetworkPropertiesUpdated'. | 597 // All property updates signal 'NetworkPropertiesUpdated'. |
600 NetworkPropertiesUpdated(network); | 598 NotifyNetworkPropertiesUpdated(network); |
601 | 599 |
602 // If added to a Profile, request a full update so that a FavoriteState | 600 // If added to a Profile, request a full update so that a FavoriteState |
603 // gets created. | 601 // gets created. |
604 if (prev_profile_path.empty() && !network->profile_path().empty()) | 602 if (prev_profile_path.empty() && !network->profile_path().empty()) |
605 RequestUpdateForNetwork(service_path); | 603 RequestUpdateForNetwork(service_path); |
606 } | 604 } |
607 | 605 |
608 void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path, | 606 void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path, |
609 const std::string& key, | 607 const std::string& key, |
610 const base::Value& value) { | 608 const base::Value& value) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
650 } | 648 } |
651 | 649 |
652 void NetworkStateHandler::ManagedStateListChanged( | 650 void NetworkStateHandler::ManagedStateListChanged( |
653 ManagedState::ManagedType type) { | 651 ManagedState::ManagedType type) { |
654 if (type == ManagedState::MANAGED_TYPE_NETWORK) { | 652 if (type == ManagedState::MANAGED_TYPE_NETWORK) { |
655 // Notify observers that the list of networks has changed. | 653 // Notify observers that the list of networks has changed. |
656 NET_LOG_EVENT("NetworkListChanged", | 654 NET_LOG_EVENT("NetworkListChanged", |
657 base::StringPrintf("Size:%" PRIuS, network_list_.size())); | 655 base::StringPrintf("Size:%" PRIuS, network_list_.size())); |
658 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 656 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
659 NetworkListChanged()); | 657 NetworkListChanged()); |
660 // The list order may have changed, so check if the default network changed. | |
661 if (CheckDefaultNetworkChanged()) | |
662 OnDefaultNetworkChanged(); | |
663 // Update UMA stats. | 658 // Update UMA stats. |
664 UMA_HISTOGRAM_COUNTS_100("Networks.Visible", network_list_.size()); | 659 UMA_HISTOGRAM_COUNTS_100("Networks.Visible", network_list_.size()); |
665 } else if (type == ManagedState::MANAGED_TYPE_FAVORITE) { | 660 } else if (type == ManagedState::MANAGED_TYPE_FAVORITE) { |
666 NET_LOG_DEBUG("FavoriteListChanged", | 661 NET_LOG_DEBUG("FavoriteListChanged", |
667 base::StringPrintf("Size:%" PRIuS, favorite_list_.size())); | 662 base::StringPrintf("Size:%" PRIuS, favorite_list_.size())); |
668 // The FavoriteState list only changes when the NetworkState list changes, | 663 // The FavoriteState list only changes when the NetworkState list changes, |
669 // so no need to signal observers here again. | 664 // so no need to signal observers here again. |
670 | 665 |
671 // Update UMA stats. | 666 // Update UMA stats. |
672 size_t shared = 0, unshared = 0; | 667 size_t shared = 0, unshared = 0; |
673 for (ManagedStateList::iterator iter = favorite_list_.begin(); | 668 for (ManagedStateList::iterator iter = favorite_list_.begin(); |
674 iter != favorite_list_.end(); ++iter) { | 669 iter != favorite_list_.end(); ++iter) { |
675 FavoriteState* favorite = (*iter)->AsFavoriteState(); | 670 FavoriteState* favorite = (*iter)->AsFavoriteState(); |
676 if (!favorite->is_favorite()) | 671 if (!favorite->is_favorite()) |
677 continue; | 672 continue; |
678 if (favorite->IsPrivate()) | 673 if (favorite->IsPrivate()) |
679 ++unshared; | 674 ++unshared; |
680 else | 675 else |
681 ++shared; | 676 ++shared; |
682 } | 677 } |
683 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedShared", shared); | 678 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedShared", shared); |
684 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedUnshared", unshared); | 679 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedUnshared", unshared); |
685 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { | 680 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { |
686 NotifyDeviceListChanged(); | 681 NotifyDeviceListChanged(); |
687 } else { | 682 } else { |
688 NOTREACHED(); | 683 NOTREACHED(); |
689 } | 684 } |
690 } | 685 } |
691 | 686 |
687 void NetworkStateHandler::DefaultNetworkServiceChanged( | |
688 const std::string& service_path) { | |
689 default_network_path_ = service_path; | |
690 const NetworkState* network = DefaultNetwork(); | |
691 NET_LOG_EVENT("DefaultNetworkServiceChanged", | |
692 GetManagedStateLogName(network)); | |
693 NotifyDefaultNetworkChanged(network); | |
694 } | |
695 | |
692 //------------------------------------------------------------------------------ | 696 //------------------------------------------------------------------------------ |
693 // Private methods | 697 // Private methods |
694 | 698 |
695 void NetworkStateHandler::NotifyDeviceListChanged() { | 699 void NetworkStateHandler::NotifyDeviceListChanged() { |
696 NET_LOG_DEBUG("NotifyDeviceListChanged", | 700 NET_LOG_DEBUG("NotifyDeviceListChanged", |
697 base::StringPrintf("Size:%" PRIuS, device_list_.size())); | 701 base::StringPrintf("Size:%" PRIuS, device_list_.size())); |
698 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 702 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
699 DeviceListChanged()); | 703 DeviceListChanged()); |
700 } | 704 } |
701 | 705 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
738 case ManagedState::MANAGED_TYPE_DEVICE: | 742 case ManagedState::MANAGED_TYPE_DEVICE: |
739 return &device_list_; | 743 return &device_list_; |
740 } | 744 } |
741 NOTREACHED(); | 745 NOTREACHED(); |
742 return NULL; | 746 return NULL; |
743 } | 747 } |
744 | 748 |
745 void NetworkStateHandler::OnNetworkConnectionStateChanged( | 749 void NetworkStateHandler::OnNetworkConnectionStateChanged( |
746 NetworkState* network) { | 750 NetworkState* network) { |
747 DCHECK(network); | 751 DCHECK(network); |
748 NET_LOG_EVENT("NetworkConnectionStateChanged", base::StringPrintf( | 752 std::string event = "NetworkConnectionStateChanged"; |
749 "%s:%s", GetManagedStateLogName(network).c_str(), | 753 if (network->path() == default_network_path_) |
750 network->connection_state().c_str())); | 754 event = "Default" + event; |
755 NET_LOG_EVENT(event + ": " + network->connection_state(), | |
756 GetManagedStateLogName(network)); | |
pneubeck (no reviews)
2014/02/24 09:22:58
just an idea: you could also add "(default)" to th
stevenjb
2014/02/24 23:59:42
Interesting thought. I'm not sure I want to length
| |
751 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 757 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
752 NetworkConnectionStateChanged(network)); | 758 NetworkConnectionStateChanged(network)); |
753 if (CheckDefaultNetworkChanged() || network->path() == default_network_path_) | 759 if (network->path() == default_network_path_) |
754 OnDefaultNetworkChanged(); | 760 NotifyDefaultNetworkChanged(network); |
755 } | 761 } |
756 | 762 |
757 bool NetworkStateHandler::CheckDefaultNetworkChanged() { | 763 void NetworkStateHandler::NotifyDefaultNetworkChanged( |
758 std::string new_default_network_path; | 764 const NetworkState* default_network) { |
759 const NetworkState* new_default_network = DefaultNetwork(); | |
760 if (new_default_network) | |
761 new_default_network_path = new_default_network->path(); | |
762 if (new_default_network_path == default_network_path_) | |
763 return false; | |
764 default_network_path_ = new_default_network_path; | |
765 return true; | |
766 } | |
767 | |
768 void NetworkStateHandler::OnDefaultNetworkChanged() { | |
769 const NetworkState* default_network = DefaultNetwork(); | |
770 NET_LOG_EVENT("DefaultNetworkChanged", | |
771 GetManagedStateLogName(default_network)); | |
772 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 765 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
773 DefaultNetworkChanged(default_network)); | 766 DefaultNetworkChanged(default_network)); |
774 } | 767 } |
775 | 768 |
776 void NetworkStateHandler::NetworkPropertiesUpdated( | 769 void NetworkStateHandler::NotifyNetworkPropertiesUpdated( |
777 const NetworkState* network) { | 770 const NetworkState* network) { |
778 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 771 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
779 NetworkPropertiesUpdated(network)); | 772 NetworkPropertiesUpdated(network)); |
780 } | 773 } |
781 | 774 |
782 void NetworkStateHandler::ScanCompleted(const std::string& type) { | 775 void NetworkStateHandler::ScanCompleted(const std::string& type) { |
783 size_t num_callbacks = scan_complete_callbacks_.count(type); | 776 size_t num_callbacks = scan_complete_callbacks_.count(type); |
784 NET_LOG_EVENT("ScanCompleted", | 777 NET_LOG_EVENT("ScanCompleted", |
785 base::StringPrintf("%s:%" PRIuS, type.c_str(), num_callbacks)); | 778 base::StringPrintf("%s:%" PRIuS, type.c_str(), num_callbacks)); |
786 if (num_callbacks == 0) | 779 if (num_callbacks == 0) |
(...skipping 24 matching lines...) Expand all Loading... | |
811 } | 804 } |
812 | 805 |
813 if (type.MatchesType(shill::kTypeCellular)) | 806 if (type.MatchesType(shill::kTypeCellular)) |
814 return shill::kTypeCellular; | 807 return shill::kTypeCellular; |
815 | 808 |
816 NOTREACHED(); | 809 NOTREACHED(); |
817 return std::string(); | 810 return std::string(); |
818 } | 811 } |
819 | 812 |
820 } // namespace chromeos | 813 } // namespace chromeos |
OLD | NEW |