Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(575)

Side by Side Diff: webrtc/base/network.h

Issue 1391703003: Create network change notifier. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Minor fix on the comment Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 NetworkChangeNotifier;
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
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
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
226 // Creates the network change notifier and starts to listen to the update.
227 void StartNetworkChangeNotifier();
228 // Removes the network change notifier.
229 void StopNetworkChangeNotifier();
230 // Called when it receives the update from the network change notifier.
231 void OnNetworkChangeNotified();
232
233 // Updates the network and reschedule the next update.
234 void UpdateNetworks();
235 // Only updates the network; do not reschedule the next update.
pthatcher1 2015/10/09 23:11:29 do not => does not
honghaiz3 2015/10/13 23:19:56 Done.
225 void DoUpdateNetworks(); 236 void DoUpdateNetworks();
pthatcher1 2015/10/09 23:11:29 I think a better name pair would be UpdateNetworks
honghaiz3 2015/10/13 23:19:56 Done.
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<NetworkChangeNotifier> network_change_notifier_;
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
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_
OLDNEW
« no previous file with comments | « webrtc/base/base.gyp ('k') | webrtc/base/network.cc » ('j') | webrtc/base/network.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698