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

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

Issue 2791243002: Rewrite base::Bind into base::BindOnce on trivial cases in base (Closed)
Patch Set: rebase 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
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 10
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } 180 }
181 181
182 class NestedPumpWatcher : public MessagePumpLibevent::Watcher { 182 class NestedPumpWatcher : public MessagePumpLibevent::Watcher {
183 public: 183 public:
184 NestedPumpWatcher() {} 184 NestedPumpWatcher() {}
185 ~NestedPumpWatcher() override {} 185 ~NestedPumpWatcher() override {}
186 186
187 void OnFileCanReadWithoutBlocking(int /* fd */) override { 187 void OnFileCanReadWithoutBlocking(int /* fd */) override {
188 RunLoop runloop; 188 RunLoop runloop;
189 ThreadTaskRunnerHandle::Get()->PostTask( 189 ThreadTaskRunnerHandle::Get()->PostTask(
190 FROM_HERE, Bind(&QuitMessageLoopAndStart, runloop.QuitClosure())); 190 FROM_HERE, BindOnce(&QuitMessageLoopAndStart, runloop.QuitClosure()));
191 runloop.Run(); 191 runloop.Run();
192 } 192 }
193 193
194 void OnFileCanWriteWithoutBlocking(int /* fd */) override {} 194 void OnFileCanWriteWithoutBlocking(int /* fd */) override {}
195 }; 195 };
196 196
197 TEST_F(MessagePumpLibeventTest, NestedPumpWatcher) { 197 TEST_F(MessagePumpLibeventTest, NestedPumpWatcher) {
198 std::unique_ptr<MessagePumpLibevent> pump(new MessagePumpLibevent); 198 std::unique_ptr<MessagePumpLibevent> pump(new MessagePumpLibevent);
199 MessagePumpLibevent::FileDescriptorWatcher watcher(FROM_HERE); 199 MessagePumpLibevent::FileDescriptorWatcher watcher(FROM_HERE);
200 NestedPumpWatcher delegate; 200 NestedPumpWatcher delegate;
(...skipping 10 matching lines...) Expand all
211 211
212 class QuitWatcher : public BaseWatcher { 212 class QuitWatcher : public BaseWatcher {
213 public: 213 public:
214 QuitWatcher(MessagePumpLibevent::FileDescriptorWatcher* controller, 214 QuitWatcher(MessagePumpLibevent::FileDescriptorWatcher* controller,
215 RunLoop* run_loop) 215 RunLoop* run_loop)
216 : BaseWatcher(controller), run_loop_(run_loop) {} 216 : BaseWatcher(controller), run_loop_(run_loop) {}
217 ~QuitWatcher() override {} 217 ~QuitWatcher() override {}
218 218
219 void OnFileCanReadWithoutBlocking(int /* fd */) override { 219 void OnFileCanReadWithoutBlocking(int /* fd */) override {
220 // Post a fatal closure to the MessageLoop before we quit it. 220 // Post a fatal closure to the MessageLoop before we quit it.
221 ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, Bind(&FatalClosure)); 221 ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, BindOnce(&FatalClosure));
222 222
223 // Now quit the MessageLoop. 223 // Now quit the MessageLoop.
224 run_loop_->Quit(); 224 run_loop_->Quit();
225 } 225 }
226 226
227 private: 227 private:
228 RunLoop* run_loop_; // weak 228 RunLoop* run_loop_; // weak
229 }; 229 };
230 230
231 void WriteFDWrapper(const int fd, 231 void WriteFDWrapper(const int fd,
(...skipping 20 matching lines...) Expand all
252 252
253 // Tell the pump to watch the pipe. 253 // Tell the pump to watch the pipe.
254 pump->WatchFileDescriptor(pipefds_[0], false, MessagePumpLibevent::WATCH_READ, 254 pump->WatchFileDescriptor(pipefds_[0], false, MessagePumpLibevent::WATCH_READ,
255 &controller, &delegate); 255 &controller, &delegate);
256 256
257 // Make the IO thread wait for |event| before writing to pipefds[1]. 257 // Make the IO thread wait for |event| before writing to pipefds[1].
258 const char buf = 0; 258 const char buf = 0;
259 const WaitableEventWatcher::EventCallback write_fd_task = 259 const WaitableEventWatcher::EventCallback write_fd_task =
260 Bind(&WriteFDWrapper, pipefds_[1], &buf, 1); 260 Bind(&WriteFDWrapper, pipefds_[1], &buf, 1);
261 io_loop()->task_runner()->PostTask( 261 io_loop()->task_runner()->PostTask(
262 FROM_HERE, Bind(IgnoreResult(&WaitableEventWatcher::StartWatching), 262 FROM_HERE, BindOnce(IgnoreResult(&WaitableEventWatcher::StartWatching),
263 Unretained(watcher.get()), &event, write_fd_task)); 263 Unretained(watcher.get()), &event, write_fd_task));
264 264
265 // Queue |event| to signal on |loop|. 265 // Queue |event| to signal on |loop|.
266 loop.task_runner()->PostTask( 266 loop.task_runner()->PostTask(
267 FROM_HERE, Bind(&WaitableEvent::Signal, Unretained(&event))); 267 FROM_HERE, BindOnce(&WaitableEvent::Signal, Unretained(&event)));
268 268
269 // Now run the MessageLoop. 269 // Now run the MessageLoop.
270 run_loop.Run(); 270 run_loop.Run();
271 271
272 // StartWatching can move |watcher| to IO thread. Release on IO thread. 272 // StartWatching can move |watcher| to IO thread. Release on IO thread.
273 io_loop()->task_runner()->PostTask( 273 io_loop()->task_runner()->PostTask(
274 FROM_HERE, 274 FROM_HERE,
275 Bind(&WaitableEventWatcher::StopWatching, Owned(watcher.release()))); 275 BindOnce(&WaitableEventWatcher::StopWatching, Owned(watcher.release())));
276 } 276 }
277 277
278 } // namespace 278 } // namespace
279 279
280 } // namespace base 280 } // namespace base
OLDNEW
« no previous file with comments | « base/message_loop/message_pump_glib_unittest.cc ('k') | base/message_loop/message_pump_perftest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698