Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "device/serial/async_waiter.h" | |
| 6 | |
| 7 namespace device { | |
| 8 | |
| 9 AsyncWaiter::AsyncWaiter(mojo::Handle handle, | |
| 10 MojoHandleSignals signals, | |
| 11 const Callback& callback) | |
| 12 : waiter_(mojo::Environment::GetDefaultAsyncWaiter()), | |
| 13 id_(0), | |
| 14 callback_(callback) { | |
| 15 id_ = waiter_->AsyncWait(handle.value(), | |
| 16 signals, | |
| 17 MOJO_DEADLINE_INDEFINITE, | |
| 18 &AsyncWaiter::WaitComplete, | |
| 19 this); | |
| 20 } | |
| 21 | |
| 22 AsyncWaiter::~AsyncWaiter() { | |
| 23 if (id_) | |
| 24 waiter_->CancelWait(id_); | |
| 25 } | |
| 26 | |
| 27 // static | |
| 28 void AsyncWaiter::WaitComplete(void* waiter, MojoResult result) { | |
| 29 static_cast<AsyncWaiter*>(waiter)->WaitCompleteInternal(result); | |
| 30 } | |
| 31 | |
| 32 void AsyncWaiter::WaitCompleteInternal(MojoResult result) { | |
| 33 id_ = 0; | |
| 34 Callback callback = callback_; | |
| 35 callback.Run(result); | |
|
raymes
2014/08/05 06:26:44
Why not just make the member non-const and call ca
Sam McNally
2014/08/05 07:26:33
Done.
| |
| 36 } | |
| 37 | |
| 38 } // namespace device | |
| OLD | NEW |