Commit 7f60c8ef authored by maksim.sisov's avatar maksim.sisov Committed by Commit bot

Use modifed URLRequest API in net/websockets

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/2333553002
Cr-Original-Commit-Position: refs/heads/master@{#418014}
Cr-Commit-Position: refs/heads/master@{#419250}
parent 32c0c163
...@@ -435,7 +435,7 @@ TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HstsHttpsToWebSocket)) { ...@@ -435,7 +435,7 @@ TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HstsHttpsToWebSocket)) {
request->Start(); request->Start();
// TestDelegate exits the message loop when the request completes. // TestDelegate exits the message loop when the request completes.
base::RunLoop().Run(); base::RunLoop().Run();
EXPECT_TRUE(request->status().is_success()); EXPECT_EQ(OK, delegate.request_status());
// Check HSTS with ws: // Check HSTS with ws:
// Change the scheme from wss: to ws: to verify that it is switched back. // Change the scheme from wss: to ws: to verify that it is switched back.
...@@ -469,7 +469,7 @@ TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HstsWebSocketToHttps)) { ...@@ -469,7 +469,7 @@ TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HstsWebSocketToHttps)) {
request->Start(); request->Start();
// TestDelegate exits the message loop when the request completes. // TestDelegate exits the message loop when the request completes.
base::RunLoop().Run(); base::RunLoop().Run();
EXPECT_TRUE(request->status().is_success()); EXPECT_EQ(OK, delegate.request_status());
EXPECT_TRUE(request->url().SchemeIs("https")); EXPECT_TRUE(request->url().SchemeIs("https"));
} }
......
...@@ -61,7 +61,7 @@ class Delegate : public URLRequest::Delegate { ...@@ -61,7 +61,7 @@ class Delegate : public URLRequest::Delegate {
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 OnAuthRequired(URLRequest* request, void OnAuthRequired(URLRequest* request,
AuthChallengeInfo* auth_info) override; AuthChallengeInfo* auth_info) override;
...@@ -153,9 +153,8 @@ class WebSocketStreamRequestImpl : public WebSocketStreamRequest { ...@@ -153,9 +153,8 @@ class WebSocketStreamRequestImpl : public WebSocketStreamRequest {
connect_delegate_->OnSuccess(handshake_stream->Upgrade()); connect_delegate_->OnSuccess(handshake_stream->Upgrade());
} }
std::string FailureMessageFromNetError() { std::string FailureMessageFromNetError(int net_error) {
int error = url_request_->status().error(); if (net_error == ERR_TUNNEL_CONNECTION_FAILED) {
if (error == ERR_TUNNEL_CONNECTION_FAILED) {
// This error is common and confusing, so special-case it. // This error is common and confusing, so special-case it.
// TODO(ricea): Include the HostPortPair of the selected proxy server in // TODO(ricea): Include the HostPortPair of the selected proxy server in
// the error message. This is not currently possible because it isn't set // the error message. This is not currently possible because it isn't set
...@@ -163,26 +162,26 @@ class WebSocketStreamRequestImpl : public WebSocketStreamRequest { ...@@ -163,26 +162,26 @@ class WebSocketStreamRequestImpl : public WebSocketStreamRequest {
return "Establishing a tunnel via proxy server failed."; return "Establishing a tunnel via proxy server failed.";
} else { } else {
return std::string("Error in connection establishment: ") + return std::string("Error in connection establishment: ") +
ErrorToString(url_request_->status().error()); ErrorToString(net_error);
} }
} }
void ReportFailure() { void ReportFailure(int net_error) {
DCHECK(timer_); DCHECK(timer_);
timer_->Stop(); timer_->Stop();
if (failure_message_.empty()) { if (failure_message_.empty()) {
switch (url_request_->status().status()) { switch (net_error) {
case URLRequestStatus::SUCCESS: case OK:
case URLRequestStatus::IO_PENDING: case ERR_IO_PENDING:
break; break;
case URLRequestStatus::CANCELED: case ERR_ABORTED:
if (url_request_->status().error() == ERR_TIMED_OUT) failure_message_ = "WebSocket opening handshake was canceled";
failure_message_ = "WebSocket opening handshake timed out";
else
failure_message_ = "WebSocket opening handshake was canceled";
break; break;
case URLRequestStatus::FAILED: case ERR_TIMED_OUT:
failure_message_ = FailureMessageFromNetError(); failure_message_ = "WebSocket opening handshake timed out";
break;
default:
failure_message_ = FailureMessageFromNetError(net_error);
break; break;
} }
} }
...@@ -282,14 +281,14 @@ void Delegate::OnReceivedRedirect(URLRequest* request, ...@@ -282,14 +281,14 @@ void Delegate::OnReceivedRedirect(URLRequest* request,
} }
} }
void Delegate::OnResponseStarted(URLRequest* request) { void Delegate::OnResponseStarted(URLRequest* request, int net_error) {
DCHECK_NE(ERR_IO_PENDING, net_error);
// All error codes, including OK and ABORTED, as with // All error codes, including OK and ABORTED, as with
// Net.ErrorCodesForMainFrame3 // Net.ErrorCodesForMainFrame3
UMA_HISTOGRAM_SPARSE_SLOWLY("Net.WebSocket.ErrorCodes", UMA_HISTOGRAM_SPARSE_SLOWLY("Net.WebSocket.ErrorCodes", -net_error);
-request->status().error()); if (net_error != OK) {
if (!request->status().is_success()) {
DVLOG(3) << "OnResponseStarted (request failed)"; DVLOG(3) << "OnResponseStarted (request failed)";
owner_->ReportFailure(); owner_->ReportFailure(net_error);
return; return;
} }
const int response_code = request->GetResponseCode(); const int response_code = request->GetResponseCode();
...@@ -315,7 +314,7 @@ void Delegate::OnResponseStarted(URLRequest* request) { ...@@ -315,7 +314,7 @@ void Delegate::OnResponseStarted(URLRequest* request) {
default: default:
result_ = FAILED; result_ = FAILED;
owner_->ReportFailure(); owner_->ReportFailure(net_error);
} }
} }
......
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