Skip to content

Commit

Permalink
Simplify RunTaskOnThread
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hashimoto@chromium.org committed Jul 23, 2014
1 parent f1ab0f1 commit c929c93
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion chrome/browser/chromeos/drive/file_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 4 additions & 0 deletions chrome/browser/chromeos/drive/file_cache_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/chromeos/drive/fileapi/async_file_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
Expand All @@ -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));
}
Expand Down
12 changes: 4 additions & 8 deletions google_apis/drive/task_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions google_apis/drive/task_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit c929c93

Please sign in to comment.