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

Side by Side Diff: net/http/http_stream_parser.cc

Issue 1320683003: Move logic to figure out if a socket can be reused into HttpStream. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/http/http_stream_parser.h" 5 #include "net/http/http_stream_parser.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 195
196 // 2 CRLFs + max of 8 hex chars. 196 // 2 CRLFs + max of 8 hex chars.
197 const size_t HttpStreamParser::kChunkHeaderFooterSize = 12; 197 const size_t HttpStreamParser::kChunkHeaderFooterSize = 12;
198 198
199 HttpStreamParser::HttpStreamParser(ClientSocketHandle* connection, 199 HttpStreamParser::HttpStreamParser(ClientSocketHandle* connection,
200 const HttpRequestInfo* request, 200 const HttpRequestInfo* request,
201 GrowableIOBuffer* read_buffer, 201 GrowableIOBuffer* read_buffer,
202 const BoundNetLog& net_log) 202 const BoundNetLog& net_log)
203 : io_state_(STATE_NONE), 203 : io_state_(STATE_NONE),
204 request_(request), 204 request_(request),
205 request_headers_(NULL), 205 request_headers_(nullptr),
206 request_headers_length_(0), 206 request_headers_length_(0),
207 read_buf_(read_buffer), 207 read_buf_(read_buffer),
208 read_buf_unused_offset_(0), 208 read_buf_unused_offset_(0),
209 response_header_start_offset_(-1), 209 response_header_start_offset_(-1),
210 received_bytes_(0), 210 received_bytes_(0),
211 response_(nullptr),
211 response_body_length_(-1), 212 response_body_length_(-1),
212 response_body_read_(0), 213 response_body_read_(0),
213 user_read_buf_(NULL), 214 user_read_buf_(nullptr),
214 user_read_buf_len_(0), 215 user_read_buf_len_(0),
215 connection_(connection), 216 connection_(connection),
216 net_log_(net_log), 217 net_log_(net_log),
217 sent_last_chunk_(false), 218 sent_last_chunk_(false),
218 upload_error_(OK), 219 upload_error_(OK),
219 weak_ptr_factory_(this) { 220 weak_ptr_factory_(this) {
220 io_callback_ = base::Bind(&HttpStreamParser::OnIOComplete, 221 io_callback_ = base::Bind(&HttpStreamParser::OnIOComplete,
221 weak_ptr_factory_.GetWeakPtr()); 222 weak_ptr_factory_.GetWeakPtr());
222 } 223 }
223 224
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 bool HttpStreamParser::IsConnectionReused() const { 1063 bool HttpStreamParser::IsConnectionReused() const {
1063 ClientSocketHandle::SocketReuseType reuse_type = connection_->reuse_type(); 1064 ClientSocketHandle::SocketReuseType reuse_type = connection_->reuse_type();
1064 return connection_->is_reused() || 1065 return connection_->is_reused() ||
1065 reuse_type == ClientSocketHandle::UNUSED_IDLE; 1066 reuse_type == ClientSocketHandle::UNUSED_IDLE;
1066 } 1067 }
1067 1068
1068 void HttpStreamParser::SetConnectionReused() { 1069 void HttpStreamParser::SetConnectionReused() {
1069 connection_->set_reuse_type(ClientSocketHandle::REUSED_IDLE); 1070 connection_->set_reuse_type(ClientSocketHandle::REUSED_IDLE);
1070 } 1071 }
1071 1072
1072 bool HttpStreamParser::IsConnectionReusable() const { 1073 bool HttpStreamParser::CanReuseConnection() const {
1074 if (!CanFindEndOfResponse())
1075 return false;
1076 if (!response_->headers || !response_->headers->IsKeepAlive())
1077 return false;
1073 return connection_->socket() && connection_->socket()->IsConnectedAndIdle(); 1078 return connection_->socket() && connection_->socket()->IsConnectedAndIdle();
1074 } 1079 }
1075 1080
1076 void HttpStreamParser::GetSSLInfo(SSLInfo* ssl_info) { 1081 void HttpStreamParser::GetSSLInfo(SSLInfo* ssl_info) {
1077 if (request_->url.SchemeIsCryptographic() && connection_->socket()) { 1082 if (request_->url.SchemeIsCryptographic() && connection_->socket()) {
1078 SSLClientSocket* ssl_socket = 1083 SSLClientSocket* ssl_socket =
1079 static_cast<SSLClientSocket*>(connection_->socket()); 1084 static_cast<SSLClientSocket*>(connection_->socket());
1080 ssl_socket->GetSSLInfo(ssl_info); 1085 ssl_socket->GetSSLInfo(ssl_info);
1081 } 1086 }
1082 } 1087 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 } 1135 }
1131 1136
1132 void HttpStreamParser::ValidateStatusLine(const std::string& status_line) { 1137 void HttpStreamParser::ValidateStatusLine(const std::string& status_line) {
1133 HttpStatusLineValidator::StatusLineStatus status = 1138 HttpStatusLineValidator::StatusLineStatus status =
1134 HttpStatusLineValidator::ValidateStatusLine(status_line); 1139 HttpStatusLineValidator::ValidateStatusLine(status_line);
1135 UMA_HISTOGRAM_ENUMERATION("Net.HttpStatusLineStatus", status, 1140 UMA_HISTOGRAM_ENUMERATION("Net.HttpStatusLineStatus", status,
1136 HttpStatusLineValidator::STATUS_LINE_MAX); 1141 HttpStatusLineValidator::STATUS_LINE_MAX);
1137 } 1142 }
1138 1143
1139 } // namespace net 1144 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698