Chromium Code Reviews| 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 #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 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 | 58 |
| 59 AddressMap GetAddressMap() const; | 59 AddressMap GetAddressMap() const; |
| 60 | 60 |
| 61 // Returns set of interface indicies for online interfaces. | 61 // Returns set of interface indicies for online interfaces. |
| 62 base::hash_set<int> GetOnlineLinks() const; | 62 base::hash_set<int> GetOnlineLinks() const; |
| 63 | 63 |
| 64 // Implementation of NetworkChangeNotifierLinux::GetCurrentConnectionType(). | 64 // Implementation of NetworkChangeNotifierLinux::GetCurrentConnectionType(). |
| 65 // Safe to call from any thread, but will block until Init() has completed. | 65 // Safe to call from any thread, but will block until Init() has completed. |
| 66 NetworkChangeNotifier::ConnectionType GetCurrentConnectionType(); | 66 NetworkChangeNotifier::ConnectionType GetCurrentConnectionType(); |
| 67 | 67 |
| 68 // Adds/removes a netif name to ignore. Returns true if success. | |
| 69 bool AddNetifToIgnore(const std::string& netif_name); | |
| 70 bool RemoveNetifToIgnore(const std::string& netif_name); | |
| 71 | |
| 72 bool GetNetworkList(NetworkInterfaceList* networks, int policy) const; | |
|
pauljensen
2014/11/21 18:55:36
This API is exposed in net_util.h and should not b
derekjchow1
2014/11/21 23:13:58
Done.
| |
| 73 std::string GetPrimaryNetif() const; | |
|
pauljensen
2014/11/21 18:55:36
This cannot be accurate as there may be multiple i
derekjchow1
2014/11/21 23:13:58
What should the correct behavior of NetworkChangeN
pauljensen
2014/11/24 12:33:18
The correct behavior of NetworkChangeNotifier::Get
| |
| 74 | |
| 68 private: | 75 private: |
| 69 friend class AddressTrackerLinuxTest; | 76 friend class AddressTrackerLinuxTest; |
| 70 | 77 |
| 71 // In tracking mode, holds |lock| while alive. In non-tracking mode, | 78 // In tracking mode, holds |lock| while alive. In non-tracking mode, |
| 72 // enforces single-threaded access. | 79 // enforces single-threaded access. |
| 73 class AddressTrackerAutoLock { | 80 class AddressTrackerAutoLock { |
| 74 public: | 81 public: |
| 75 AddressTrackerAutoLock(const AddressTrackerLinux& tracker, | 82 AddressTrackerAutoLock(const AddressTrackerLinux& tracker, |
| 76 base::Lock& lock); | 83 base::Lock& lock); |
| 77 ~AddressTrackerAutoLock(); | 84 ~AddressTrackerAutoLock(); |
| 78 | 85 |
| 79 private: | 86 private: |
| 80 const AddressTrackerLinux& tracker_; | 87 const AddressTrackerLinux& tracker_; |
| 81 base::Lock& lock_; | 88 base::Lock& lock_; |
| 82 DISALLOW_COPY_AND_ASSIGN(AddressTrackerAutoLock); | 89 DISALLOW_COPY_AND_ASSIGN(AddressTrackerAutoLock); |
| 83 }; | 90 }; |
| 84 | 91 |
| 85 // A function that returns the name of an interface given the interface index | 92 // A function that returns the name of an interface given the interface index |
| 86 // in |interface_index|. | 93 // in |interface_index|. |
| 87 typedef const char* (*GetInterfaceNameFunction)(int interface_index); | 94 typedef char* (*GetInterfaceNameFunction)(unsigned int interface_index, |
| 88 | 95 char* ifname); |
| 89 // Sets |*address_changed| to indicate whether |address_map_| changed and | 96 // Sets |*address_changed| to indicate whether |address_map_| changed and |
| 90 // sets |*link_changed| to indicate if |online_links_| changed and sets | 97 // sets |*link_changed| to indicate if |online_links_| changed and sets |
| 91 // |*tunnel_changed| to indicate if |online_links_| changed with regards to a | 98 // |*tunnel_changed| to indicate if |online_links_| changed with regards to a |
| 92 // tunnel interface while reading messages from |netlink_fd_|. | 99 // tunnel interface while reading messages from |netlink_fd_|. |
| 93 void ReadMessages(bool* address_changed, | 100 void ReadMessages(bool* address_changed, |
| 94 bool* link_changed, | 101 bool* link_changed, |
| 95 bool* tunnel_changed); | 102 bool* tunnel_changed); |
| 96 | 103 |
| 97 // Sets |*address_changed| to true if |address_map_| changed, sets | 104 // Sets |*address_changed| to true if |address_map_| changed, sets |
| 98 // |*link_changed| to true if |online_links_| changed, sets |*tunnel_changed| | 105 // |*link_changed| to true if |online_links_| changed, sets |*tunnel_changed| |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 125 base::Closure address_callback_; | 132 base::Closure address_callback_; |
| 126 base::Closure link_callback_; | 133 base::Closure link_callback_; |
| 127 base::Closure tunnel_callback_; | 134 base::Closure tunnel_callback_; |
| 128 | 135 |
| 129 int netlink_fd_; | 136 int netlink_fd_; |
| 130 base::MessageLoopForIO::FileDescriptorWatcher watcher_; | 137 base::MessageLoopForIO::FileDescriptorWatcher watcher_; |
| 131 | 138 |
| 132 mutable base::Lock address_map_lock_; | 139 mutable base::Lock address_map_lock_; |
| 133 AddressMap address_map_; | 140 AddressMap address_map_; |
| 134 | 141 |
| 142 base::hash_set<std::string> netifs_to_ignore_; | |
| 143 | |
| 135 // Set of interface indices for links that are currently online. | 144 // Set of interface indices for links that are currently online. |
| 136 mutable base::Lock online_links_lock_; | 145 mutable base::Lock online_links_lock_; |
| 137 base::hash_set<int> online_links_; | 146 base::hash_set<int> online_links_; |
| 138 | 147 |
| 139 base::Lock is_offline_lock_; | 148 base::Lock is_offline_lock_; |
| 140 bool is_offline_; | 149 bool is_offline_; |
| 141 bool is_offline_initialized_; | 150 bool is_offline_initialized_; |
| 142 base::ConditionVariable is_offline_initialized_cv_; | 151 base::ConditionVariable is_offline_initialized_cv_; |
| 143 bool tracking_; | 152 bool tracking_; |
| 144 | 153 |
| 145 // Used to verify single-threaded access in non-tracking mode. | 154 // Used to verify single-threaded access in non-tracking mode. |
| 146 base::ThreadChecker thread_checker_; | 155 base::ThreadChecker thread_checker_; |
| 147 }; | 156 }; |
| 148 | 157 |
| 149 } // namespace internal | 158 } // namespace internal |
| 150 } // namespace net | 159 } // namespace net |
| 151 | 160 |
| 152 #endif // NET_BASE_ADDRESS_TRACKER_LINUX_H_ | 161 #endif // NET_BASE_ADDRESS_TRACKER_LINUX_H_ |
| OLD | NEW |