Commit 43fd1051 authored by maksim.sisov's avatar maksim.sisov Committed by Commit bot

Use modifed URLRequest API in net/ for fetcher_core

This cl splits the big CL with changes to net/ folder and
has changes only to net/url_request *fetcher_core files
according to the changes to URLRequest API.

What the big cl does:
It modifies net/ clients that use URLRequest API as long as
URLRequest::Read returns int net errors and
URLRequest::Delegate and NetworkDelegate methods
(for example, OnResponseStarted or OnCompleted) have int
net_error in the arguments now.

The reason behind splitting the CL into small one is that
an android bot started to be unstable and unittests became
flaky. It was not possible to locate the problem and the
decision was to split the CL and upload small parts with a
6+ hours interval in order to make it possible to locate
the problematic code.

The big CL is located here -
https://codereview.chromium.org/2265873002/

BUG=423484

Committed: https://crrev.com/a74d3cbc572fa1c85cc2c0434a9f8e2f9cba0cd9
Review-Url: https://codereview.chromium.org/2331853002
Cr-Original-Commit-Position: refs/heads/master@{#418014}
Cr-Commit-Position: refs/heads/master@{#419143}
parent 12af1f69
...@@ -407,15 +407,17 @@ void URLFetcherCore::OnReceivedRedirect(URLRequest* request, ...@@ -407,15 +407,17 @@ void URLFetcherCore::OnReceivedRedirect(URLRequest* request,
was_fetched_via_proxy_ = request_->was_fetched_via_proxy(); was_fetched_via_proxy_ = request_->was_fetched_via_proxy();
was_cached_ = request_->was_cached(); was_cached_ = request_->was_cached();
total_received_bytes_ += request_->GetTotalReceivedBytes(); total_received_bytes_ += request_->GetTotalReceivedBytes();
request->Cancel(); int result = request->Cancel();
OnReadCompleted(request, 0); OnReadCompleted(request, result);
} }
} }
void URLFetcherCore::OnResponseStarted(URLRequest* request) { void URLFetcherCore::OnResponseStarted(URLRequest* request, int net_error) {
DCHECK_EQ(request, request_.get()); DCHECK_EQ(request, request_.get());
DCHECK(network_task_runner_->BelongsToCurrentThread()); DCHECK(network_task_runner_->BelongsToCurrentThread());
if (request_->status().is_success()) { DCHECK_NE(ERR_IO_PENDING, net_error);
if (net_error == OK) {
response_code_ = request_->GetResponseCode(); response_code_ = request_->GetResponseCode();
response_headers_ = request_->response_headers(); response_headers_ = request_->response_headers();
socket_address_ = request_->GetSocketAddress(); socket_address_ = request_->GetSocketAddress();
...@@ -452,10 +454,7 @@ void URLFetcherCore::OnReadCompleted(URLRequest* request, ...@@ -452,10 +454,7 @@ void URLFetcherCore::OnReadCompleted(URLRequest* request,
if (throttler_manager) if (throttler_manager)
url_throttler_entry_ = throttler_manager->RegisterRequestUrl(url_); url_throttler_entry_ = throttler_manager->RegisterRequestUrl(url_);
do { while (bytes_read > 0) {
if (!request_->status().is_success() || bytes_read <= 0)
break;
current_response_bytes_ += bytes_read; current_response_bytes_ += bytes_read;
InformDelegateDownloadProgress(); InformDelegateDownloadProgress();
...@@ -465,13 +464,12 @@ void URLFetcherCore::OnReadCompleted(URLRequest* request, ...@@ -465,13 +464,12 @@ void URLFetcherCore::OnReadCompleted(URLRequest* request,
// Write failed or waiting for write completion. // Write failed or waiting for write completion.
return; return;
} }
} while (request_->Read(buffer_.get(), kBufferSize, &bytes_read)); bytes_read = request_->Read(buffer_.get(), kBufferSize);
}
const URLRequestStatus status = request_->status();
// See comments re: HEAD requests in ReadResponse(). // See comments re: HEAD requests in ReadResponse().
if (!status.is_io_pending() || request_type_ == URLFetcher::HEAD) { if (bytes_read != ERR_IO_PENDING || request_type_ == URLFetcher::HEAD) {
status_ = status; status_ = URLRequestStatus::FromError(bytes_read);
received_response_content_length_ = received_response_content_length_ =
request_->received_response_content_length(); request_->received_response_content_length();
total_received_bytes_ += request_->GetTotalReceivedBytes(); total_received_bytes_ += request_->GetTotalReceivedBytes();
...@@ -886,11 +884,9 @@ void URLFetcherCore::ReadResponse() { ...@@ -886,11 +884,9 @@ void URLFetcherCore::ReadResponse() {
// completed immediately, without trying to read any data back (all we care // completed immediately, without trying to read any data back (all we care
// about is the response code and headers, which we already have). // about is the response code and headers, which we already have).
int bytes_read = 0; int bytes_read = 0;
if (request_->status().is_success() && if (request_type_ != URLFetcher::HEAD)
(request_type_ != URLFetcher::HEAD)) { bytes_read = request_->Read(buffer_.get(), kBufferSize);
if (!request_->Read(buffer_.get(), kBufferSize, &bytes_read))
bytes_read = -1; // Match OnReadCompleted() interface contract.
}
OnReadCompleted(request_.get(), bytes_read); OnReadCompleted(request_.get(), bytes_read);
} }
......
...@@ -136,7 +136,7 @@ class URLFetcherCore : public base::RefCountedThreadSafe<URLFetcherCore>, ...@@ -136,7 +136,7 @@ class URLFetcherCore : public base::RefCountedThreadSafe<URLFetcherCore>,
void OnReceivedRedirect(URLRequest* request, void OnReceivedRedirect(URLRequest* request,
const RedirectInfo& redirect_info, const RedirectInfo& redirect_info,
bool* defer_redirect) override; bool* defer_redirect) override;
void OnResponseStarted(URLRequest* request) override; void OnResponseStarted(URLRequest* request, int net_error) override;
void OnReadCompleted(URLRequest* request, int bytes_read) override; void OnReadCompleted(URLRequest* request, int bytes_read) override;
void OnCertificateRequested(URLRequest* request, void OnCertificateRequested(URLRequest* request,
SSLCertRequestInfo* cert_request_info) override; SSLCertRequestInfo* cert_request_info) override;
......
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