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

Side by Side Diff: trunk/src/base/message_loop/message_pump_io_ios.h

Issue 19737005: Revert 212948 "Made MessagePump a non-thread safe class." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 5 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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_IO_IOS_H_ 5 #ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_IO_IOS_H_
6 #define BASE_MESSAGE_LOOP_MESSAGE_PUMP_IO_IOS_H_ 6 #define BASE_MESSAGE_LOOP_MESSAGE_PUMP_IO_IOS_H_
7 7
8 #include "base/base_export.h" 8 #include "base/base_export.h"
9 #include "base/mac/scoped_cffiledescriptorref.h" 9 #include "base/mac/scoped_cffiledescriptorref.h"
10 #include "base/mac/scoped_cftyperef.h" 10 #include "base/mac/scoped_cftyperef.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/message_loop/message_pump_mac.h" 12 #include "base/message_loop/message_pump_mac.h"
14 #include "base/observer_list.h" 13 #include "base/observer_list.h"
15 14
16 namespace base { 15 namespace base {
17 16
18 // This file introduces a class to monitor sockets and issue callbacks when 17 // This file introduces a class to monitor sockets and issue callbacks when
19 // sockets are ready for I/O on iOS. 18 // sockets are ready for I/O on iOS.
20 class BASE_EXPORT MessagePumpIOSForIO : public MessagePumpNSRunLoop { 19 class BASE_EXPORT MessagePumpIOSForIO : public MessagePumpNSRunLoop {
21 public: 20 public:
22 class IOObserver { 21 class IOObserver {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 friend class MessagePumpIOSForIO; 63 friend class MessagePumpIOSForIO;
65 friend class MessagePumpIOSForIOTest; 64 friend class MessagePumpIOSForIOTest;
66 65
67 // Called by MessagePumpIOSForIO, ownership of |fdref| and |fd_source| 66 // Called by MessagePumpIOSForIO, ownership of |fdref| and |fd_source|
68 // is transferred to this object. 67 // is transferred to this object.
69 void Init(CFFileDescriptorRef fdref, 68 void Init(CFFileDescriptorRef fdref,
70 CFOptionFlags callback_types, 69 CFOptionFlags callback_types,
71 CFRunLoopSourceRef fd_source, 70 CFRunLoopSourceRef fd_source,
72 bool is_persistent); 71 bool is_persistent);
73 72
74 void set_pump(base::WeakPtr<MessagePumpIOSForIO> pump) { pump_ = pump; } 73 void set_pump(MessagePumpIOSForIO* pump) { pump_ = pump; }
75 const base::WeakPtr<MessagePumpIOSForIO>& pump() const { return pump_; } 74 MessagePumpIOSForIO* pump() const { return pump_; }
76 75
77 void set_watcher(Watcher* watcher) { watcher_ = watcher; } 76 void set_watcher(Watcher* watcher) { watcher_ = watcher; }
78 77
79 void OnFileCanReadWithoutBlocking(int fd, MessagePumpIOSForIO* pump); 78 void OnFileCanReadWithoutBlocking(int fd, MessagePumpIOSForIO* pump);
80 void OnFileCanWriteWithoutBlocking(int fd, MessagePumpIOSForIO* pump); 79 void OnFileCanWriteWithoutBlocking(int fd, MessagePumpIOSForIO* pump);
81 80
82 bool is_persistent_; // false if this event is one-shot. 81 bool is_persistent_; // false if this event is one-shot.
83 base::mac::ScopedCFFileDescriptorRef fdref_; 82 base::mac::ScopedCFFileDescriptorRef fdref_;
84 CFOptionFlags callback_types_; 83 CFOptionFlags callback_types_;
85 base::ScopedCFTypeRef<CFRunLoopSourceRef> fd_source_; 84 base::ScopedCFTypeRef<CFRunLoopSourceRef> fd_source_;
86 base::WeakPtr<MessagePumpIOSForIO> pump_; 85 scoped_refptr<MessagePumpIOSForIO> pump_;
87 Watcher* watcher_; 86 Watcher* watcher_;
88 87
89 DISALLOW_COPY_AND_ASSIGN(FileDescriptorWatcher); 88 DISALLOW_COPY_AND_ASSIGN(FileDescriptorWatcher);
90 }; 89 };
91 90
92 enum Mode { 91 enum Mode {
93 WATCH_READ = 1 << 0, 92 WATCH_READ = 1 << 0,
94 WATCH_WRITE = 1 << 1, 93 WATCH_WRITE = 1 << 1,
95 WATCH_READ_WRITE = WATCH_READ | WATCH_WRITE 94 WATCH_READ_WRITE = WATCH_READ | WATCH_WRITE
96 }; 95 };
97 96
98 MessagePumpIOSForIO(); 97 MessagePumpIOSForIO();
99 virtual ~MessagePumpIOSForIO();
100 98
101 // Have the current thread's message loop watch for a a situation in which 99 // Have the current thread's message loop watch for a a situation in which
102 // reading/writing to the FD can be performed without blocking. 100 // reading/writing to the FD can be performed without blocking.
103 // Callers must provide a preallocated FileDescriptorWatcher object which 101 // Callers must provide a preallocated FileDescriptorWatcher object which
104 // can later be used to manage the lifetime of this event. 102 // can later be used to manage the lifetime of this event.
105 // If a FileDescriptorWatcher is passed in which is already attached to 103 // If a FileDescriptorWatcher is passed in which is already attached to
106 // an event, then the effect is cumulative i.e. after the call |controller| 104 // an event, then the effect is cumulative i.e. after the call |controller|
107 // will watch both the previous event and the new one. 105 // will watch both the previous event and the new one.
108 // If an error occurs while calling this method in a cumulative fashion, the 106 // If an error occurs while calling this method in a cumulative fashion, the
109 // event previously attached to |controller| is aborted. 107 // event previously attached to |controller| is aborted.
110 // Returns true on success. 108 // Returns true on success.
111 // Must be called on the same thread the message_pump is running on. 109 // Must be called on the same thread the message_pump is running on.
112 bool WatchFileDescriptor(int fd, 110 bool WatchFileDescriptor(int fd,
113 bool persistent, 111 bool persistent,
114 int mode, 112 int mode,
115 FileDescriptorWatcher *controller, 113 FileDescriptorWatcher *controller,
116 Watcher *delegate); 114 Watcher *delegate);
117 115
118 void RemoveRunLoopSource(CFRunLoopSourceRef source); 116 void RemoveRunLoopSource(CFRunLoopSourceRef source);
119 117
120 void AddIOObserver(IOObserver* obs); 118 void AddIOObserver(IOObserver* obs);
121 void RemoveIOObserver(IOObserver* obs); 119 void RemoveIOObserver(IOObserver* obs);
122 120
121 protected:
122 virtual ~MessagePumpIOSForIO();
123
123 private: 124 private:
124 friend class MessagePumpIOSForIOTest; 125 friend class MessagePumpIOSForIOTest;
125 126
126 void WillProcessIOEvent(); 127 void WillProcessIOEvent();
127 void DidProcessIOEvent(); 128 void DidProcessIOEvent();
128 129
129 static void HandleFdIOEvent(CFFileDescriptorRef fdref, 130 static void HandleFdIOEvent(CFFileDescriptorRef fdref,
130 CFOptionFlags callback_types, 131 CFOptionFlags callback_types,
131 void* context); 132 void* context);
132 133
133 ObserverList<IOObserver> io_observers_; 134 ObserverList<IOObserver> io_observers_;
134 ThreadChecker watch_file_descriptor_caller_checker_; 135 ThreadChecker watch_file_descriptor_caller_checker_;
135 136
136 base::WeakPtrFactory<MessagePumpIOSForIO> weak_factory_;
137
138 DISALLOW_COPY_AND_ASSIGN(MessagePumpIOSForIO); 137 DISALLOW_COPY_AND_ASSIGN(MessagePumpIOSForIO);
139 }; 138 };
140 139
141 } // namespace base 140 } // namespace base
142 141
143 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_IO_IOS_H_ 142 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_IO_IOS_H_
OLDNEW
« no previous file with comments | « trunk/src/base/message_loop/message_pump_gtk.cc ('k') | trunk/src/base/message_loop/message_pump_io_ios.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698