OLD | NEW |
---|---|
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 #include "base/message_loop/message_pump_libevent.h" | 5 #include "base/message_loop/message_pump_libevent.h" |
6 | 6 |
7 #include <unistd.h> | 7 #include <unistd.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 TEST_F(MessagePumpLibeventTest, QuitWatcher) { | 239 TEST_F(MessagePumpLibeventTest, QuitWatcher) { |
240 // Delete the old MessageLoop so that we can manage our own one here. | 240 // Delete the old MessageLoop so that we can manage our own one here. |
241 ui_loop_.reset(); | 241 ui_loop_.reset(); |
242 | 242 |
243 MessagePumpLibevent* pump = new MessagePumpLibevent; // owned by |loop|. | 243 MessagePumpLibevent* pump = new MessagePumpLibevent; // owned by |loop|. |
244 MessageLoop loop(make_scoped_ptr(pump)); | 244 MessageLoop loop(make_scoped_ptr(pump)); |
245 RunLoop run_loop; | 245 RunLoop run_loop; |
246 MessagePumpLibevent::FileDescriptorWatcher controller; | 246 MessagePumpLibevent::FileDescriptorWatcher controller; |
247 QuitWatcher delegate(&controller, &run_loop); | 247 QuitWatcher delegate(&controller, &run_loop); |
248 WaitableEvent event(false /* manual_reset */, false /* initially_signaled */); | 248 WaitableEvent event(false /* manual_reset */, false /* initially_signaled */); |
249 WaitableEventWatcher watcher; | 249 scoped_ptr<WaitableEventWatcher> watcher(new WaitableEventWatcher); |
250 | 250 |
251 // Tell the pump to watch the pipe. | 251 // Tell the pump to watch the pipe. |
252 pump->WatchFileDescriptor(pipefds_[0], false, MessagePumpLibevent::WATCH_READ, | 252 pump->WatchFileDescriptor(pipefds_[0], false, MessagePumpLibevent::WATCH_READ, |
253 &controller, &delegate); | 253 &controller, &delegate); |
254 | 254 |
255 // Make the IO thread wait for |event| before writing to pipefds[1]. | 255 // Make the IO thread wait for |event| before writing to pipefds[1]. |
256 const char buf = 0; | 256 const char buf = 0; |
257 const WaitableEventWatcher::EventCallback write_fd_task = | 257 const WaitableEventWatcher::EventCallback write_fd_task = |
258 Bind(&WriteFDWrapper, pipefds_[1], &buf, 1); | 258 Bind(&WriteFDWrapper, pipefds_[1], &buf, 1); |
259 io_loop()->PostTask(FROM_HERE, | 259 io_loop()->PostTask(FROM_HERE, |
260 Bind(IgnoreResult(&WaitableEventWatcher::StartWatching), | 260 Bind(IgnoreResult(&WaitableEventWatcher::StartWatching), |
261 Unretained(&watcher), &event, write_fd_task)); | 261 Unretained(watcher.get()), &event, write_fd_task)); |
262 | 262 |
263 // Queue |event| to signal on |loop|. | 263 // Queue |event| to signal on |loop|. |
264 loop.PostTask(FROM_HERE, Bind(&WaitableEvent::Signal, Unretained(&event))); | 264 loop.PostTask(FROM_HERE, Bind(&WaitableEvent::Signal, Unretained(&event))); |
265 | 265 |
266 // Now run the MessageLoop. | 266 // Now run the MessageLoop. |
267 run_loop.Run(); | 267 run_loop.Run(); |
268 | |
269 // StartWatching can move |watcher| to IO thread. Release on IO thread. | |
270 io_loop()->PostTask(FROM_HERE, Bind(&WaitableEventWatcher::StopWatching, | |
271 Unretained(watcher.get()))); | |
Chirantan Ekbote
2015/06/20 00:09:37
Why not just use base::Passed here?
derekjchow1
2015/06/20 00:34:07
I don't think we can Pass a scoped_ptr as the "thi
| |
272 io_loop()->DeleteSoon(FROM_HERE, watcher.release()); | |
268 } | 273 } |
269 | 274 |
270 } // namespace | 275 } // namespace |
271 | 276 |
272 } // namespace base | 277 } // namespace base |
OLD | NEW |