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

Side by Side Diff: base/message_loop/message_pump_libevent_unittest.cc

Issue 2801593002: Convert WaitableEvent::EventCallback to OnceCallback (Closed)
Patch Set: +#include <utility> Created 3 years, 8 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
« no previous file with comments | « no previous file | base/synchronization/waitable_event_watcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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 <memory> 9 #include <memory>
10 #include <utility>
10 11
11 #include "base/bind.h" 12 #include "base/bind.h"
12 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
13 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
14 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
15 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
16 #include "base/posix/eintr_wrapper.h" 17 #include "base/posix/eintr_wrapper.h"
17 #include "base/run_loop.h" 18 #include "base/run_loop.h"
18 #include "base/single_thread_task_runner.h" 19 #include "base/single_thread_task_runner.h"
19 #include "base/synchronization/waitable_event.h" 20 #include "base/synchronization/waitable_event.h"
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 WaitableEvent event(WaitableEvent::ResetPolicy::AUTOMATIC, 250 WaitableEvent event(WaitableEvent::ResetPolicy::AUTOMATIC,
250 WaitableEvent::InitialState::NOT_SIGNALED); 251 WaitableEvent::InitialState::NOT_SIGNALED);
251 std::unique_ptr<WaitableEventWatcher> watcher(new WaitableEventWatcher); 252 std::unique_ptr<WaitableEventWatcher> watcher(new WaitableEventWatcher);
252 253
253 // Tell the pump to watch the pipe. 254 // Tell the pump to watch the pipe.
254 pump->WatchFileDescriptor(pipefds_[0], false, MessagePumpLibevent::WATCH_READ, 255 pump->WatchFileDescriptor(pipefds_[0], false, MessagePumpLibevent::WATCH_READ,
255 &controller, &delegate); 256 &controller, &delegate);
256 257
257 // Make the IO thread wait for |event| before writing to pipefds[1]. 258 // Make the IO thread wait for |event| before writing to pipefds[1].
258 const char buf = 0; 259 const char buf = 0;
259 const WaitableEventWatcher::EventCallback write_fd_task = 260 WaitableEventWatcher::EventCallback write_fd_task =
260 Bind(&WriteFDWrapper, pipefds_[1], &buf, 1); 261 BindOnce(&WriteFDWrapper, pipefds_[1], &buf, 1);
261 io_loop()->task_runner()->PostTask( 262 io_loop()->task_runner()->PostTask(
262 FROM_HERE, BindOnce(IgnoreResult(&WaitableEventWatcher::StartWatching), 263 FROM_HERE,
263 Unretained(watcher.get()), &event, write_fd_task)); 264 BindOnce(IgnoreResult(&WaitableEventWatcher::StartWatching),
265 Unretained(watcher.get()), &event, std::move(write_fd_task)));
264 266
265 // Queue |event| to signal on |loop|. 267 // Queue |event| to signal on |loop|.
266 loop.task_runner()->PostTask( 268 loop.task_runner()->PostTask(
267 FROM_HERE, BindOnce(&WaitableEvent::Signal, Unretained(&event))); 269 FROM_HERE, BindOnce(&WaitableEvent::Signal, Unretained(&event)));
268 270
269 // Now run the MessageLoop. 271 // Now run the MessageLoop.
270 run_loop.Run(); 272 run_loop.Run();
271 273
272 // StartWatching can move |watcher| to IO thread. Release on IO thread. 274 // StartWatching can move |watcher| to IO thread. Release on IO thread.
273 io_loop()->task_runner()->PostTask( 275 io_loop()->task_runner()->PostTask(
274 FROM_HERE, 276 FROM_HERE,
275 BindOnce(&WaitableEventWatcher::StopWatching, Owned(watcher.release()))); 277 BindOnce(&WaitableEventWatcher::StopWatching, Owned(watcher.release())));
276 } 278 }
277 279
278 } // namespace 280 } // namespace
279 281
280 } // namespace base 282 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/synchronization/waitable_event_watcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698