diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-05 02:18:18 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-05 02:18:18 +0000 |
commit | e7b3a61984f86ccb238664542699c3b8a75b54c6 (patch) | |
tree | a75e7830c5fa93c5af7bcebf0c60485513ce6a1e /content | |
parent | 9c66adca4f62f3b85593068aea30cf1568690987 (diff) | |
download | chromium_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 'content')
-rw-r--r-- | content/browser/browser_thread_impl.cc | 102 | ||||
-rw-r--r-- | content/browser/browser_thread_impl.h | 9 | ||||
-rw-r--r-- | content/browser/browser_thread_unittest.cc | 63 | ||||
-rw-r--r-- | content/public/browser/browser_thread.h | 19 |
4 files changed, 4 insertions, 189 deletions
diff --git a/content/browser/browser_thread_impl.cc b/content/browser/browser_thread_impl.cc index 94ef3f1..a66477a 100644 --- a/content/browser/browser_thread_impl.cc +++ b/content/browser/browser_thread_impl.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. @@ -116,47 +116,6 @@ BrowserThreadImpl::~BrowserThreadImpl() { bool BrowserThreadImpl::PostTaskHelper( BrowserThread::ID identifier, const tracked_objects::Location& from_here, - Task* task, - int64 delay_ms, - bool nestable) { - DCHECK(identifier >= 0 && identifier < ID_COUNT); - // Optimization: to avoid unnecessary locks, we listed the ID enumeration in - // order of lifetime. So no need to lock if we know that the other thread - // outlives this one. - // Note: since the array is so small, ok to loop instead of creating a map, - // which would require a lock because std::map isn't thread safe, defeating - // the whole purpose of this optimization. - BrowserThread::ID current_thread; - bool guaranteed_to_outlive_target_thread = - GetCurrentThreadIdentifier(¤t_thread) && - current_thread <= identifier; - - if (!guaranteed_to_outlive_target_thread) - g_lock.Get().Acquire(); - - MessageLoop* message_loop = g_browser_threads[identifier] ? - g_browser_threads[identifier]->message_loop() : NULL; - if (message_loop) { - if (nestable) { - message_loop->PostDelayedTask(from_here, task, delay_ms); - } else { - message_loop->PostNonNestableDelayedTask(from_here, task, delay_ms); - } - } - - if (!guaranteed_to_outlive_target_thread) - g_lock.Get().Release(); - - if (!message_loop) - delete task; - - return !!message_loop; -} - -// static -bool BrowserThreadImpl::PostTaskHelper( - BrowserThread::ID identifier, - const tracked_objects::Location& from_here, const base::Closure& task, int64 delay_ms, bool nestable) { @@ -201,29 +160,6 @@ class BrowserThreadMessageLoopProxy : public base::MessageLoopProxy { // MessageLoopProxy implementation. virtual bool PostTask(const tracked_objects::Location& from_here, - Task* task) { - return BrowserThread::PostTask(id_, from_here, task); - } - - virtual bool PostDelayedTask(const tracked_objects::Location& from_here, - Task* task, int64 delay_ms) { - return BrowserThread::PostDelayedTask(id_, from_here, task, delay_ms); - } - - virtual bool PostNonNestableTask(const tracked_objects::Location& from_here, - Task* task) { - return BrowserThread::PostNonNestableTask(id_, from_here, task); - } - - virtual bool PostNonNestableDelayedTask( - const tracked_objects::Location& from_here, - Task* task, - int64 delay_ms) { - return BrowserThread::PostNonNestableDelayedTask(id_, from_here, task, - delay_ms); - } - - virtual bool PostTask(const tracked_objects::Location& from_here, const base::Closure& task) { return BrowserThread::PostTask(id_, from_here, task); } @@ -321,42 +257,6 @@ bool BrowserThread::PostNonNestableDelayedTask( } // static -bool BrowserThread::PostTask(ID identifier, - const tracked_objects::Location& from_here, - Task* task) { - return BrowserThreadImpl::PostTaskHelper( - identifier, from_here, task, 0, true); -} - -// static -bool BrowserThread::PostDelayedTask(ID identifier, - const tracked_objects::Location& from_here, - Task* task, - int64 delay_ms) { - return BrowserThreadImpl::PostTaskHelper( - identifier, from_here, task, delay_ms, true); -} - -// static -bool BrowserThread::PostNonNestableTask( - ID identifier, - const tracked_objects::Location& from_here, - Task* task) { - return BrowserThreadImpl::PostTaskHelper( - identifier, from_here, task, 0, false); -} - -// static -bool BrowserThread::PostNonNestableDelayedTask( - ID identifier, - const tracked_objects::Location& from_here, - Task* task, - int64 delay_ms) { - return BrowserThreadImpl::PostTaskHelper( - identifier, from_here, task, delay_ms, false); -} - -// static bool BrowserThread::PostTaskAndReply( ID identifier, const tracked_objects::Location& from_here, diff --git a/content/browser/browser_thread_impl.h b/content/browser/browser_thread_impl.h index d00ff5b..feea986 100644 --- a/content/browser/browser_thread_impl.h +++ b/content/browser/browser_thread_impl.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. @@ -35,13 +35,6 @@ class CONTENT_EXPORT BrowserThreadImpl // the API cleaner. Therefore make BrowserThread a friend class. friend class BrowserThread; - // TODO(brettw) remove this variant when Task->Closure migration is complete. - static bool PostTaskHelper( - BrowserThread::ID identifier, - const tracked_objects::Location& from_here, - Task* task, - int64 delay_ms, - bool nestable); static bool PostTaskHelper( BrowserThread::ID identifier, const tracked_objects::Location& from_here, diff --git a/content/browser/browser_thread_unittest.cc b/content/browser/browser_thread_unittest.cc index 59ec5f7..458f872 100644 --- a/content/browser/browser_thread_unittest.cc +++ b/content/browser/browser_thread_unittest.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. @@ -41,21 +41,6 @@ class BrowserThreadTest : public testing::Test { static void DoNothing() { } - class DummyTask : public Task { - public: - explicit DummyTask(bool* deleted) : deleted_(deleted) { } - ~DummyTask() { - *deleted_ = true; - } - - void Run() { - CHECK(false); - } - - private: - bool* deleted_; - }; - class DeletedOnFile : public base::RefCountedThreadSafe< DeletedOnFile, BrowserThread::DeleteOnFileThread> { @@ -101,14 +86,6 @@ TEST_F(BrowserThreadTest, Release) { MessageLoop::current()->Run(); } -TEST_F(BrowserThreadTest, TaskToNonExistentThreadIsDeleted) { - bool deleted = false; - BrowserThread::PostTask( - BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, - new DummyTask(&deleted)); - EXPECT_TRUE(deleted); -} - TEST_F(BrowserThreadTest, ReleasedOnCorrectThread) { { scoped_refptr<DeletedOnFile> test( @@ -148,42 +125,4 @@ TEST_F(BrowserThreadTest, PostTaskAndReply) { MessageLoop::current()->Run(); } - -TEST_F(BrowserThreadTest, TaskToNonExistentThreadIsDeletedViaMessageLoopProxy) { - bool deleted = false; - scoped_refptr<base::MessageLoopProxy> message_loop_proxy = - BrowserThread::GetMessageLoopProxyForThread( - BrowserThread::WEBKIT_DEPRECATED); - message_loop_proxy->PostTask(FROM_HERE, new DummyTask(&deleted)); - EXPECT_TRUE(deleted); -} - -TEST_F(BrowserThreadTest, PostTaskViaMessageLoopProxyAfterThreadExits) { - scoped_ptr<BrowserThreadImpl> io_thread( - new BrowserThreadImpl(BrowserThread::IO)); - io_thread->Start(); - io_thread->Stop(); - - bool deleted = false; - scoped_refptr<base::MessageLoopProxy> message_loop_proxy = - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); - bool ret = message_loop_proxy->PostTask(FROM_HERE, new DummyTask(&deleted)); - EXPECT_FALSE(ret); - EXPECT_TRUE(deleted); -} - -TEST_F(BrowserThreadTest, PostTaskViaMessageLoopProxyAfterThreadIsDeleted) { - { - scoped_ptr<BrowserThreadImpl> io_thread( - new BrowserThreadImpl(BrowserThread::IO)); - io_thread->Start(); - } - bool deleted = false; - scoped_refptr<base::MessageLoopProxy> message_loop_proxy = - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); - bool ret = message_loop_proxy->PostTask(FROM_HERE, new DummyTask(&deleted)); - EXPECT_FALSE(ret); - EXPECT_TRUE(deleted); -} - } diff --git a/content/public/browser/browser_thread.h b/content/public/browser/browser_thread.h index 5cc594a..ae9b6a8 100644 --- a/content/public/browser/browser_thread.h +++ b/content/public/browser/browser_thread.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. @@ -118,23 +118,6 @@ class CONTENT_EXPORT BrowserThread { const base::Closure& task, int64 delay_ms); - // TODO(brettw) remove these when Task->Closure conversion is done. - static bool PostTask(ID identifier, - const tracked_objects::Location& from_here, - Task* task); - static bool PostDelayedTask(ID identifier, - const tracked_objects::Location& from_here, - Task* task, - int64 delay_ms); - static bool PostNonNestableTask(ID identifier, - const tracked_objects::Location& from_here, - Task* task); - static bool PostNonNestableDelayedTask( - ID identifier, - const tracked_objects::Location& from_here, - Task* task, - int64 delay_ms); - static bool PostTaskAndReply( ID identifier, const tracked_objects::Location& from_here, |