Add a basic settings page with a Polymer paper element which loads at chrome://md...
[chromium-blink-merge.git] / ipc / mojo / async_handle_waiter.h
blob55acb3eb8e2ecdec369dd56420a678b2da2be810
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 "ipc/ipc_export.h"
12 #include "third_party/mojo/src/mojo/public/c/system/types.h"
14 namespace IPC {
15 namespace internal {
17 // |AsyncHandleWaiter| waits on a mojo handle asynchronously and
18 // invokes the given |callback| through |runner| when it is signaled.
19 // * To start waiting, the client must call |AsyncHandleWaiter::Wait()|.
20 // The client can call |Wait()| again once it is signaled and
21 // the |callback| is invoked.
22 // * To cancel waiting, delete the instance.
24 // |AsyncHandleWaiter| must be created, used and deleted only from the IO
25 // |thread.
26 class IPC_MOJO_EXPORT AsyncHandleWaiter {
27 public:
28 class Context;
30 explicit AsyncHandleWaiter(base::Callback<void(MojoResult)> callback);
31 ~AsyncHandleWaiter();
33 MojoResult Wait(MojoHandle handle, MojoHandleSignals signals);
35 private:
36 void InvokeCallback(MojoResult result);
38 scoped_refptr<Context> context_;
39 base::Callback<void(MojoResult)> callback_;
40 base::WeakPtrFactory<AsyncHandleWaiter> weak_factory_;
42 DISALLOW_COPY_AND_ASSIGN(AsyncHandleWaiter);
45 } // namespace internal
46 } // namespace IPC
48 #endif // IPC_MOJO_ASYNC_HANDLE_WAITER_H_