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

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

Issue 1255263002: Remove a race around NetworkChangeNotifier::test_notifications_only_ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Possible iOS fix Created 5 years, 4 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
« no previous file with comments | « net/base/network_change_notifier.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 class MockNetworkChangeNotifier : public NetworkChangeNotifier { 47 class MockNetworkChangeNotifier : public NetworkChangeNotifier {
48 public: 48 public:
49 ConnectionType GetCurrentConnectionType() const override { 49 ConnectionType GetCurrentConnectionType() const override {
50 return CONNECTION_UNKNOWN; 50 return CONNECTION_UNKNOWN;
51 } 51 }
52 }; 52 };
53 53
54 } // namespace 54 } // namespace
55 55
56 // static
57 bool NetworkChangeNotifier::test_notifications_only_ = false;
58
56 // The main observer class that records UMAs for network events. 59 // The main observer class that records UMAs for network events.
57 class HistogramWatcher 60 class HistogramWatcher
58 : public NetworkChangeNotifier::ConnectionTypeObserver, 61 : public NetworkChangeNotifier::ConnectionTypeObserver,
59 public NetworkChangeNotifier::IPAddressObserver, 62 public NetworkChangeNotifier::IPAddressObserver,
60 public NetworkChangeNotifier::DNSObserver, 63 public NetworkChangeNotifier::DNSObserver,
61 public NetworkChangeNotifier::NetworkChangeObserver { 64 public NetworkChangeNotifier::NetworkChangeObserver {
62 public: 65 public:
63 HistogramWatcher() 66 HistogramWatcher()
64 : last_ip_address_change_(base::TimeTicks::Now()), 67 : last_ip_address_change_(base::TimeTicks::Now()),
65 last_connection_change_(base::TimeTicks::Now()), 68 last_connection_change_(base::TimeTicks::Now()),
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 } 785 }
783 786
784 // static 787 // static
785 void NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigReadForTests() { 788 void NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigReadForTests() {
786 if (g_network_change_notifier) 789 if (g_network_change_notifier)
787 g_network_change_notifier->NotifyObserversOfInitialDNSConfigReadImpl(); 790 g_network_change_notifier->NotifyObserversOfInitialDNSConfigReadImpl();
788 } 791 }
789 792
790 // static 793 // static
791 void NetworkChangeNotifier::SetTestNotificationsOnly(bool test_only) { 794 void NetworkChangeNotifier::SetTestNotificationsOnly(bool test_only) {
792 if (g_network_change_notifier) 795 DCHECK(!g_network_change_notifier);
793 g_network_change_notifier->test_notifications_only_ = test_only; 796 NetworkChangeNotifier::test_notifications_only_ = test_only;
794 } 797 }
795 798
796 NetworkChangeNotifier::NetworkChangeNotifier( 799 NetworkChangeNotifier::NetworkChangeNotifier(
797 const NetworkChangeCalculatorParams& params 800 const NetworkChangeCalculatorParams& params
798 /*= NetworkChangeCalculatorParams()*/) 801 /*= NetworkChangeCalculatorParams()*/)
799 : ip_address_observer_list_( 802 : ip_address_observer_list_(
800 new base::ObserverListThreadSafe<IPAddressObserver>( 803 new base::ObserverListThreadSafe<IPAddressObserver>(
801 base::ObserverListBase<IPAddressObserver>::NOTIFY_EXISTING_ONLY)), 804 base::ObserverListBase<IPAddressObserver>::NOTIFY_EXISTING_ONLY)),
802 connection_type_observer_list_( 805 connection_type_observer_list_(
803 new base::ObserverListThreadSafe<ConnectionTypeObserver>( 806 new base::ObserverListThreadSafe<ConnectionTypeObserver>(
804 base::ObserverListBase< 807 base::ObserverListBase<
805 ConnectionTypeObserver>::NOTIFY_EXISTING_ONLY)), 808 ConnectionTypeObserver>::NOTIFY_EXISTING_ONLY)),
806 resolver_state_observer_list_( 809 resolver_state_observer_list_(
807 new base::ObserverListThreadSafe<DNSObserver>( 810 new base::ObserverListThreadSafe<DNSObserver>(
808 base::ObserverListBase<DNSObserver>::NOTIFY_EXISTING_ONLY)), 811 base::ObserverListBase<DNSObserver>::NOTIFY_EXISTING_ONLY)),
809 network_change_observer_list_(new base::ObserverListThreadSafe< 812 network_change_observer_list_(new base::ObserverListThreadSafe<
810 NetworkChangeObserver>( 813 NetworkChangeObserver>(
811 base::ObserverListBase<NetworkChangeObserver>::NOTIFY_EXISTING_ONLY)), 814 base::ObserverListBase<NetworkChangeObserver>::NOTIFY_EXISTING_ONLY)),
812 max_bandwidth_observer_list_(new base::ObserverListThreadSafe< 815 max_bandwidth_observer_list_(new base::ObserverListThreadSafe<
813 MaxBandwidthObserver>( 816 MaxBandwidthObserver>(
814 base::ObserverListBase<MaxBandwidthObserver>::NOTIFY_EXISTING_ONLY)), 817 base::ObserverListBase<MaxBandwidthObserver>::NOTIFY_EXISTING_ONLY)),
815 network_state_(new NetworkState()), 818 network_state_(new NetworkState()),
816 network_change_calculator_(new NetworkChangeCalculator(params)), 819 network_change_calculator_(new NetworkChangeCalculator(params)) {
817 test_notifications_only_(false) {
818 DCHECK(!g_network_change_notifier); 820 DCHECK(!g_network_change_notifier);
819 g_network_change_notifier = this; 821 g_network_change_notifier = this;
820 network_change_calculator_->Init(); 822 network_change_calculator_->Init();
821 } 823 }
822 824
823 #if defined(OS_LINUX) 825 #if defined(OS_LINUX)
824 const internal::AddressTrackerLinux* 826 const internal::AddressTrackerLinux*
825 NetworkChangeNotifier::GetAddressTrackerInternal() const { 827 NetworkChangeNotifier::GetAddressTrackerInternal() const {
826 return NULL; 828 return NULL;
827 } 829 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 case SUBTYPE_OTHER: 909 case SUBTYPE_OTHER:
908 return std::numeric_limits<double>::infinity(); 910 return std::numeric_limits<double>::infinity();
909 } 911 }
910 NOTREACHED(); 912 NOTREACHED();
911 return std::numeric_limits<double>::infinity(); 913 return std::numeric_limits<double>::infinity();
912 } 914 }
913 915
914 // static 916 // static
915 void NetworkChangeNotifier::NotifyObserversOfIPAddressChange() { 917 void NetworkChangeNotifier::NotifyObserversOfIPAddressChange() {
916 if (g_network_change_notifier && 918 if (g_network_change_notifier &&
917 !g_network_change_notifier->test_notifications_only_) { 919 !NetworkChangeNotifier::test_notifications_only_) {
918 g_network_change_notifier->NotifyObserversOfIPAddressChangeImpl(); 920 g_network_change_notifier->NotifyObserversOfIPAddressChangeImpl();
919 } 921 }
920 } 922 }
921 923
922 // static 924 // static
923 void NetworkChangeNotifier::NotifyObserversOfConnectionTypeChange() { 925 void NetworkChangeNotifier::NotifyObserversOfConnectionTypeChange() {
924 if (g_network_change_notifier && 926 if (g_network_change_notifier &&
925 !g_network_change_notifier->test_notifications_only_) { 927 !NetworkChangeNotifier::test_notifications_only_) {
926 g_network_change_notifier->NotifyObserversOfConnectionTypeChangeImpl( 928 g_network_change_notifier->NotifyObserversOfConnectionTypeChangeImpl(
927 GetConnectionType()); 929 GetConnectionType());
928 } 930 }
929 } 931 }
930 932
931 // static 933 // static
932 void NetworkChangeNotifier::NotifyObserversOfNetworkChange( 934 void NetworkChangeNotifier::NotifyObserversOfNetworkChange(
933 ConnectionType type) { 935 ConnectionType type) {
934 if (g_network_change_notifier && 936 if (g_network_change_notifier &&
935 !g_network_change_notifier->test_notifications_only_) { 937 !NetworkChangeNotifier::test_notifications_only_) {
936 g_network_change_notifier->NotifyObserversOfNetworkChangeImpl(type); 938 g_network_change_notifier->NotifyObserversOfNetworkChangeImpl(type);
937 } 939 }
938 } 940 }
939 941
940 // static 942 // static
941 void NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChange( 943 void NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChange(
942 double max_bandwidth_mbps) { 944 double max_bandwidth_mbps) {
943 if (g_network_change_notifier && 945 if (g_network_change_notifier &&
944 !g_network_change_notifier->test_notifications_only_) { 946 !NetworkChangeNotifier::test_notifications_only_) {
945 g_network_change_notifier->NotifyObserversOfMaxBandwidthChangeImpl( 947 g_network_change_notifier->NotifyObserversOfMaxBandwidthChangeImpl(
946 max_bandwidth_mbps); 948 max_bandwidth_mbps);
947 } 949 }
948 } 950 }
949 951
950 // static 952 // static
951 void NetworkChangeNotifier::NotifyObserversOfDNSChange() { 953 void NetworkChangeNotifier::NotifyObserversOfDNSChange() {
952 if (g_network_change_notifier && 954 if (g_network_change_notifier &&
953 !g_network_change_notifier->test_notifications_only_) { 955 !NetworkChangeNotifier::test_notifications_only_) {
954 g_network_change_notifier->NotifyObserversOfDNSChangeImpl(); 956 g_network_change_notifier->NotifyObserversOfDNSChangeImpl();
955 } 957 }
956 } 958 }
957 959
958 // static 960 // static
959 void NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigRead() { 961 void NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigRead() {
960 if (g_network_change_notifier && 962 if (g_network_change_notifier &&
961 !g_network_change_notifier->test_notifications_only_) { 963 !NetworkChangeNotifier::test_notifications_only_) {
962 g_network_change_notifier->NotifyObserversOfInitialDNSConfigReadImpl(); 964 g_network_change_notifier->NotifyObserversOfInitialDNSConfigReadImpl();
963 } 965 }
964 } 966 }
965 967
966 // static 968 // static
967 void NetworkChangeNotifier::SetDnsConfig(const DnsConfig& config) { 969 void NetworkChangeNotifier::SetDnsConfig(const DnsConfig& config) {
968 if (!g_network_change_notifier) 970 if (!g_network_change_notifier)
969 return; 971 return;
970 g_network_change_notifier->network_state_->SetDnsConfig(config); 972 g_network_change_notifier->network_state_->SetDnsConfig(config);
971 NotifyObserversOfDNSChange(); 973 NotifyObserversOfDNSChange();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 1028
1027 NetworkChangeNotifier::DisableForTest::~DisableForTest() { 1029 NetworkChangeNotifier::DisableForTest::~DisableForTest() {
1028 DCHECK(!g_network_change_notifier); 1030 DCHECK(!g_network_change_notifier);
1029 g_network_change_notifier = network_change_notifier_; 1031 g_network_change_notifier = network_change_notifier_;
1030 } 1032 }
1031 1033
1032 void NetworkChangeNotifier::DNSObserver::OnInitialDNSConfigRead() { 1034 void NetworkChangeNotifier::DNSObserver::OnInitialDNSConfigRead() {
1033 } 1035 }
1034 1036
1035 } // namespace net 1037 } // namespace net
OLDNEW
« no previous file with comments | « net/base/network_change_notifier.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698