Commit d21e9163 authored by maksim.sisov's avatar maksim.sisov Committed by Commit bot

Make net/sdch to use new URLRequest::Read and its modified delegate methods.

This cl splits the big CL with changes to net/ folder and
has changes only to net/sdch 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

Review-Url: https://codereview.chromium.org/2329903002
Cr-Commit-Position: refs/heads/master@{#418489}
parent 1229b141
...@@ -32,17 +32,15 @@ const int kBufferSize = 4096; ...@@ -32,17 +32,15 @@ const int kBufferSize = 4096;
// Map the bytes_read result from a read attempt and a URLRequest's // Map the bytes_read result from a read attempt and a URLRequest's
// status into a single net return value. // status into a single net return value.
int GetReadResult(int bytes_read, const URLRequest* request) { int GetReadResult(int rv, const URLRequest* request) {
int rv = request->status().error(); DCHECK_NE(ERR_IO_PENDING, rv);
if (request->status().is_success() && bytes_read < 0) {
if (rv < 0) {
rv = ERR_FAILED; rv = ERR_FAILED;
request->net_log().AddEventWithNetErrorCode( request->net_log().AddEventWithNetErrorCode(
NetLogEventType::SDCH_DICTIONARY_FETCH_IMPLIED_ERROR, rv); NetLogEventType::SDCH_DICTIONARY_FETCH_IMPLIED_ERROR, rv);
} }
if (rv == OK)
rv = bytes_read;
return rv; return rv;
} }
...@@ -156,28 +154,29 @@ void SdchDictionaryFetcher::OnReceivedRedirect( ...@@ -156,28 +154,29 @@ void SdchDictionaryFetcher::OnReceivedRedirect(
DoLoop(OK); DoLoop(OK);
} }
void SdchDictionaryFetcher::OnResponseStarted(URLRequest* request) { void SdchDictionaryFetcher::OnResponseStarted(URLRequest* request,
int net_error) {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
DCHECK_EQ(request, current_request_.get()); DCHECK_EQ(request, current_request_.get());
DCHECK_EQ(next_state_, STATE_SEND_REQUEST_PENDING); DCHECK_EQ(next_state_, STATE_SEND_REQUEST_PENDING);
DCHECK(!in_loop_); DCHECK(!in_loop_);
DCHECK_NE(ERR_IO_PENDING, net_error);
// Confirm that the response isn't a stale read from the cache (as // Confirm that the response isn't a stale read from the cache (as
// may happen in the reload case). If the response was not retrieved over // may happen in the reload case). If the response was not retrieved over
// HTTP, it is presumed to be fresh. // HTTP, it is presumed to be fresh.
HttpResponseHeaders* response_headers = request->response_headers(); HttpResponseHeaders* response_headers = request->response_headers();
int result = request->status().error(); if (net_error == OK && response_headers) {
if (result == OK && response_headers) {
ValidationType validation_type = response_headers->RequiresValidation( ValidationType validation_type = response_headers->RequiresValidation(
request->response_info().request_time, request->response_info().request_time,
request->response_info().response_time, base::Time::Now()); request->response_info().response_time, base::Time::Now());
// TODO(rdsmith): Maybe handle VALIDATION_ASYNCHRONOUS by queueing // TODO(rdsmith): Maybe handle VALIDATION_ASYNCHRONOUS by queueing
// a non-reload request for the dictionary. // a non-reload request for the dictionary.
if (validation_type != VALIDATION_NONE) if (validation_type != VALIDATION_NONE)
result = ERR_FAILED; net_error = ERR_FAILED;
} }
DoLoop(result); DoLoop(net_error);
} }
void SdchDictionaryFetcher::OnReadCompleted(URLRequest* request, void SdchDictionaryFetcher::OnReadCompleted(URLRequest* request,
...@@ -186,6 +185,7 @@ void SdchDictionaryFetcher::OnReadCompleted(URLRequest* request, ...@@ -186,6 +185,7 @@ void SdchDictionaryFetcher::OnReadCompleted(URLRequest* request,
DCHECK_EQ(request, current_request_.get()); DCHECK_EQ(request, current_request_.get());
DCHECK_EQ(next_state_, STATE_READ_BODY_COMPLETE); DCHECK_EQ(next_state_, STATE_READ_BODY_COMPLETE);
DCHECK(!in_loop_); DCHECK(!in_loop_);
DCHECK_NE(ERR_IO_PENDING, bytes_read);
DoLoop(GetReadResult(bytes_read, current_request_.get())); DoLoop(GetReadResult(bytes_read, current_request_.get()));
} }
...@@ -330,9 +330,8 @@ int SdchDictionaryFetcher::DoReadBody(int rv) { ...@@ -330,9 +330,8 @@ int SdchDictionaryFetcher::DoReadBody(int rv) {
} }
next_state_ = STATE_READ_BODY_COMPLETE; next_state_ = STATE_READ_BODY_COMPLETE;
int bytes_read = 0; int bytes_read = current_request_->Read(buffer_.get(), kBufferSize);
current_request_->Read(buffer_.get(), kBufferSize, &bytes_read); if (bytes_read == ERR_IO_PENDING)
if (current_request_->status().is_io_pending())
return ERR_IO_PENDING; return ERR_IO_PENDING;
return GetReadResult(bytes_read, current_request_.get()); return GetReadResult(bytes_read, current_request_.get());
...@@ -348,7 +347,7 @@ int SdchDictionaryFetcher::DoReadBodyComplete(int rv) { ...@@ -348,7 +347,7 @@ int SdchDictionaryFetcher::DoReadBodyComplete(int rv) {
return OK; return OK;
} }
DCHECK(current_request_->status().is_success()); DCHECK_GE(rv, 0);
// Data; append to the dictionary and look for more data. // Data; append to the dictionary and look for more data.
if (rv > 0) { if (rv > 0) {
......
...@@ -65,7 +65,7 @@ class NET_EXPORT SdchDictionaryFetcher : public URLRequest::Delegate, ...@@ -65,7 +65,7 @@ class NET_EXPORT SdchDictionaryFetcher : public URLRequest::Delegate,
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;
private: private:
......
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