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

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

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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/url_request/url_request_job.cc ('k') | net/websockets/websocket_stream_cookie_test.cc » ('j') | 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 "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/metrics/sparse_histogram.h" 10 #include "base/metrics/sparse_histogram.h"
11 #include "base/profiler/scoped_tracker.h" 11 #include "base/profiler/scoped_tracker.h"
12 #include "base/strings/stringprintf.h"
12 #include "base/time/time.h" 13 #include "base/time/time.h"
13 #include "base/timer/timer.h" 14 #include "base/timer/timer.h"
14 #include "net/base/load_flags.h" 15 #include "net/base/load_flags.h"
15 #include "net/http/http_request_headers.h" 16 #include "net/http/http_request_headers.h"
16 #include "net/http/http_response_headers.h" 17 #include "net/http/http_response_headers.h"
17 #include "net/http/http_status_code.h" 18 #include "net/http/http_status_code.h"
18 #include "net/url_request/redirect_info.h" 19 #include "net/url_request/redirect_info.h"
19 #include "net/url_request/url_request.h" 20 #include "net/url_request/url_request.h"
20 #include "net/url_request/url_request_context.h" 21 #include "net/url_request/url_request_context.h"
21 #include "net/websockets/websocket_errors.h" 22 #include "net/websockets/websocket_errors.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 base::Unretained(this))); 129 base::Unretained(this)));
129 url_request_->Start(); 130 url_request_->Start();
130 } 131 }
131 132
132 void PerformUpgrade() { 133 void PerformUpgrade() {
133 DCHECK(timer_); 134 DCHECK(timer_);
134 timer_->Stop(); 135 timer_->Stop();
135 connect_delegate_->OnSuccess(create_helper_->Upgrade()); 136 connect_delegate_->OnSuccess(create_helper_->Upgrade());
136 } 137 }
137 138
139 std::string FailureMessageFromNetError() {
140 int error = url_request_->status().error();
141 if (error == ERR_TUNNEL_CONNECTION_FAILED) {
142 // This error is common and confusing, so special-case it.
143 // TODO(ricea): Include the HostPortPair of the selected proxy server in
144 // the error message. This is not currently possible because it isn't set
145 // in HttpResponseInfo when a ERR_TUNNEL_CONNECTION_FAILED error happens.
146 return "Establishing a tunnel via proxy server failed.";
147 } else {
148 return std::string("Error in connection establishment: ") +
149 ErrorToString(url_request_->status().error());
150 }
151 }
152
138 void ReportFailure() { 153 void ReportFailure() {
139 DCHECK(timer_); 154 DCHECK(timer_);
140 timer_->Stop(); 155 timer_->Stop();
141 if (failure_message_.empty()) { 156 if (failure_message_.empty()) {
142 switch (url_request_->status().status()) { 157 switch (url_request_->status().status()) {
143 case URLRequestStatus::SUCCESS: 158 case URLRequestStatus::SUCCESS:
144 case URLRequestStatus::IO_PENDING: 159 case URLRequestStatus::IO_PENDING:
145 break; 160 break;
146 case URLRequestStatus::CANCELED: 161 case URLRequestStatus::CANCELED:
147 if (url_request_->status().error() == ERR_TIMED_OUT) 162 if (url_request_->status().error() == ERR_TIMED_OUT)
148 failure_message_ = "WebSocket opening handshake timed out"; 163 failure_message_ = "WebSocket opening handshake timed out";
149 else 164 else
150 failure_message_ = "WebSocket opening handshake was canceled"; 165 failure_message_ = "WebSocket opening handshake was canceled";
151 break; 166 break;
152 case URLRequestStatus::FAILED: 167 case URLRequestStatus::FAILED:
153 failure_message_ = 168 failure_message_ = FailureMessageFromNetError();
154 std::string("Error in connection establishment: ") +
155 ErrorToString(url_request_->status().error());
156 break; 169 break;
157 } 170 }
158 } 171 }
159 ReportFailureWithMessage(failure_message_); 172 ReportFailureWithMessage(failure_message_);
160 } 173 }
161 174
162 void ReportFailureWithMessage(const std::string& failure_message) { 175 void ReportFailureWithMessage(const std::string& failure_message) {
163 connect_delegate_->OnFailure(failure_message); 176 connect_delegate_->OnFailure(failure_message);
164 } 177 }
165 178
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 connect_delegate->OnFinishOpeningHandshake(make_scoped_ptr( 363 connect_delegate->OnFinishOpeningHandshake(make_scoped_ptr(
351 new WebSocketHandshakeResponseInfo(url, 364 new WebSocketHandshakeResponseInfo(url,
352 headers->response_code(), 365 headers->response_code(),
353 headers->GetStatusText(), 366 headers->GetStatusText(),
354 headers, 367 headers,
355 response_time))); 368 response_time)));
356 } 369 }
357 } 370 }
358 371
359 } // namespace net 372 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_job.cc ('k') | net/websockets/websocket_stream_cookie_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698