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 "mojo/environment/default_async_waiter_impl.h" | 5 #include "mojo/environment/default_async_waiter_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "mojo/common/handle_watcher.h" | 8 #include "mojo/common/handle_watcher.h" |
9 | 9 |
10 namespace mojo { | 10 namespace mojo { |
11 namespace internal { | 11 namespace internal { |
12 namespace { | 12 namespace { |
13 | 13 |
14 void OnHandleReady(common::HandleWatcher* watcher, | 14 void OnHandleReady(common::HandleWatcher* watcher, |
15 MojoAsyncWaitCallback callback, | 15 MojoAsyncWaitCallback callback, |
16 void* closure, | 16 void* closure, |
17 MojoResult result) { | 17 MojoResult result) { |
18 delete watcher; | 18 delete watcher; |
19 callback(closure, result); | 19 callback(closure, result); |
20 } | 20 } |
21 | 21 |
22 MojoAsyncWaitID AsyncWait(MojoHandle handle, | 22 MojoAsyncWaitID AsyncWait(MojoHandle handle, |
23 MojoWaitFlags flags, | 23 MojoHandleSignals signals, |
24 MojoDeadline deadline, | 24 MojoDeadline deadline, |
25 MojoAsyncWaitCallback callback, | 25 MojoAsyncWaitCallback callback, |
26 void* closure) { | 26 void* closure) { |
27 // This instance will be deleted when done or cancelled. | 27 // This instance will be deleted when done or cancelled. |
28 common::HandleWatcher* watcher = new common::HandleWatcher(); | 28 common::HandleWatcher* watcher = new common::HandleWatcher(); |
29 watcher->Start(Handle(handle), flags, deadline, | 29 watcher->Start(Handle(handle), signals, deadline, |
30 base::Bind(&OnHandleReady, watcher, callback, closure)); | 30 base::Bind(&OnHandleReady, watcher, callback, closure)); |
31 return reinterpret_cast<MojoAsyncWaitID>(watcher); | 31 return reinterpret_cast<MojoAsyncWaitID>(watcher); |
32 } | 32 } |
33 | 33 |
34 void CancelWait(MojoAsyncWaitID wait_id) { | 34 void CancelWait(MojoAsyncWaitID wait_id) { |
35 delete reinterpret_cast<common::HandleWatcher*>(wait_id); | 35 delete reinterpret_cast<common::HandleWatcher*>(wait_id); |
36 } | 36 } |
37 | 37 |
38 const MojoAsyncWaiter kDefaultAsyncWaiter = { | 38 const MojoAsyncWaiter kDefaultAsyncWaiter = { |
39 AsyncWait, | 39 AsyncWait, |
40 CancelWait | 40 CancelWait |
41 }; | 41 }; |
42 | 42 |
43 } // namespace | 43 } // namespace |
44 | 44 |
45 const MojoAsyncWaiter* GetDefaultAsyncWaiterImpl() { | 45 const MojoAsyncWaiter* GetDefaultAsyncWaiterImpl() { |
46 return &kDefaultAsyncWaiter; | 46 return &kDefaultAsyncWaiter; |
47 } | 47 } |
48 | 48 |
49 } // namespace internal | 49 } // namespace internal |
50 } // namespace mojo | 50 } // namespace mojo |
OLD | NEW |