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

Side by Side Diff: base/message_loop/message_pump_libevent.h

Issue 2695593009: Use the location where FileDescriptorWatcher is created to track the libevent handlers (Closed)
Patch Set: fix mac. Created 3 years, 10 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
OLDNEW
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 BASE_MESSAGE_LOOP_MESSAGE_PUMP_LIBEVENT_H_ 5 #ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_LIBEVENT_H_
6 #define BASE_MESSAGE_LOOP_MESSAGE_PUMP_LIBEVENT_H_ 6 #define BASE_MESSAGE_LOOP_MESSAGE_PUMP_LIBEVENT_H_
7 7
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/location.h"
9 #include "base/macros.h" 10 #include "base/macros.h"
10 #include "base/message_loop/message_pump.h" 11 #include "base/message_loop/message_pump.h"
11 #include "base/threading/thread_checker.h" 12 #include "base/threading/thread_checker.h"
12 #include "base/time/time.h" 13 #include "base/time/time.h"
13 14
14 // Declare structs we need from libevent.h rather than including it 15 // Declare structs we need from libevent.h rather than including it
15 struct event_base; 16 struct event_base;
16 struct event; 17 struct event;
17 18
18 namespace base { 19 namespace base {
(...skipping 11 matching lines...) Expand all
30 virtual void OnFileCanReadWithoutBlocking(int fd) = 0; 31 virtual void OnFileCanReadWithoutBlocking(int fd) = 0;
31 virtual void OnFileCanWriteWithoutBlocking(int fd) = 0; 32 virtual void OnFileCanWriteWithoutBlocking(int fd) = 0;
32 33
33 protected: 34 protected:
34 virtual ~Watcher() {} 35 virtual ~Watcher() {}
35 }; 36 };
36 37
37 // Object returned by WatchFileDescriptor to manage further watching. 38 // Object returned by WatchFileDescriptor to manage further watching.
38 class FileDescriptorWatcher { 39 class FileDescriptorWatcher {
39 public: 40 public:
40 FileDescriptorWatcher(); 41 explicit FileDescriptorWatcher(const tracked_objects::Location& from_here);
41 ~FileDescriptorWatcher(); // Implicitly calls StopWatchingFileDescriptor. 42 ~FileDescriptorWatcher(); // Implicitly calls StopWatchingFileDescriptor.
42 43
43 // NOTE: These methods aren't called StartWatching()/StopWatching() to 44 // NOTE: These methods aren't called StartWatching()/StopWatching() to
44 // avoid confusion with the win32 ObjectWatcher class. 45 // avoid confusion with the win32 ObjectWatcher class.
45 46
46 // Stop watching the FD, always safe to call. No-op if there's nothing 47 // Stop watching the FD, always safe to call. No-op if there's nothing
47 // to do. 48 // to do.
48 bool StopWatchingFileDescriptor(); 49 bool StopWatchingFileDescriptor();
49 50
51 const tracked_objects::Location& created_from_location() {
52 return created_from_location_;
53 }
54
50 private: 55 private:
51 friend class MessagePumpLibevent; 56 friend class MessagePumpLibevent;
52 friend class MessagePumpLibeventTest; 57 friend class MessagePumpLibeventTest;
53 58
54 // Called by MessagePumpLibevent, ownership of |e| is transferred to this 59 // Called by MessagePumpLibevent, ownership of |e| is transferred to this
55 // object. 60 // object.
56 void Init(event* e); 61 void Init(event* e);
57 62
58 // Used by MessagePumpLibevent to take ownership of event_. 63 // Used by MessagePumpLibevent to take ownership of event_.
59 event* ReleaseEvent(); 64 event* ReleaseEvent();
60 65
61 void set_pump(MessagePumpLibevent* pump) { pump_ = pump; } 66 void set_pump(MessagePumpLibevent* pump) { pump_ = pump; }
62 MessagePumpLibevent* pump() const { return pump_; } 67 MessagePumpLibevent* pump() const { return pump_; }
63 68
64 void set_watcher(Watcher* watcher) { watcher_ = watcher; } 69 void set_watcher(Watcher* watcher) { watcher_ = watcher; }
65 70
66 void OnFileCanReadWithoutBlocking(int fd, MessagePumpLibevent* pump); 71 void OnFileCanReadWithoutBlocking(int fd, MessagePumpLibevent* pump);
67 void OnFileCanWriteWithoutBlocking(int fd, MessagePumpLibevent* pump); 72 void OnFileCanWriteWithoutBlocking(int fd, MessagePumpLibevent* pump);
68 73
69 event* event_; 74 event* event_;
70 MessagePumpLibevent* pump_; 75 MessagePumpLibevent* pump_;
71 Watcher* watcher_; 76 Watcher* watcher_;
72 // If this pointer is non-NULL, the pointee is set to true in the 77 // If this pointer is non-NULL, the pointee is set to true in the
73 // destructor. 78 // destructor.
74 bool* was_destroyed_; 79 bool* was_destroyed_;
75 80
81 const tracked_objects::Location created_from_location_;
82
76 DISALLOW_COPY_AND_ASSIGN(FileDescriptorWatcher); 83 DISALLOW_COPY_AND_ASSIGN(FileDescriptorWatcher);
77 }; 84 };
78 85
79 enum Mode { 86 enum Mode {
80 WATCH_READ = 1 << 0, 87 WATCH_READ = 1 << 0,
81 WATCH_WRITE = 1 << 1, 88 WATCH_WRITE = 1 << 1,
82 WATCH_READ_WRITE = WATCH_READ | WATCH_WRITE 89 WATCH_READ_WRITE = WATCH_READ | WATCH_WRITE
83 }; 90 };
84 91
85 MessagePumpLibevent(); 92 MessagePumpLibevent();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 // ... libevent wrapper for read end 152 // ... libevent wrapper for read end
146 event* wakeup_event_; 153 event* wakeup_event_;
147 154
148 ThreadChecker watch_file_descriptor_caller_checker_; 155 ThreadChecker watch_file_descriptor_caller_checker_;
149 DISALLOW_COPY_AND_ASSIGN(MessagePumpLibevent); 156 DISALLOW_COPY_AND_ASSIGN(MessagePumpLibevent);
150 }; 157 };
151 158
152 } // namespace base 159 } // namespace base
153 160
154 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_LIBEVENT_H_ 161 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_LIBEVENT_H_
OLDNEW
« no previous file with comments | « base/message_loop/message_pump_io_ios_unittest.cc ('k') | base/message_loop/message_pump_libevent.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698