Commit 4887d11c authored by maksim.sisov's avatar maksim.sisov Committed by Commit bot

Use modifed URLRequest API in net/spdy and test embedded server

This cl splits the big CL with changes to net/ folder and
has changes only to net/cert_net 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/2335513003
Cr-Original-Commit-Position: refs/heads/master@{#418014}
Cr-Commit-Position: refs/heads/master@{#419386}
parent 533dcff1
...@@ -2288,7 +2288,7 @@ TEST_F(SpdyNetworkTransactionTest, DISABLED_RedirectGetRequest) { ...@@ -2288,7 +2288,7 @@ TEST_F(SpdyNetworkTransactionTest, DISABLED_RedirectGetRequest) {
base::RunLoop().Run(); base::RunLoop().Run();
EXPECT_EQ(1, d.response_started_count()); EXPECT_EQ(1, d.response_started_count());
EXPECT_FALSE(d.received_data_before_response()); EXPECT_FALSE(d.received_data_before_response());
EXPECT_EQ(OK, r->status().error()); EXPECT_EQ(OK, d.request_status());
std::string contents("hello!"); std::string contents("hello!");
EXPECT_EQ(contents, d.data_received()); EXPECT_EQ(contents, d.data_received());
} }
...@@ -2374,7 +2374,7 @@ TEST_F(SpdyNetworkTransactionTest, DISABLED_RedirectServerPush) { ...@@ -2374,7 +2374,7 @@ TEST_F(SpdyNetworkTransactionTest, DISABLED_RedirectServerPush) {
base::RunLoop().Run(); base::RunLoop().Run();
EXPECT_EQ(1, d2.response_started_count()); EXPECT_EQ(1, d2.response_started_count());
EXPECT_FALSE(d2.received_data_before_response()); EXPECT_FALSE(d2.received_data_before_response());
EXPECT_EQ(OK, r2->status().error()); EXPECT_EQ(OK, d2.request_status());
std::string contents2("hello!"); std::string contents2("hello!");
EXPECT_EQ(contents2, d2.data_received()); EXPECT_EQ(contents2, d2.data_received());
} }
......
...@@ -228,12 +228,14 @@ void SpawnerCommunicator::OnTimeout(int id) { ...@@ -228,12 +228,14 @@ void SpawnerCommunicator::OnTimeout(int id) {
if (!data->DoesRequestIdMatch(id)) if (!data->DoesRequestIdMatch(id))
return; return;
// Set the result code and cancel the timed-out task. // Set the result code and cancel the timed-out task.
data->SetResultCode(ERR_TIMED_OUT); int result = cur_request_->CancelWithError(ERR_TIMED_OUT);
cur_request_->Cancel(); OnSpawnerCommandCompleted(cur_request_.get(), result);
OnSpawnerCommandCompleted(cur_request_.get());
} }
void SpawnerCommunicator::OnSpawnerCommandCompleted(URLRequest* request) { void SpawnerCommunicator::OnSpawnerCommandCompleted(URLRequest* request,
int net_error) {
DCHECK_NE(ERR_IO_PENDING, net_error);
if (!cur_request_.get()) if (!cur_request_.get())
return; return;
DCHECK_EQ(request, cur_request_.get()); DCHECK_EQ(request, cur_request_.get());
...@@ -242,13 +244,11 @@ void SpawnerCommunicator::OnSpawnerCommandCompleted(URLRequest* request) { ...@@ -242,13 +244,11 @@ void SpawnerCommunicator::OnSpawnerCommandCompleted(URLRequest* request) {
DCHECK(data); DCHECK(data);
// If request is faild,return the error code. // If request is faild,return the error code.
if (!cur_request_->status().is_success()) if (net_error != OK)
data->SetResultCode(cur_request_->status().error()); data->SetResultCode(net_error);
if (!data->IsResultOK()) { if (!data->IsResultOK()) {
LOG(ERROR) << "request failed, status: " LOG(ERROR) << "request failed, error: " << net_error;
<< static_cast<int>(request->status().status())
<< ", error: " << request->status().error();
// Clear the buffer of received data if any net error happened. // Clear the buffer of received data if any net error happened.
data->ClearReceivedData(); data->ClearReceivedData();
} else { } else {
...@@ -275,30 +275,35 @@ void SpawnerCommunicator::ReadResult(URLRequest* request) { ...@@ -275,30 +275,35 @@ void SpawnerCommunicator::ReadResult(URLRequest* request) {
IOBuffer* buf = data->buf(); IOBuffer* buf = data->buf();
// Read as many bytes as are available synchronously. // Read as many bytes as are available synchronously.
while (true) { while (true) {
int num_bytes; int rv = request->Read(buf, kBufferSize);
if (!request->Read(buf, kBufferSize, &num_bytes)) { if (rv == ERR_IO_PENDING)
// Check whether the read failed synchronously. return;
if (!request->status().is_io_pending())
OnSpawnerCommandCompleted(request); if (rv < 0) {
OnSpawnerCommandCompleted(request, rv);
return; return;
} }
if (!data->ConsumeBytesRead(num_bytes)) {
OnSpawnerCommandCompleted(request); if (!data->ConsumeBytesRead(rv)) {
OnSpawnerCommandCompleted(request, rv);
return; return;
} }
} }
} }
void SpawnerCommunicator::OnResponseStarted(URLRequest* request) { void SpawnerCommunicator::OnResponseStarted(URLRequest* request,
int net_error) {
DCHECK_EQ(request, cur_request_.get()); DCHECK_EQ(request, cur_request_.get());
DCHECK_NE(ERR_IO_PENDING, net_error);
SpawnerRequestData* data = SpawnerRequestData* data =
static_cast<SpawnerRequestData*>(cur_request_->GetUserData(this)); static_cast<SpawnerRequestData*>(cur_request_->GetUserData(this));
DCHECK(data); DCHECK(data);
data->IncreaseResponseStartedCount(); data->IncreaseResponseStartedCount();
if (!request->status().is_success()) { if (net_error != OK) {
OnSpawnerCommandCompleted(request); OnSpawnerCommandCompleted(request, net_error);
return; return;
} }
...@@ -308,7 +313,7 @@ void SpawnerCommunicator::OnResponseStarted(URLRequest* request) { ...@@ -308,7 +313,7 @@ void SpawnerCommunicator::OnResponseStarted(URLRequest* request) {
<< request->response_headers()->GetStatusLine(); << request->response_headers()->GetStatusLine();
data->SetResultCode(ERR_FAILED); data->SetResultCode(ERR_FAILED);
request->Cancel(); request->Cancel();
OnSpawnerCommandCompleted(request); OnSpawnerCommandCompleted(request, ERR_ABORTED);
return; return;
} }
...@@ -316,6 +321,8 @@ void SpawnerCommunicator::OnResponseStarted(URLRequest* request) { ...@@ -316,6 +321,8 @@ void SpawnerCommunicator::OnResponseStarted(URLRequest* request) {
} }
void SpawnerCommunicator::OnReadCompleted(URLRequest* request, int num_bytes) { void SpawnerCommunicator::OnReadCompleted(URLRequest* request, int num_bytes) {
DCHECK_NE(ERR_IO_PENDING, num_bytes);
if (!cur_request_.get()) if (!cur_request_.get())
return; return;
DCHECK_EQ(request, cur_request_.get()); DCHECK_EQ(request, cur_request_.get());
...@@ -327,7 +334,9 @@ void SpawnerCommunicator::OnReadCompleted(URLRequest* request, int num_bytes) { ...@@ -327,7 +334,9 @@ void SpawnerCommunicator::OnReadCompleted(URLRequest* request, int num_bytes) {
// Keep reading. // Keep reading.
ReadResult(request); ReadResult(request);
} else { } else {
OnSpawnerCommandCompleted(request); // |bytes_read| < 0
int net_error = num_bytes;
OnSpawnerCommandCompleted(request, net_error);
} }
} }
......
...@@ -102,14 +102,14 @@ class SpawnerCommunicator : public URLRequest::Delegate { ...@@ -102,14 +102,14 @@ class SpawnerCommunicator : public URLRequest::Delegate {
std::string* data_received); std::string* data_received);
// URLRequest::Delegate methods. Called on the IO thread. // URLRequest::Delegate methods. Called on the IO thread.
void OnResponseStarted(URLRequest* request) override; void OnResponseStarted(URLRequest* request, int net_error) override;
void OnReadCompleted(URLRequest* request, int num_bytes) override; void OnReadCompleted(URLRequest* request, int num_bytes) override;
// Reads Result from the response. Called on the IO thread. // Reads Result from the response. Called on the IO thread.
void ReadResult(URLRequest* request); void ReadResult(URLRequest* request);
// Called on the IO thread upon completion of the spawner command. // Called on the IO thread upon completion of the spawner command.
void OnSpawnerCommandCompleted(URLRequest* request); void OnSpawnerCommandCompleted(URLRequest* request, int net_error);
// Callback on the IO thread for time-out task of request with id |id|. // Callback on the IO thread for time-out task of request with id |id|.
void OnTimeout(int id); void OnTimeout(int id);
......
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