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 "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/synchronization/lock.h" | 8 #include "base/synchronization/lock.h" |
9 #include "base/threading/thread_checker.h" | 9 #include "base/threading/thread_checker.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 } | 756 } |
757 | 757 |
758 // static | 758 // static |
759 void NetworkChangeNotifier::SetDnsConfig(const DnsConfig& config) { | 759 void NetworkChangeNotifier::SetDnsConfig(const DnsConfig& config) { |
760 if (!g_network_change_notifier) | 760 if (!g_network_change_notifier) |
761 return; | 761 return; |
762 g_network_change_notifier->network_state_->SetDnsConfig(config); | 762 g_network_change_notifier->network_state_->SetDnsConfig(config); |
763 NotifyObserversOfDNSChange(); | 763 NotifyObserversOfDNSChange(); |
764 } | 764 } |
765 | 765 |
| 766 // static |
| 767 NetworkChangeNotifier::ConnectionType |
| 768 NetworkChangeNotifier::ConnectionTypeFromInterfaces() { |
| 769 NetworkInterfaceList interfaces; |
| 770 if (!GetNetworkList(&interfaces, EXCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES)) |
| 771 return CONNECTION_UNKNOWN; |
| 772 return ConnectionTypeFromInterfaceList(interfaces); |
| 773 } |
| 774 |
| 775 //static |
| 776 NetworkChangeNotifier::ConnectionType |
| 777 NetworkChangeNotifier::ConnectionTypeFromInterfaceList( |
| 778 const NetworkInterfaceList& interfaces) { |
| 779 bool first = true; |
| 780 ConnectionType result = CONNECTION_UNKNOWN; |
| 781 for (size_t i = 0; i < interfaces.size(); ++i) { |
| 782 #if defined(OS_WIN) |
| 783 if (interfaces[i].friendly_name == "Teredo Tunneling Pseudo-Interface") |
| 784 continue; |
| 785 #endif |
| 786 if (first) { |
| 787 first = false; |
| 788 result = interfaces[i].type; |
| 789 } else if (result != interfaces[i].type) { |
| 790 return CONNECTION_UNKNOWN; |
| 791 } |
| 792 } |
| 793 return result; |
| 794 } |
| 795 |
766 void NetworkChangeNotifier::NotifyObserversOfConnectionTypeChange() { | 796 void NetworkChangeNotifier::NotifyObserversOfConnectionTypeChange() { |
767 if (g_network_change_notifier) { | 797 if (g_network_change_notifier) { |
768 g_network_change_notifier->connection_type_observer_list_->Notify( | 798 g_network_change_notifier->connection_type_observer_list_->Notify( |
769 &ConnectionTypeObserver::OnConnectionTypeChanged, | 799 &ConnectionTypeObserver::OnConnectionTypeChanged, |
770 GetConnectionType()); | 800 GetConnectionType()); |
771 } | 801 } |
772 } | 802 } |
773 | 803 |
774 void NetworkChangeNotifier::NotifyObserversOfNetworkChange( | 804 void NetworkChangeNotifier::NotifyObserversOfNetworkChange( |
775 ConnectionType type) { | 805 ConnectionType type) { |
776 if (g_network_change_notifier) { | 806 if (g_network_change_notifier) { |
777 g_network_change_notifier->network_change_observer_list_->Notify( | 807 g_network_change_notifier->network_change_observer_list_->Notify( |
778 &NetworkChangeObserver::OnNetworkChanged, | 808 &NetworkChangeObserver::OnNetworkChanged, |
779 type); | 809 type); |
780 } | 810 } |
781 } | 811 } |
782 | 812 |
783 NetworkChangeNotifier::DisableForTest::DisableForTest() | 813 NetworkChangeNotifier::DisableForTest::DisableForTest() |
784 : network_change_notifier_(g_network_change_notifier) { | 814 : network_change_notifier_(g_network_change_notifier) { |
785 DCHECK(g_network_change_notifier); | 815 DCHECK(g_network_change_notifier); |
786 g_network_change_notifier = NULL; | 816 g_network_change_notifier = NULL; |
787 } | 817 } |
788 | 818 |
789 NetworkChangeNotifier::DisableForTest::~DisableForTest() { | 819 NetworkChangeNotifier::DisableForTest::~DisableForTest() { |
790 DCHECK(!g_network_change_notifier); | 820 DCHECK(!g_network_change_notifier); |
791 g_network_change_notifier = network_change_notifier_; | 821 g_network_change_notifier = network_change_notifier_; |
792 } | 822 } |
793 | 823 |
794 } // namespace net | 824 } // namespace net |
OLD | NEW |