blob: e82c27ae29c171ffa153651992f8d8121ba1d0d4 [file] [log] [blame]
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h"
#include "ipc/ipc_export.h"
#include "mojo/public/c/system/types.h"
namespace IPC {
namespace internal {
// |AsyncHandleWaiter| waits on a mojo handle asynchronously and
// invokes the given |callback| through |runner| when it is signaled.
// * To start waiting, the client must call |AsyncHandleWaiter::Wait()|.
// The client can call |Wait()| again once it is signaled and
// the |callback| is invoked.
// * To cancel waiting, delete the instance.
// |AsyncHandleWaiter| must be created, used and deleted only from the IO
// |thread.
class IPC_MOJO_EXPORT AsyncHandleWaiter {
class Context;
explicit AsyncHandleWaiter(base::Callback<void(MojoResult)> callback);
MojoResult Wait(MojoHandle handle, MojoHandleSignals signals);
base::MessageLoopForIO::IOObserver* GetIOObserverForTest();
base::Callback<void(MojoResult)> GetWaitCallbackForTest();
void InvokeCallback(MojoResult result);
scoped_refptr<Context> context_;
base::Callback<void(MojoResult)> callback_;
base::WeakPtrFactory<AsyncHandleWaiter> weak_factory_;
} // namespace internal
} // namespace IPC