Chromium Code Reviews| Index: components/certificate_transparency/log_proof_fetcher.cc |
| diff --git a/components/certificate_transparency/log_proof_fetcher.cc b/components/certificate_transparency/log_proof_fetcher.cc |
| index 53c2e7c73398e654918e0fa06fa1fc9add0383d1..09a0438a8dee7b3bc07022a5fc58b8cf8430044e 100644 |
| --- a/components/certificate_transparency/log_proof_fetcher.cc |
| +++ b/components/certificate_transparency/log_proof_fetcher.cc |
| @@ -47,7 +47,7 @@ class LogFetcher : public net::URLRequest::Delegate { |
| ~LogFetcher() override {} |
| // net::URLRequest::Delegate |
| - void OnResponseStarted(net::URLRequest* request) override; |
| + void OnResponseStarted(net::URLRequest* request, int net_error) override; |
| void OnReadCompleted(net::URLRequest* request, int bytes_read) override; |
| const std::string& assembled_response() const { return assembled_response_; } |
| @@ -102,12 +102,13 @@ LogFetcher::LogFetcher(net::URLRequestContext* request_context, |
| url_request_->Start(); |
| } |
| -void LogFetcher::OnResponseStarted(net::URLRequest* request) { |
| +void LogFetcher::OnResponseStarted(net::URLRequest* request, int net_error) { |
| + DCHECK_NE(net::ERR_IO_PENDING, net_error); |
| DCHECK_EQ(url_request_.get(), request); |
| int http_response_code = request->GetResponseCode(); |
| - if (!request->status().is_success()) { |
| - InvokeFailureCallback(request->status().error(), http_response_code); |
| + if (net_error != net::OK) { |
| + InvokeFailureCallback(net_error, http_response_code); |
| return; |
| } |
| @@ -134,21 +135,9 @@ void LogFetcher::OnReadCompleted(net::URLRequest* request, int bytes_read) { |
| } |
| bool LogFetcher::HandleReadResult(int bytes_read) { |
| - // Start by checking for an error condition. |
| - // If there are errors, invoke the failure callback and clean up the |
| - // request. |
| - if (!url_request_->status().is_success() || bytes_read < 0) { |
| - int net_error = url_request_->status().error(); |
| - if (net_error == net::OK) |
| - net_error = net::URLRequestStatus::FAILED; |
| - |
| - InvokeFailureCallback(net_error, net::HTTP_OK); |
| - return false; |
| - } |
| - |
| // Not an error, but no data available, so wait for OnReadCompleted |
| // callback. |
| - if (url_request_->status().is_io_pending()) |
| + if (bytes_read == net::ERR_IO_PENDING) |
| return false; |
| // Nothing more to read from the stream - finish handling the response. |
| @@ -157,6 +146,15 @@ bool LogFetcher::HandleReadResult(int bytes_read) { |
| return false; |
| } |
| + // Check for an error condition. |
|
Ryan Sleevi
2016/09/07 18:48:08
You can drop this line; it no longer grammatically
|
| + // If there are errors, invoke the failure callback and clean up the |
| + // request. |
| + if (bytes_read < 0) { |
| + int net_error = bytes_read; |
| + InvokeFailureCallback(net_error, net::HTTP_OK); |
| + return false; |
| + } |
| + |
| // Data is available, collect it and indicate another read is needed. |
| DCHECK_GE(bytes_read, 0); |
| // |bytes_read| is non-negative at this point, casting to size_t should be |
| @@ -177,9 +175,8 @@ bool LogFetcher::HandleReadResult(int bytes_read) { |
| void LogFetcher::StartNextReadLoop() { |
| bool continue_reading = true; |
| while (continue_reading) { |
| - int read_bytes = 0; |
| - url_request_->Read(response_buffer_.get(), response_buffer_->size(), |
| - &read_bytes); |
| + int read_bytes = |
| + url_request_->Read(response_buffer_.get(), response_buffer_->size()); |
| continue_reading = HandleReadResult(read_bytes); |
| } |
| } |