Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(975)

Unified Diff: content/browser/cache_storage/cache_storage_cache_unittest.cc

Issue 2947753002: CacheStorage: Migrate to BindOnce/OnceCallback/OnceClosure (Closed)
Patch Set: Untangle Batch logic (relies on AdaptCallbackForRepeating) Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/cache_storage/cache_storage_cache_unittest.cc
diff --git a/content/browser/cache_storage/cache_storage_cache_unittest.cc b/content/browser/cache_storage/cache_storage_cache_unittest.cc
index 3f0227b43bcb896b1ce3036d6b6f7e68871f1850..581fc72bceafefc845e93610f6f379cd91ce25e1 100644
--- a/content/browser/cache_storage/cache_storage_cache_unittest.cc
+++ b/content/browser/cache_storage/cache_storage_cache_unittest.cc
@@ -85,8 +85,9 @@ class DelayableBackend : public disk_cache::Backend {
int DoomEntry(const std::string& key,
const CompletionCallback& callback) override {
if (delay_doom_) {
- doom_entry_callback_ = base::Bind(&DelayableBackend::DoomEntryDelayedImpl,
- base::Unretained(this), key, callback);
+ doom_entry_callback_ =
+ base::BindOnce(&DelayableBackend::DoomEntryDelayedImpl,
+ base::Unretained(this), key, callback);
return net::ERR_IO_PENDING;
}
@@ -128,7 +129,7 @@ class DelayableBackend : public disk_cache::Backend {
// Call to continue a delayed doom.
void DoomEntryContinue() {
EXPECT_FALSE(doom_entry_callback_.is_null());
- doom_entry_callback_.Run();
+ std::move(doom_entry_callback_).Run();
}
void set_delay_doom(bool value) { delay_doom_ = value; }
@@ -143,7 +144,7 @@ class DelayableBackend : public disk_cache::Backend {
std::unique_ptr<disk_cache::Backend> backend_;
bool delay_doom_;
- base::Closure doom_entry_callback_;
+ base::OnceClosure doom_entry_callback_;
};
void CopyBody(const storage::BlobDataHandle& blob_handle, std::string* output) {
@@ -293,15 +294,15 @@ class TestCacheStorageCache : public CacheStorageCache {
0 /* cache_size */),
delay_backend_creation_(false) {}
- void CreateBackend(const ErrorCallback& callback) override {
- backend_creation_callback_ = callback;
+ void CreateBackend(ErrorCallback callback) override {
+ backend_creation_callback_ = std::move(callback);
if (delay_backend_creation_)
return;
ContinueCreateBackend();
}
void ContinueCreateBackend() {
- CacheStorageCache::CreateBackend(backend_creation_callback_);
+ CacheStorageCache::CreateBackend(std::move(backend_creation_callback_));
}
void set_delay_backend_creation(bool delay) {
@@ -464,8 +465,8 @@ class CacheStorageCacheTest : public testing::Test {
cache_->BatchOperation(
operations,
- base::Bind(&CacheStorageCacheTest::ErrorTypeCallback,
- base::Unretained(this), base::Unretained(loop.get())));
+ base::BindOnce(&CacheStorageCacheTest::ErrorTypeCallback,
+ base::Unretained(this), base::Unretained(loop.get())));
// TODO(jkarlin): These functions should use base::RunLoop().RunUntilIdle()
// once the cache uses a passed in task runner instead of the CACHE thread.
loop->Run();
@@ -492,8 +493,8 @@ class CacheStorageCacheTest : public testing::Test {
cache_->Match(
CopyFetchRequest(request), match_params,
- base::Bind(&CacheStorageCacheTest::ResponseAndErrorCallback,
- base::Unretained(this), base::Unretained(loop.get())));
+ base::BindOnce(&CacheStorageCacheTest::ResponseAndErrorCallback,
+ base::Unretained(this), base::Unretained(loop.get())));
loop->Run();
return callback_error_ == CACHE_STORAGE_OK;
@@ -507,9 +508,9 @@ class CacheStorageCacheTest : public testing::Test {
base::RunLoop loop;
cache_->MatchAll(
CopyFetchRequest(request), match_params,
- base::Bind(&CacheStorageCacheTest::ResponsesAndErrorCallback,
- base::Unretained(this), loop.QuitClosure(), responses,
- body_handles));
+ base::BindOnce(&CacheStorageCacheTest::ResponsesAndErrorCallback,
+ base::Unretained(this), loop.QuitClosure(), responses,
+ body_handles));
loop.Run();
return callback_error_ == CACHE_STORAGE_OK;
}
@@ -542,8 +543,8 @@ class CacheStorageCacheTest : public testing::Test {
cache_->Keys(
CopyFetchRequest(request), match_params,
- base::Bind(&CacheStorageCacheTest::RequestsCallback,
- base::Unretained(this), base::Unretained(loop.get())));
+ base::BindOnce(&CacheStorageCacheTest::RequestsCallback,
+ base::Unretained(this), base::Unretained(loop.get())));
loop->Run();
return callback_error_ == CACHE_STORAGE_OK;
@@ -552,9 +553,9 @@ class CacheStorageCacheTest : public testing::Test {
bool Close() {
std::unique_ptr<base::RunLoop> loop(new base::RunLoop());
- cache_->Close(base::Bind(&CacheStorageCacheTest::CloseCallback,
- base::Unretained(this),
- base::Unretained(loop.get())));
+ cache_->Close(base::BindOnce(&CacheStorageCacheTest::CloseCallback,
+ base::Unretained(this),
+ base::Unretained(loop.get())));
loop->Run();
return callback_closed_;
}
@@ -565,8 +566,8 @@ class CacheStorageCacheTest : public testing::Test {
int buf_len) {
base::RunLoop run_loop;
cache_->WriteSideData(
- base::Bind(&CacheStorageCacheTest::ErrorTypeCallback,
- base::Unretained(this), base::Unretained(&run_loop)),
+ base::BindOnce(&CacheStorageCacheTest::ErrorTypeCallback,
+ base::Unretained(this), base::Unretained(&run_loop)),
url, expected_response_time, buffer, buf_len);
run_loop.Run();
@@ -580,9 +581,9 @@ class CacheStorageCacheTest : public testing::Test {
base::RunLoop run_loop;
bool callback_called = false;
- cache_->Size(base::Bind(&CacheStorageCacheTest::SizeCallback,
- base::Unretained(this), &run_loop,
- &callback_called));
+ cache_->Size(base::BindOnce(&CacheStorageCacheTest::SizeCallback,
+ base::Unretained(this), &run_loop,
+ &callback_called));
run_loop.Run();
EXPECT_TRUE(callback_called);
return callback_size_;
@@ -591,9 +592,9 @@ class CacheStorageCacheTest : public testing::Test {
int64_t GetSizeThenClose() {
base::RunLoop run_loop;
bool callback_called = false;
- cache_->GetSizeThenClose(base::Bind(&CacheStorageCacheTest::SizeCallback,
- base::Unretained(this), &run_loop,
- &callback_called));
+ cache_->GetSizeThenClose(
+ base::BindOnce(&CacheStorageCacheTest::SizeCallback,
+ base::Unretained(this), &run_loop, &callback_called));
run_loop.Run();
EXPECT_TRUE(callback_called);
return callback_size_;
@@ -644,7 +645,7 @@ class CacheStorageCacheTest : public testing::Test {
}
void ResponsesAndErrorCallback(
- const base::Closure& quit_closure,
+ base::OnceClosure quit_closure,
std::unique_ptr<CacheStorageCache::Responses>* responses_out,
std::unique_ptr<CacheStorageCache::BlobDataHandles>* body_handles_out,
CacheStorageError error,
@@ -653,7 +654,7 @@ class CacheStorageCacheTest : public testing::Test {
callback_error_ = error;
responses_out->swap(responses);
body_handles_out->swap(body_handles);
- quit_closure.Run();
+ std::move(quit_closure).Run();
}
void CloseCallback(base::RunLoop* run_loop) {
@@ -866,8 +867,8 @@ TEST_F(CacheStorageCacheTest, PutBodyDropBlobRef) {
std::unique_ptr<base::RunLoop> loop(new base::RunLoop());
cache_->BatchOperation(
std::vector<CacheStorageBatchOperation>(1, operation),
- base::Bind(&CacheStorageCacheTestP::ErrorTypeCallback,
- base::Unretained(this), base::Unretained(loop.get())));
+ base::BindOnce(&CacheStorageCacheTestP::ErrorTypeCallback,
+ base::Unretained(this), base::Unretained(loop.get())));
// The handle should be held by the cache now so the deref here should be
// okay.
blob_handle_.reset();
@@ -1625,8 +1626,9 @@ TEST_P(CacheStorageCacheTestP, VerifySerialScheduling) {
std::unique_ptr<base::RunLoop> close_loop1(new base::RunLoop());
cache_->BatchOperation(
std::vector<CacheStorageBatchOperation>(1, operation1),
- base::Bind(&CacheStorageCacheTest::SequenceCallback,
- base::Unretained(this), 1, &sequence_out, close_loop1.get()));
+ base::BindOnce(&CacheStorageCacheTest::SequenceCallback,
+ base::Unretained(this), 1, &sequence_out,
+ close_loop1.get()));
// Blocks on creating the cache entry.
base::RunLoop().RunUntilIdle();
@@ -1640,8 +1642,9 @@ TEST_P(CacheStorageCacheTestP, VerifySerialScheduling) {
std::unique_ptr<base::RunLoop> close_loop2(new base::RunLoop());
cache_->BatchOperation(
std::vector<CacheStorageBatchOperation>(1, operation2),
- base::Bind(&CacheStorageCacheTest::SequenceCallback,
- base::Unretained(this), 2, &sequence_out, close_loop2.get()));
+ base::BindOnce(&CacheStorageCacheTest::SequenceCallback,
+ base::Unretained(this), 2, &sequence_out,
+ close_loop2.get()));
// The second put operation should wait for the first to complete.
base::RunLoop().RunUntilIdle();

Powered by Google App Engine
This is Rietveld 408576698