Skip to content

Commit

Permalink
Migrate disk_cache API to CompletionOnceCallback.
Browse files Browse the repository at this point in the history
The users, including tests were not touched except when they had test subclasses and the like.

Bug: 807724
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: Ide1b12faccf01adf252aff3671f5095cb06231cf
Reviewed-on: https://chromium-review.googlesource.com/1077057
Reviewed-by: Antoine Labour <piman@chromium.org>
Reviewed-by: Joshua Bell <jsbell@chromium.org>
Reviewed-by: Bence Béky <bnc@chromium.org>
Commit-Queue: Maks Orlovich <morlovich@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565232}
  • Loading branch information
Maks Orlovich authored and Commit Bot committed Jun 7, 2018
1 parent 95edae1 commit 4acf0b5
Show file tree
Hide file tree
Showing 31 changed files with 956 additions and 958 deletions.
42 changes: 23 additions & 19 deletions content/browser/cache_storage/cache_storage_cache_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,42 +84,44 @@ class DelayableBackend : public disk_cache::Backend {
int OpenEntry(const std::string& key,
net::RequestPriority request_priority,
disk_cache::Entry** entry,
const CompletionCallback& callback) override {
CompletionOnceCallback callback) override {
if (delay_open_entry_ && open_entry_callback_.is_null()) {
open_entry_callback_ = base::BindOnce(
&DelayableBackend::OpenEntryDelayedImpl, base::Unretained(this), key,
base::Unretained(entry), callback);
base::Unretained(entry), std::move(callback));
return net::ERR_IO_PENDING;
}
return backend_->OpenEntry(key, request_priority, entry, callback);
return backend_->OpenEntry(key, request_priority, entry,
std::move(callback));
}

