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.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 } | 769 } |
770 | 770 |
771 // static | 771 // static |
772 void NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests( | 772 void NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests( |
773 ConnectionType type) { | 773 ConnectionType type) { |
774 if (g_network_change_notifier) | 774 if (g_network_change_notifier) |
775 g_network_change_notifier->NotifyObserversOfNetworkChangeImpl(type); | 775 g_network_change_notifier->NotifyObserversOfNetworkChangeImpl(type); |
776 } | 776 } |
777 | 777 |
778 // static | 778 // static |
| 779 void NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigReadForTests() { |
| 780 if (g_network_change_notifier) |
| 781 g_network_change_notifier->NotifyObserversOfInitialDNSConfigReadImpl(); |
| 782 } |
| 783 |
| 784 // static |
779 void NetworkChangeNotifier::SetTestNotificationsOnly(bool test_only) { | 785 void NetworkChangeNotifier::SetTestNotificationsOnly(bool test_only) { |
780 if (g_network_change_notifier) | 786 if (g_network_change_notifier) |
781 g_network_change_notifier->test_notifications_only_ = test_only; | 787 g_network_change_notifier->test_notifications_only_ = test_only; |
782 } | 788 } |
783 | 789 |
784 NetworkChangeNotifier::NetworkChangeNotifier( | 790 NetworkChangeNotifier::NetworkChangeNotifier( |
785 const NetworkChangeCalculatorParams& params | 791 const NetworkChangeCalculatorParams& params |
786 /*= NetworkChangeCalculatorParams()*/) | 792 /*= NetworkChangeCalculatorParams()*/) |
787 : ip_address_observer_list_(new ObserverListThreadSafe<IPAddressObserver>( | 793 : ip_address_observer_list_(new ObserverListThreadSafe<IPAddressObserver>( |
788 ObserverListBase<IPAddressObserver>::NOTIFY_EXISTING_ONLY)), | 794 ObserverListBase<IPAddressObserver>::NOTIFY_EXISTING_ONLY)), |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
934 | 940 |
935 // static | 941 // static |
936 void NetworkChangeNotifier::NotifyObserversOfDNSChange() { | 942 void NetworkChangeNotifier::NotifyObserversOfDNSChange() { |
937 if (g_network_change_notifier && | 943 if (g_network_change_notifier && |
938 !g_network_change_notifier->test_notifications_only_) { | 944 !g_network_change_notifier->test_notifications_only_) { |
939 g_network_change_notifier->NotifyObserversOfDNSChangeImpl(); | 945 g_network_change_notifier->NotifyObserversOfDNSChangeImpl(); |
940 } | 946 } |
941 } | 947 } |
942 | 948 |
943 // static | 949 // static |
| 950 void NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigRead() { |
| 951 if (g_network_change_notifier && |
| 952 !g_network_change_notifier->test_notifications_only_) { |
| 953 g_network_change_notifier->NotifyObserversOfInitialDNSConfigReadImpl(); |
| 954 } |
| 955 } |
| 956 |
| 957 // static |
944 void NetworkChangeNotifier::SetDnsConfig(const DnsConfig& config) { | 958 void NetworkChangeNotifier::SetDnsConfig(const DnsConfig& config) { |
945 if (!g_network_change_notifier) | 959 if (!g_network_change_notifier) |
946 return; | 960 return; |
947 g_network_change_notifier->network_state_->SetDnsConfig(config); | 961 g_network_change_notifier->network_state_->SetDnsConfig(config); |
948 NotifyObserversOfDNSChange(); | 962 NotifyObserversOfDNSChange(); |
949 } | 963 } |
950 | 964 |
| 965 // static |
| 966 void NetworkChangeNotifier::SetInitialDnsConfig(const DnsConfig& config) { |
| 967 if (!g_network_change_notifier) |
| 968 return; |
| 969 #if DCHECK_IS_ON() |
| 970 // Verify we've never received a valid DnsConfig previously. |
| 971 DnsConfig old_config; |
| 972 g_network_change_notifier->network_state_->GetDnsConfig(&old_config); |
| 973 DCHECK(!old_config.IsValid()); |
| 974 #endif |
| 975 g_network_change_notifier->network_state_->SetDnsConfig(config); |
| 976 NotifyObserversOfInitialDNSConfigRead(); |
| 977 } |
| 978 |
951 void NetworkChangeNotifier::NotifyObserversOfIPAddressChangeImpl() { | 979 void NetworkChangeNotifier::NotifyObserversOfIPAddressChangeImpl() { |
952 ip_address_observer_list_->Notify(FROM_HERE, | 980 ip_address_observer_list_->Notify(FROM_HERE, |
953 &IPAddressObserver::OnIPAddressChanged); | 981 &IPAddressObserver::OnIPAddressChanged); |
954 } | 982 } |
955 | 983 |
956 void NetworkChangeNotifier::NotifyObserversOfConnectionTypeChangeImpl( | 984 void NetworkChangeNotifier::NotifyObserversOfConnectionTypeChangeImpl( |
957 ConnectionType type) { | 985 ConnectionType type) { |
958 connection_type_observer_list_->Notify( | 986 connection_type_observer_list_->Notify( |
959 FROM_HERE, &ConnectionTypeObserver::OnConnectionTypeChanged, type); | 987 FROM_HERE, &ConnectionTypeObserver::OnConnectionTypeChanged, type); |
960 } | 988 } |
961 | 989 |
962 void NetworkChangeNotifier::NotifyObserversOfNetworkChangeImpl( | 990 void NetworkChangeNotifier::NotifyObserversOfNetworkChangeImpl( |
963 ConnectionType type) { | 991 ConnectionType type) { |
964 network_change_observer_list_->Notify( | 992 network_change_observer_list_->Notify( |
965 FROM_HERE, &NetworkChangeObserver::OnNetworkChanged, type); | 993 FROM_HERE, &NetworkChangeObserver::OnNetworkChanged, type); |
966 } | 994 } |
967 | 995 |
968 void NetworkChangeNotifier::NotifyObserversOfDNSChangeImpl() { | 996 void NetworkChangeNotifier::NotifyObserversOfDNSChangeImpl() { |
969 resolver_state_observer_list_->Notify(FROM_HERE, &DNSObserver::OnDNSChanged); | 997 resolver_state_observer_list_->Notify(FROM_HERE, &DNSObserver::OnDNSChanged); |
970 } | 998 } |
971 | 999 |
| 1000 void NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigReadImpl() { |
| 1001 resolver_state_observer_list_->Notify(FROM_HERE, |
| 1002 &DNSObserver::OnInitialDNSConfigRead); |
| 1003 } |
| 1004 |
972 void NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChangeImpl( | 1005 void NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChangeImpl( |
973 double max_bandwidth_mbps) { | 1006 double max_bandwidth_mbps) { |
974 max_bandwidth_observer_list_->Notify( | 1007 max_bandwidth_observer_list_->Notify( |
975 FROM_HERE, &MaxBandwidthObserver::OnMaxBandwidthChanged, | 1008 FROM_HERE, &MaxBandwidthObserver::OnMaxBandwidthChanged, |
976 max_bandwidth_mbps); | 1009 max_bandwidth_mbps); |
977 } | 1010 } |
978 | 1011 |
979 NetworkChangeNotifier::DisableForTest::DisableForTest() | 1012 NetworkChangeNotifier::DisableForTest::DisableForTest() |
980 : network_change_notifier_(g_network_change_notifier) { | 1013 : network_change_notifier_(g_network_change_notifier) { |
981 DCHECK(g_network_change_notifier); | 1014 DCHECK(g_network_change_notifier); |
982 g_network_change_notifier = NULL; | 1015 g_network_change_notifier = NULL; |
983 } | 1016 } |
984 | 1017 |
985 NetworkChangeNotifier::DisableForTest::~DisableForTest() { | 1018 NetworkChangeNotifier::DisableForTest::~DisableForTest() { |
986 DCHECK(!g_network_change_notifier); | 1019 DCHECK(!g_network_change_notifier); |
987 g_network_change_notifier = network_change_notifier_; | 1020 g_network_change_notifier = network_change_notifier_; |
988 } | 1021 } |
989 | 1022 |
| 1023 void NetworkChangeNotifier::DNSObserver::OnInitialDNSConfigRead() { |
| 1024 } |
| 1025 |
990 } // namespace net | 1026 } // namespace net |
OLD | NEW |