Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Side by Side Diff: net/base/network_change_notifier.cc

Issue 1306653003: Add connection type to NCN::MaxBandwidthChanged (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comment nit Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 double NetworkChangeNotifier::GetMaxBandwidthAndConnectionType(
546 return g_network_change_notifier ? 546 ConnectionType* connection_type) {
547 g_network_change_notifier->GetCurrentMaxBandwidth() : 547 if (!g_network_change_notifier) {
548 std::numeric_limits<double>::infinity(); 548 if (connection_type != nullptr)
549 *connection_type = CONNECTION_UNKNOWN;
550 return GetMaxBandwidthForConnectionSubtype(SUBTYPE_UNKNOWN);
551 }
552
553 return g_network_change_notifier->GetCurrentMaxBandwidthAndConnectionType(
554 connection_type);
549 } 555 }
550 556
551 // static 557 // static
552 void NetworkChangeNotifier::GetDnsConfig(DnsConfig* config) { 558 void NetworkChangeNotifier::GetDnsConfig(DnsConfig* config) {
553 if (!g_network_change_notifier) { 559 if (!g_network_change_notifier) {
554 *config = DnsConfig(); 560 *config = DnsConfig();
555 } else { 561 } else {
556 g_network_change_notifier->network_state_->GetDnsConfig(config); 562 g_network_change_notifier->network_state_->GetDnsConfig(config);
557 } 563 }
558 } 564 }
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 g_network_change_notifier->NotifyObserversOfNetworkChangeImpl(type); 791 g_network_change_notifier->NotifyObserversOfNetworkChangeImpl(type);
786 } 792 }
787 793
788 // static 794 // static
789 void NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigReadForTests() { 795 void NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigReadForTests() {
790 if (g_network_change_notifier) 796 if (g_network_change_notifier)
791 g_network_change_notifier->NotifyObserversOfInitialDNSConfigReadImpl(); 797 g_network_change_notifier->NotifyObserversOfInitialDNSConfigReadImpl();
792 } 798 }
793 799
794 // static 800 // static
801 void NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChangeForTests(
802 ConnectionType type,
803 double max_bandwidth) {
804 if (g_network_change_notifier)
805 g_network_change_notifier->NotifyObserversOfMaxBandwidthChangeImpl(
806 type, max_bandwidth);
807 }
808
809 // static
795 void NetworkChangeNotifier::SetTestNotificationsOnly(bool test_only) { 810 void NetworkChangeNotifier::SetTestNotificationsOnly(bool test_only) {
796 DCHECK(!g_network_change_notifier); 811 DCHECK(!g_network_change_notifier);
797 NetworkChangeNotifier::test_notifications_only_ = test_only; 812 NetworkChangeNotifier::test_notifications_only_ = test_only;
798 } 813 }
799 814
800 NetworkChangeNotifier::NetworkChangeNotifier( 815 NetworkChangeNotifier::NetworkChangeNotifier(
801 const NetworkChangeCalculatorParams& params 816 const NetworkChangeCalculatorParams& params
802 /*= NetworkChangeCalculatorParams()*/) 817 /*= NetworkChangeCalculatorParams()*/)
803 : ip_address_observer_list_( 818 : ip_address_observer_list_(
804 new base::ObserverListThreadSafe<IPAddressObserver>( 819 new base::ObserverListThreadSafe<IPAddressObserver>(
(...skipping 18 matching lines...) Expand all
823 network_change_calculator_->Init(); 838 network_change_calculator_->Init();
824 } 839 }
825 840
826 #if defined(OS_LINUX) 841 #if defined(OS_LINUX)
827 const internal::AddressTrackerLinux* 842 const internal::AddressTrackerLinux*
828 NetworkChangeNotifier::GetAddressTrackerInternal() const { 843 NetworkChangeNotifier::GetAddressTrackerInternal() const {
829 return NULL; 844 return NULL;
830 } 845 }
831 #endif 846 #endif
832 847
833 double NetworkChangeNotifier::GetCurrentMaxBandwidth() const { 848 double NetworkChangeNotifier::GetCurrentMaxBandwidthAndConnectionType(
849 ConnectionType* connection_type) const {
834 // This default implementation conforms to the NetInfo V3 specification but 850 // This default implementation conforms to the NetInfo V3 specification but
835 // should be overridden to provide specific bandwidth data based on the 851 // should be overridden to provide specific bandwidth data based on the
836 // platform. 852 // platform.
837 if (GetCurrentConnectionType() == CONNECTION_NONE) 853 if (connection_type != nullptr)
838 return 0.0; 854 *connection_type = GetCurrentConnectionType();
839 return std::numeric_limits<double>::infinity(); 855 return *connection_type == CONNECTION_NONE
856 ? GetMaxBandwidthForConnectionSubtype(SUBTYPE_NONE)
857 : GetMaxBandwidthForConnectionSubtype(SUBTYPE_UNKNOWN);
840 } 858 }
841 859
842 // static 860 // static
843 double NetworkChangeNotifier::GetMaxBandwidthForConnectionSubtype( 861 double NetworkChangeNotifier::GetMaxBandwidthForConnectionSubtype(
844 ConnectionSubtype subtype) { 862 ConnectionSubtype subtype) {
845 switch (subtype) { 863 switch (subtype) {
846 case SUBTYPE_GSM: 864 case SUBTYPE_GSM:
847 return 0.01; 865 return 0.01;
848 case SUBTYPE_IDEN: 866 case SUBTYPE_IDEN:
849 return 0.064; 867 return 0.064;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 void NetworkChangeNotifier::NotifyObserversOfNetworkChange( 953 void NetworkChangeNotifier::NotifyObserversOfNetworkChange(
936 ConnectionType type) { 954 ConnectionType type) {
937 if (g_network_change_notifier && 955 if (g_network_change_notifier &&
938 !NetworkChangeNotifier::test_notifications_only_) { 956 !NetworkChangeNotifier::test_notifications_only_) {
939 g_network_change_notifier->NotifyObserversOfNetworkChangeImpl(type); 957 g_network_change_notifier->NotifyObserversOfNetworkChangeImpl(type);
940 } 958 }
941 } 959 }
942 960
943 // static 961 // static
944 void NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChange( 962 void NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChange(
963 ConnectionType type,
945 double max_bandwidth_mbps) { 964 double max_bandwidth_mbps) {
946 if (g_network_change_notifier && 965 if (g_network_change_notifier &&
947 !NetworkChangeNotifier::test_notifications_only_) { 966 !NetworkChangeNotifier::test_notifications_only_) {
948 g_network_change_notifier->NotifyObserversOfMaxBandwidthChangeImpl( 967 g_network_change_notifier->NotifyObserversOfMaxBandwidthChangeImpl(
949 max_bandwidth_mbps); 968 type, max_bandwidth_mbps);
950 } 969 }
951 } 970 }
952 971
953 // static 972 // static
954 void NetworkChangeNotifier::NotifyObserversOfDNSChange() { 973 void NetworkChangeNotifier::NotifyObserversOfDNSChange() {
955 if (g_network_change_notifier && 974 if (g_network_change_notifier &&
956 !NetworkChangeNotifier::test_notifications_only_) { 975 !NetworkChangeNotifier::test_notifications_only_) {
957 g_network_change_notifier->NotifyObserversOfDNSChangeImpl(); 976 g_network_change_notifier->NotifyObserversOfDNSChangeImpl();
958 } 977 }
959 } 978 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 void NetworkChangeNotifier::NotifyObserversOfDNSChangeImpl() { 1027 void NetworkChangeNotifier::NotifyObserversOfDNSChangeImpl() {
1009 resolver_state_observer_list_->Notify(FROM_HERE, &DNSObserver::OnDNSChanged); 1028 resolver_state_observer_list_->Notify(FROM_HERE, &DNSObserver::OnDNSChanged);
1010 } 1029 }
1011 1030
1012 void NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigReadImpl() { 1031 void NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigReadImpl() {
1013 resolver_state_observer_list_->Notify(FROM_HERE, 1032 resolver_state_observer_list_->Notify(FROM_HERE,
1014 &DNSObserver::OnInitialDNSConfigRead); 1033 &DNSObserver::OnInitialDNSConfigRead);
1015 } 1034 }
1016 1035
1017 void NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChangeImpl( 1036 void NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChangeImpl(
1037 ConnectionType type,
1018 double max_bandwidth_mbps) { 1038 double max_bandwidth_mbps) {
1019 max_bandwidth_observer_list_->Notify( 1039 max_bandwidth_observer_list_->Notify(
1020 FROM_HERE, &MaxBandwidthObserver::OnMaxBandwidthChanged, 1040 FROM_HERE, &MaxBandwidthObserver::OnMaxBandwidthChanged, type,
1021 max_bandwidth_mbps); 1041 max_bandwidth_mbps);
1022 } 1042 }
1023 1043
1024 NetworkChangeNotifier::DisableForTest::DisableForTest() 1044 NetworkChangeNotifier::DisableForTest::DisableForTest()
1025 : network_change_notifier_(g_network_change_notifier) { 1045 : network_change_notifier_(g_network_change_notifier) {
1026 DCHECK(g_network_change_notifier); 1046 DCHECK(g_network_change_notifier);
1027 g_network_change_notifier = NULL; 1047 g_network_change_notifier = NULL;
1028 } 1048 }
1029 1049
1030 NetworkChangeNotifier::DisableForTest::~DisableForTest() { 1050 NetworkChangeNotifier::DisableForTest::~DisableForTest() {
1031 DCHECK(!g_network_change_notifier); 1051 DCHECK(!g_network_change_notifier);
1032 g_network_change_notifier = network_change_notifier_; 1052 g_network_change_notifier = network_change_notifier_;
1033 } 1053 }
1034 1054
1035 void NetworkChangeNotifier::DNSObserver::OnInitialDNSConfigRead() { 1055 void NetworkChangeNotifier::DNSObserver::OnInitialDNSConfigRead() {
1036 } 1056 }
1037 1057
1038 } // namespace net 1058 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698