From 0d37563e4df3e98c429f3bd71816451becbe06d7 Mon Sep 17 00:00:00 2001 From: "darin@chromium.org" <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> Date: Tue, 14 Jan 2014 16:27:51 +0000 Subject: Mojo: AsyncWaiter and mojo/public/environment Summary of changes: o BindingsSupport is gone: - mojo/public/bindings/lib depends on mojo/public/environment/, which is also a static library. - mojo/public/environment provides a default implementation of MojoAsyncWaiter (replacing the AsyncWait functionality of BindingsSupport). - mojo/public/environment provides TLS support for storing the current Buffer* (replacing the Set/GetCurrentBuffer functionality of BindingsSupport). - mojo/public/environment provides the Environment class, formerly part of mojo/public/utility/ - The standalone implementation of mojo/public/environment/ depends on mojo/public/utility/ and assumes clients will be instantiating RunLoops on their threads. - The chromium-specific implementation of mojo/public/environment/ depends on mojo/common/ and assumes clients will be instantiating MessageLoops on their threads. - The chromium-specific implementation of mojo/public/environment/ is divided into two targets: mojo_environment_chromium and mojo_environment_chromium_impl. The former is a static library and the latter is a component. (This way all of the state--TLS keys-- associated with the environment is kept in a DSO when using a component build.) o RemotePtr and Connector may optionally be parameterized with a MojoAsyncWaiter*, allowing users to customize how AsyncWait is implemented for a particular usage of bindings. This is needed by the GL library so that it can schedule work on an application defined run loop. o RunLoop gains a RunUntilIdle method to support tests. This allows us to delete SimpleBindingsSupport instead of converting it over to an implementation of MojoAsyncWaiter. Review URL: https://codereview.chromium.org/134253004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@244739 0039d316-1c4b-4281-b951-d872f2087c98 --- mojo/environment/async_waiter_impl.cc | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 mojo/environment/async_waiter_impl.cc (limited to 'mojo/environment/async_waiter_impl.cc') diff --git a/mojo/environment/async_waiter_impl.cc b/mojo/environment/async_waiter_impl.cc new file mode 100644 index 0000000..ab0599a --- /dev/null +++ b/mojo/environment/async_waiter_impl.cc @@ -0,0 +1,51 @@ +// Copyright 2014 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 "mojo/environment/async_waiter_impl.h" + +#include "base/bind.h" +#include "mojo/common/handle_watcher.h" + +namespace mojo { +namespace internal { +namespace { + +void OnHandleReady(common::HandleWatcher* watcher, + MojoAsyncWaitCallback callback, + uintptr_t user_data, + MojoResult result) { + delete watcher; + callback(user_data, result); +} + +MojoAsyncWaitID AsyncWait(MojoAsyncWaiter* waiter, + MojoHandle handle, + MojoWaitFlags flags, + MojoDeadline deadline, + MojoAsyncWaitCallback callback, + uintptr_t user_data) { + // This instance will be deleted when done or cancelled. + common::HandleWatcher* watcher = new common::HandleWatcher(); + watcher->Start(Handle(handle), flags, deadline, + base::Bind(&OnHandleReady, watcher, callback, user_data)); + return reinterpret_cast<MojoAsyncWaitID>(watcher); +} + +void CancelWait(MojoAsyncWaiter* waiter, MojoAsyncWaitID wait_id) { + delete reinterpret_cast<common::HandleWatcher*>(wait_id); +} + +MojoAsyncWaiter s_default_async_waiter = { + AsyncWait, + CancelWait +}; + +} // namespace + +MojoAsyncWaiter* GetDefaultAsyncWaiterImpl() { + return &s_default_async_waiter; +} + +} // namespace internal +} // namespace mojo -- cgit v1.1