summaryrefslogtreecommitdiffstats
path: root/remoting/base/scoped_thread_proxy.cc
diff options
context:
space:
mode:
authorwez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-30 21:09:33 +0000
committerwez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-30 21:09:33 +0000
commitb6791a77ae5c2eec843b8c9b4ad3d9fa9c11fda7 (patch)
tree608a649c16b2af968a0d250ba1c30b118e6bb3ba /remoting/base/scoped_thread_proxy.cc
parent910875d9a35955b0e51d150c40879eb892250155 (diff)
downloadchromium_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.cc')
-rw-r--r--remoting/base/scoped_thread_proxy.cc86
1 files changed, 86 insertions, 0 deletions
diff --git a/remoting/base/scoped_thread_proxy.cc b/remoting/base/scoped_thread_proxy.cc
new file mode 100644
index 0000000..d1dcc26
--- /dev/null
+++ b/remoting/base/scoped_thread_proxy.cc
@@ -0,0 +1,86 @@
+// Copyright (c) 2011 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 "remoting/base/scoped_thread_proxy.h"
+
+#include "base/bind.h"
+
+namespace remoting {
+
+class ScopedThreadProxy::Core : public base::RefCountedThreadSafe<Core> {
+ public:
+ Core(base::MessageLoopProxy* message_loop)
+ : message_loop_(message_loop),
+ canceled_(false) {
+ }
+
+ void PostTask(const tracked_objects::Location& from_here,
+ const base::Closure& closure) {
+ if (!canceled_)
+ message_loop_->PostTask(from_here, Wrap(closure));
+ }
+
+ void PostDelayedTask(
+ const tracked_objects::Location& from_here,
+ const base::Closure& closure,
+ int64 delay_ms) {
+ if (!canceled_) {
+ message_loop_->PostDelayedTask(from_here, Wrap(closure), delay_ms);
+ }
+ }
+
+ void Detach() {
+ DCHECK(message_loop_->BelongsToCurrentThread());
+ canceled_ = true;
+ }
+
+ private:
+ friend class base::RefCountedThreadSafe<Core>;
+
+ ~Core() {
+ DCHECK(canceled_);
+ }
+
+ base::Closure Wrap(const base::Closure& closure) {
+ return base::Bind(&Core::CallClosure, this, closure);
+ }
+
+ void CallClosure(const base::Closure& closure) {
+ DCHECK(message_loop_->BelongsToCurrentThread());
+
+ if (!canceled_)
+ closure.Run();
+ }
+
+ scoped_refptr<base::MessageLoopProxy> message_loop_;
+ bool canceled_;
+
+ DISALLOW_COPY_AND_ASSIGN(Core);
+};
+
+ScopedThreadProxy::ScopedThreadProxy(base::MessageLoopProxy* message_loop)
+ : core_(new Core(message_loop)) {
+}
+
+ScopedThreadProxy::~ScopedThreadProxy() {
+ Detach();
+}
+
+void ScopedThreadProxy::PostTask(const tracked_objects::Location& from_here,
+ const base::Closure& closure) {
+ core_->PostTask(from_here, closure);
+}
+
+void ScopedThreadProxy::PostDelayedTask(
+ const tracked_objects::Location& from_here,
+ const base::Closure& closure,
+ int64 delay_ms) {
+ core_->PostDelayedTask(from_here, closure, delay_ms);
+}
+
+void ScopedThreadProxy::Detach() {
+ core_->Detach();
+}
+
+} // namespace remoting