Commit 30abaff3 authored by Francois Doray's avatar Francois Doray Committed by Commit Bot

Use TaskScheduler instead of SequencedWorkerPool in blockfile cache.

This CL migrates calls from SequencedWorkerPool to TaskScheduler in
the posix blockfile cache. The calls were already redirected to
TaskScheduler under the hood (via
EnableWithRedirectionToTaskSchedulerForProcess).

Bug: 667892
Change-Id: I8abdb3df6d0fc4b35ad96109c8af818828a4df79
Reviewed-on: https://chromium-review.googlesource.com/850754
Commit-Queue: François Doray <fdoray@chromium.org>
Reviewed-by: default avatarJosh Karlin <jkarlin@chromium.org>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#528385}
parent 4e4ab263
...@@ -68,6 +68,8 @@ class NET_EXPORT_PRIVATE File : public base::RefCounted<File> { ...@@ -68,6 +68,8 @@ class NET_EXPORT_PRIVATE File : public base::RefCounted<File> {
size_t GetLength(); size_t GetLength();
// Blocks until |num_pending_io| IO operations complete. // Blocks until |num_pending_io| IO operations complete.
// TODO(fdoray): Rename to WaitForPendingIOForTesting() since this should only
// be called in tests.
static void WaitForPendingIO(int* num_pending_io); static void WaitForPendingIO(int* num_pending_io);
// Drops current pending operations without waiting for them to complete. // Drops current pending operations without waiting for them to complete.
......
...@@ -9,36 +9,14 @@ ...@@ -9,36 +9,14 @@
#include <utility> #include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/lazy_instance.h"
#include "base/location.h" #include "base/location.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/task_runner_util.h" #include "base/task_scheduler/post_task.h"
#include "base/threading/sequenced_worker_pool.h" #include "base/task_scheduler/task_scheduler.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "net/disk_cache/disk_cache.h" #include "net/disk_cache/disk_cache.h"
namespace {
// The maximum number of threads for this pool.
const int kMaxThreads = 5;
class FileWorkerPool : public base::SequencedWorkerPool {
public:
FileWorkerPool()
: base::SequencedWorkerPool(kMaxThreads,
"CachePool",
base::TaskPriority::USER_BLOCKING) {}
protected:
~FileWorkerPool() override = default;
};
base::LazyInstance<FileWorkerPool>::Leaky s_worker_pool =
LAZY_INSTANCE_INITIALIZER;
} // namespace
namespace disk_cache { namespace disk_cache {
File::File(base::File file) File::File(base::File file)
...@@ -95,11 +73,11 @@ bool File::Read(void* buffer, size_t buffer_len, size_t offset, ...@@ -95,11 +73,11 @@ bool File::Read(void* buffer, size_t buffer_len, size_t offset,
return false; return false;
} }
base::PostTaskAndReplyWithResult( base::PostTaskWithTraitsAndReplyWithResult(
s_worker_pool.Pointer(), FROM_HERE, FROM_HERE, {base::TaskPriority::USER_BLOCKING, base::MayBlock()},
base::Bind(&File::DoRead, base::Unretained(this), buffer, buffer_len, base::BindOnce(&File::DoRead, base::Unretained(this), buffer, buffer_len,
offset), offset),
base::Bind(&File::OnOperationComplete, this, callback)); base::BindOnce(&File::OnOperationComplete, this, callback));
*completed = false; *completed = false;
return true; return true;
...@@ -119,11 +97,15 @@ bool File::Write(const void* buffer, size_t buffer_len, size_t offset, ...@@ -119,11 +97,15 @@ bool File::Write(const void* buffer, size_t buffer_len, size_t offset,
return false; return false;
} }
base::PostTaskAndReplyWithResult( // The priority is USER_BLOCKING because the cache waits for the write to
s_worker_pool.Pointer(), FROM_HERE, // finish before it reads from the network again.
base::Bind(&File::DoWrite, base::Unretained(this), buffer, buffer_len, // TODO(fdoray): Consider removing this from the critical path of network
offset), // requests and changing the priority to BACKGROUND.
base::Bind(&File::OnOperationComplete, this, callback)); base::PostTaskWithTraitsAndReplyWithResult(
FROM_HERE, {base::TaskPriority::USER_BLOCKING, base::MayBlock()},
base::BindOnce(&File::DoWrite, base::Unretained(this), buffer, buffer_len,
offset),
base::BindOnce(&File::OnOperationComplete, this, callback));
*completed = false; *completed = false;
return true; return true;
...@@ -151,10 +133,11 @@ size_t File::GetLength() { ...@@ -151,10 +133,11 @@ size_t File::GetLength() {
// Static. // Static.
void File::WaitForPendingIO(int* num_pending_io) { void File::WaitForPendingIO(int* num_pending_io) {
// We are running unit tests so we should wait for all callbacks. Sadly, the // We are running unit tests so we should wait for all callbacks.
// worker pool only waits for tasks on the worker pool, not the "Reply" tasks
// so we have to let the current message loop to run. // This waits for callbacks running on worker threads.
s_worker_pool.Get().FlushForTesting(); base::TaskScheduler::GetInstance()->FlushForTesting();
// This waits for the "Reply" tasks running on the current MessageLoop.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
......
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