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

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: Fixes 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 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 }
552
pauljensen 2015/09/15 18:17:40 so if !g_network_change_notifier we dereference it
jkarlin 2015/09/16 12:12:22 Meant to have an early return, good catch. Thanks.
553 g_network_change_notifier->GetCurrentMaxBandwidthAndConnectionType(
554 max_bandwidth_mbps, 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) {
pauljensen 2015/09/15 18:17:40 add _mbps suffix
jkarlin 2015/09/16 12:12:22 Done.
804 if (g_network_change_notifier)
pauljensen 2015/09/15 18:17:40 need curly braces when more than one line clause
jkarlin 2015/09/16 12:12:22 Done.
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 void NetworkChangeNotifier::GetCurrentMaxBandwidthAndConnectionType(
849 double* max_bandwidth_mbps,
850 ConnectionType* connection_type) const {
834 // This default implementation conforms to the NetInfo V3 specification but 851 // This default implementation conforms to the NetInfo V3 specification but
835 // should be overridden to provide specific bandwidth data based on the 852 // should be overridden to provide specific bandwidth data based on the
836 // platform. 853 // platform.
837 if (GetCurrentConnectionType() == CONNECTION_NONE) 854 *connection_type = GetCurrentConnectionType();
838 return 0.0; 855 *max_bandwidth_mbps =
839 return std::numeric_limits<double>::infinity(); 856 *connection_type == CONNECTION_NONE
857 ? GetMaxBandwidthForConnectionSubtype(SUBTYPE_NONE)
858 : GetMaxBandwidthForConnectionSubtype(SUBTYPE_UNKNOWN);
840 } 859 }
841 860
842 // static 861 // static
843 double NetworkChangeNotifier::GetMaxBandwidthForConnectionSubtype( 862 double NetworkChangeNotifier::GetMaxBandwidthForConnectionSubtype(
844 ConnectionSubtype subtype) { 863 ConnectionSubtype subtype) {
845 switch (subtype) { 864 switch (subtype) {
846 case SUBTYPE_GSM: 865 case SUBTYPE_GSM:
847 return 0.01; 866 return 0.01;
848 case SUBTYPE_IDEN: 867 case SUBTYPE_IDEN:
849 return 0.064; 868 return 0.064;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 void NetworkChangeNotifier::NotifyObserversOfNetworkChange( 954 void NetworkChangeNotifier::NotifyObserversOfNetworkChange(
936 ConnectionType type) { 955 ConnectionType type) {
937 if (g_network_change_notifier && 956 if (g_network_change_notifier &&
938 !NetworkChangeNotifier::test_notifications_only_) { 957 !NetworkChangeNotifier::test_notifications_only_) {
939 g_network_change_notifier->NotifyObserversOfNetworkChangeImpl(type); 958 g_network_change_notifier->NotifyObserversOfNetworkChangeImpl(type);
940 } 959 }
941 } 960 }
942 961
943 // static 962 // static
944 void NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChange( 963 void NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChange(
964 ConnectionType type,
945 double max_bandwidth_mbps) { 965 double max_bandwidth_mbps) {
946 if (g_network_change_notifier && 966 if (g_network_change_notifier &&
947 !NetworkChangeNotifier::test_notifications_only_) { 967 !NetworkChangeNotifier::test_notifications_only_) {
948 g_network_change_notifier->NotifyObserversOfMaxBandwidthChangeImpl( 968 g_network_change_notifier->NotifyObserversOfMaxBandwidthChangeImpl(
949 max_bandwidth_mbps); 969 type, max_bandwidth_mbps);
950 } 970 }
951 } 971 }
952 972
953 // static 973 // static
954 void NetworkChangeNotifier::NotifyObserversOfDNSChange() { 974 void NetworkChangeNotifier::NotifyObserversOfDNSChange() {
955 if (g_network_change_notifier && 975 if (g_network_change_notifier &&
956 !NetworkChangeNotifier::test_notifications_only_) { 976 !NetworkChangeNotifier::test_notifications_only_) {
957 g_network_change_notifier->NotifyObserversOfDNSChangeImpl(); 977 g_network_change_notifier->NotifyObserversOfDNSChangeImpl();
958 } 978 }
959 } 979 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 void NetworkChangeNotifier::NotifyObserversOfDNSChangeImpl() { 1028 void NetworkChangeNotifier::NotifyObserversOfDNSChangeImpl() {
1009 resolver_state_observer_list_->Notify(FROM_HERE, &DNSObserver::OnDNSChanged); 1029 resolver_state_observer_list_->Notify(FROM_HERE, &DNSObserver::OnDNSChanged);
1010 } 1030 }
1011 1031
1012 void NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigReadImpl() { 1032 void NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigReadImpl() {
1013 resolver_state_observer_list_->Notify(FROM_HERE, 1033 resolver_state_observer_list_->Notify(FROM_HERE,
1014 &DNSObserver::OnInitialDNSConfigRead); 1034 &DNSObserver::OnInitialDNSConfigRead);
1015 } 1035 }
1016 1036
1017 void NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChangeImpl( 1037 void NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChangeImpl(
1038 ConnectionType type,
1018 double max_bandwidth_mbps) { 1039 double max_bandwidth_mbps) {
1019 max_bandwidth_observer_list_->Notify( 1040 max_bandwidth_observer_list_->Notify(
1020 FROM_HERE, &MaxBandwidthObserver::OnMaxBandwidthChanged, 1041 FROM_HERE, &MaxBandwidthObserver::OnMaxBandwidthChanged, type,
1021 max_bandwidth_mbps); 1042 max_bandwidth_mbps);
1022 } 1043 }
1023 1044
1024 NetworkChangeNotifier::DisableForTest::DisableForTest() 1045 NetworkChangeNotifier::DisableForTest::DisableForTest()
1025 : network_change_notifier_(g_network_change_notifier) { 1046 : network_change_notifier_(g_network_change_notifier) {
1026 DCHECK(g_network_change_notifier); 1047 DCHECK(g_network_change_notifier);
1027 g_network_change_notifier = NULL; 1048 g_network_change_notifier = NULL;
1028 } 1049 }
1029 1050
1030 NetworkChangeNotifier::DisableForTest::~DisableForTest() { 1051 NetworkChangeNotifier::DisableForTest::~DisableForTest() {
1031 DCHECK(!g_network_change_notifier); 1052 DCHECK(!g_network_change_notifier);
1032 g_network_change_notifier = network_change_notifier_; 1053 g_network_change_notifier = network_change_notifier_;
1033 } 1054 }
1034 1055
1035 void NetworkChangeNotifier::DNSObserver::OnInitialDNSConfigRead() { 1056 void NetworkChangeNotifier::DNSObserver::OnInitialDNSConfigRead() {
1036 } 1057 }
1037 1058
1038 } // namespace net 1059 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698