diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-14 16:27:51 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-14 16:27:51 +0000 |
commit | 0d37563e4df3e98c429f3bd71816451becbe06d7 (patch) | |
tree | 8724e2770a1eb259d8ffd267e8dc7a587098e59b /mojo/common | |
parent | 0d55b916994bb03c4b2b5ecac90ad77c1124c453 (diff) | |
download | chromium_src-0d37563e4df3e98c429f3bd71816451becbe06d7.zip chromium_src-0d37563e4df3e98c429f3bd71816451becbe06d7.tar.gz chromium_src-0d37563e4df3e98c429f3bd71816451becbe06d7.tar.bz2 |
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
Diffstat (limited to 'mojo/common')
-rw-r--r-- | mojo/common/bindings_support_impl.cc | 80 | ||||
-rw-r--r-- | mojo/common/bindings_support_impl.h | 41 | ||||
-rw-r--r-- | mojo/common/common_type_converters_unittest.cc | 16 |
3 files changed, 1 insertions, 136 deletions
diff --git a/mojo/common/bindings_support_impl.cc b/mojo/common/bindings_support_impl.cc deleted file mode 100644 index 0e1f6a1..0000000 --- a/mojo/common/bindings_support_impl.cc +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2013 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/common/bindings_support_impl.h" - -#include "base/atomic_ref_count.h" -#include "base/bind.h" -#include "base/lazy_instance.h" -#include "base/threading/thread_local.h" -#include "mojo/common/handle_watcher.h" - -namespace mojo { -namespace common { -namespace { -base::LazyInstance<base::ThreadLocalPointer<Buffer> >::Leaky lazy_tls_ptr = - LAZY_INSTANCE_INITIALIZER; -} - -// Context is used to track the number of HandleWatcher objects in use by a -// particular BindingsSupportImpl instance. -class BindingsSupportImpl::Context - : public base::RefCountedThreadSafe<BindingsSupportImpl::Context> { - public: - void CallOnHandleReady(HandleWatcher* watcher, - AsyncWaitCallback* callback, - MojoResult result) { - delete watcher; - callback->OnHandleReady(result); - } - - private: - friend class base::RefCountedThreadSafe<Context>; - virtual ~Context() {} -}; - -BindingsSupportImpl::BindingsSupportImpl() - : context_(new Context()) { -} - -BindingsSupportImpl::~BindingsSupportImpl() { - // All HandleWatcher instances created through this interface should have - // been destroyed. - DCHECK(context_->HasOneRef()); -} - -Buffer* BindingsSupportImpl::GetCurrentBuffer() { - return lazy_tls_ptr.Pointer()->Get(); -} - -Buffer* BindingsSupportImpl::SetCurrentBuffer(Buffer* buf) { - Buffer* old_buf = lazy_tls_ptr.Pointer()->Get(); - lazy_tls_ptr.Pointer()->Set(buf); - return old_buf; -} - -BindingsSupport::AsyncWaitID BindingsSupportImpl::AsyncWait( - const Handle& handle, - MojoWaitFlags flags, - AsyncWaitCallback* callback) { - // This instance will be deleted when done or cancelled. - HandleWatcher* watcher = new HandleWatcher(); - - watcher->Start(handle, - flags, - MOJO_DEADLINE_INDEFINITE, - base::Bind(&Context::CallOnHandleReady, - context_, - watcher, - callback)); - return watcher; -} - -void BindingsSupportImpl::CancelWait(AsyncWaitID async_wait_id) { - HandleWatcher* watcher = static_cast<HandleWatcher*>(async_wait_id); - delete watcher; -} - -} // namespace common -} // namespace mojo diff --git a/mojo/common/bindings_support_impl.h b/mojo/common/bindings_support_impl.h deleted file mode 100644 index 2f08ba07..0000000 --- a/mojo/common/bindings_support_impl.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2013 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. - -#ifndef MOJO_COMMON_BINDINGS_SUPPORT_IMPL_H_ -#define MOJO_COMMON_BINDINGS_SUPPORT_IMPL_H_ - -#include "mojo/public/bindings/lib/bindings_support.h" - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/memory/ref_counted.h" -#include "mojo/common/mojo_common_export.h" - -namespace mojo { -namespace common { - -class MOJO_COMMON_EXPORT BindingsSupportImpl - : NON_EXPORTED_BASE(public BindingsSupport) { - public: - BindingsSupportImpl(); - virtual ~BindingsSupportImpl(); - - // BindingsSupport methods: - virtual Buffer* GetCurrentBuffer() OVERRIDE; - virtual Buffer* SetCurrentBuffer(Buffer* buf) OVERRIDE; - virtual AsyncWaitID AsyncWait(const Handle& handle, MojoWaitFlags flags, - AsyncWaitCallback* callback) OVERRIDE; - virtual void CancelWait(AsyncWaitID async_wait_id) OVERRIDE; - - private: - class Context; - scoped_refptr<Context> context_; - - DISALLOW_COPY_AND_ASSIGN(BindingsSupportImpl); -}; - -} // namespace common -} // namespace mojo - -#endif // MOJO_COMMON_BINDINGS_SUPPORT_IMPL_H_ diff --git a/mojo/common/common_type_converters_unittest.cc b/mojo/common/common_type_converters_unittest.cc index 90649fd..39e770a 100644 --- a/mojo/common/common_type_converters_unittest.cc +++ b/mojo/common/common_type_converters_unittest.cc @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "mojo/common/bindings_support_impl.h" #include "mojo/common/common_type_converters.h" #include "testing/gtest/include/gtest/gtest.h" @@ -23,20 +22,7 @@ void ExpectEqualsMojoString(const std::string& expected, } // namespace -class CommonTypeConvertersTest : public testing::Test { - private: - virtual void SetUp() OVERRIDE { - BindingsSupport::Set(&bindings_support_); - } - - virtual void TearDown() OVERRIDE { - BindingsSupport::Set(NULL); - } - - BindingsSupportImpl bindings_support_; -}; - -TEST_F(CommonTypeConvertersTest, StringPiece) { +TEST(CommonTypeConvertersTest, StringPiece) { AllocationScope scope; std::string kText("hello world"); |