OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "webrtc/base/scoped_ptr.h" | 22 #include "webrtc/base/scoped_ptr.h" |
23 #include "webrtc/base/sigslot.h" | 23 #include "webrtc/base/sigslot.h" |
24 | 24 |
25 #if defined(WEBRTC_POSIX) | 25 #if defined(WEBRTC_POSIX) |
26 struct ifaddrs; | 26 struct ifaddrs; |
27 #endif // defined(WEBRTC_POSIX) | 27 #endif // defined(WEBRTC_POSIX) |
28 | 28 |
29 namespace rtc { | 29 namespace rtc { |
30 | 30 |
31 class Network; | 31 class Network; |
| 32 class NetworkMonitorInterface; |
32 class Thread; | 33 class Thread; |
33 | 34 |
34 enum AdapterType { | 35 enum AdapterType { |
35 // This enum resembles the one in Chromium net::ConnectionType. | 36 // This enum resembles the one in Chromium net::ConnectionType. |
36 ADAPTER_TYPE_UNKNOWN = 0, | 37 ADAPTER_TYPE_UNKNOWN = 0, |
37 ADAPTER_TYPE_ETHERNET = 1 << 0, | 38 ADAPTER_TYPE_ETHERNET = 1 << 0, |
38 ADAPTER_TYPE_WIFI = 1 << 1, | 39 ADAPTER_TYPE_WIFI = 1 << 1, |
39 ADAPTER_TYPE_CELLULAR = 1 << 2, | 40 ADAPTER_TYPE_CELLULAR = 1 << 2, |
40 ADAPTER_TYPE_VPN = 1 << 3, | 41 ADAPTER_TYPE_VPN = 1 << 3, |
41 ADAPTER_TYPE_LOOPBACK = 1 << 4 | 42 ADAPTER_TYPE_LOOPBACK = 1 << 4 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 void MergeNetworkList(const NetworkList& list, | 141 void MergeNetworkList(const NetworkList& list, |
141 bool* changed, | 142 bool* changed, |
142 NetworkManager::Stats* stats); | 143 NetworkManager::Stats* stats); |
143 | 144 |
144 void set_enumeration_permission(EnumerationPermission state) { | 145 void set_enumeration_permission(EnumerationPermission state) { |
145 enumeration_permission_ = state; | 146 enumeration_permission_ = state; |
146 } | 147 } |
147 | 148 |
148 private: | 149 private: |
149 friend class NetworkTest; | 150 friend class NetworkTest; |
150 void DoUpdateNetworks(); | |
151 | 151 |
152 EnumerationPermission enumeration_permission_; | 152 EnumerationPermission enumeration_permission_; |
153 | 153 |
154 NetworkList networks_; | 154 NetworkList networks_; |
155 int max_ipv6_networks_; | 155 int max_ipv6_networks_; |
156 | 156 |
157 NetworkMap networks_map_; | 157 NetworkMap networks_map_; |
158 bool ipv6_enabled_; | 158 bool ipv6_enabled_; |
159 | 159 |
160 rtc::scoped_ptr<rtc::Network> ipv4_any_address_network_; | 160 rtc::scoped_ptr<rtc::Network> ipv4_any_address_network_; |
161 rtc::scoped_ptr<rtc::Network> ipv6_any_address_network_; | 161 rtc::scoped_ptr<rtc::Network> ipv6_any_address_network_; |
162 }; | 162 }; |
163 | 163 |
164 // Basic implementation of the NetworkManager interface that gets list | 164 // Basic implementation of the NetworkManager interface that gets list |
165 // of networks using OS APIs. | 165 // of networks using OS APIs. |
166 class BasicNetworkManager : public NetworkManagerBase, | 166 class BasicNetworkManager : public NetworkManagerBase, |
167 public MessageHandler { | 167 public MessageHandler, |
| 168 public sigslot::has_slots<> { |
168 public: | 169 public: |
169 BasicNetworkManager(); | 170 BasicNetworkManager(); |
170 ~BasicNetworkManager() override; | 171 ~BasicNetworkManager() override; |
171 | 172 |
172 void StartUpdating() override; | 173 void StartUpdating() override; |
173 void StopUpdating() override; | 174 void StopUpdating() override; |
174 | 175 |
175 // Logs the available networks. | 176 // Logs the available networks. |
176 void DumpNetworks(bool include_ignored) override; | 177 void DumpNetworks(bool include_ignored) override; |
177 | 178 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 // Creates a network object for each network available on the machine. | 216 // Creates a network object for each network available on the machine. |
216 bool CreateNetworks(bool include_ignored, NetworkList* networks) const; | 217 bool CreateNetworks(bool include_ignored, NetworkList* networks) const; |
217 | 218 |
218 // Determines if a network should be ignored. This should only be determined | 219 // Determines if a network should be ignored. This should only be determined |
219 // based on the network's property instead of any individual IP. | 220 // based on the network's property instead of any individual IP. |
220 bool IsIgnoredNetwork(const Network& network) const; | 221 bool IsIgnoredNetwork(const Network& network) const; |
221 | 222 |
222 private: | 223 private: |
223 friend class NetworkTest; | 224 friend class NetworkTest; |
224 | 225 |
225 void DoUpdateNetworks(); | 226 // Creates a network monitor and listens for network updates. |
| 227 void StartNetworkMonitor(); |
| 228 // Stops and removes the network monitor. |
| 229 void StopNetworkMonitor(); |
| 230 // Called when it receives updates from the network monitor. |
| 231 void OnNetworksChanged(); |
| 232 |
| 233 // Updates the networks and reschedules the next update. |
| 234 void UpdateNetworksContinually(); |
| 235 // Only updates the networks; does not reschedule the next update. |
| 236 void UpdateNetworksOnce(); |
226 | 237 |
227 Thread* thread_; | 238 Thread* thread_; |
228 bool sent_first_update_; | 239 bool sent_first_update_; |
229 int start_count_; | 240 int start_count_; |
230 std::vector<std::string> network_ignore_list_; | 241 std::vector<std::string> network_ignore_list_; |
231 int network_ignore_mask_; | 242 int network_ignore_mask_; |
232 bool ignore_non_default_routes_; | 243 bool ignore_non_default_routes_; |
| 244 scoped_ptr<NetworkMonitorInterface> network_monitor_; |
233 }; | 245 }; |
234 | 246 |
235 // Represents a Unix-type network interface, with a name and single address. | 247 // Represents a Unix-type network interface, with a name and single address. |
236 class Network { | 248 class Network { |
237 public: | 249 public: |
238 Network(const std::string& name, const std::string& description, | 250 Network(const std::string& name, const std::string& description, |
239 const IPAddress& prefix, int prefix_length); | 251 const IPAddress& prefix, int prefix_length); |
240 | 252 |
241 Network(const std::string& name, const std::string& description, | 253 Network(const std::string& name, const std::string& description, |
242 const IPAddress& prefix, int prefix_length, AdapterType type); | 254 const IPAddress& prefix, int prefix_length, AdapterType type); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 bool ignored_; | 333 bool ignored_; |
322 AdapterType type_; | 334 AdapterType type_; |
323 int preference_; | 335 int preference_; |
324 | 336 |
325 friend class NetworkManager; | 337 friend class NetworkManager; |
326 }; | 338 }; |
327 | 339 |
328 } // namespace rtc | 340 } // namespace rtc |
329 | 341 |
330 #endif // WEBRTC_BASE_NETWORK_H_ | 342 #endif // WEBRTC_BASE_NETWORK_H_ |
OLD | NEW |