diff --git a/atom/browser/net/url_request_fetch_job.cc b/atom/browser/net/url_request_fetch_job.cc index 52a5f7359747..971c4bb3f720 100644 --- a/atom/browser/net/url_request_fetch_job.cc +++ b/atom/browser/net/url_request_fetch_job.cc @@ -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 diff --git a/atom/browser/net/url_request_fetch_job.h b/atom/browser/net/url_request_fetch_job.h index 9966b3fc80b7..cbeb6ed3224b 100644 --- a/atom/browser/net/url_request_fetch_job.h +++ b/atom/browser/net/url_request_fetch_job.h @@ -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 write_buffer_; int write_num_bytes_ = 0; - net::CompletionCallback write_callback_; + net::CompletionOnceCallback write_callback_; base::WeakPtrFactory weak_factory_; diff --git a/atom/browser/ui/inspectable_web_contents_impl.cc b/atom/browser/ui/inspectable_web_contents_impl.cc index d41c4f286ecf..4343175cd22f 100644 --- a/atom/browser/ui/inspectable_web_contents_impl.cc +++ b/atom/browser/ui/inspectable_web_contents_impl.cc @@ -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 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; }