Update V8 to version 4.7.24.
[chromium-blink-merge.git] / ipc / mojo / async_handle_waiter.h
blobd6cc74510b28eb0e189faf2ae489522f8b6d63f5
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
3 // found in the LICENSE file.
5 #ifndef IPC_MOJO_ASYNC_HANDLE_WAITER_H_
6 #define IPC_MOJO_ASYNC_HANDLE_WAITER_H_
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/message_loop/message_loop.h"
12 #include "ipc/ipc_export.h"
13 #include "third_party/mojo/src/mojo/public/c/system/types.h"
15 namespace IPC {
16 namespace internal {
18 // |AsyncHandleWaiter| waits on a mojo handle asynchronously and
19 // invokes the given |callback| through |runner| when it is signaled.
20 // * To start waiting, the client must call |AsyncHandleWaiter::Wait()|.
21 // The client can call |Wait()| again once it is signaled and
22 // the |callback| is invoked.
23 // * To cancel waiting, delete the instance.
25 // |AsyncHandleWaiter| must be created, used and deleted only from the IO
26 // |thread.
27 class IPC_MOJO_EXPORT AsyncHandleWaiter {
28 public:
29 class Context;
31 explicit AsyncHandleWaiter(base::Callback<void(MojoResult)> callback);
32 ~AsyncHandleWaiter();
34 MojoResult Wait(MojoHandle handle, MojoHandleSignals signals);
36 base::MessageLoopForIO::IOObserver* GetIOObserverForTest();
37 base::Callback<void(MojoResult)> GetWaitCallbackForTest();
39 private:
40 void InvokeCallback(MojoResult result);
42 scoped_refptr<Context> context_;
43 base::Callback<void(MojoResult)> callback_;
44 base::WeakPtrFactory<AsyncHandleWaiter> weak_factory_;
46 DISALLOW_COPY_AND_ASSIGN(AsyncHandleWaiter);
49 } // namespace internal
50 } // namespace IPC
52 #endif // IPC_MOJO_ASYNC_HANDLE_WAITER_H_