OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "third_party/mojo/src/mojo/public/cpp/environment/async_waiter.h" | 5 #include "mojo/public/cpp/environment/async_waiter.h" |
6 | 6 |
7 namespace mojo { | 7 namespace mojo { |
8 | 8 |
9 AsyncWaiter::AsyncWaiter(Handle handle, | 9 AsyncWaiter::AsyncWaiter(Handle handle, |
10 MojoHandleSignals signals, | 10 MojoHandleSignals signals, |
11 const Callback& callback) | 11 const Callback& callback) |
12 : waiter_(Environment::GetDefaultAsyncWaiter()), | 12 : waiter_(Environment::GetDefaultAsyncWaiter()), |
13 id_(0), | 13 id_(0), |
14 callback_(callback) { | 14 callback_(callback) { |
15 id_ = waiter_->AsyncWait(handle.value(), signals, MOJO_DEADLINE_INDEFINITE, | 15 id_ = waiter_->AsyncWait(handle.value(), signals, MOJO_DEADLINE_INDEFINITE, |
16 &AsyncWaiter::WaitComplete, this); | 16 &AsyncWaiter::WaitComplete, this); |
17 } | 17 } |
18 | 18 |
19 AsyncWaiter::~AsyncWaiter() { | 19 AsyncWaiter::~AsyncWaiter() { |
20 if (id_) | 20 if (id_) |
21 waiter_->CancelWait(id_); | 21 waiter_->CancelWait(id_); |
22 } | 22 } |
23 | 23 |
24 // static | 24 // static |
25 void AsyncWaiter::WaitComplete(void* waiter, MojoResult result) { | 25 void AsyncWaiter::WaitComplete(void* waiter, MojoResult result) { |
26 static_cast<AsyncWaiter*>(waiter)->WaitCompleteInternal(result); | 26 static_cast<AsyncWaiter*>(waiter)->WaitCompleteInternal(result); |
27 } | 27 } |
28 | 28 |
29 void AsyncWaiter::WaitCompleteInternal(MojoResult result) { | 29 void AsyncWaiter::WaitCompleteInternal(MojoResult result) { |
30 id_ = 0; | 30 id_ = 0; |
31 callback_.Run(result); | 31 callback_.Run(result); |
32 } | 32 } |
33 | 33 |
34 } // namespace mojo | 34 } // namespace mojo |
OLD | NEW |