Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(747)

Unified Diff: net/test/spawned_test_server/spawner_communicator.cc

Issue 2265873002: Adjust callers and networking delegates in net/ to modified APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@URLRequestRead
Patch Set: rebased Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/test/spawned_test_server/spawner_communicator.cc
diff --git a/net/test/spawned_test_server/spawner_communicator.cc b/net/test/spawned_test_server/spawner_communicator.cc
index 952b85c74bf76cf4096fe88d2bd31cc0a6bf7e6e..05d0eec221d2ad7a1aa19114269c3fa7232389d3 100644
--- a/net/test/spawned_test_server/spawner_communicator.cc
+++ b/net/test/spawned_test_server/spawner_communicator.cc
@@ -229,11 +229,14 @@ void SpawnerCommunicator::OnTimeout(int id) {
return;
// Set the result code and cancel the timed-out task.
data->SetResultCode(ERR_TIMED_OUT);
- cur_request_->Cancel();
- OnSpawnerCommandCompleted(cur_request_.get());
+ int result = cur_request_->Cancel();
+ OnSpawnerCommandCompleted(cur_request_.get(), result);
mmenke 2016/08/30 22:13:22 This code is actually buggy - note the ERR_TIMED_O
maksims (do not use this acc) 2016/09/01 12:22:30 Done.
}
-void SpawnerCommunicator::OnSpawnerCommandCompleted(URLRequest* request) {
+void SpawnerCommunicator::OnSpawnerCommandCompleted(URLRequest* request,
+ int net_error) {
+ DCHECK_NE(ERR_IO_PENDING, net_error);
+
if (!cur_request_.get())
return;
DCHECK_EQ(request, cur_request_.get());
@@ -242,13 +245,11 @@ void SpawnerCommunicator::OnSpawnerCommandCompleted(URLRequest* request) {
DCHECK(data);
// If request is faild,return the error code.
- if (!cur_request_->status().is_success())
- data->SetResultCode(cur_request_->status().error());
+ if (net_error != OK)
+ data->SetResultCode(net_error);
if (!data->IsResultOK()) {
- LOG(ERROR) << "request failed, status: "
- << static_cast<int>(request->status().status())
- << ", error: " << request->status().error();
+ LOG(ERROR) << "request failed, error: " << net_error;
// Clear the buffer of received data if any net error happened.
data->ClearReceivedData();
} else {
@@ -275,30 +276,33 @@ void SpawnerCommunicator::ReadResult(URLRequest* request) {
IOBuffer* buf = data->buf();
// Read as many bytes as are available synchronously.
while (true) {
- int num_bytes;
- if (!request->Read(buf, kBufferSize, &num_bytes)) {
+ int rv = request->Read(buf, kBufferSize);
+ if (rv < 0) {
// Check whether the read failed synchronously.
- if (!request->status().is_io_pending())
- OnSpawnerCommandCompleted(request);
+ if (rv != ERR_IO_PENDING)
+ OnSpawnerCommandCompleted(request, rv);
return;
}
- if (!data->ConsumeBytesRead(num_bytes)) {
- OnSpawnerCommandCompleted(request);
+ if (!data->ConsumeBytesRead(rv)) {
+ OnSpawnerCommandCompleted(request, rv);
return;
}
mmenke 2016/08/30 22:13:22 As suggested elsewhere, suggest 3 non-nested if st
maksims (do not use this acc) 2016/09/01 12:22:30 Done.
}
}
-void SpawnerCommunicator::OnResponseStarted(URLRequest* request) {
+void SpawnerCommunicator::OnResponseStarted(URLRequest* request,
+ int net_error) {
DCHECK_EQ(request, cur_request_.get());
+ DCHECK_NE(ERR_IO_PENDING, net_error);
+
SpawnerRequestData* data =
static_cast<SpawnerRequestData*>(cur_request_->GetUserData(this));
DCHECK(data);
data->IncreaseResponseStartedCount();
- if (!request->status().is_success()) {
- OnSpawnerCommandCompleted(request);
+ if (net_error != OK) {
+ OnSpawnerCommandCompleted(request, net_error);
return;
}
@@ -308,7 +312,7 @@ void SpawnerCommunicator::OnResponseStarted(URLRequest* request) {
<< request->response_headers()->GetStatusLine();
data->SetResultCode(ERR_FAILED);
request->Cancel();
- OnSpawnerCommandCompleted(request);
+ OnSpawnerCommandCompleted(request, ERR_ABORTED);
return;
}
@@ -316,6 +320,8 @@ void SpawnerCommunicator::OnResponseStarted(URLRequest* request) {
}
void SpawnerCommunicator::OnReadCompleted(URLRequest* request, int num_bytes) {
+ DCHECK_NE(ERR_IO_PENDING, num_bytes);
+
if (!cur_request_.get())
return;
DCHECK_EQ(request, cur_request_.get());
@@ -327,7 +333,9 @@ void SpawnerCommunicator::OnReadCompleted(URLRequest* request, int num_bytes) {
// Keep reading.
ReadResult(request);
} else {
- OnSpawnerCommandCompleted(request);
+ // |bytes_read| < 0
+ int net_error = num_bytes;
+ OnSpawnerCommandCompleted(request, net_error);
}
}

Powered by Google App Engine
This is Rietveld 408576698