James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 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 | |
Viet-Trung Luu | e766dce | 2015-07-29 14:55:47 -0700 | [diff] [blame] | 5 | #include "mojo/environment/default_async_waiter.h" |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 6 | |
| 7 | #include "base/bind.h" |
James Robinson | 94ade6b | 2015-08-25 13:02:06 -0700 | [diff] [blame] | 8 | #include "mojo/message_pump/handle_watcher.h" |
Viet-Trung Luu | e766dce | 2015-07-29 14:55:47 -0700 | [diff] [blame] | 9 | #include "mojo/public/c/environment/async_waiter.h" |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 10 | |
| 11 | namespace mojo { |
| 12 | namespace internal { |
| 13 | namespace { |
| 14 | |
| 15 | void OnHandleReady(common::HandleWatcher* watcher, |
| 16 | MojoAsyncWaitCallback callback, |
| 17 | void* closure, |
| 18 | MojoResult result) { |
| 19 | delete watcher; |
| 20 | callback(closure, result); |
| 21 | } |
| 22 | |
| 23 | MojoAsyncWaitID AsyncWait(MojoHandle handle, |
| 24 | MojoHandleSignals signals, |
| 25 | MojoDeadline deadline, |
| 26 | MojoAsyncWaitCallback callback, |
| 27 | void* closure) { |
| 28 | // This instance will be deleted when done or cancelled. |
| 29 | common::HandleWatcher* watcher = new common::HandleWatcher(); |
| 30 | watcher->Start(Handle(handle), signals, deadline, |
| 31 | base::Bind(&OnHandleReady, watcher, callback, closure)); |
| 32 | return reinterpret_cast<MojoAsyncWaitID>(watcher); |
| 33 | } |
| 34 | |
| 35 | void CancelWait(MojoAsyncWaitID wait_id) { |
| 36 | delete reinterpret_cast<common::HandleWatcher*>(wait_id); |
| 37 | } |
| 38 | |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 39 | } // namespace |
| 40 | |
Viet-Trung Luu | e766dce | 2015-07-29 14:55:47 -0700 | [diff] [blame] | 41 | const MojoAsyncWaiter kDefaultAsyncWaiter = {AsyncWait, CancelWait}; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 42 | |
| 43 | } // namespace internal |
| 44 | } // namespace mojo |