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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 base::Lock& lock); | 76 base::Lock& lock); |
| 77 ~AddressTrackerAutoLock(); | 77 ~AddressTrackerAutoLock(); |
| 78 | 78 |
| 79 private: | 79 private: |
| 80 const AddressTrackerLinux& tracker_; | 80 const AddressTrackerLinux& tracker_; |
| 81 base::Lock& lock_; | 81 base::Lock& lock_; |
| 82 DISALLOW_COPY_AND_ASSIGN(AddressTrackerAutoLock); | 82 DISALLOW_COPY_AND_ASSIGN(AddressTrackerAutoLock); |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 // A function that returns the name of an interface given the interface index | 85 // A function that returns the name of an interface given the interface index |
| 86 // in |interface_index|. | 86 // in |interface_index|. |
|
pauljensen
2015/01/13 13:14:29
Please explain |ifname| argument. e.g. what size s
derekjchow1
2015/01/13 21:32:35
Done.
| |
| 87 typedef const char* (*GetInterfaceNameFunction)(int interface_index); | 87 typedef char* (*GetInterfaceNameFunction)(unsigned int interface_index, |
| 88 | 88 char* ifname); |
| 89 // Sets |*address_changed| to indicate whether |address_map_| changed and | 89 // Sets |*address_changed| to indicate whether |address_map_| changed and |
| 90 // sets |*link_changed| to indicate if |online_links_| changed and sets | 90 // sets |*link_changed| to indicate if |online_links_| changed and sets |
| 91 // |*tunnel_changed| to indicate if |online_links_| changed with regards to a | 91 // |*tunnel_changed| to indicate if |online_links_| changed with regards to a |
| 92 // tunnel interface while reading messages from |netlink_fd_|. | 92 // tunnel interface while reading messages from |netlink_fd_|. |
| 93 void ReadMessages(bool* address_changed, | 93 void ReadMessages(bool* address_changed, |
| 94 bool* link_changed, | 94 bool* link_changed, |
| 95 bool* tunnel_changed); | 95 bool* tunnel_changed); |
| 96 | 96 |
| 97 // Sets |*address_changed| to true if |address_map_| changed, sets | 97 // Sets |*address_changed| to true if |address_map_| changed, sets |
| 98 // |*link_changed| to true if |online_links_| changed, sets |*tunnel_changed| | 98 // |*link_changed| to true if |online_links_| changed, sets |*tunnel_changed| |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 110 // MessageLoopForIO::Watcher: | 110 // MessageLoopForIO::Watcher: |
| 111 void OnFileCanReadWithoutBlocking(int fd) override; | 111 void OnFileCanReadWithoutBlocking(int fd) override; |
| 112 void OnFileCanWriteWithoutBlocking(int /* fd */) override; | 112 void OnFileCanWriteWithoutBlocking(int /* fd */) override; |
| 113 | 113 |
| 114 // Close |netlink_fd_| | 114 // Close |netlink_fd_| |
| 115 void CloseSocket(); | 115 void CloseSocket(); |
| 116 | 116 |
| 117 // Does |msg| refer to a tunnel interface? | 117 // Does |msg| refer to a tunnel interface? |
| 118 bool IsTunnelInterface(const struct ifinfomsg* msg) const; | 118 bool IsTunnelInterface(const struct ifinfomsg* msg) const; |
| 119 | 119 |
| 120 // Gets the current connection type from online_links_. Returns | |
| 121 // CONNECTION_UNKNOWN if two interfaces have different connection types. | |
| 122 NetworkChangeNotifier::ConnectionType GetNewConnectionType(); | |
|
pauljensen
2015/01/13 13:14:30
I think "New" in the name is confusing, can we rep
derekjchow1
2015/01/13 21:32:35
I changed the function to UpdateCurrentConnectionT
| |
| 123 | |
| 120 // Gets the name of an interface given the interface index |interface_index|. | 124 // Gets the name of an interface given the interface index |interface_index|. |
| 121 // May return empty string if it fails but should not return NULL. This is | 125 // May return empty string if it fails but should not return NULL. This is |
| 122 // overridden by tests. | 126 // overridden by tests. |
| 123 GetInterfaceNameFunction get_interface_name_; | 127 GetInterfaceNameFunction get_interface_name_; |
| 124 | 128 |
| 125 base::Closure address_callback_; | 129 base::Closure address_callback_; |
| 126 base::Closure link_callback_; | 130 base::Closure link_callback_; |
| 127 base::Closure tunnel_callback_; | 131 base::Closure tunnel_callback_; |
| 128 | 132 |
| 129 int netlink_fd_; | 133 int netlink_fd_; |
| 130 base::MessageLoopForIO::FileDescriptorWatcher watcher_; | 134 base::MessageLoopForIO::FileDescriptorWatcher watcher_; |
| 131 | 135 |
| 132 mutable base::Lock address_map_lock_; | 136 mutable base::Lock address_map_lock_; |
| 133 AddressMap address_map_; | 137 AddressMap address_map_; |
| 134 | 138 |
| 135 // Set of interface indices for links that are currently online. | 139 // Set of interface indices for links that are currently online. |
| 136 mutable base::Lock online_links_lock_; | 140 mutable base::Lock online_links_lock_; |
| 137 base::hash_set<int> online_links_; | 141 base::hash_set<int> online_links_; |
| 138 | 142 |
| 139 base::Lock is_offline_lock_; | 143 base::Lock connection_type_lock_; |
| 140 bool is_offline_; | 144 bool is_initialized_; |
|
pauljensen
2015/01/13 13:14:30
Can you rename this to be more precise? i.e. is_c
derekjchow1
2015/01/13 21:32:35
Done.
| |
| 141 bool is_offline_initialized_; | 145 base::ConditionVariable is_initialized_cv_; |
|
pauljensen
2015/01/13 13:14:29
Ditto.
derekjchow1
2015/01/13 21:32:35
Done.
| |
| 142 base::ConditionVariable is_offline_initialized_cv_; | 146 NetworkChangeNotifier::ConnectionType current_connection_type_; |
| 143 bool tracking_; | 147 bool tracking_; |
| 144 | 148 |
| 145 // Used to verify single-threaded access in non-tracking mode. | 149 // Used to verify single-threaded access in non-tracking mode. |
| 146 base::ThreadChecker thread_checker_; | 150 base::ThreadChecker thread_checker_; |
| 147 }; | 151 }; |
| 148 | 152 |
| 149 } // namespace internal | 153 } // namespace internal |
| 150 } // namespace net | 154 } // namespace net |
| 151 | 155 |
| 152 #endif // NET_BASE_ADDRESS_TRACKER_LINUX_H_ | 156 #endif // NET_BASE_ADDRESS_TRACKER_LINUX_H_ |
| OLD | NEW |