Commit 34db9f35 authored by fdoray's avatar fdoray Committed by Commit bot

Use TaskScheduler instead of WorkerPool in file_ios.cc.

The following traits are used:

Priority: Inherited (default)
  The priority is inherited from the calling context (i.e. TaskTraits
  are initialized with the priority of the current task).

Shutdown behavior: CONTINUE_ON_SHUTDOWN
  Tasks posted with this mode which have not started executing before
  shutdown is initiated will never run. Tasks with this mode running at
  shutdown will be ignored (the worker will not be joined).

  Note: Tasks that were previously posted to base::WorkerPool should
  use this shutdown behavior because this is how base::WorkerPool
  handles all its tasks.

May Block:
  Tasks posted with MayBlock() may block. This includes but is not
  limited to tasks that wait on synchronous file I/O operations:
  read or write a file from disk, interact with a pipe or a socket,
  rename or delete a file, enumerate files in a directory, etc. This
  trait isn't required for the mere use of locks.

BUG=659191

Review-Url: https://codereview.chromium.org/2608093002
Cr-Commit-Position: refs/heads/master@{#442971}
parent 4702f8e8
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "base/location.h" #include "base/location.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/threading/worker_pool.h" #include "base/task_scheduler/post_task.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "net/disk_cache/blockfile/in_flight_io.h" #include "net/disk_cache/blockfile/in_flight_io.h"
#include "net/disk_cache/disk_cache.h" #include "net/disk_cache/disk_cache.h"
...@@ -121,8 +121,12 @@ void FileInFlightIO::PostRead(disk_cache::File *file, void* buf, size_t buf_len, ...@@ -121,8 +121,12 @@ void FileInFlightIO::PostRead(disk_cache::File *file, void* buf, size_t buf_len,
new FileBackgroundIO(file, buf, buf_len, offset, callback, this)); new FileBackgroundIO(file, buf, buf_len, offset, callback, this));
file->AddRef(); // Balanced on OnOperationComplete() file->AddRef(); // Balanced on OnOperationComplete()
base::WorkerPool::PostTask(FROM_HERE, base::PostTaskWithTraits(
base::Bind(&FileBackgroundIO::Read, operation.get()), true); FROM_HERE, base::TaskTraits()
.WithShutdownBehavior(
base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)
.MayBlock(),
base::Bind(&FileBackgroundIO::Read, operation.get()));
OnOperationPosted(operation.get()); OnOperationPosted(operation.get());
} }
...@@ -133,8 +137,12 @@ void FileInFlightIO::PostWrite(disk_cache::File* file, const void* buf, ...@@ -133,8 +137,12 @@ void FileInFlightIO::PostWrite(disk_cache::File* file, const void* buf,
new FileBackgroundIO(file, buf, buf_len, offset, callback, this)); new FileBackgroundIO(file, buf, buf_len, offset, callback, this));
file->AddRef(); // Balanced on OnOperationComplete() file->AddRef(); // Balanced on OnOperationComplete()
base::WorkerPool::PostTask(FROM_HERE, base::PostTaskWithTraits(
base::Bind(&FileBackgroundIO::Write, operation.get()), true); FROM_HERE, base::TaskTraits()
.WithShutdownBehavior(
base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)
.MayBlock(),
base::Bind(&FileBackgroundIO::Write, operation.get()));
OnOperationPosted(operation.get()); OnOperationPosted(operation.get());
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/test/scoped_async_task_scheduler.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "net/base/cache_type.h" #include "net/base/cache_type.h"
#include "net/disk_cache/disk_cache.h" #include "net/disk_cache/disk_cache.h"
...@@ -56,6 +57,12 @@ class DiskCacheTest : public PlatformTest { ...@@ -56,6 +57,12 @@ class DiskCacheTest : public PlatformTest {
private: private:
base::ScopedTempDir temp_dir_; base::ScopedTempDir temp_dir_;
std::unique_ptr<base::MessageLoop> message_loop_; std::unique_ptr<base::MessageLoop> message_loop_;
// Use a ScopedAsyncTaskScheduler instead of a ScopedTaskScheduler to allow
// disk_cache::InFlightIO::WaitForPendingIO to wait for TaskScheduler tasks
// from the main thread using WaitableEvents (this wouldn't work if
// TaskScheduler tasks ran on the main thread).
base::test::ScopedAsyncTaskScheduler scoped_async_task_scheduler_;
}; };
// Provides basic support for cache related tests. // Provides basic support for cache related tests.
......
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