Commit f9cc9601 authored by Maks Orlovich's avatar Maks Orlovich Committed by Commit Bot

SimpleCache: Port (unsequenced) use of SequencedWorkerPool over to TaskScheduler

This is what it does behind scenes in Chrome anyway, but always using the scheduler
in tests as well is helpful since it means a single TaskScheduler::FlushForTesting() call
rather than needing both TaskScheduler and SequencedWorkerPool versions of FlushForTesting()
as separate calls, which causes trouble when control jumps back and forth between the two.

Bug: 766221
Change-Id: Iab6a49cad86f1fd5a31c66c50d25e2962c538d53
Reviewed-on: https://chromium-review.googlesource.com/697925Reviewed-by: default avatarAsanka Herath <asanka@chromium.org>
Reviewed-by: default avatarScott Graham <scottmg@chromium.org>
Commit-Queue: Maks Orlovich <morlovich@chromium.org>
Cr-Commit-Position: refs/heads/master@{#506395}
parent ccceef0e
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include "base/sys_info.h" #include "base/sys_info.h"
#include "base/task_runner_util.h" #include "base/task_runner_util.h"
#include "base/task_scheduler/post_task.h" #include "base/task_scheduler/post_task.h"
#include "base/threading/sequenced_worker_pool.h" #include "base/task_scheduler/task_scheduler.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/trace_event/memory_usage_estimator.h" #include "base/trace_event/memory_usage_estimator.h"
...@@ -49,7 +49,6 @@ ...@@ -49,7 +49,6 @@
using base::Callback; using base::Callback;
using base::Closure; using base::Closure;
using base::FilePath; using base::FilePath;
using base::SequencedWorkerPool;
using base::Time; using base::Time;
using base::DirectoryExists; using base::DirectoryExists;
using base::CreateDirectory; using base::CreateDirectory;
...@@ -58,39 +57,9 @@ namespace disk_cache { ...@@ -58,39 +57,9 @@ namespace disk_cache {
namespace { namespace {
// Maximum number of concurrent worker pool threads, which also is the limit
// on concurrent IO (as we use one thread per IO request).
const size_t kMaxWorkerThreads = 5U;
const char kThreadNamePrefix[] = "SimpleCache";
// Maximum fraction of the cache that one entry can consume. // Maximum fraction of the cache that one entry can consume.
const int kMaxFileRatio = 8; const int kMaxFileRatio = 8;
class LeakySequencedWorkerPool {
public:
LeakySequencedWorkerPool()
: sequenced_worker_pool_(
new SequencedWorkerPool(kMaxWorkerThreads,
kThreadNamePrefix,
base::TaskPriority::USER_BLOCKING)) {}
void FlushForTesting() { sequenced_worker_pool_->FlushForTesting(); }
scoped_refptr<base::TaskRunner> GetTaskRunner() {
return sequenced_worker_pool_->GetTaskRunnerWithShutdownBehavior(
SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
}
private:
scoped_refptr<SequencedWorkerPool> sequenced_worker_pool_;
DISALLOW_COPY_AND_ASSIGN(LeakySequencedWorkerPool);
};
base::LazyInstance<LeakySequencedWorkerPool>::Leaky g_sequenced_worker_pool =
LAZY_INSTANCE_INITIALIZER;
scoped_refptr<base::SequencedTaskRunner> FallbackToInternalIfNull( scoped_refptr<base::SequencedTaskRunner> FallbackToInternalIfNull(
const scoped_refptr<base::SequencedTaskRunner>& cache_runner) { const scoped_refptr<base::SequencedTaskRunner>& cache_runner) {
if (cache_runner) if (cache_runner)
...@@ -278,7 +247,10 @@ SimpleBackendImpl::~SimpleBackendImpl() { ...@@ -278,7 +247,10 @@ SimpleBackendImpl::~SimpleBackendImpl() {
} }
int SimpleBackendImpl::Init(const CompletionCallback& completion_callback) { int SimpleBackendImpl::Init(const CompletionCallback& completion_callback) {
worker_pool_ = g_sequenced_worker_pool.Get().GetTaskRunner(); worker_pool_ = base::TaskScheduler::GetInstance()->CreateTaskRunnerWithTraits(
{base::MayBlock(), base::WithBaseSyncPrimitives(),
base::TaskPriority::USER_BLOCKING,
base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN});
index_ = std::make_unique<SimpleIndex>( index_ = std::make_unique<SimpleIndex>(
base::ThreadTaskRunnerHandle::Get(), cleanup_tracker_.get(), this, base::ThreadTaskRunnerHandle::Get(), cleanup_tracker_.get(), this,
...@@ -818,9 +790,8 @@ void SimpleBackendImpl::DoomEntriesComplete( ...@@ -818,9 +790,8 @@ void SimpleBackendImpl::DoomEntriesComplete(
// static // static
void SimpleBackendImpl::FlushWorkerPoolForTesting() { void SimpleBackendImpl::FlushWorkerPoolForTesting() {
// We only need to do this if we there is an active task runner. // TODO(morlovich): Remove this, move everything over to disk_cache:: use.
if (base::ThreadTaskRunnerHandle::IsSet()) base::TaskScheduler::GetInstance()->FlushForTesting();
g_sequenced_worker_pool.Get().FlushForTesting();
} }
} // namespace disk_cache } // namespace disk_cache
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