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

Side by Side Diff: net/websockets/websocket_stream.cc

Issue 2313013002: Revert of Adjust callers and networking delegates in net/ to modified APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@URLRequestRead
Patch Set: Created 4 years, 3 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 unified diff | Download patch
« no previous file with comments | « net/websockets/websocket_end_to_end_test.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/websockets/websocket_stream.h" 5 #include "net/websockets/websocket_stream.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 ~Delegate() override { 54 ~Delegate() override {
55 UMA_HISTOGRAM_ENUMERATION( 55 UMA_HISTOGRAM_ENUMERATION(
56 "Net.WebSocket.HandshakeResult", result_, NUM_HANDSHAKE_RESULT_TYPES); 56 "Net.WebSocket.HandshakeResult", result_, NUM_HANDSHAKE_RESULT_TYPES);
57 } 57 }
58 58
59 // Implementation of URLRequest::Delegate methods. 59 // Implementation of URLRequest::Delegate methods.
60 void OnReceivedRedirect(URLRequest* request, 60 void OnReceivedRedirect(URLRequest* request,
61 const RedirectInfo& redirect_info, 61 const RedirectInfo& redirect_info,
62 bool* defer_redirect) override; 62 bool* defer_redirect) override;
63 63
64 void OnResponseStarted(URLRequest* request, int net_error) override; 64 void OnResponseStarted(URLRequest* request) override;
65 65
66 void OnAuthRequired(URLRequest* request, 66 void OnAuthRequired(URLRequest* request,
67 AuthChallengeInfo* auth_info) override; 67 AuthChallengeInfo* auth_info) override;
68 68
69 void OnCertificateRequested(URLRequest* request, 69 void OnCertificateRequested(URLRequest* request,
70 SSLCertRequestInfo* cert_request_info) override; 70 SSLCertRequestInfo* cert_request_info) override;
71 71
72 void OnSSLCertificateError(URLRequest* request, 72 void OnSSLCertificateError(URLRequest* request,
73 const SSLInfo& ssl_info, 73 const SSLInfo& ssl_info,
74 bool fatal) override; 74 bool fatal) override;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 DCHECK(timer_); 146 DCHECK(timer_);
147 DCHECK(handshake_stream_); 147 DCHECK(handshake_stream_);
148 148
149 timer_->Stop(); 149 timer_->Stop();
150 150
151 WebSocketHandshakeStreamBase* handshake_stream = handshake_stream_; 151 WebSocketHandshakeStreamBase* handshake_stream = handshake_stream_;
152 handshake_stream_ = nullptr; 152 handshake_stream_ = nullptr;
153 connect_delegate_->OnSuccess(handshake_stream->Upgrade()); 153 connect_delegate_->OnSuccess(handshake_stream->Upgrade());
154 } 154 }
155 155
156 std::string FailureMessageFromNetError(int net_error) { 156 std::string FailureMessageFromNetError() {
157 if (net_error == ERR_TUNNEL_CONNECTION_FAILED) { 157 int error = url_request_->status().error();
158 if (error == ERR_TUNNEL_CONNECTION_FAILED) {
158 // This error is common and confusing, so special-case it. 159 // This error is common and confusing, so special-case it.
159 // TODO(ricea): Include the HostPortPair of the selected proxy server in 160 // TODO(ricea): Include the HostPortPair of the selected proxy server in
160 // the error message. This is not currently possible because it isn't set 161 // the error message. This is not currently possible because it isn't set
161 // in HttpResponseInfo when a ERR_TUNNEL_CONNECTION_FAILED error happens. 162 // in HttpResponseInfo when a ERR_TUNNEL_CONNECTION_FAILED error happens.
162 return "Establishing a tunnel via proxy server failed."; 163 return "Establishing a tunnel via proxy server failed.";
163 } else { 164 } else {
164 return std::string("Error in connection establishment: ") + 165 return std::string("Error in connection establishment: ") +
165 ErrorToString(net_error); 166 ErrorToString(url_request_->status().error());
166 } 167 }
167 } 168 }
168 169
169 void ReportFailure(int net_error) { 170 void ReportFailure() {
170 DCHECK(timer_); 171 DCHECK(timer_);
171 timer_->Stop(); 172 timer_->Stop();
172 if (failure_message_.empty()) { 173 if (failure_message_.empty()) {
173 switch (net_error) { 174 switch (url_request_->status().status()) {
174 case OK: 175 case URLRequestStatus::SUCCESS:
175 case ERR_IO_PENDING: 176 case URLRequestStatus::IO_PENDING:
176 break; 177 break;
177 case ERR_ABORTED: 178 case URLRequestStatus::CANCELED:
178 failure_message_ = "WebSocket opening handshake was canceled"; 179 if (url_request_->status().error() == ERR_TIMED_OUT)
180 failure_message_ = "WebSocket opening handshake timed out";
181 else
182 failure_message_ = "WebSocket opening handshake was canceled";
179 break; 183 break;
180 case ERR_TIMED_OUT: 184 case URLRequestStatus::FAILED:
181 failure_message_ = "WebSocket opening handshake timed out"; 185 failure_message_ = FailureMessageFromNetError();
182 break;
183 default:
184 failure_message_ = FailureMessageFromNetError(net_error);
185 break; 186 break;
186 } 187 }
187 } 188 }
188 ReportFailureWithMessage(failure_message_); 189 ReportFailureWithMessage(failure_message_);
189 } 190 }
190 191
191 void ReportFailureWithMessage(const std::string& failure_message) { 192 void ReportFailureWithMessage(const std::string& failure_message) {
192 connect_delegate_->OnFailure(failure_message); 193 connect_delegate_->OnFailure(failure_message);
193 } 194 }
194 195
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 if (redirect_info.new_method != "GET" || 275 if (redirect_info.new_method != "GET" ||
275 redirect_info.new_url != expected_url) { 276 redirect_info.new_url != expected_url) {
276 // This should not happen. 277 // This should not happen.
277 DLOG(FATAL) << "Unauthorized WebSocket redirect to " 278 DLOG(FATAL) << "Unauthorized WebSocket redirect to "
278 << redirect_info.new_method << " " 279 << redirect_info.new_method << " "
279 << redirect_info.new_url.spec(); 280 << redirect_info.new_url.spec();
280 request->Cancel(); 281 request->Cancel();
281 } 282 }
282 } 283 }
283 284
284 void Delegate::OnResponseStarted(URLRequest* request, int net_error) { 285 void Delegate::OnResponseStarted(URLRequest* request) {
285 DCHECK_NE(ERR_IO_PENDING, net_error);
286 // All error codes, including OK and ABORTED, as with 286 // All error codes, including OK and ABORTED, as with
287 // Net.ErrorCodesForMainFrame3 287 // Net.ErrorCodesForMainFrame3
288 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.WebSocket.ErrorCodes", -net_error); 288 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.WebSocket.ErrorCodes",
289 if (net_error != OK) { 289 -request->status().error());
290 if (!request->status().is_success()) {
290 DVLOG(3) << "OnResponseStarted (request failed)"; 291 DVLOG(3) << "OnResponseStarted (request failed)";
291 owner_->ReportFailure(net_error); 292 owner_->ReportFailure();
292 return; 293 return;
293 } 294 }
294 const int response_code = request->GetResponseCode(); 295 const int response_code = request->GetResponseCode();
295 DVLOG(3) << "OnResponseStarted (response code " << response_code << ")"; 296 DVLOG(3) << "OnResponseStarted (response code " << response_code << ")";
296 switch (response_code) { 297 switch (response_code) {
297 case HTTP_SWITCHING_PROTOCOLS: 298 case HTTP_SWITCHING_PROTOCOLS:
298 result_ = CONNECTED; 299 result_ = CONNECTED;
299 owner_->PerformUpgrade(); 300 owner_->PerformUpgrade();
300 return; 301 return;
301 302
302 case HTTP_UNAUTHORIZED: 303 case HTTP_UNAUTHORIZED:
303 result_ = FAILED; 304 result_ = FAILED;
304 owner_->OnFinishOpeningHandshake(); 305 owner_->OnFinishOpeningHandshake();
305 owner_->ReportFailureWithMessage( 306 owner_->ReportFailureWithMessage(
306 "HTTP Authentication failed; no valid credentials available"); 307 "HTTP Authentication failed; no valid credentials available");
307 return; 308 return;
308 309
309 case HTTP_PROXY_AUTHENTICATION_REQUIRED: 310 case HTTP_PROXY_AUTHENTICATION_REQUIRED:
310 result_ = FAILED; 311 result_ = FAILED;
311 owner_->OnFinishOpeningHandshake(); 312 owner_->OnFinishOpeningHandshake();
312 owner_->ReportFailureWithMessage("Proxy authentication failed"); 313 owner_->ReportFailureWithMessage("Proxy authentication failed");
313 return; 314 return;
314 315
315 default: 316 default:
316 result_ = FAILED; 317 result_ = FAILED;
317 owner_->ReportFailure(net_error); 318 owner_->ReportFailure();
318 } 319 }
319 } 320 }
320 321
321 void Delegate::OnAuthRequired(URLRequest* request, 322 void Delegate::OnAuthRequired(URLRequest* request,
322 AuthChallengeInfo* auth_info) { 323 AuthChallengeInfo* auth_info) {
323 // This should only be called if credentials are not already stored. 324 // This should only be called if credentials are not already stored.
324 request->CancelAuth(); 325 request->CancelAuth();
325 } 326 }
326 327
327 void Delegate::OnCertificateRequested(URLRequest* request, 328 void Delegate::OnCertificateRequested(URLRequest* request,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 DCHECK(connect_delegate); 404 DCHECK(connect_delegate);
404 if (headers.get()) { 405 if (headers.get()) {
405 connect_delegate->OnFinishOpeningHandshake( 406 connect_delegate->OnFinishOpeningHandshake(
406 base::WrapUnique(new WebSocketHandshakeResponseInfo( 407 base::WrapUnique(new WebSocketHandshakeResponseInfo(
407 url, headers->response_code(), headers->GetStatusText(), headers, 408 url, headers->response_code(), headers->GetStatusText(), headers,
408 response_time))); 409 response_time)));
409 } 410 }
410 } 411 }
411 412
412 } // namespace net 413 } // namespace net
OLDNEW
« no previous file with comments | « net/websockets/websocket_end_to_end_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698