diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-19 18:44:58 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-19 18:44:58 +0000 |
commit | 6d603aab761645693dbf88cfe12c1964c7920ad2 (patch) | |
tree | 4e2494978df12617d574fef7930f80582aa22463 /net/base/network_change_notifier_linux.h | |
parent | 3a38fe9996db9d25c0c44ee68afdb2620c50b6b1 (diff) | |
download | chromium_src-6d603aab761645693dbf88cfe12c1964c7920ad2.zip chromium_src-6d603aab761645693dbf88cfe12c1964c7920ad2.tar.gz chromium_src-6d603aab761645693dbf88cfe12c1964c7920ad2.tar.bz2 |
Re-lands r39417: "Implement NetworkChangeNotifierLinux."
The change broke certain linux buildbots due to netlink.h forward declaring struct net, which conflicts with the net namespace. The fix is to move the netlink code into a separate file which is not in the net namespace.
Review URL: http://codereview.chromium.org/650009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39465 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/network_change_notifier_linux.h')
-rw-r--r-- | net/base/network_change_notifier_linux.h | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/net/base/network_change_notifier_linux.h b/net/base/network_change_notifier_linux.h index 78111c9..323ea55 100644 --- a/net/base/network_change_notifier_linux.h +++ b/net/base/network_change_notifier_linux.h @@ -6,14 +6,18 @@ #define NET_BASE_NETWORK_CHANGE_NOTIFIER_LINUX_H_ #include "base/basictypes.h" +#include "base/message_loop.h" #include "net/base/network_change_notifier_helper.h" namespace net { -class NetworkChangeNotifierLinux : public NetworkChangeNotifier { +class NetworkChangeNotifierLinux + : public NetworkChangeNotifier, public MessageLoopForIO::Watcher { public: NetworkChangeNotifierLinux(); + // NetworkChangeNotifier methods: + virtual void AddObserver(Observer* observer) { helper_.AddObserver(observer); } @@ -22,13 +26,32 @@ class NetworkChangeNotifierLinux : public NetworkChangeNotifier { helper_.RemoveObserver(observer); } + // MessageLoopForIO::Watcher methods: + + virtual void OnFileCanReadWithoutBlocking(int fd); + virtual void OnFileCanWriteWithoutBlocking(int /* fd */); + private: virtual ~NetworkChangeNotifierLinux(); - void OnIPAddressChanged() { helper_.OnIPAddressChanged(); } + // Starts listening for netlink messages. Also handles the messages if there + // are any available on the netlink socket. + void ListenForNotifications(); + + // Attempts to read from the netlink socket into |buf| of length |len|. + // Returns the bytes read on synchronous success and ERR_IO_PENDING if the + // recv() would block. Otherwise, it returns a net error code. + int ReadNotificationMessage(char* buf, size_t len); + + // Handles the netlink message and notifies the observers. + void HandleNotifications(const char* buf, size_t len); internal::NetworkChangeNotifierHelper helper_; + int netlink_fd_; // This is the netlink socket descriptor. + MessageLoopForIO* const loop_; + MessageLoopForIO::FileDescriptorWatcher netlink_watcher_; + DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierLinux); }; |