| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/metrics/histogram.h" | |
| 10 #include "base/sys_byteorder.h" | 9 #include "base/sys_byteorder.h" |
| 11 #include "content/public/common/content_switches.h" | 10 #include "content/public/common/content_switches.h" |
| 12 #include "net/base/net_util.h" | 11 #include "net/base/net_util.h" |
| 13 | 12 |
| 14 namespace content { | 13 namespace content { |
| 15 | 14 |
| 16 namespace { | 15 namespace { |
| 17 | 16 |
| 18 talk_base::AdapterType ConvertConnectionTypeToAdapterType( | 17 talk_base::AdapterType ConvertConnectionTypeToAdapterType( |
| 19 net::NetworkChangeNotifier::ConnectionType type) { | 18 net::NetworkChangeNotifier::ConnectionType type) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 68 |
| 70 // Update flag if network list received for the first time. | 69 // Update flag if network list received for the first time. |
| 71 if (!network_list_received_) | 70 if (!network_list_received_) |
| 72 network_list_received_ = true; | 71 network_list_received_ = true; |
| 73 | 72 |
| 74 // Note: 32 and 64 are the arbitrary(kind of) prefix length used to | 73 // Note: 32 and 64 are the arbitrary(kind of) prefix length used to |
| 75 // differentiate IPv4 and IPv6 addresses. | 74 // differentiate IPv4 and IPv6 addresses. |
| 76 // talk_base::Network uses these prefix_length to compare network | 75 // talk_base::Network uses these prefix_length to compare network |
| 77 // interfaces discovered. | 76 // interfaces discovered. |
| 78 std::vector<talk_base::Network*> networks; | 77 std::vector<talk_base::Network*> networks; |
| 79 int ipv4_interfaces = 0; | |
| 80 int ipv6_interfaces = 0; | |
| 81 for (net::NetworkInterfaceList::const_iterator it = list.begin(); | 78 for (net::NetworkInterfaceList::const_iterator it = list.begin(); |
| 82 it != list.end(); it++) { | 79 it != list.end(); it++) { |
| 83 if (it->address.size() == net::kIPv4AddressSize) { | 80 if (it->address.size() == net::kIPv4AddressSize) { |
| 84 uint32 address; | 81 uint32 address; |
| 85 memcpy(&address, &it->address[0], sizeof(uint32)); | 82 memcpy(&address, &it->address[0], sizeof(uint32)); |
| 86 address = talk_base::NetworkToHost32(address); | 83 address = talk_base::NetworkToHost32(address); |
| 87 talk_base::Network* network = new talk_base::Network( | 84 talk_base::Network* network = new talk_base::Network( |
| 88 it->name, it->name, talk_base::IPAddress(address), 32, | 85 it->name, it->name, talk_base::IPAddress(address), 32, |
| 89 ConvertConnectionTypeToAdapterType(it->type)); | 86 ConvertConnectionTypeToAdapterType(it->type)); |
| 90 network->AddIP(talk_base::IPAddress(address)); | 87 network->AddIP(talk_base::IPAddress(address)); |
| 91 networks.push_back(network); | 88 networks.push_back(network); |
| 92 ++ipv4_interfaces; | |
| 93 } else if (it->address.size() == net::kIPv6AddressSize) { | 89 } else if (it->address.size() == net::kIPv6AddressSize) { |
| 94 in6_addr address; | 90 in6_addr address; |
| 95 memcpy(&address, &it->address[0], sizeof(in6_addr)); | 91 memcpy(&address, &it->address[0], sizeof(in6_addr)); |
| 96 talk_base::IPAddress ip6_addr(address); | 92 talk_base::IPAddress ip6_addr(address); |
| 97 if (!talk_base::IPIsPrivate(ip6_addr)) { | 93 if (!talk_base::IPIsPrivate(ip6_addr)) { |
| 98 talk_base::Network* network = new talk_base::Network( | 94 talk_base::Network* network = new talk_base::Network( |
| 99 it->name, it->name, ip6_addr, 64, | 95 it->name, it->name, ip6_addr, 64, |
| 100 ConvertConnectionTypeToAdapterType(it->type)); | 96 ConvertConnectionTypeToAdapterType(it->type)); |
| 101 network->AddIP(ip6_addr); | 97 network->AddIP(ip6_addr); |
| 102 networks.push_back(network); | 98 networks.push_back(network); |
| 103 ++ipv6_interfaces; | |
| 104 } | 99 } |
| 105 } | 100 } |
| 106 } | 101 } |
| 107 | 102 |
| 108 if (ipv4_interfaces > 0) { | |
| 109 UMA_HISTOGRAM_COUNTS_100("WebRTC.PeerConnection.IPv4Interfaces", | |
| 110 ipv4_interfaces); | |
| 111 } | |
| 112 | |
| 113 if (ipv6_interfaces > 0) { | |
| 114 UMA_HISTOGRAM_COUNTS_100("WebRTC.PeerConnection.IPv6Interfaces", | |
| 115 ipv6_interfaces); | |
| 116 } | |
| 117 | |
| 118 if (CommandLine::ForCurrentProcess()->HasSwitch( | 103 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 119 switches::kAllowLoopbackInPeerConnection)) { | 104 switches::kAllowLoopbackInPeerConnection)) { |
| 120 std::string name_v4("loopback_ipv4"); | 105 std::string name_v4("loopback_ipv4"); |
| 121 talk_base::IPAddress ip_address_v4(INADDR_LOOPBACK); | 106 talk_base::IPAddress ip_address_v4(INADDR_LOOPBACK); |
| 122 talk_base::Network* network_v4 = new talk_base::Network( | 107 talk_base::Network* network_v4 = new talk_base::Network( |
| 123 name_v4, name_v4, ip_address_v4, 32, talk_base::ADAPTER_TYPE_UNKNOWN); | 108 name_v4, name_v4, ip_address_v4, 32, talk_base::ADAPTER_TYPE_UNKNOWN); |
| 124 network_v4->AddIP(ip_address_v4); | 109 network_v4->AddIP(ip_address_v4); |
| 125 networks.push_back(network_v4); | 110 networks.push_back(network_v4); |
| 126 | 111 |
| 127 std::string name_v6("loopback_ipv6"); | 112 std::string name_v6("loopback_ipv6"); |
| 128 talk_base::IPAddress ip_address_v6(in6addr_loopback); | 113 talk_base::IPAddress ip_address_v6(in6addr_loopback); |
| 129 talk_base::Network* network_v6 = new talk_base::Network( | 114 talk_base::Network* network_v6 = new talk_base::Network( |
| 130 name_v6, name_v6, ip_address_v6, 64, talk_base::ADAPTER_TYPE_UNKNOWN); | 115 name_v6, name_v6, ip_address_v6, 64, talk_base::ADAPTER_TYPE_UNKNOWN); |
| 131 network_v6->AddIP(ip_address_v6); | 116 network_v6->AddIP(ip_address_v6); |
| 132 networks.push_back(network_v6); | 117 networks.push_back(network_v6); |
| 133 } | 118 } |
| 134 | 119 |
| 135 bool changed = false; | 120 bool changed = false; |
| 136 MergeNetworkList(networks, &changed); | 121 MergeNetworkList(networks, &changed); |
| 137 if (changed) | 122 if (changed) |
| 138 SignalNetworksChanged(); | 123 SignalNetworksChanged(); |
| 139 } | 124 } |
| 140 | 125 |
| 141 void IpcNetworkManager::SendNetworksChangedSignal() { | 126 void IpcNetworkManager::SendNetworksChangedSignal() { |
| 142 SignalNetworksChanged(); | 127 SignalNetworksChanged(); |
| 143 } | 128 } |
| 144 | 129 |
| 145 } // namespace content | 130 } // namespace content |
| OLD | NEW |