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 "content/renderer/p2p/ipc_network_manager.h" | 5 #include "content/renderer/p2p/ipc_network_manager.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "base/sys_byteorder.h" | 13 #include "base/sys_byteorder.h" |
14 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
15 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
16 #include "jingle/glue/utils.h" | 16 #include "jingle/glue/utils.h" |
17 #include "net/base/ip_address_number.h" | 17 #include "net/base/ip_address.h" |
18 #include "net/base/network_change_notifier.h" | 18 #include "net/base/network_change_notifier.h" |
19 #include "net/base/network_interfaces.h" | 19 #include "net/base/network_interfaces.h" |
20 #include "third_party/webrtc/base/socketaddress.h" | 20 #include "third_party/webrtc/base/socketaddress.h" |
21 | 21 |
22 namespace content { | 22 namespace content { |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 rtc::AdapterType ConvertConnectionTypeToAdapterType( | 26 rtc::AdapterType ConvertConnectionTypeToAdapterType( |
27 net::NetworkChangeNotifier::ConnectionType type) { | 27 net::NetworkChangeNotifier::ConnectionType type) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 ++start_count_; | 66 ++start_count_; |
67 } | 67 } |
68 | 68 |
69 void IpcNetworkManager::StopUpdating() { | 69 void IpcNetworkManager::StopUpdating() { |
70 DCHECK_GT(start_count_, 0); | 70 DCHECK_GT(start_count_, 0); |
71 --start_count_; | 71 --start_count_; |
72 } | 72 } |
73 | 73 |
74 void IpcNetworkManager::OnNetworkListChanged( | 74 void IpcNetworkManager::OnNetworkListChanged( |
75 const net::NetworkInterfaceList& list, | 75 const net::NetworkInterfaceList& list, |
76 const net::IPAddressNumber& default_ipv4_local_address, | 76 const net::IPAddress& default_ipv4_local_address, |
77 const net::IPAddressNumber& default_ipv6_local_address) { | 77 const net::IPAddress& default_ipv6_local_address) { |
78 // Update flag if network list received for the first time. | 78 // Update flag if network list received for the first time. |
79 if (!network_list_received_) | 79 if (!network_list_received_) |
80 network_list_received_ = true; | 80 network_list_received_ = true; |
81 | 81 |
82 // Default addresses should be set only when they are in the filtered list of | 82 // Default addresses should be set only when they are in the filtered list of |
83 // network addresses. | 83 // network addresses. |
84 bool use_default_ipv4_address = false; | 84 bool use_default_ipv4_address = false; |
85 bool use_default_ipv6_address = false; | 85 bool use_default_ipv6_address = false; |
86 | 86 |
87 // rtc::Network uses these prefix_length to compare network | 87 // rtc::Network uses these prefix_length to compare network |
88 // interfaces discovered. | 88 // interfaces discovered. |
89 std::vector<rtc::Network*> networks; | 89 std::vector<rtc::Network*> networks; |
90 for (net::NetworkInterfaceList::const_iterator it = list.begin(); | 90 for (net::NetworkInterfaceList::const_iterator it = list.begin(); |
91 it != list.end(); it++) { | 91 it != list.end(); it++) { |
92 rtc::IPAddress ip_address = | 92 rtc::IPAddress ip_address = |
93 jingle_glue::IPAddressNumberToIPAddress(it->address.bytes()); | 93 jingle_glue::NetIPAddressToRtcIPAddress(it->address); |
94 DCHECK(!ip_address.IsNil()); | 94 DCHECK(!ip_address.IsNil()); |
95 | 95 |
96 rtc::IPAddress prefix = rtc::TruncateIP(ip_address, it->prefix_length); | 96 rtc::IPAddress prefix = rtc::TruncateIP(ip_address, it->prefix_length); |
97 scoped_ptr<rtc::Network> network( | 97 scoped_ptr<rtc::Network> network( |
98 new rtc::Network(it->name, it->name, prefix, it->prefix_length, | 98 new rtc::Network(it->name, it->name, prefix, it->prefix_length, |
99 ConvertConnectionTypeToAdapterType(it->type))); | 99 ConvertConnectionTypeToAdapterType(it->type))); |
100 network->set_default_local_address_provider(this); | 100 network->set_default_local_address_provider(this); |
101 | 101 |
102 rtc::InterfaceAddress iface_addr; | 102 rtc::InterfaceAddress iface_addr; |
103 if (it->address.IsIPv4()) { | 103 if (it->address.IsIPv4()) { |
104 use_default_ipv4_address |= | 104 use_default_ipv4_address |= (default_ipv4_local_address == it->address); |
105 (default_ipv4_local_address == it->address.bytes()); | |
106 iface_addr = rtc::InterfaceAddress(ip_address); | 105 iface_addr = rtc::InterfaceAddress(ip_address); |
107 } else { | 106 } else { |
108 DCHECK(it->address.IsIPv6()); | 107 DCHECK(it->address.IsIPv6()); |
109 iface_addr = rtc::InterfaceAddress(ip_address, it->ip_address_attributes); | 108 iface_addr = rtc::InterfaceAddress(ip_address, it->ip_address_attributes); |
110 | 109 |
111 // Only allow non-private, non-deprecated IPv6 addresses which don't | 110 // Only allow non-private, non-deprecated IPv6 addresses which don't |
112 // contain MAC. | 111 // contain MAC. |
113 if (rtc::IPIsMacBased(iface_addr) || | 112 if (rtc::IPIsMacBased(iface_addr) || |
114 (it->ip_address_attributes & net::IP_ADDRESS_ATTRIBUTE_DEPRECATED) || | 113 (it->ip_address_attributes & net::IP_ADDRESS_ATTRIBUTE_DEPRECATED) || |
115 rtc::IPIsPrivate(iface_addr)) { | 114 rtc::IPIsPrivate(iface_addr)) { |
116 continue; | 115 continue; |
117 } | 116 } |
118 | 117 |
119 use_default_ipv6_address |= | 118 use_default_ipv6_address |= (default_ipv6_local_address == it->address); |
120 (default_ipv6_local_address == it->address.bytes()); | |
121 } | 119 } |
122 network->AddIP(iface_addr); | 120 network->AddIP(iface_addr); |
123 networks.push_back(network.release()); | 121 networks.push_back(network.release()); |
124 } | 122 } |
125 | 123 |
126 // Update the default local addresses. | 124 // Update the default local addresses. |
127 rtc::IPAddress ipv4_default; | 125 rtc::IPAddress ipv4_default; |
128 rtc::IPAddress ipv6_defualt; | 126 rtc::IPAddress ipv6_defualt; |
129 if (use_default_ipv4_address) { | 127 if (use_default_ipv4_address) { |
130 ipv4_default = | 128 ipv4_default = |
131 jingle_glue::IPAddressNumberToIPAddress(default_ipv4_local_address); | 129 jingle_glue::NetIPAddressToRtcIPAddress(default_ipv4_local_address); |
132 } | 130 } |
133 if (use_default_ipv6_address) { | 131 if (use_default_ipv6_address) { |
134 ipv6_defualt = | 132 ipv6_defualt = |
135 jingle_glue::IPAddressNumberToIPAddress(default_ipv6_local_address); | 133 jingle_glue::NetIPAddressToRtcIPAddress(default_ipv6_local_address); |
136 } | 134 } |
137 set_default_local_addresses(ipv4_default, ipv6_defualt); | 135 set_default_local_addresses(ipv4_default, ipv6_defualt); |
138 | 136 |
139 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 137 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
140 switches::kAllowLoopbackInPeerConnection)) { | 138 switches::kAllowLoopbackInPeerConnection)) { |
141 std::string name_v4("loopback_ipv4"); | 139 std::string name_v4("loopback_ipv4"); |
142 rtc::IPAddress ip_address_v4(INADDR_LOOPBACK); | 140 rtc::IPAddress ip_address_v4(INADDR_LOOPBACK); |
143 rtc::Network* network_v4 = new rtc::Network( | 141 rtc::Network* network_v4 = new rtc::Network( |
144 name_v4, name_v4, ip_address_v4, 32, rtc::ADAPTER_TYPE_UNKNOWN); | 142 name_v4, name_v4, ip_address_v4, 32, rtc::ADAPTER_TYPE_UNKNOWN); |
145 network_v4->set_default_local_address_provider(this); | 143 network_v4->set_default_local_address_provider(this); |
(...skipping 27 matching lines...) Expand all Loading... |
173 stats.ipv4_network_count); | 171 stats.ipv4_network_count); |
174 UMA_HISTOGRAM_COUNTS_100("WebRTC.PeerConnection.IPv6Interfaces", | 172 UMA_HISTOGRAM_COUNTS_100("WebRTC.PeerConnection.IPv6Interfaces", |
175 stats.ipv6_network_count); | 173 stats.ipv6_network_count); |
176 } | 174 } |
177 | 175 |
178 void IpcNetworkManager::SendNetworksChangedSignal() { | 176 void IpcNetworkManager::SendNetworksChangedSignal() { |
179 SignalNetworksChanged(); | 177 SignalNetworksChanged(); |
180 } | 178 } |
181 | 179 |
182 } // namespace content | 180 } // namespace content |
OLD | NEW |