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