Simplify RunTaskOnThread

RunTaskOnThread has been running tasks synchronously if the task runner belongs to the current thread.
This behavior was necessary when it was allowed to access drive::FileSystem from both UI and IO threads.
But now, no one needs this behavior and every user uses this method to post tasks to the specified runner.

BUG=None

Review URL: https://codereview.chromium.org/408153003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284851 0039d316-1c4b-4281-b951-d872f2087c98
parent f1ab0f16
...@@ -284,7 +284,7 @@ FileError FileCache::OpenForWrite( ...@@ -284,7 +284,7 @@ FileError FileCache::OpenForWrite(
write_opened_files_[id]++; write_opened_files_[id]++;
file_closer->reset(new base::ScopedClosureRunner( file_closer->reset(new base::ScopedClosureRunner(
base::Bind(&google_apis::RunTaskOnThread, base::Bind(&google_apis::RunTaskWithTaskRunner,
blocking_task_runner_, blocking_task_runner_,
base::Bind(&FileCache::CloseForWrite, base::Bind(&FileCache::CloseForWrite,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(),
......
...@@ -381,6 +381,7 @@ TEST_F(FileCacheTest, OpenForWrite) { ...@@ -381,6 +381,7 @@ TEST_F(FileCacheTest, OpenForWrite) {
// Close (1). // Close (1).
file_closer1.reset(); file_closer1.reset();
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(cache_->IsOpenedForWrite(id)); EXPECT_TRUE(cache_->IsOpenedForWrite(id));
// last_modified is updated. // last_modified is updated.
...@@ -389,6 +390,7 @@ TEST_F(FileCacheTest, OpenForWrite) { ...@@ -389,6 +390,7 @@ TEST_F(FileCacheTest, OpenForWrite) {
// Close (2). // Close (2).
file_closer2.reset(); file_closer2.reset();
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(cache_->IsOpenedForWrite(id)); EXPECT_FALSE(cache_->IsOpenedForWrite(id));
// Try to open non-existent file. // Try to open non-existent file.
...@@ -424,6 +426,7 @@ TEST_F(FileCacheTest, UpdateMd5) { ...@@ -424,6 +426,7 @@ TEST_F(FileCacheTest, UpdateMd5) {
// Close file. // Close file.
file_closer.reset(); file_closer.reset();
base::RunLoop().RunUntilIdle();
// MD5 was cleared by OpenForWrite(). // MD5 was cleared by OpenForWrite().
EXPECT_EQ(FILE_ERROR_OK, metadata_storage_->GetEntry(id, &entry)); EXPECT_EQ(FILE_ERROR_OK, metadata_storage_->GetEntry(id, &entry));
...@@ -461,6 +464,7 @@ TEST_F(FileCacheTest, ClearDirty) { ...@@ -461,6 +464,7 @@ TEST_F(FileCacheTest, ClearDirty) {
// Close the file and clear the dirty bit. // Close the file and clear the dirty bit.
file_closer.reset(); file_closer.reset();
base::RunLoop().RunUntilIdle();
EXPECT_EQ(FILE_ERROR_OK, cache_->ClearDirty(id)); EXPECT_EQ(FILE_ERROR_OK, cache_->ClearDirty(id));
// Entry is not dirty. // Entry is not dirty.
......
...@@ -57,7 +57,7 @@ void PostFileSystemCallback( ...@@ -57,7 +57,7 @@ void PostFileSystemCallback(
file_system_getter, function, file_system_getter, function,
on_error_callback.is_null() ? on_error_callback.is_null() ?
base::Closure() : base::Closure() :
base::Bind(&google_apis::RunTaskOnThread, base::Bind(&google_apis::RunTaskWithTaskRunner,
base::MessageLoopProxy::current(), base::MessageLoopProxy::current(),
on_error_callback))); on_error_callback)));
} }
...@@ -74,7 +74,7 @@ void RunCreateOrOpenFileCallback( ...@@ -74,7 +74,7 @@ void RunCreateOrOpenFileCallback(
// (crbug.com/259184). // (crbug.com/259184).
callback.Run( callback.Run(
file.Pass(), file.Pass(),
base::Bind(&google_apis::RunTaskOnThread, base::Bind(&google_apis::RunTaskWithTaskRunner,
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
close_callback_on_ui_thread)); close_callback_on_ui_thread));
} }
......
...@@ -8,14 +8,10 @@ ...@@ -8,14 +8,10 @@
namespace google_apis { namespace google_apis {
void RunTaskOnThread(scoped_refptr<base::SequencedTaskRunner> task_runner, void RunTaskWithTaskRunner(scoped_refptr<base::TaskRunner> task_runner,
const base::Closure& task) { const base::Closure& task) {
if (task_runner->RunsTasksOnCurrentThread()) { const bool posted = task_runner->PostTask(FROM_HERE, task);
task.Run(); DCHECK(posted);
} else {
const bool posted = task_runner->PostTask(FROM_HERE, task);
DCHECK(posted);
}
} }
} // namespace google_apis } // namespace google_apis
...@@ -10,9 +10,9 @@ ...@@ -10,9 +10,9 @@
namespace google_apis { namespace google_apis {
// Runs task on a thread on which |task_runner| may run tasks. // Runs the task with the task runner.
void RunTaskOnThread(scoped_refptr<base::SequencedTaskRunner> task_runner, void RunTaskWithTaskRunner(scoped_refptr<base::TaskRunner> task_runner,
const base::Closure& task); const base::Closure& task);
namespace internal { namespace internal {
...@@ -116,7 +116,7 @@ CallbackType CreateComposedCallback( ...@@ -116,7 +116,7 @@ CallbackType CreateComposedCallback(
template<typename CallbackType> template<typename CallbackType>
CallbackType CreateRelayCallback(const CallbackType& callback) { CallbackType CreateRelayCallback(const CallbackType& callback) {
return CreateComposedCallback( return CreateComposedCallback(
base::Bind(&RunTaskOnThread, base::MessageLoopProxy::current()), base::Bind(&RunTaskWithTaskRunner, base::MessageLoopProxy::current()),
callback); callback);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment