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

Side by Side Diff: net/base/network_change_notifier_linux.h

Issue 2802015: Massively simplify the NetworkChangeNotifier infrastructure:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_NETWORK_CHANGE_NOTIFIER_LINUX_H_ 5 #ifndef NET_BASE_NETWORK_CHANGE_NOTIFIER_LINUX_H_
6 #define NET_BASE_NETWORK_CHANGE_NOTIFIER_LINUX_H_ 6 #define NET_BASE_NETWORK_CHANGE_NOTIFIER_LINUX_H_
7 7
8 #include "base/basictypes.h"
9 #include "base/message_loop.h" 8 #include "base/message_loop.h"
10 #include "base/non_thread_safe.h"
11 #include "base/observer_list.h"
12 #include "net/base/network_change_notifier.h" 9 #include "net/base/network_change_notifier.h"
13 10
14 #if defined(OS_CHROMEOS) 11 namespace base {
15 #include "base/task.h" 12 class Thread;
16 #endif 13 }
17 14
18 namespace net { 15 namespace net {
19 16
20 class NetworkChangeNotifierLinux 17 class NetworkChangeNotifierLinux : public MessageLoop::DestructionObserver,
21 : public NetworkChangeNotifier, 18 public MessageLoopForIO::Watcher,
22 public NonThreadSafe, 19 public NetworkChangeNotifier {
23 public MessageLoopForIO::Watcher,
24 public MessageLoop::DestructionObserver {
25 public: 20 public:
26 NetworkChangeNotifierLinux(); 21 NetworkChangeNotifierLinux();
27 22
28 // NetworkChangeNotifier methods:
29 virtual void AddObserver(Observer* observer);
30 virtual void RemoveObserver(Observer* observer);
31
32 // MessageLoopForIO::Watcher methods:
33 virtual void OnFileCanReadWithoutBlocking(int fd);
34 virtual void OnFileCanWriteWithoutBlocking(int /* fd */);
35
36 // MessageLoop::DestructionObserver methods:
37 virtual void WillDestroyCurrentMessageLoop();
38
39 private: 23 private:
40 virtual ~NetworkChangeNotifierLinux(); 24 virtual ~NetworkChangeNotifierLinux();
41 25
26 // MessageLoop::DestructionObserver:
willchan no longer on Chromium 2010/06/25 15:36:22 There's no clear style consensus on this anywhere,
Peter Kasting 2010/06/25 17:51:33 I don't feel violently. It seems like a slight pl
willchan no longer on Chromium 2010/06/25 19:09:29 Yeah, it's the confusion, because it can be mislea
27 virtual void WillDestroyCurrentMessageLoop();
28
29 // MessageLoopForIO::Watcher:
30 virtual void OnFileCanReadWithoutBlocking(int fd);
31 virtual void OnFileCanWriteWithoutBlocking(int /* fd */);
32
33 // Called on the notifier thread to initialize the notification
34 // implementation.
35 void Init();
36
42 // Starts listening for netlink messages. Also handles the messages if there 37 // Starts listening for netlink messages. Also handles the messages if there
43 // are any available on the netlink socket. 38 // are any available on the netlink socket.
44 void ListenForNotifications(); 39 void ListenForNotifications();
45 40
46 // Attempts to read from the netlink socket into |buf| of length |len|. 41 // Attempts to read from the netlink socket into |buf| of length |len|.
47 // Returns the bytes read on synchronous success and ERR_IO_PENDING if the 42 // Returns the bytes read on synchronous success and ERR_IO_PENDING if the
48 // recv() would block. Otherwise, it returns a net error code. 43 // recv() would block. Otherwise, it returns a net error code.
49 int ReadNotificationMessage(char* buf, size_t len); 44 int ReadNotificationMessage(char* buf, size_t len);
50 45
51 // Stops watching the netlink file descriptor. 46 // The thread used to listen for notifications. This relays the notification
52 void StopWatching(); 47 // to the registered observers without posting back to the thread the object
48 // was created on.
49 scoped_ptr<base::Thread> notifier_thread_;
willchan no longer on Chromium 2010/06/25 15:36:22 You are deleting includes and neglecting to includ
Peter Kasting 2010/06/25 17:51:33 Wait, what did I delete here? base::Thread is dec
willchan no longer on Chromium 2010/06/25 19:09:29 You've deleted basictypes.h, which IIRC is require
Peter Kasting 2010/06/25 20:01:37 Oh, oops. Fixed in all the network_change_notifie
53 50
54 void NotifyObserversIPAddressChanged(); 51 // The netlink socket descriptor.
52 int netlink_fd_;
55 53
56 // http://crbug.com/36890.
57 ObserverList<Observer, false> observers_;
58
59 int netlink_fd_; // This is the netlink socket descriptor.
60
61 #if defined(OS_CHROMEOS)
62 ScopedRunnableMethodFactory<NetworkChangeNotifierLinux> factory_;
63 #endif
64
65 MessageLoopForIO* loop_;
66 MessageLoopForIO::FileDescriptorWatcher netlink_watcher_; 54 MessageLoopForIO::FileDescriptorWatcher netlink_watcher_;
67 55
68 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierLinux); 56 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierLinux);
69 }; 57 };
70 58
71 } // namespace net 59 } // namespace net
72 60
73 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_LINUX_H_ 61 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_LINUX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698