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/metrics/histogram.h" |
10 #include "base/sys_byteorder.h" | 10 #include "base/sys_byteorder.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 case net::NetworkChangeNotifier::CONNECTION_3G: | 28 case net::NetworkChangeNotifier::CONNECTION_3G: |
29 case net::NetworkChangeNotifier::CONNECTION_4G: | 29 case net::NetworkChangeNotifier::CONNECTION_4G: |
30 return rtc::ADAPTER_TYPE_CELLULAR; | 30 return rtc::ADAPTER_TYPE_CELLULAR; |
31 default: | 31 default: |
32 return rtc::ADAPTER_TYPE_UNKNOWN; | 32 return rtc::ADAPTER_TYPE_UNKNOWN; |
33 } | 33 } |
34 } | 34 } |
35 | 35 |
36 } // namespace | 36 } // namespace |
37 | 37 |
38 IpcNetworkManager::IpcNetworkManager(P2PSocketDispatcher* socket_dispatcher) | 38 IpcNetworkManager::IpcNetworkManager( |
| 39 P2PSocketDispatcherInterface* socket_dispatcher) |
39 : socket_dispatcher_(socket_dispatcher), | 40 : socket_dispatcher_(socket_dispatcher), |
40 start_count_(0), | 41 start_count_(0), |
41 network_list_received_(false), | 42 network_list_received_(false), |
42 weak_factory_(this) { | 43 weak_factory_(this) { |
43 socket_dispatcher_->AddNetworkListObserver(this); | 44 socket_dispatcher_->AddNetworkListObserver(this); |
44 } | 45 } |
45 | 46 |
46 IpcNetworkManager::~IpcNetworkManager() { | 47 IpcNetworkManager::~IpcNetworkManager() { |
47 DCHECK(!start_count_); | 48 DCHECK(!start_count_); |
48 socket_dispatcher_->RemoveNetworkListObserver(this); | 49 socket_dispatcher_->RemoveNetworkListObserver(this); |
(...skipping 15 matching lines...) Expand all Loading... |
64 --start_count_; | 65 --start_count_; |
65 } | 66 } |
66 | 67 |
67 void IpcNetworkManager::OnNetworkListChanged( | 68 void IpcNetworkManager::OnNetworkListChanged( |
68 const net::NetworkInterfaceList& list) { | 69 const net::NetworkInterfaceList& list) { |
69 | 70 |
70 // Update flag if network list received for the first time. | 71 // Update flag if network list received for the first time. |
71 if (!network_list_received_) | 72 if (!network_list_received_) |
72 network_list_received_ = true; | 73 network_list_received_ = true; |
73 | 74 |
74 // Note: 32 and 64 are the arbitrary(kind of) prefix length used to | |
75 // differentiate IPv4 and IPv6 addresses. | |
76 // rtc::Network uses these prefix_length to compare network | 75 // rtc::Network uses these prefix_length to compare network |
77 // interfaces discovered. | 76 // interfaces discovered. |
78 std::vector<rtc::Network*> networks; | 77 std::vector<rtc::Network*> networks; |
79 int ipv4_interfaces = 0; | 78 int ipv4_interfaces = 0; |
80 int ipv6_interfaces = 0; | 79 int ipv6_interfaces = 0; |
81 for (net::NetworkInterfaceList::const_iterator it = list.begin(); | 80 for (net::NetworkInterfaceList::const_iterator it = list.begin(); |
82 it != list.end(); it++) { | 81 it != list.end(); it++) { |
83 if (it->address.size() == net::kIPv4AddressSize) { | 82 if (it->address.size() == net::kIPv4AddressSize) { |
84 uint32 address; | 83 uint32 address; |
85 memcpy(&address, &it->address[0], sizeof(uint32)); | 84 memcpy(&address, &it->address[0], sizeof(uint32)); |
86 address = rtc::NetworkToHost32(address); | 85 address = rtc::NetworkToHost32(address); |
| 86 rtc::IPAddress prefix = rtc::TruncateIP(rtc::IPAddress(address), |
| 87 it->network_prefix); |
87 rtc::Network* network = new rtc::Network( | 88 rtc::Network* network = new rtc::Network( |
88 it->name, it->name, rtc::IPAddress(address), 32, | 89 it->name, it->name, prefix, it->network_prefix, |
89 ConvertConnectionTypeToAdapterType(it->type)); | 90 ConvertConnectionTypeToAdapterType(it->type)); |
90 network->AddIP(rtc::IPAddress(address)); | 91 network->AddIP(rtc::IPAddress(address)); |
91 networks.push_back(network); | 92 networks.push_back(network); |
92 ++ipv4_interfaces; | 93 ++ipv4_interfaces; |
93 } else if (it->address.size() == net::kIPv6AddressSize) { | 94 } else if (it->address.size() == net::kIPv6AddressSize) { |
94 in6_addr address; | 95 in6_addr address; |
95 memcpy(&address, &it->address[0], sizeof(in6_addr)); | 96 memcpy(&address, &it->address[0], sizeof(in6_addr)); |
96 rtc::IPAddress ip6_addr(address); | 97 rtc::IPAddress ip6_addr(address); |
97 if (!rtc::IPIsPrivate(ip6_addr)) { | 98 if (!rtc::IPIsPrivate(ip6_addr)) { |
| 99 rtc::IPAddress prefix = rtc::TruncateIP(rtc::IPAddress(ip6_addr), |
| 100 it->network_prefix); |
98 rtc::Network* network = new rtc::Network( | 101 rtc::Network* network = new rtc::Network( |
99 it->name, it->name, ip6_addr, 64, | 102 it->name, it->name, prefix, it->network_prefix, |
100 ConvertConnectionTypeToAdapterType(it->type)); | 103 ConvertConnectionTypeToAdapterType(it->type)); |
101 network->AddIP(ip6_addr); | 104 network->AddIP(ip6_addr); |
102 networks.push_back(network); | 105 networks.push_back(network); |
103 ++ipv6_interfaces; | 106 ++ipv6_interfaces; |
104 } | 107 } |
105 } | 108 } |
106 } | 109 } |
107 | 110 |
108 | 111 |
109 // Send interface counts to UMA. | 112 // Send interface counts to UMA. |
(...skipping 23 matching lines...) Expand all Loading... |
133 MergeNetworkList(networks, &changed); | 136 MergeNetworkList(networks, &changed); |
134 if (changed) | 137 if (changed) |
135 SignalNetworksChanged(); | 138 SignalNetworksChanged(); |
136 } | 139 } |
137 | 140 |
138 void IpcNetworkManager::SendNetworksChangedSignal() { | 141 void IpcNetworkManager::SendNetworksChangedSignal() { |
139 SignalNetworksChanged(); | 142 SignalNetworksChanged(); |
140 } | 143 } |
141 | 144 |
142 } // namespace content | 145 } // namespace content |
OLD | NEW |