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 "net/base/network_change_notifier.h" | 5 #include "net/base/network_change_notifier.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 | 535 |
536 // static | 536 // static |
537 NetworkChangeNotifier::ConnectionType | 537 NetworkChangeNotifier::ConnectionType |
538 NetworkChangeNotifier::GetConnectionType() { | 538 NetworkChangeNotifier::GetConnectionType() { |
539 return g_network_change_notifier ? | 539 return g_network_change_notifier ? |
540 g_network_change_notifier->GetCurrentConnectionType() : | 540 g_network_change_notifier->GetCurrentConnectionType() : |
541 CONNECTION_UNKNOWN; | 541 CONNECTION_UNKNOWN; |
542 } | 542 } |
543 | 543 |
544 // static | 544 // static |
545 double NetworkChangeNotifier::GetMaxBandwidth() { | 545 void NetworkChangeNotifier::GetMaxBandwidthAndConnectionType( |
546 return g_network_change_notifier ? | 546 double* max_bandwidth_mbps, |
547 g_network_change_notifier->GetCurrentMaxBandwidth() : | 547 ConnectionType* connection_type) { |
548 std::numeric_limits<double>::infinity(); | 548 if (!g_network_change_notifier) { |
| 549 *connection_type = CONNECTION_UNKNOWN; |
| 550 *max_bandwidth_mbps = GetMaxBandwidthForConnectionSubtype(SUBTYPE_UNKNOWN); |
| 551 return; |
| 552 } |
| 553 |
| 554 g_network_change_notifier->GetCurrentMaxBandwidthAndConnectionType( |
| 555 max_bandwidth_mbps, connection_type); |
549 } | 556 } |
550 | 557 |
551 // static | 558 // static |
552 void NetworkChangeNotifier::GetDnsConfig(DnsConfig* config) { | 559 void NetworkChangeNotifier::GetDnsConfig(DnsConfig* config) { |
553 if (!g_network_change_notifier) { | 560 if (!g_network_change_notifier) { |
554 *config = DnsConfig(); | 561 *config = DnsConfig(); |
555 } else { | 562 } else { |
556 g_network_change_notifier->network_state_->GetDnsConfig(config); | 563 g_network_change_notifier->network_state_->GetDnsConfig(config); |
557 } | 564 } |
558 } | 565 } |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 g_network_change_notifier->NotifyObserversOfNetworkChangeImpl(type); | 792 g_network_change_notifier->NotifyObserversOfNetworkChangeImpl(type); |
786 } | 793 } |
787 | 794 |
788 // static | 795 // static |
789 void NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigReadForTests() { | 796 void NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigReadForTests() { |
790 if (g_network_change_notifier) | 797 if (g_network_change_notifier) |
791 g_network_change_notifier->NotifyObserversOfInitialDNSConfigReadImpl(); | 798 g_network_change_notifier->NotifyObserversOfInitialDNSConfigReadImpl(); |
792 } | 799 } |
793 | 800 |
794 // static | 801 // static |
| 802 void NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChangeForTests( |
| 803 double max_bandwidth_mbps, |
| 804 ConnectionType type) { |
| 805 if (g_network_change_notifier) { |
| 806 g_network_change_notifier->NotifyObserversOfMaxBandwidthChangeImpl( |
| 807 max_bandwidth_mbps, type); |
| 808 } |
| 809 } |
| 810 |
| 811 // static |
795 void NetworkChangeNotifier::SetTestNotificationsOnly(bool test_only) { | 812 void NetworkChangeNotifier::SetTestNotificationsOnly(bool test_only) { |
796 DCHECK(!g_network_change_notifier); | 813 DCHECK(!g_network_change_notifier); |
797 NetworkChangeNotifier::test_notifications_only_ = test_only; | 814 NetworkChangeNotifier::test_notifications_only_ = test_only; |
798 } | 815 } |
799 | 816 |
800 NetworkChangeNotifier::NetworkChangeNotifier( | 817 NetworkChangeNotifier::NetworkChangeNotifier( |
801 const NetworkChangeCalculatorParams& params | 818 const NetworkChangeCalculatorParams& params |
802 /*= NetworkChangeCalculatorParams()*/) | 819 /*= NetworkChangeCalculatorParams()*/) |
803 : ip_address_observer_list_( | 820 : ip_address_observer_list_( |
804 new base::ObserverListThreadSafe<IPAddressObserver>( | 821 new base::ObserverListThreadSafe<IPAddressObserver>( |
(...skipping 18 matching lines...) Expand all Loading... |
823 network_change_calculator_->Init(); | 840 network_change_calculator_->Init(); |
824 } | 841 } |
825 | 842 |
826 #if defined(OS_LINUX) | 843 #if defined(OS_LINUX) |
827 const internal::AddressTrackerLinux* | 844 const internal::AddressTrackerLinux* |
828 NetworkChangeNotifier::GetAddressTrackerInternal() const { | 845 NetworkChangeNotifier::GetAddressTrackerInternal() const { |
829 return NULL; | 846 return NULL; |
830 } | 847 } |
831 #endif | 848 #endif |
832 | 849 |
833 double NetworkChangeNotifier::GetCurrentMaxBandwidth() const { | 850 void NetworkChangeNotifier::GetCurrentMaxBandwidthAndConnectionType( |
| 851 double* max_bandwidth_mbps, |
| 852 ConnectionType* connection_type) const { |
834 // This default implementation conforms to the NetInfo V3 specification but | 853 // This default implementation conforms to the NetInfo V3 specification but |
835 // should be overridden to provide specific bandwidth data based on the | 854 // should be overridden to provide specific bandwidth data based on the |
836 // platform. | 855 // platform. |
837 if (GetCurrentConnectionType() == CONNECTION_NONE) | 856 *connection_type = GetCurrentConnectionType(); |
838 return 0.0; | 857 *max_bandwidth_mbps = |
839 return std::numeric_limits<double>::infinity(); | 858 *connection_type == CONNECTION_NONE |
| 859 ? GetMaxBandwidthForConnectionSubtype(SUBTYPE_NONE) |
| 860 : GetMaxBandwidthForConnectionSubtype(SUBTYPE_UNKNOWN); |
840 } | 861 } |
841 | 862 |
842 // static | 863 // static |
843 double NetworkChangeNotifier::GetMaxBandwidthForConnectionSubtype( | 864 double NetworkChangeNotifier::GetMaxBandwidthForConnectionSubtype( |
844 ConnectionSubtype subtype) { | 865 ConnectionSubtype subtype) { |
845 switch (subtype) { | 866 switch (subtype) { |
846 case SUBTYPE_GSM: | 867 case SUBTYPE_GSM: |
847 return 0.01; | 868 return 0.01; |
848 case SUBTYPE_IDEN: | 869 case SUBTYPE_IDEN: |
849 return 0.064; | 870 return 0.064; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 void NetworkChangeNotifier::NotifyObserversOfNetworkChange( | 956 void NetworkChangeNotifier::NotifyObserversOfNetworkChange( |
936 ConnectionType type) { | 957 ConnectionType type) { |
937 if (g_network_change_notifier && | 958 if (g_network_change_notifier && |
938 !NetworkChangeNotifier::test_notifications_only_) { | 959 !NetworkChangeNotifier::test_notifications_only_) { |
939 g_network_change_notifier->NotifyObserversOfNetworkChangeImpl(type); | 960 g_network_change_notifier->NotifyObserversOfNetworkChangeImpl(type); |
940 } | 961 } |
941 } | 962 } |
942 | 963 |
943 // static | 964 // static |
944 void NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChange( | 965 void NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChange( |
945 double max_bandwidth_mbps) { | 966 double max_bandwidth_mbps, |
| 967 ConnectionType type) { |
946 if (g_network_change_notifier && | 968 if (g_network_change_notifier && |
947 !NetworkChangeNotifier::test_notifications_only_) { | 969 !NetworkChangeNotifier::test_notifications_only_) { |
948 g_network_change_notifier->NotifyObserversOfMaxBandwidthChangeImpl( | 970 g_network_change_notifier->NotifyObserversOfMaxBandwidthChangeImpl( |
949 max_bandwidth_mbps); | 971 max_bandwidth_mbps, type); |
950 } | 972 } |
951 } | 973 } |
952 | 974 |
953 // static | 975 // static |
954 void NetworkChangeNotifier::NotifyObserversOfDNSChange() { | 976 void NetworkChangeNotifier::NotifyObserversOfDNSChange() { |
955 if (g_network_change_notifier && | 977 if (g_network_change_notifier && |
956 !NetworkChangeNotifier::test_notifications_only_) { | 978 !NetworkChangeNotifier::test_notifications_only_) { |
957 g_network_change_notifier->NotifyObserversOfDNSChangeImpl(); | 979 g_network_change_notifier->NotifyObserversOfDNSChangeImpl(); |
958 } | 980 } |
959 } | 981 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1008 void NetworkChangeNotifier::NotifyObserversOfDNSChangeImpl() { | 1030 void NetworkChangeNotifier::NotifyObserversOfDNSChangeImpl() { |
1009 resolver_state_observer_list_->Notify(FROM_HERE, &DNSObserver::OnDNSChanged); | 1031 resolver_state_observer_list_->Notify(FROM_HERE, &DNSObserver::OnDNSChanged); |
1010 } | 1032 } |
1011 | 1033 |
1012 void NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigReadImpl() { | 1034 void NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigReadImpl() { |
1013 resolver_state_observer_list_->Notify(FROM_HERE, | 1035 resolver_state_observer_list_->Notify(FROM_HERE, |
1014 &DNSObserver::OnInitialDNSConfigRead); | 1036 &DNSObserver::OnInitialDNSConfigRead); |
1015 } | 1037 } |
1016 | 1038 |
1017 void NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChangeImpl( | 1039 void NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChangeImpl( |
1018 double max_bandwidth_mbps) { | 1040 double max_bandwidth_mbps, |
| 1041 ConnectionType type) { |
1019 max_bandwidth_observer_list_->Notify( | 1042 max_bandwidth_observer_list_->Notify( |
1020 FROM_HERE, &MaxBandwidthObserver::OnMaxBandwidthChanged, | 1043 FROM_HERE, &MaxBandwidthObserver::OnMaxBandwidthChanged, |
1021 max_bandwidth_mbps); | 1044 max_bandwidth_mbps, type); |
1022 } | 1045 } |
1023 | 1046 |
1024 NetworkChangeNotifier::DisableForTest::DisableForTest() | 1047 NetworkChangeNotifier::DisableForTest::DisableForTest() |
1025 : network_change_notifier_(g_network_change_notifier) { | 1048 : network_change_notifier_(g_network_change_notifier) { |
1026 DCHECK(g_network_change_notifier); | 1049 DCHECK(g_network_change_notifier); |
1027 g_network_change_notifier = NULL; | 1050 g_network_change_notifier = NULL; |
1028 } | 1051 } |
1029 | 1052 |
1030 NetworkChangeNotifier::DisableForTest::~DisableForTest() { | 1053 NetworkChangeNotifier::DisableForTest::~DisableForTest() { |
1031 DCHECK(!g_network_change_notifier); | 1054 DCHECK(!g_network_change_notifier); |
1032 g_network_change_notifier = network_change_notifier_; | 1055 g_network_change_notifier = network_change_notifier_; |
1033 } | 1056 } |
1034 | 1057 |
1035 void NetworkChangeNotifier::DNSObserver::OnInitialDNSConfigRead() { | 1058 void NetworkChangeNotifier::DNSObserver::OnInitialDNSConfigRead() { |
1036 } | 1059 } |
1037 | 1060 |
1038 } // namespace net | 1061 } // namespace net |
OLD | NEW |