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

Side by Side Diff: net/base/address_tracker_linux.h

Issue 1884453002: Revert of Convert //net and //chromecast to std::unordered_* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « net/android/network_change_notifier_android.cc ('k') | net/base/address_tracker_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef NET_BASE_ADDRESS_TRACKER_LINUX_H_ 5 #ifndef NET_BASE_ADDRESS_TRACKER_LINUX_H_
6 #define NET_BASE_ADDRESS_TRACKER_LINUX_H_ 6 #define NET_BASE_ADDRESS_TRACKER_LINUX_H_
7 7
8 #include <sys/socket.h> // Needed to include netlink. 8 #include <sys/socket.h> // Needed to include netlink.
9 // Mask superfluous definition of |struct net|. This is fixed in Linux 2.6.38. 9 // Mask superfluous definition of |struct net|. This is fixed in Linux 2.6.38.
10 #define net net_kernel 10 #define net net_kernel
11 #include <linux/rtnetlink.h> 11 #include <linux/rtnetlink.h>
12 #undef net 12 #undef net
13 #include <stddef.h> 13 #include <stddef.h>
14 14
15 #include <map> 15 #include <map>
16 #include <unordered_set>
17 16
18 #include "base/callback.h" 17 #include "base/callback.h"
19 #include "base/compiler_specific.h" 18 #include "base/compiler_specific.h"
19 #include "base/containers/hash_tables.h"
20 #include "base/macros.h" 20 #include "base/macros.h"
21 #include "base/message_loop/message_loop.h" 21 #include "base/message_loop/message_loop.h"
22 #include "base/synchronization/condition_variable.h" 22 #include "base/synchronization/condition_variable.h"
23 #include "base/synchronization/lock.h" 23 #include "base/synchronization/lock.h"
24 #include "base/threading/thread_checker.h" 24 #include "base/threading/thread_checker.h"
25 #include "net/base/ip_address.h" 25 #include "net/base/ip_address.h"
26 #include "net/base/network_change_notifier.h" 26 #include "net/base/network_change_notifier.h"
27 27
28 namespace net { 28 namespace net {
29 namespace internal { 29 namespace internal {
(...skipping 14 matching lines...) Expand all
44 // Tracking version constructor: it will run |address_callback| when 44 // Tracking version constructor: it will run |address_callback| when
45 // the AddressMap changes, |link_callback| when the list of online 45 // the AddressMap changes, |link_callback| when the list of online
46 // links changes, and |tunnel_callback| when the list of online 46 // links changes, and |tunnel_callback| when the list of online
47 // tunnels changes. 47 // tunnels changes.
48 // |ignored_interfaces| is the list of interfaces to ignore. Changes to an 48 // |ignored_interfaces| is the list of interfaces to ignore. Changes to an
49 // ignored interface will not cause any callback to be run. An ignored 49 // ignored interface will not cause any callback to be run. An ignored
50 // interface will not have entries in GetAddressMap() and GetOnlineLinks(). 50 // interface will not have entries in GetAddressMap() and GetOnlineLinks().
51 // NOTE: Only ignore interfaces not used to connect to the internet. Adding 51 // NOTE: Only ignore interfaces not used to connect to the internet. Adding
52 // interfaces used to connect to the internet can cause critical network 52 // interfaces used to connect to the internet can cause critical network
53 // changed signals to be lost allowing incorrect stale state to persist. 53 // changed signals to be lost allowing incorrect stale state to persist.
54 AddressTrackerLinux( 54 AddressTrackerLinux(const base::Closure& address_callback,
55 const base::Closure& address_callback, 55 const base::Closure& link_callback,
56 const base::Closure& link_callback, 56 const base::Closure& tunnel_callback,
57 const base::Closure& tunnel_callback, 57 const base::hash_set<std::string>& ignored_interfaces);
58 const std::unordered_set<std::string>& ignored_interfaces);
59 ~AddressTrackerLinux() override; 58 ~AddressTrackerLinux() override;
60 59
61 // In tracking mode, it starts watching the system configuration for 60 // In tracking mode, it starts watching the system configuration for
62 // changes. The current thread must have a MessageLoopForIO. In 61 // changes. The current thread must have a MessageLoopForIO. In
63 // non-tracking mode, once Init() returns, a snapshot of the system 62 // non-tracking mode, once Init() returns, a snapshot of the system
64 // configuration is available through GetOnlineLinks() and 63 // configuration is available through GetOnlineLinks() and
65 // GetAddressMap(). 64 // GetAddressMap().
66 void Init(); 65 void Init();
67 66
68 AddressMap GetAddressMap() const; 67 AddressMap GetAddressMap() const;
69 68
70 // Returns set of interface indicies for online interfaces. 69 // Returns set of interface indicies for online interfaces.
71 std::unordered_set<int> GetOnlineLinks() const; 70 base::hash_set<int> GetOnlineLinks() const;
72 71
73 // Implementation of NetworkChangeNotifierLinux::GetCurrentConnectionType(). 72 // Implementation of NetworkChangeNotifierLinux::GetCurrentConnectionType().
74 // Safe to call from any thread, but will block until Init() has completed. 73 // Safe to call from any thread, but will block until Init() has completed.
75 NetworkChangeNotifier::ConnectionType GetCurrentConnectionType(); 74 NetworkChangeNotifier::ConnectionType GetCurrentConnectionType();
76 75
77 // Returns the name for the interface with interface index |interface_index|. 76 // Returns the name for the interface with interface index |interface_index|.
78 // |buf| should be a pointer to an array of size IFNAMSIZ. The returned 77 // |buf| should be a pointer to an array of size IFNAMSIZ. The returned
79 // pointer will point to |buf|. This function acts like if_indextoname which 78 // pointer will point to |buf|. This function acts like if_indextoname which
80 // cannot be used as net/if.h cannot be mixed with linux/if.h. We'll stick 79 // cannot be used as net/if.h cannot be mixed with linux/if.h. We'll stick
81 // with exclusively talking to the kernel and not the C library. 80 // with exclusively talking to the kernel and not the C library.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 base::Closure tunnel_callback_; 153 base::Closure tunnel_callback_;
155 154
156 int netlink_fd_; 155 int netlink_fd_;
157 base::MessageLoopForIO::FileDescriptorWatcher watcher_; 156 base::MessageLoopForIO::FileDescriptorWatcher watcher_;
158 157
159 mutable base::Lock address_map_lock_; 158 mutable base::Lock address_map_lock_;
160 AddressMap address_map_; 159 AddressMap address_map_;
161 160
162 // Set of interface indices for links that are currently online. 161 // Set of interface indices for links that are currently online.
163 mutable base::Lock online_links_lock_; 162 mutable base::Lock online_links_lock_;
164 std::unordered_set<int> online_links_; 163 base::hash_set<int> online_links_;
165 164
166 // Set of interface names that should be ignored. 165 // Set of interface names that should be ignored.
167 const std::unordered_set<std::string> ignored_interfaces_; 166 const base::hash_set<std::string> ignored_interfaces_;
168 167
169 base::Lock connection_type_lock_; 168 base::Lock connection_type_lock_;
170 bool connection_type_initialized_; 169 bool connection_type_initialized_;
171 base::ConditionVariable connection_type_initialized_cv_; 170 base::ConditionVariable connection_type_initialized_cv_;
172 NetworkChangeNotifier::ConnectionType current_connection_type_; 171 NetworkChangeNotifier::ConnectionType current_connection_type_;
173 bool tracking_; 172 bool tracking_;
174 int threads_waiting_for_connection_type_initialization_; 173 int threads_waiting_for_connection_type_initialization_;
175 174
176 // Used to verify single-threaded access in non-tracking mode. 175 // Used to verify single-threaded access in non-tracking mode.
177 base::ThreadChecker thread_checker_; 176 base::ThreadChecker thread_checker_;
178 }; 177 };
179 178
180 } // namespace internal 179 } // namespace internal
181 } // namespace net 180 } // namespace net
182 181
183 #endif // NET_BASE_ADDRESS_TRACKER_LINUX_H_ 182 #endif // NET_BASE_ADDRESS_TRACKER_LINUX_H_
OLDNEW
« no previous file with comments | « net/android/network_change_notifier_android.cc ('k') | net/base/address_tracker_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698