diff options
| author | wez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-30 21:09:33 +0000 |
|---|---|---|
| committer | wez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-30 21:09:33 +0000 |
| commit | b6791a77ae5c2eec843b8c9b4ad3d9fa9c11fda7 (patch) | |
| tree | 608a649c16b2af968a0d250ba1c30b118e6bb3ba /remoting/base/scoped_thread_proxy.h | |
| parent | 910875d9a35955b0e51d150c40879eb892250155 (diff) | |
| download | chromium_src-b6791a77ae5c2eec843b8c9b4ad3d9fa9c11fda7.zip chromium_src-b6791a77ae5c2eec843b8c9b4ad3d9fa9c11fda7.tar.gz chromium_src-b6791a77ae5c2eec843b8c9b4ad3d9fa9c11fda7.tar.bz2 | |
Revert 139623 - Replace ScopedThreadProxy with MessageLoopProxy & WeakPtrs.
This affects the following classes:
* ChromotingClient
* ChromotingInstance
* HostUserInterface
* It2MeHostUserInterface
The MessageLoopProxy/WeakPtr combination requires that the WeakPtr is created on the thread referred to by the proxy; code in which that is hard to arrange usually has subtle race-conditions.
TEST=Existing unit-tests, and manual testing.
Review URL: https://chromiumcodereview.appspot.com/10454040
TBR=wez@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10446088
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139633 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/base/scoped_thread_proxy.h')
| -rw-r--r-- | remoting/base/scoped_thread_proxy.h | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/remoting/base/scoped_thread_proxy.h b/remoting/base/scoped_thread_proxy.h new file mode 100644 index 0000000..9e43a15 --- /dev/null +++ b/remoting/base/scoped_thread_proxy.h @@ -0,0 +1,73 @@ +// Copyright (c) 2012 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 REMOTING_BASE_SCOPED_THREAD_PROXY_H_ +#define REMOTING_BASE_SCOPED_THREAD_PROXY_H_ + +#include "base/callback_forward.h" +#include "base/message_loop_proxy.h" + +namespace remoting { + +// ScopedThreadProxy is proxy for message loops that cancels all +// pending tasks when it is destroyed. It can be used to post tasks +// for a non-refcounted object. Must be deleted on the thread it +// belongs to. +// +// +// The main difference from WeakPtr<> is that this class can be used safely to +// post tasks from different threads. +// It is similar to WeakHandle<> used in sync: the main difference is +// that WeakHandle<> creates closures itself, while ScopedThreadProxy +// accepts base::Closure instances which caller needs to create using +// base::Bind(). +// +// TODO(sergeyu): Potentially we could use WeakHandle<> instead of +// this class. Consider migrating to WeakHandle<> when it is moved to +// src/base and support for delayed tasks is implemented. +// +// Usage: +// class MyClass { +// public: +// MyClass() +// : thread_proxy_(base::MessageLoopProxy::current()) {} +// +// // Always called on the thread on which this object was created. +// void NonThreadSafeMethod() {} +// +// // Can be called on any thread. +// void ThreadSafeMethod() { +// thread_proxy_.PostTask(FROM_HERE, base::Bind( +// &MyClass::NonThreadSafeMethod, base::Unretained(this))); +// } +// +// private: +// ScopedThreadProxy thread_proxy_; +// }; +class ScopedThreadProxy { + public: + ScopedThreadProxy(base::MessageLoopProxy* message_loop); + ~ScopedThreadProxy(); + + void PostTask(const tracked_objects::Location& from_here, + const base::Closure& closure); + void PostDelayedTask(const tracked_objects::Location& from_here, + const base::Closure& closure, + int64 delay_ms); + + // Cancels all tasks posted via this proxy. Must be called on the + // thread this object belongs to. + void Detach(); + + private: + class Core; + + scoped_refptr<Core> core_; + + DISALLOW_COPY_AND_ASSIGN(ScopedThreadProxy); +}; + +} // namespace remoting + +#endif // REMOTING_BASE_SCOPED_THREAD_PROXY_H_ |
