summaryrefslogtreecommitdiffstats
path: root/net/base/address_tracker_linux.h
diff options
context:
space:
mode:
authorpauljensen@chromium.org <pauljensen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-29 17:11:55 +0000
committerpauljensen@chromium.org <pauljensen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-29 17:11:55 +0000
commitd3eada55f844f6c5a698f48ebc4a2197885b5135 (patch)
tree844cf611b9bdeadb7164516240e6f3074acb2c9d /net/base/address_tracker_linux.h
parentc46c2a993a37c4f2e7b69319abbbbbc63f7ba019 (diff)
downloadchromium_src-d3eada55f844f6c5a698f48ebc4a2197885b5135.zip
chromium_src-d3eada55f844f6c5a698f48ebc4a2197885b5135.tar.gz
chromium_src-d3eada55f844f6c5a698f48ebc4a2197885b5135.tar.bz2
Use Netlink instead of NetworkManager (via D-bus) to monitor network
connectivity on Linux. BUG=117973 Review URL: https://chromiumcodereview.appspot.com/11359141 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@170211 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/address_tracker_linux.h')
-rw-r--r--net/base/address_tracker_linux.h49
1 files changed, 40 insertions, 9 deletions
diff --git a/net/base/address_tracker_linux.h b/net/base/address_tracker_linux.h
index a70a14c..87ce139 100644
--- a/net/base/address_tracker_linux.h
+++ b/net/base/address_tracker_linux.h
@@ -16,9 +16,12 @@
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/compiler_specific.h"
+#include "base/hash_tables.h"
#include "base/message_loop.h"
+#include "base/synchronization/condition_variable.h"
#include "base/synchronization/lock.h"
#include "net/base/net_util.h"
+#include "net/base/network_change_notifier.h"
namespace net {
namespace internal {
@@ -30,8 +33,10 @@ class NET_EXPORT_PRIVATE AddressTrackerLinux
public:
typedef std::map<IPAddressNumber, struct ifaddrmsg> AddressMap;
- // Will run |callback| when the AddressMap changes.
- explicit AddressTrackerLinux(const base::Closure& callback);
+ // Will run |address_callback| when the AddressMap changes and will run
+ // |link_callback| when the list of online links changes.
+ AddressTrackerLinux(const base::Closure& address_callback,
+ const base::Closure& link_callback);
virtual ~AddressTrackerLinux();
// Starts watching system configuration for changes. The current thread must
@@ -40,26 +45,52 @@ class NET_EXPORT_PRIVATE AddressTrackerLinux
AddressMap GetAddressMap() const;
+ // Implementation of NetworkChangeNotifierLinux::GetCurrentConnectionType().
+ // Safe to call from any thread, but will block until Init() has completed.
+ NetworkChangeNotifier::ConnectionType GetCurrentConnectionType();
+
private:
friend class AddressTrackerLinuxTest;
- // Returns true if |map_| changed while reading messages from |netlink_fd_|.
- bool ReadMessages();
+ // Sets |*address_changed| to indicate whether |address_map_| changed and
+ // sets |*link_changed| to indicate if |online_links_| changed while reading
+ // messages from |netlink_fd_|.
+ void ReadMessages(bool* address_changed, bool* link_changed);
+
+ // Sets |*address_changed| to true if |address_map_| changed, sets
+ // |*link_changed| to true if |online_links_| changed while reading the
+ // message from |buffer|.
+ void HandleMessage(const char* buffer,
+ size_t length,
+ bool* address_changed,
+ bool* link_changed);
- // Returns true if |map_| changed while reading the message from |buffer|.
- bool HandleMessage(const char* buffer, size_t length);
+ // Call when some part of initialization failed; forces online and unblocks.
+ void AbortAndForceOnline();
// MessageLoopForIO::Watcher:
virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE;
- base::Closure callback_;
+ // Close |netlink_fd_|
+ void CloseSocket();
+
+ base::Closure address_callback_;
+ base::Closure link_callback_;
int netlink_fd_;
MessageLoopForIO::FileDescriptorWatcher watcher_;
- mutable base::Lock lock_;
- AddressMap map_;
+ mutable base::Lock address_map_lock_;
+ AddressMap address_map_;
+
+ // Set of interface indices for links that are currently online.
+ base::hash_set<int> online_links_;
+
+ base::Lock is_offline_lock_;
+ bool is_offline_;
+ bool is_offline_initialized_;
+ base::ConditionVariable is_offline_initialized_cv_;
};
} // namespace internal