Commit 3561fad5 authored by Mark Pilgrim's avatar Mark Pilgrim Committed by Commit Bot

Appcache: BindOnce refactoring

Use OnceCompletionCallback in AppCacheResponseReader (ReadInfo and
ReadData)

TBR=michaeln@chromium.org

Bug: 714018
Change-Id: Ide4ee3a281f4318c66014302c4bb596cff000d27
Reviewed-on: https://chromium-review.googlesource.com/675725Reviewed-by: default avatarMark Pilgrim <pilgrim@chromium.org>
Commit-Queue: Mark Pilgrim <pilgrim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#503430}
parent 8c76fd44
......@@ -200,7 +200,7 @@ AppCacheResponseReader::~AppCacheResponseReader() {
}
void AppCacheResponseReader::ReadInfo(HttpResponseInfoIOBuffer* info_buf,
const net::CompletionCallback& callback) {
OnceCompletionCallback callback) {
DCHECK(!callback.is_null());
DCHECK(!IsReadPending());
DCHECK(info_buf);
......@@ -209,7 +209,7 @@ void AppCacheResponseReader::ReadInfo(HttpResponseInfoIOBuffer* info_buf,
DCHECK(!info_buffer_.get());
info_buffer_ = info_buf;
callback_ = callback; // cleared on completion
callback_ = std::move(callback); // cleared on completion
OpenEntryIfNeeded();
}
......@@ -224,8 +224,9 @@ void AppCacheResponseReader::ContinueReadInfo() {
ReadRaw(kResponseInfoIndex, 0, buffer_.get(), size);
}
void AppCacheResponseReader::ReadData(net::IOBuffer* buf, int buf_len,
const net::CompletionCallback& callback) {
void AppCacheResponseReader::ReadData(net::IOBuffer* buf,
int buf_len,
OnceCompletionCallback callback) {
DCHECK(!callback.is_null());
DCHECK(!IsReadPending());
DCHECK(buf);
......@@ -235,7 +236,7 @@ void AppCacheResponseReader::ReadData(net::IOBuffer* buf, int buf_len,
buffer_ = buf;
buffer_len_ = buf_len;
callback_ = callback; // cleared on completion
callback_ = std::move(callback); // cleared on completion
OpenEntryIfNeeded();
}
......
......@@ -174,7 +174,7 @@ class CONTENT_EXPORT AppCacheResponseReader
// Should only be called where there is no Read operation in progress.
// (virtual for testing)
virtual void ReadInfo(HttpResponseInfoIOBuffer* info_buf,
const net::CompletionCallback& callback);
OnceCompletionCallback callback);
// Reads data from storage. Always returns the result of the read
// asynchronously through the 'callback'. Returns the number of bytes read
......@@ -184,8 +184,9 @@ class CONTENT_EXPORT AppCacheResponseReader
// or the number of bytes read. The 'callback' is a required parameter.
// Should only be called where there is no Read operation in progress.
// (virtual for testing)
virtual void ReadData(net::IOBuffer* buf, int buf_len,
const net::CompletionCallback& callback);
virtual void ReadData(net::IOBuffer* buf,
int buf_len,
OnceCompletionCallback callback);
// Returns true if there is a read operation, for data or info, pending.
bool IsReadPending() { return IsIOPending(); }
......
......@@ -50,9 +50,9 @@ class MockResponseReader : public AppCacheResponseReader {
data_(data),
data_size_(data_size) {}
void ReadInfo(HttpResponseInfoIOBuffer* info_buf,
const net::CompletionCallback& callback) override {
OnceCompletionCallback callback) override {
info_buffer_ = info_buf;
callback_ = callback; // Cleared on completion.
callback_ = std::move(callback); // Cleared on completion.
int rv = info_.get() ? info_size_ : net::ERR_FAILED;
info_buffer_->http_info.reset(info_.release());
......@@ -61,10 +61,10 @@ class MockResponseReader : public AppCacheResponseReader {
}
void ReadData(net::IOBuffer* buf,
int buf_len,
const net::CompletionCallback& callback) override {
OnceCompletionCallback callback) override {
buffer_ = buf;
buffer_len_ = buf_len;
callback_ = callback; // Cleared on completion.
callback_ = std::move(callback); // Cleared on completion.
if (!data_) {
ScheduleUserCallback(net::ERR_CACHE_READ_FAILURE);
......
......@@ -47,10 +47,10 @@ class MockServiceWorkerResponseReader : public ServiceWorkerResponseReader {
// ServiceWorkerResponseReader overrides
void ReadInfo(HttpResponseInfoIOBuffer* info_buf,
const net::CompletionCallback& callback) override;
OnceCompletionCallback callback) override;
void ReadData(net::IOBuffer* buf,
int buf_len,
const net::CompletionCallback& callback) override;
OnceCompletionCallback callback) override;
// Test helpers. ExpectReadInfo() and ExpectReadData() give precise control
// over both the data to be written and the result to return.
......@@ -100,29 +100,29 @@ class MockServiceWorkerResponseReader : public ServiceWorkerResponseReader {
void MockServiceWorkerResponseReader::ReadInfo(
HttpResponseInfoIOBuffer* info_buf,
const net::CompletionCallback& callback) {
OnceCompletionCallback callback) {
DCHECK(!expected_reads_.empty());
ExpectedRead expected = expected_reads_.front();
EXPECT_TRUE(expected.info);
if (expected.async) {
pending_info_ = info_buf;
pending_callback_ = callback;
pending_callback_ = std::move(callback);
} else {
expected_reads_.pop();
info_buf->response_data_size = expected.len;
callback.Run(expected.result);
std::move(callback).Run(expected.result);
}
}
void MockServiceWorkerResponseReader::ReadData(
net::IOBuffer* buf,
int buf_len,
const net::CompletionCallback& callback) {
OnceCompletionCallback callback) {
DCHECK(!expected_reads_.empty());
ExpectedRead expected = expected_reads_.front();
EXPECT_FALSE(expected.info);
if (expected.async) {
pending_callback_ = callback;
pending_callback_ = std::move(callback);
pending_buffer_ = buf;
pending_buffer_len_ = static_cast<size_t>(buf_len);
} else {
......@@ -131,7 +131,7 @@ void MockServiceWorkerResponseReader::ReadData(
size_t to_read = std::min(static_cast<size_t>(buf_len), expected.len);
memcpy(buf->data(), expected.data, to_read);
}
callback.Run(expected.result);
std::move(callback).Run(expected.result);
}
}
......
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