summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-05 02:18:18 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-05 02:18:18 +0000
commite7b3a61984f86ccb238664542699c3b8a75b54c6 (patch)
treea75e7830c5fa93c5af7bcebf0c60485513ce6a1e /remoting
parent9c66adca4f62f3b85593068aea30cf1568690987 (diff)
downloadchromium_src-e7b3a61984f86ccb238664542699c3b8a75b54c6.zip
chromium_src-e7b3a61984f86ccb238664542699c3b8a75b54c6.tar.gz
chromium_src-e7b3a61984f86ccb238664542699c3b8a75b54c6.tar.bz2
base::Bind: Remove Task.
BUG=none TEST=none R=awong Review URL: http://codereview.chromium.org/9086002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116439 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/base/plugin_message_loop_proxy.cc49
-rw-r--r--remoting/base/plugin_message_loop_proxy.h20
-rw-r--r--remoting/jingle_glue/jingle_thread_unittest.cc38
3 files changed, 28 insertions, 79 deletions
diff --git a/remoting/base/plugin_message_loop_proxy.cc b/remoting/base/plugin_message_loop_proxy.cc
index 3a8b48e..b3bc453 100644
--- a/remoting/base/plugin_message_loop_proxy.cc
+++ b/remoting/base/plugin_message_loop_proxy.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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.
@@ -24,42 +24,6 @@ void PluginMessageLoopProxy::Detach() {
}
}
-// MessageLoopProxy interface implementation.
-bool PluginMessageLoopProxy::PostTask(
- const tracked_objects::Location& from_here,
- Task* task) {
- return PostDelayedTask(from_here, task, 0);
-}
-
-bool PluginMessageLoopProxy::PostDelayedTask(
- const tracked_objects::Location& from_here,
- Task* task,
- int64 delay_ms) {
- base::AutoLock auto_lock(lock_);
- if (!delegate_)
- return false;
-
- base::Closure* springpad_closure = new base::Closure(base::Bind(
- &PluginMessageLoopProxy::RunTaskIf, this, task));
- return delegate_->RunOnPluginThread(
- delay_ms, &PluginMessageLoopProxy::TaskSpringboard, springpad_closure);
-}
-
-bool PluginMessageLoopProxy::PostNonNestableTask(
- const tracked_objects::Location& from_here,
- Task* task) {
- // All tasks running on this message loop are non-nestable.
- return PostTask(from_here, task);
-}
-
-bool PluginMessageLoopProxy::PostNonNestableDelayedTask(
- const tracked_objects::Location& from_here,
- Task* task,
- int64 delay_ms) {
- // All tasks running on this message loop are non-nestable.
- return PostDelayedTask(from_here, task, delay_ms);
-}
-
bool PluginMessageLoopProxy::PostTask(
const tracked_objects::Location& from_here,
const base::Closure& task) {
@@ -97,7 +61,7 @@ bool PluginMessageLoopProxy::PostNonNestableDelayedTask(
bool PluginMessageLoopProxy::BelongsToCurrentThread() {
// In pepper plugins ideally we should use pp::Core::IsMainThread,
- // but it is problematic becase we would need to keep reference to
+ // but it is problematic because we would need to keep reference to
// Core somewhere, e.g. make the delegate ref-counted.
return base::PlatformThread::CurrentId() == plugin_thread_id_;
}
@@ -109,15 +73,6 @@ void PluginMessageLoopProxy::TaskSpringboard(void* data) {
delete task;
}
-void PluginMessageLoopProxy::RunTaskIf(Task* task) {
- DCHECK(BelongsToCurrentThread());
- // |delegate_| can be changed only from our thread, so it's safe to
- // access it without acquiring |lock_|.
- if (delegate_)
- task->Run();
- delete task;
-}
-
void PluginMessageLoopProxy::RunClosureIf(const base::Closure& task) {
// |delegate_| can be changed only from our thread, so it's safe to
// access it without acquiring |lock_|.
diff --git a/remoting/base/plugin_message_loop_proxy.h b/remoting/base/plugin_message_loop_proxy.h
index 8a0d840..19082a0 100644
--- a/remoting/base/plugin_message_loop_proxy.h
+++ b/remoting/base/plugin_message_loop_proxy.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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.
@@ -31,22 +31,7 @@ class PluginMessageLoopProxy : public base::MessageLoopProxy {
void Detach();
- // base::MessageLoopProxy interface.
- virtual bool PostTask(
- const tracked_objects::Location& from_here,
- Task* task) OVERRIDE;
- virtual bool PostDelayedTask(
- const tracked_objects::Location& from_here,
- Task* task,
- int64 delay_ms) OVERRIDE;
- virtual bool PostNonNestableTask(
- const tracked_objects::Location& from_here,
- Task* task) OVERRIDE;
- virtual bool PostNonNestableDelayedTask(
- const tracked_objects::Location& from_here,
- Task* task,
- int64 delay_ms) OVERRIDE;
-
+ // base::MessageLoopProxy implementation.
virtual bool PostTask(
const tracked_objects::Location& from_here,
const base::Closure& task) OVERRIDE;
@@ -67,7 +52,6 @@ class PluginMessageLoopProxy : public base::MessageLoopProxy {
private:
static void TaskSpringboard(void* data);
- void RunTaskIf(Task* task);
void RunClosureIf(const base::Closure& task);
base::PlatformThreadId plugin_thread_id_;
diff --git a/remoting/jingle_glue/jingle_thread_unittest.cc b/remoting/jingle_glue/jingle_thread_unittest.cc
index 287af05..9deb8db 100644
--- a/remoting/jingle_glue/jingle_thread_unittest.cc
+++ b/remoting/jingle_glue/jingle_thread_unittest.cc
@@ -1,7 +1,9 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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.
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/message_loop.h"
#include "base/time.h"
#include "base/synchronization/waitable_event.h"
@@ -11,35 +13,39 @@
namespace remoting {
-class MockTask : public Task {
+class MockCallback {
public:
MOCK_METHOD0(Run, void());
};
namespace {
+
// Delay used to test delayed tasks. Shouldn't be too big, so that we don't
// slow down the test, yet, should be big enough to be measurable.
int kDelayMs = 50; // 0.05 s.
int kDelayTimeoutMs = 10000; // 10 s.
+
} // namespace
TEST(JingleThreadTest, PostTask) {
JingleThread thread;
- MockTask* task = new MockTask();
- EXPECT_CALL(*task, Run());
+ MockCallback task;
+ EXPECT_CALL(task, Run());
thread.Start();
- thread.message_loop()->PostTask(FROM_HERE, task);
+ thread.message_loop()->PostTask(
+ FROM_HERE, base::Bind(&MockCallback::Run, base::Unretained(&task)));
thread.Stop();
}
TEST(JingleThreadTest, PostNonNestableTask) {
JingleThread thread;
- MockTask* task = new MockTask();
- EXPECT_CALL(*task, Run());
+ MockCallback task;
+ EXPECT_CALL(task, Run());
thread.Start();
- thread.message_loop()->PostNonNestableTask(FROM_HERE, task);
+ thread.message_loop()->PostNonNestableTask(
+ FROM_HERE, base::Bind(&MockCallback::Run, base::Unretained(&task)));
thread.Stop();
}
@@ -49,13 +55,15 @@ ACTION_P(SignalEvent, event) {
TEST(JingleThreadTest, PostDelayedTask) {
JingleThread thread;
- MockTask* task = new MockTask();
+ MockCallback task;
base::WaitableEvent event(true, false);
- EXPECT_CALL(*task, Run()).WillOnce(SignalEvent(&event));
+ EXPECT_CALL(task, Run()).WillOnce(SignalEvent(&event));
thread.Start();
base::Time start = base::Time::Now();
- thread.message_loop()->PostDelayedTask(FROM_HERE, task, kDelayMs);
+ thread.message_loop()->PostDelayedTask(
+ FROM_HERE, base::Bind(&MockCallback::Run, base::Unretained(&task)),
+ kDelayMs);
event.TimedWait(base::TimeDelta::FromMilliseconds(kDelayTimeoutMs));
base::Time end = base::Time::Now();
thread.Stop();
@@ -65,13 +73,15 @@ TEST(JingleThreadTest, PostDelayedTask) {
TEST(JingleThreadTest, PostNonNestableDelayedTask) {
JingleThread thread;
- MockTask* task = new MockTask();
+ MockCallback task;
base::WaitableEvent event(true, false);
- EXPECT_CALL(*task, Run()).WillOnce(SignalEvent(&event));
+ EXPECT_CALL(task, Run()).WillOnce(SignalEvent(&event));
thread.Start();
base::Time start = base::Time::Now();
- thread.message_loop()->PostNonNestableDelayedTask(FROM_HERE, task, kDelayMs);
+ thread.message_loop()->PostNonNestableDelayedTask(
+ FROM_HERE, base::Bind(&MockCallback::Run, base::Unretained(&task)),
+ kDelayMs);
event.TimedWait(base::TimeDelta::FromMilliseconds(kDelayTimeoutMs));
base::Time end = base::Time::Now();
thread.Stop();