int CreateEntry(const std::string& key,
net::RequestPriority request_priority,
disk_cache::Entry** entry,
const CompletionCallback& callback) override {
return backend_->CreateEntry(key, request_priority, entry, callback);
CompletionOnceCallback callback) override {
return backend_->CreateEntry(key, request_priority, entry,
std::move(callback));
}
int DoomEntry(const std::string& key,
net::RequestPriority request_priority,
const CompletionCallback& callback) override {
return backend_->DoomEntry(key, request_priority, callback);
CompletionOnceCallback callback) override {
return backend_->DoomEntry(key, request_priority, std::move(callback));
}
int DoomAllEntries(const CompletionCallback& callback) override {
return backend_->DoomAllEntries(callback);
int DoomAllEntries(CompletionOnceCallback callback) override {
return backend_->DoomAllEntries(std::move(callback));
}
int DoomEntriesBetween(base::Time initial_time,
base::Time end_time,
const CompletionCallback& callback) override {
return backend_->DoomEntriesBetween(initial_time, end_time, callback);
CompletionOnceCallback callback) override {
return backend_->DoomEntriesBetween(initial_time, end_time,
std::move(callback));
}
int DoomEntriesSince(base::Time initial_time,
const CompletionCallback& callback) override {
return backend_->DoomEntriesSince(initial_time, callback);
CompletionOnceCallback callback) override {
return backend_->DoomEntriesSince(initial_time, std::move(callback));
}
int CalculateSizeOfAllEntries(
const CompletionCallback& callback) override {
return backend_->CalculateSizeOfAllEntries(callback);
int CalculateSizeOfAllEntries(CompletionOnceCallback callback) override {
return backend_->CalculateSizeOfAllEntries(std::move(callback));
}
std::unique_ptr<Iterator> CreateIterator() override {
return backend_->CreateIterator();
Expand Down Expand Up @@ -151,10 +153,12 @@ class DelayableBackend : public disk_cache::Backend {
private:
void OpenEntryDelayedImpl(const std::string& key,
disk_cache::Entry** entry,
const CompletionCallback& callback) {
int rv = backend_->OpenEntry(key, net::HIGHEST, entry, callback);
CompletionOnceCallback callback) {
auto copyable_callback =
base::AdaptCallbackForRepeating(std::move(callback));
int rv = backend_->OpenEntry(key, net::HIGHEST, entry, copyable_callback);
if (rv != net::ERR_IO_PENDING)
callback.Run(rv);
copyable_callback.Run(rv);
}

std::unique_ptr<disk_cache::Backend> backend_;
Expand Down
1 change: 1 addition & 0 deletions gpu/ipc/host/shader_disk_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/threading/thread_checker.h"
#include "net/base/completion_callback.h"
#include "net/disk_cache/disk_cache.h"

namespace gpu {
Expand Down
57 changes: 31 additions & 26 deletions net/disk_cache/blockfile/backend_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,16 @@ BackendImpl::~BackendImpl() {
CleanupCache();
} else {
background_queue_.background_thread()->PostTask(
FROM_HERE, base::Bind(&FinalCleanupCallback, base::Unretained(this)));
FROM_HERE,
base::BindOnce(&FinalCleanupCallback, base::Unretained(this)));
// http://crbug.com/74623
base::ThreadRestrictions::ScopedAllowWait allow_wait;
done_.Wait();
}
}

int BackendImpl::Init(const CompletionCallback& callback) {
background_queue_.Init(callback);
int BackendImpl::Init(CompletionOnceCallback callback) {
background_queue_.Init(std::move(callback));
return net::ERR_IO_PENDING;
}

Expand Down Expand Up @@ -1076,7 +1077,8 @@ void BackendImpl::CriticalError(int error) {

if (!num_refs_)
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(&BackendImpl::RestartCache, GetWeakPtr(), true));
FROM_HERE,
base::BindOnce(&BackendImpl::RestartCache, GetWeakPtr(), true));
}

void BackendImpl::ReportError(int error) {
Expand Down Expand Up @@ -1178,14 +1180,14 @@ void BackendImpl::ClearRefCountForTest() {
num_refs_ = 0;
}

int BackendImpl::FlushQueueForTest(const CompletionCallback& callback) {
background_queue_.FlushQueue(callback);
int BackendImpl::FlushQueueForTest(CompletionOnceCallback callback) {
background_queue_.FlushQueue(std::move(callback));
return net::ERR_IO_PENDING;
}

int BackendImpl::RunTaskForTest(const base::Closure& task,
const CompletionCallback& callback) {
background_queue_.RunTask(task, callback);
int BackendImpl::RunTaskForTest(base::OnceClosure task,
CompletionOnceCallback callback) {
background_queue_.RunTask(std::move(task), std::move(callback));
return net::ERR_IO_PENDING;
}

Expand Down Expand Up @@ -1256,53 +1258,54 @@ int32_t BackendImpl::GetEntryCount() const {
int BackendImpl::OpenEntry(const std::string& key,
net::RequestPriority request_priority,
Entry** entry,
const CompletionCallback& callback) {
CompletionOnceCallback callback) {
DCHECK(!callback.is_null());
background_queue_.OpenEntry(key, entry, callback);
background_queue_.OpenEntry(key, entry, std::move(callback));
return net::ERR_IO_PENDING;
}

int BackendImpl::CreateEntry(const std::string& key,
net::RequestPriority request_priority,
Entry** entry,
const CompletionCallback& callback) {
CompletionOnceCallback callback) {
DCHECK(!callback.is_null());
background_queue_.CreateEntry(key, entry, callback);
background_queue_.CreateEntry(key, entry, std::move(callback));
return net::ERR_IO_PENDING;
}

int BackendImpl::DoomEntry(const std::string& key,
net::RequestPriority priority,
const CompletionCallback& callback) {
CompletionOnceCallback callback) {
DCHECK(!callback.is_null());
background_queue_.DoomEntry(key, callback);
background_queue_.DoomEntry(key, std::move(callback));
return net::ERR_IO_PENDING;
}

int BackendImpl::DoomAllEntries(const CompletionCallback& callback) {
int BackendImpl::DoomAllEntries(CompletionOnceCallback callback) {
DCHECK(!callback.is_null());
background_queue_.DoomAllEntries(callback);
background_queue_.DoomAllEntries(std::move(callback));
return net::ERR_IO_PENDING;
}

int BackendImpl::DoomEntriesBetween(const base::Time initial_time,
const base::Time end_time,
const CompletionCallback& callback) {
CompletionOnceCallback callback) {
DCHECK(!callback.is_null());
background_queue_.DoomEntriesBetween(initial_time, end_time, callback);
background_queue_.DoomEntriesBetween(initial_time, end_time,
std::move(callback));
return net::ERR_IO_PENDING;
}

int BackendImpl::DoomEntriesSince(const base::Time initial_time,
const CompletionCallback& callback) {
CompletionOnceCallback callback) {
DCHECK(!callback.is_null());
background_queue_.DoomEntriesSince(initial_time, callback);
background_queue_.DoomEntriesSince(initial_time, std::move(callback));
return net::ERR_IO_PENDING;
}

int BackendImpl::CalculateSizeOfAllEntries(const CompletionCallback& callback) {
int BackendImpl::CalculateSizeOfAllEntries(CompletionOnceCallback callback) {
DCHECK(!callback.is_null());
background_queue_.CalculateSizeOfAllEntries(callback);
background_queue_.CalculateSizeOfAllEntries(std::move(callback));
return net::ERR_IO_PENDING;
}

Expand All @@ -1319,10 +1322,11 @@ class BackendImpl::IteratorImpl : public Backend::Iterator {
}

int OpenNextEntry(Entry** next_entry,
const net::CompletionCallback& callback) override {
net::CompletionOnceCallback callback) override {
if (!background_queue_)
return net::ERR_FAILED;
background_queue_->OpenNextEntry(iterator_.get(), next_entry, callback);
background_queue_->OpenNextEntry(iterator_.get(), next_entry,
std::move(callback));
return net::ERR_IO_PENDING;
}

Expand Down Expand Up @@ -1869,7 +1873,8 @@ void BackendImpl::DecreaseNumRefs() {

if (!num_refs_ && disabled_)
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(&BackendImpl::RestartCache, GetWeakPtr(), true));
FROM_HERE,
base::BindOnce(&BackendImpl::RestartCache, GetWeakPtr(), true));
}

void BackendImpl::IncreaseNumEntries() {
Expand Down
21 changes: 10 additions & 11 deletions net/disk_cache/blockfile/backend_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class NET_EXPORT_PRIVATE BackendImpl : public Backend {
~BackendImpl() override;

// Performs general initialization for this current instance of the cache.
int Init(const CompletionCallback& callback);
int Init(CompletionOnceCallback callback);

// Performs the actual initialization and final cleanup on destruction.
int SyncInit();
Expand Down Expand Up @@ -247,12 +247,11 @@ class NET_EXPORT_PRIVATE BackendImpl : public Backend {
void ClearRefCountForTest();

// Sends a dummy operation through the operation queue, for unit tests.
int FlushQueueForTest(const CompletionCallback& callback);
int FlushQueueForTest(CompletionOnceCallback callback);

// Runs the provided task on the cache thread. The task will be automatically
// deleted after it runs.
int RunTaskForTest(const base::Closure& task,
const CompletionCallback& callback);
int RunTaskForTest(base::OnceClosure task, CompletionOnceCallback callback);

// Trims an entry (all if |empty| is true) from the list of deleted
// entries. This method should be called directly on the cache thread.
Expand Down Expand Up @@ -281,21 +280,21 @@ class NET_EXPORT_PRIVATE BackendImpl : public Backend {
int OpenEntry(const std::string& key,
net::RequestPriority request_priority,
Entry** entry,
const CompletionCallback& callback) override;
CompletionOnceCallback callback) override;
int CreateEntry(const std::string& key,
net::RequestPriority request_priority,
Entry** entry,
const CompletionCallback& callback) override;
CompletionOnceCallback callback) override;
int DoomEntry(const std::string& key,
net::RequestPriority priority,
const CompletionCallback& callback) override;
int DoomAllEntries(const CompletionCallback& callback) override;
CompletionOnceCallback callback) override;
int DoomAllEntries(CompletionOnceCallback callback) override;
int DoomEntriesBetween(base::Time initial_time,
base::Time end_time,
const CompletionCallback& callback) override;
CompletionOnceCallback callback) override;
int DoomEntriesSince(base::Time initial_time,
const CompletionCallback& callback) override;
int CalculateSizeOfAllEntries(const CompletionCallback& callback) override;
CompletionOnceCallback callback) override;
int CalculateSizeOfAllEntries(CompletionOnceCallback callback) override;
// NOTE: The blockfile Backend::Iterator::OpenNextEntry method does not modify
// the last_used field of the entry, and therefore it does not impact the
// eviction ranking of the entry. However, an enumeration will go through all
Expand Down
Loading

0 comments on commit 4acf0b5

Please sign in to comment.