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

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

Issue 6591030: Add HttpStreamFactory Job orphaning semantics. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated comment. Created 9 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « net/http/http_stream_factory_impl_job.h ('k') | net/http/http_stream_factory_impl_request.h » ('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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_factory_impl_job.h" 5 #include "net/http/http_stream_factory_impl_job.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stl_util-inl.h" 8 #include "base/stl_util-inl.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 return LOAD_STATE_RESOLVING_PROXY_FOR_URL; 127 return LOAD_STATE_RESOLVING_PROXY_FOR_URL;
128 case STATE_CREATE_STREAM_COMPLETE: 128 case STATE_CREATE_STREAM_COMPLETE:
129 return connection_->GetLoadState(); 129 return connection_->GetLoadState();
130 case STATE_INIT_CONNECTION_COMPLETE: 130 case STATE_INIT_CONNECTION_COMPLETE:
131 return LOAD_STATE_SENDING_REQUEST; 131 return LOAD_STATE_SENDING_REQUEST;
132 default: 132 default:
133 return LOAD_STATE_IDLE; 133 return LOAD_STATE_IDLE;
134 } 134 }
135 } 135 }
136 136
137 void HttpStreamFactoryImpl::Job::Orphan(const Request* request) {
138 DCHECK_EQ(request_, request);
139 request_ = NULL;
140 }
141
137 bool HttpStreamFactoryImpl::Job::was_alternate_protocol_available() const { 142 bool HttpStreamFactoryImpl::Job::was_alternate_protocol_available() const {
138 return was_alternate_protocol_available_; 143 return was_alternate_protocol_available_;
139 } 144 }
140 145
141 bool HttpStreamFactoryImpl::Job::was_npn_negotiated() const { 146 bool HttpStreamFactoryImpl::Job::was_npn_negotiated() const {
142 return was_npn_negotiated_; 147 return was_npn_negotiated_;
143 } 148 }
144 149
145 bool HttpStreamFactoryImpl::Job::using_spdy() const { 150 bool HttpStreamFactoryImpl::Job::using_spdy() const {
146 return using_spdy_; 151 return using_spdy_;
(...skipping 11 matching lines...) Expand all
158 DCHECK(using_ssl_); 163 DCHECK(using_ssl_);
159 DCHECK(!establishing_tunnel_); 164 DCHECK(!establishing_tunnel_);
160 DCHECK(connection_.get() && connection_->socket()); 165 DCHECK(connection_.get() && connection_->socket());
161 SSLClientSocket* ssl_socket = 166 SSLClientSocket* ssl_socket =
162 static_cast<SSLClientSocket*>(connection_->socket()); 167 static_cast<SSLClientSocket*>(connection_->socket());
163 ssl_socket->GetSSLInfo(&ssl_info_); 168 ssl_socket->GetSSLInfo(&ssl_info_);
164 } 169 }
165 170
166 void HttpStreamFactoryImpl::Job::OnStreamReadyCallback() { 171 void HttpStreamFactoryImpl::Job::OnStreamReadyCallback() {
167 DCHECK(stream_.get()); 172 DCHECK(stream_.get());
168 request_->Complete(was_alternate_protocol_available(), 173 DCHECK(!IsPreconnecting());
169 was_npn_negotiated(), 174 if (IsOrphaned()) {
170 using_spdy(), 175 stream_factory_->OnOrphanedJobComplete(this);
171 net_log_.source()); 176 } else {
172 request_->OnStreamReady(ssl_config_, proxy_info_, stream_.release()); 177 request_->Complete(was_alternate_protocol_available(),
178 was_npn_negotiated(),
179 using_spdy(),
180 net_log_.source());
181 request_->OnStreamReady(this, ssl_config_, proxy_info_, stream_.release());
182 }
173 // |this| may be deleted after this call. 183 // |this| may be deleted after this call.
174 } 184 }
175 185
176 void HttpStreamFactoryImpl::Job::OnSpdySessionReadyCallback() { 186 void HttpStreamFactoryImpl::Job::OnSpdySessionReadyCallback() {
177 DCHECK(!stream_.get()); 187 DCHECK(!stream_.get());
188 DCHECK(!IsPreconnecting());
178 DCHECK(using_spdy()); 189 DCHECK(using_spdy());
179 DCHECK(new_spdy_session_); 190 DCHECK(new_spdy_session_);
180 scoped_refptr<SpdySession> spdy_session = new_spdy_session_; 191 scoped_refptr<SpdySession> spdy_session = new_spdy_session_;
181 new_spdy_session_ = NULL; 192 new_spdy_session_ = NULL;
182 stream_factory_->OnSpdySessionReady(this, spdy_session, spdy_session_direct_); 193 if (IsOrphaned()) {
194 stream_factory_->OnSpdySessionReady(
195 spdy_session, spdy_session_direct_, ssl_config_, proxy_info_,
196 was_alternate_protocol_available(), was_npn_negotiated(),
197 using_spdy(), net_log_.source());
198 stream_factory_->OnOrphanedJobComplete(this);
199 } else {
200 request_->OnSpdySessionReady(this, spdy_session, spdy_session_direct_);
201 }
183 // |this| may be deleted after this call. 202 // |this| may be deleted after this call.
184 } 203 }
185 204
186 void HttpStreamFactoryImpl::Job::OnStreamFailedCallback(int result) { 205 void HttpStreamFactoryImpl::Job::OnStreamFailedCallback(int result) {
187 request_->OnStreamFailed(result, ssl_config_); 206 DCHECK(!IsPreconnecting());
207 if (IsOrphaned())
208 stream_factory_->OnOrphanedJobComplete(this);
209 else
210 request_->OnStreamFailed(this, result, ssl_config_);
188 // |this| may be deleted after this call. 211 // |this| may be deleted after this call.
189 } 212 }
190 213
191 void HttpStreamFactoryImpl::Job::OnCertificateErrorCallback( 214 void HttpStreamFactoryImpl::Job::OnCertificateErrorCallback(
192 int result, const SSLInfo& ssl_info) { 215 int result, const SSLInfo& ssl_info) {
193 request_->OnCertificateError(result, ssl_config_, ssl_info); 216 DCHECK(!IsPreconnecting());
217 if (IsOrphaned())
218 stream_factory_->OnOrphanedJobComplete(this);
219 else
220 request_->OnCertificateError(this, result, ssl_config_, ssl_info);
194 // |this| may be deleted after this call. 221 // |this| may be deleted after this call.
195 } 222 }
196 223
197 void HttpStreamFactoryImpl::Job::OnNeedsProxyAuthCallback( 224 void HttpStreamFactoryImpl::Job::OnNeedsProxyAuthCallback(
198 const HttpResponseInfo& response, 225 const HttpResponseInfo& response,
199 HttpAuthController* auth_controller) { 226 HttpAuthController* auth_controller) {
200 request_->OnNeedsProxyAuth( 227 DCHECK(!IsPreconnecting());
201 response, ssl_config_, proxy_info_, auth_controller); 228 if (IsOrphaned())
229 stream_factory_->OnOrphanedJobComplete(this);
230 else
231 request_->OnNeedsProxyAuth(
232 this, response, ssl_config_, proxy_info_, auth_controller);
202 // |this| may be deleted after this call. 233 // |this| may be deleted after this call.
203 } 234 }
204 235
205 void HttpStreamFactoryImpl::Job::OnNeedsClientAuthCallback( 236 void HttpStreamFactoryImpl::Job::OnNeedsClientAuthCallback(
206 SSLCertRequestInfo* cert_info) { 237 SSLCertRequestInfo* cert_info) {
207 request_->OnNeedsClientAuth(ssl_config_, cert_info); 238 DCHECK(!IsPreconnecting());
239 if (IsOrphaned())
240 stream_factory_->OnOrphanedJobComplete(this);
241 else
242 request_->OnNeedsClientAuth(this, ssl_config_, cert_info);
208 // |this| may be deleted after this call. 243 // |this| may be deleted after this call.
209 } 244 }
210 245
211 void HttpStreamFactoryImpl::Job::OnHttpsProxyTunnelResponseCallback( 246 void HttpStreamFactoryImpl::Job::OnHttpsProxyTunnelResponseCallback(
212 const HttpResponseInfo& response_info, 247 const HttpResponseInfo& response_info,
213 HttpStream* stream) { 248 HttpStream* stream) {
214 request_->OnHttpsProxyTunnelResponse( 249 DCHECK(!IsPreconnecting());
215 response_info, ssl_config_, proxy_info_, stream); 250 if (IsOrphaned())
251 stream_factory_->OnOrphanedJobComplete(this);
252 else
253 request_->OnHttpsProxyTunnelResponse(
254 this, response_info, ssl_config_, proxy_info_, stream);
216 // |this| may be deleted after this call. 255 // |this| may be deleted after this call.
217 } 256 }
218 257
219 void HttpStreamFactoryImpl::Job::OnPreconnectsComplete() { 258 void HttpStreamFactoryImpl::Job::OnPreconnectsComplete() {
259 DCHECK(!request_);
260 if (new_spdy_session_) {
261 stream_factory_->OnSpdySessionReady(
262 new_spdy_session_, spdy_session_direct_, ssl_config_,
263 proxy_info_, was_alternate_protocol_available(),
264 was_npn_negotiated(), using_spdy(), net_log_.source());
265 }
220 stream_factory_->OnPreconnectsComplete(this); 266 stream_factory_->OnPreconnectsComplete(this);
221 // |this| may be deleted after this call. 267 // |this| may be deleted after this call.
222 } 268 }
223 269
224 void HttpStreamFactoryImpl::Job::OnIOComplete(int result) { 270 void HttpStreamFactoryImpl::Job::OnIOComplete(int result) {
225 RunLoop(result); 271 RunLoop(result);
226 } 272 }
227 273
228 int HttpStreamFactoryImpl::Job::RunLoop(int result) { 274 int HttpStreamFactoryImpl::Job::RunLoop(int result) {
229 result = DoLoop(result); 275 result = DoLoop(result);
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 HostPortProxyPair(endpoint_, proxy_info_.proxy_server()); 561 HostPortProxyPair(endpoint_, proxy_info_.proxy_server());
516 } 562 }
517 if (session_->spdy_session_pool()->HasSession(spdy_session_key)) { 563 if (session_->spdy_session_pool()->HasSession(spdy_session_key)) {
518 // If we're preconnecting, but we already have a SpdySession, we don't 564 // If we're preconnecting, but we already have a SpdySession, we don't
519 // actually need to preconnect any sockets, so we're done. 565 // actually need to preconnect any sockets, so we're done.
520 if (IsPreconnecting()) 566 if (IsPreconnecting())
521 return OK; 567 return OK;
522 using_spdy_ = true; 568 using_spdy_ = true;
523 next_state_ = STATE_CREATE_STREAM; 569 next_state_ = STATE_CREATE_STREAM;
524 return OK; 570 return OK;
525 } else if (!IsPreconnecting()) { 571 } else if (request_) {
526 // Update the spdy session key for the request that launched this job. 572 // Update the spdy session key for the request that launched this job.
527 request_->SetSpdySessionKey(spdy_session_key); 573 request_->SetSpdySessionKey(spdy_session_key);
528 } 574 }
529 } 575 }
530 576
531 // Build the string used to uniquely identify connections of this type. 577 // Build the string used to uniquely identify connections of this type.
532 // Determine the host and port to connect to. 578 // Determine the host and port to connect to.
533 std::string connection_group = endpoint_.ToString(); 579 std::string connection_group = endpoint_.ToString();
534 DCHECK(!connection_group.empty()); 580 DCHECK(!connection_group.empty());
535 581
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 NOTREACHED(); 1173 NOTREACHED();
1128 break; 1174 break;
1129 } 1175 }
1130 } 1176 }
1131 1177
1132 bool HttpStreamFactoryImpl::Job::IsPreconnecting() const { 1178 bool HttpStreamFactoryImpl::Job::IsPreconnecting() const {
1133 DCHECK_GE(num_streams_, 0); 1179 DCHECK_GE(num_streams_, 0);
1134 return num_streams_ > 0; 1180 return num_streams_ > 0;
1135 } 1181 }
1136 1182
1183 bool HttpStreamFactoryImpl::Job::IsOrphaned() const {
1184 return !IsPreconnecting() && !request_;
1185 }
1186
1137 } // namespace net 1187 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_stream_factory_impl_job.h ('k') | net/http/http_stream_factory_impl_request.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698