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(
write_opened_files_[id]++;
file_closer->reset(new base::ScopedClosureRunner(
base::Bind(&google_apis::RunTaskOnThread,
base::Bind(&google_apis::RunTaskWithTaskRunner,
blocking_task_runner_,
base::Bind(&FileCache::CloseForWrite,
weak_ptr_factory_.GetWeakPtr(),
......
......@@ -381,6 +381,7 @@ TEST_F(FileCacheTest, OpenForWrite) {
// Close (1).
file_closer1.reset();
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(cache_->IsOpenedForWrite(id));
// last_modified is updated.
......@@ -389,6 +390,7 @@ TEST_F(FileCacheTest, OpenForWrite) {
// Close (2).
file_closer2.reset();
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(cache_->IsOpenedForWrite(id));
// Try to open non-existent file.
......@@ -424,6 +426,7 @@ TEST_F(FileCacheTest, UpdateMd5) {
// Close file.
file_closer.reset();
base::RunLoop().RunUntilIdle();
// MD5 was cleared by OpenForWrite().
EXPECT_EQ(FILE_ERROR_OK, metadata_storage_->GetEntry(id, &entry));
......@@ -461,6 +464,7 @@ TEST_F(FileCacheTest, ClearDirty) {
// Close the file and clear the dirty bit.
file_closer.reset();
base::RunLoop().RunUntilIdle();
EXPECT_EQ(FILE_ERROR_OK, cache_->ClearDirty(id));
// Entry is not dirty.
......
......@@ -57,7 +57,7 @@ void PostFileSystemCallback(
file_system_getter, function,
on_error_callback.is_null() ?
base::Closure() :
base::Bind(&google_apis::RunTaskOnThread,
base::Bind(&google_apis::RunTaskWithTaskRunner,
base::MessageLoopProxy::current(),
on_error_callback)));
}
......@@ -74,7 +74,7 @@ void RunCreateOrOpenFileCallback(
// (crbug.com/259184).
callback.Run(
file.Pass(),
base::Bind(&google_apis::RunTaskOnThread,
base::Bind(&google_apis::RunTaskWithTaskRunner,
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
close_callback_on_ui_thread));
}
......
......@@ -8,14 +8,10 @@
namespace google_apis {
void RunTaskOnThread(scoped_refptr<base::SequencedTaskRunner> task_runner,
const base::Closure& task) {
if (task_runner->RunsTasksOnCurrentThread()) {
task.Run();
} else {
const bool posted = task_runner->PostTask(FROM_HERE, task);
DCHECK(posted);
}
void RunTaskWithTaskRunner(scoped_refptr<base::TaskRunner> task_runner,
const base::Closure& task) {
const bool posted = task_runner->PostTask(FROM_HERE, task);
DCHECK(posted);
}
} // namespace google_apis
......@@ -10,9 +10,9 @@
namespace google_apis {
// Runs task on a thread on which |task_runner| may run tasks.
void RunTaskOnThread(scoped_refptr<base::SequencedTaskRunner> task_runner,
const base::Closure& task);
// Runs the task with the task runner.
void RunTaskWithTaskRunner(scoped_refptr<base::TaskRunner> task_runner,
const base::Closure& task);
namespace internal {
......@@ -116,7 +116,7 @@ CallbackType CreateComposedCallback(
template<typename CallbackType>
CallbackType CreateRelayCallback(const CallbackType& callback) {
return CreateComposedCallback(
base::Bind(&RunTaskOnThread, base::MessageLoopProxy::current()),
base::Bind(&RunTaskWithTaskRunner, base::MessageLoopProxy::current()),
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