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

Unified Diff: net/base/address_tracker_linux.h

Issue 10689015: [net] Adds AddressTrackerLinux which keeps track of interface addresses using rtnetlink. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added explicit to ctor. Created 8 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/base/address_tracker_linux.cc » ('j') | net/base/address_tracker_linux.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/address_tracker_linux.h
diff --git a/net/base/address_tracker_linux.h b/net/base/address_tracker_linux.h
new file mode 100644
index 0000000000000000000000000000000000000000..a6675ae2560cd5fc938fc7325d8d4e3c65d4d973
--- /dev/null
+++ b/net/base/address_tracker_linux.h
@@ -0,0 +1,64 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_BASE_ADDRESS_TRACKER_LINUX_H_
+#define NET_BASE_ADDRESS_TRACKER_LINUX_H_
+#pragma once
+
+#include <sys/socket.h> // Needed to include netlink.
+// Mask superfluous definition of |struct net|. This is fixed in Linux 2.6.38.
+#define net net_kernel
+#include <linux/rtnetlink.h>
+#undef net
+
+#include <map>
+
+#include "base/basictypes.h"
+#include "base/callback.h"
+#include "base/message_loop.h"
+#include "base/synchronization/lock.h"
+#include "net/base/net_util.h"
+
+namespace net {
+namespace internal {
+
+// Keeps track of network interface addresses using rtnetlink. Used by
+// NetworkChangeNotifier to provide signals to registered IPAddressObservers.
+class AddressTrackerLinux : public MessageLoopForIO::Watcher {
+ public:
+ typedef std::map<IPAddressNumber, struct ifaddrmsg> AddressMap;
vandebo (ex-Chrome) 2012/06/29 22:24:29 It's not clear to me why the consumer wants the en
szym 2012/06/30 00:00:57 See: http://codereview.chromium.org/10442098/
+
+ // Will run |callback| when the AddressMap changes.
+ explicit AddressTrackerLinux(const base::Closure& callback);
+ virtual ~AddressTrackerLinux();
+
+ // Starts watching system configuration for changes. The current thread must
+ // have a MessageLoopForIO. The signals will be delivered directly to
vandebo (ex-Chrome) 2012/06/29 22:24:29 nit: comment out of date? Signals will be delivere
szym 2012/06/30 00:00:57 Right.
vandebo (ex-Chrome) 2012/07/12 18:34:26 Please update the comment.
szym 2012/07/12 18:55:47 Done.
+ // the global NetworkChangeNotifier.
+ void Init();
+
+ AddressMap GetMap() const;
vandebo (ex-Chrome) 2012/06/29 22:24:29 It seems that this method should be NetworkChangeN
szym 2012/06/30 00:00:57 Will change to GetAddressMap.
+
+ private:
+ // Returns true if |map_| changed while reading messages.
+ bool ReadMessages();
+ bool HandleMessage(char* buf, size_t len);
+
+ // MessageLoopForIO::Watcher:
+ virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
+ virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE;
+
+ base::Closure callback_;
+
+ int netlink_fd_;
+ MessageLoopForIO::FileDescriptorWatcher watcher_;
+
+ mutable base::Lock lock_;
+ AddressMap map_;
+};
+
+} // namespace internal
+} // namespace net
+
+#endif // NET_BASE_ADDRESS_TRACKER_LINUX_H_
« no previous file with comments | « no previous file | net/base/address_tracker_linux.cc » ('j') | net/base/address_tracker_linux.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698