OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef IPC_MOJO_ASYNC_HANDLE_WAITER_H_ | 5 #ifndef IPC_MOJO_ASYNC_HANDLE_WAITER_H_ |
6 #define IPC_MOJO_ASYNC_HANDLE_WAITER_H_ | 6 #define IPC_MOJO_ASYNC_HANDLE_WAITER_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "ipc/ipc_export.h" | 11 #include "ipc/ipc_export.h" |
12 #include "third_party/mojo/src/mojo/public/c/system/types.h" | 12 #include "third_party/mojo/src/mojo/public/c/system/types.h" |
13 | 13 |
14 namespace IPC { | 14 namespace IPC { |
15 namespace internal { | 15 namespace internal { |
16 | 16 |
17 // |AsyncHandleWaiter| waits on a mojo handle asynchronously and | 17 // |AsyncHandleWaiter| waits on a mojo handle asynchronously and |
18 // invokes the given |callback| through |runner| when it is signaled. | 18 // invokes the given |callback| through |runner| when it is signaled. |
19 // * To start waiting, the client must call |AsyncHandleWaiter::Wait()|. | 19 // * To start waiting, the client must call |AsyncHandleWaiter::Wait()|. |
20 // The client can call |Wait()| again once it is signaled and | 20 // The client can call |Wait()| again once it is signaled and |
21 // the |callback| is invoked. | 21 // the |callback| is invoked. |
22 // * To cancel waiting, delete the instance. | 22 // * To cancel waiting, delete the instance. |
23 // | 23 // |
24 // |AsyncHandleWaiter| must be created, used and deleted only from the IO | 24 // |AsyncHandleWaiter| must be created, used and deleted only from the IO |
25 // |thread. | 25 // |thread. |
26 class IPC_MOJO_EXPORT AsyncHandleWaiter { | 26 class IPC_MOJO_EXPORT AsyncHandleWaiter { |
27 public: | 27 public: |
28 class Context; | 28 class Context; |
29 | 29 |
30 explicit AsyncHandleWaiter(base::Callback<void(MojoResult)> callback); | 30 class Delegate { |
| 31 public: |
| 32 virtual void PipeIsReady(MojoResult result) = 0; |
| 33 virtual void MessageWasArrived(const void* bytes, uint32_t num_bytes) = 0; |
| 34 }; |
| 35 |
| 36 explicit AsyncHandleWaiter(Delegate* delegate); |
31 ~AsyncHandleWaiter(); | 37 ~AsyncHandleWaiter(); |
32 | 38 |
| 39 void SetMessageCallback(MojoHandle handle); |
| 40 void ClearMessageCallback(MojoHandle handle); |
33 MojoResult Wait(MojoHandle handle, MojoHandleSignals signals); | 41 MojoResult Wait(MojoHandle handle, MojoHandleSignals signals); |
34 | 42 |
35 private: | 43 private: |
36 void InvokeCallback(MojoResult result); | 44 void InvokeCallback(MojoResult result); |
| 45 void InvokeMessageCallback(const void* bytes, uint32_t num_bytes); |
37 | 46 |
38 scoped_refptr<Context> context_; | 47 scoped_refptr<Context> context_; |
39 base::Callback<void(MojoResult)> callback_; | 48 Delegate* delegate_; |
| 49 base::Callback<void(MojoResult)> context_callback_; |
| 50 base::Callback<bool(const void*, uint32_t)> context_message_callback_; |
40 base::WeakPtrFactory<AsyncHandleWaiter> weak_factory_; | 51 base::WeakPtrFactory<AsyncHandleWaiter> weak_factory_; |
41 | 52 |
42 DISALLOW_COPY_AND_ASSIGN(AsyncHandleWaiter); | 53 DISALLOW_COPY_AND_ASSIGN(AsyncHandleWaiter); |
43 }; | 54 }; |
44 | 55 |
45 } // namespace internal | 56 } // namespace internal |
46 } // namespace IPC | 57 } // namespace IPC |
47 | 58 |
48 #endif // IPC_MOJO_ASYNC_HANDLE_WAITER_H_ | 59 #endif // IPC_MOJO_ASYNC_HANDLE_WAITER_H_ |
OLD | NEW |