Use CompletionOnceCallback in URLFetcherResponseWriter.
https://chromium-review.googlesource.com/c/chromium/src/+/1155087
This commit is contained in:
parent
366ca47136
commit
97aa7b8e68
3 changed files with 16 additions and 17 deletions
|
@ -55,21 +55,21 @@ class ResponsePiper : public net::URLFetcherResponseWriter {
|
|||
explicit ResponsePiper(URLRequestFetchJob* job) : job_(job) {}
|
||||
|
||||
// net::URLFetcherResponseWriter:
|
||||
int Initialize(const net::CompletionCallback& callback) override {
|
||||
int Initialize(net::CompletionOnceCallback callback) override {
|
||||
return net::OK;
|
||||
}
|
||||
int Write(net::IOBuffer* buffer,
|
||||
int num_bytes,
|
||||
const net::CompletionCallback& callback) override {
|
||||
net::CompletionOnceCallback callback) override {
|
||||
if (first_write_) {
|
||||
// The URLFetcherResponseWriter doesn't have an event when headers have
|
||||
// been read, so we have to emulate by hooking to first write event.
|
||||
job_->HeadersCompleted();
|
||||
first_write_ = false;
|
||||
}
|
||||
return job_->DataAvailable(buffer, num_bytes, callback);
|
||||
return job_->DataAvailable(buffer, num_bytes, std::move(callback));
|
||||
}
|
||||
int Finish(int net_error, const net::CompletionCallback& callback) override {
|
||||
int Finish(int net_error, net::CompletionOnceCallback callback) override {
|
||||
return net::OK;
|
||||
}
|
||||
|
||||
|
@ -231,14 +231,14 @@ void URLRequestFetchJob::HeadersCompleted() {
|
|||
|
||||
int URLRequestFetchJob::DataAvailable(net::IOBuffer* buffer,
|
||||
int num_bytes,
|
||||
const net::CompletionCallback& callback) {
|
||||
net::CompletionOnceCallback callback) {
|
||||
// When pending_buffer_ is empty, there's no ReadRawData() operation waiting
|
||||
// for IO completion, we have to save the parameters until the request is
|
||||
// ready to read data.
|
||||
if (!pending_buffer_.get()) {
|
||||
write_buffer_ = buffer;
|
||||
write_num_bytes_ = num_bytes;
|
||||
write_callback_ = callback;
|
||||
write_callback_ = std::move(callback);
|
||||
return net::ERR_IO_PENDING;
|
||||
}
|
||||
|
||||
|
@ -274,9 +274,9 @@ int URLRequestFetchJob::ReadRawData(net::IOBuffer* dest, int dest_size) {
|
|||
// Read from the write buffer and clear them after reading.
|
||||
int bytes_read =
|
||||
BufferCopy(write_buffer_.get(), write_num_bytes_, dest, dest_size);
|
||||
net::CompletionCallback write_callback = write_callback_;
|
||||
ClearWriteBuffer();
|
||||
write_callback.Run(bytes_read);
|
||||
if (!write_callback_.is_null())
|
||||
std::move(write_callback_).Run(bytes_read);
|
||||
return bytes_read;
|
||||
}
|
||||
|
||||
|
@ -336,7 +336,6 @@ void URLRequestFetchJob::ClearPendingBuffer() {
|
|||
void URLRequestFetchJob::ClearWriteBuffer() {
|
||||
write_buffer_ = nullptr;
|
||||
write_num_bytes_ = 0;
|
||||
write_callback_.Reset();
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -36,7 +36,7 @@ class URLRequestFetchJob : public JsAsker,
|
|||
void HeadersCompleted();
|
||||
int DataAvailable(net::IOBuffer* buffer,
|
||||
int num_bytes,
|
||||
const net::CompletionCallback& callback);
|
||||
net::CompletionOnceCallback callback);
|
||||
|
||||
protected:
|
||||
// net::URLRequestJob:
|
||||
|
@ -69,7 +69,7 @@ class URLRequestFetchJob : public JsAsker,
|
|||
// Saved arguments passed to DataAvailable.
|
||||
scoped_refptr<net::IOBuffer> write_buffer_;
|
||||
int write_num_bytes_ = 0;
|
||||
net::CompletionCallback write_callback_;
|
||||
net::CompletionOnceCallback write_callback_;
|
||||
|
||||
base::WeakPtrFactory<URLRequestFetchJob> weak_factory_;
|
||||
|
||||
|
|
|
@ -141,11 +141,11 @@ class ResponseWriter : public net::URLFetcherResponseWriter {
|
|||
~ResponseWriter() override;
|
||||
|
||||
// URLFetcherResponseWriter overrides:
|
||||
int Initialize(const net::CompletionCallback& callback) override;
|
||||
int Initialize(net::CompletionOnceCallback callback) override;
|
||||
int Write(net::IOBuffer* buffer,
|
||||
int num_bytes,
|
||||
const net::CompletionCallback& callback) override;
|
||||
int Finish(int net_error, const net::CompletionCallback& callback) override;
|
||||
net::CompletionOnceCallback callback) override;
|
||||
int Finish(int net_error, net::CompletionOnceCallback callback) override;
|
||||
|
||||
private:
|
||||
base::WeakPtr<InspectableWebContentsImpl> bindings_;
|
||||
|
@ -161,13 +161,13 @@ ResponseWriter::ResponseWriter(
|
|||
|
||||
ResponseWriter::~ResponseWriter() {}
|
||||
|
||||
int ResponseWriter::Initialize(const net::CompletionCallback& callback) {
|
||||
int ResponseWriter::Initialize(net::CompletionOnceCallback callback) {
|
||||
return net::OK;
|
||||
}
|
||||
|
||||
int ResponseWriter::Write(net::IOBuffer* buffer,
|
||||
int num_bytes,
|
||||
const net::CompletionCallback& callback) {
|
||||
net::CompletionOnceCallback callback) {
|
||||
std::string chunk = std::string(buffer->data(), num_bytes);
|
||||
if (!base::IsStringUTF8(chunk))
|
||||
return num_bytes;
|
||||
|
@ -184,7 +184,7 @@ int ResponseWriter::Write(net::IOBuffer* buffer,
|
|||
}
|
||||
|
||||
int ResponseWriter::Finish(int net_error,
|
||||
const net::CompletionCallback& callback) {
|
||||
net::CompletionOnceCallback callback) {
|
||||
return net::OK;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue