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

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

Issue 2622193003: Clean up HttpStreamFactoryImpl::JobController when Impl::Jobs complete (Closed)
Patch Set: one more merge conflict Created 3 years, 11 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) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 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_controller.h" 5 #include "net/http/http_stream_factory_impl_job_controller.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 : alternative_job_->GetLoadState(); 137 : alternative_job_->GetLoadState();
138 } 138 }
139 139
140 void HttpStreamFactoryImpl::JobController::OnRequestComplete() { 140 void HttpStreamFactoryImpl::JobController::OnRequestComplete() {
141 CancelJobs(); 141 CancelJobs();
142 DCHECK(request_); 142 DCHECK(request_);
143 request_ = nullptr; 143 request_ = nullptr;
144 if (bound_job_) { 144 if (bound_job_) {
145 if (bound_job_->job_type() == MAIN) { 145 if (bound_job_->job_type() == MAIN) {
146 main_job_.reset(); 146 main_job_.reset();
147 // |alternative_job_| can be non-null if |main_job_| is resumed after
148 // |main_job_wait_time_| has elapsed. Allow |alternative_job_| to run to
149 // completion, rather than resetting it. OnOrphanedJobComplete() will
150 // clean up |this| when the job completes.
147 } else { 151 } else {
148 DCHECK(bound_job_->job_type() == ALTERNATIVE); 152 DCHECK(bound_job_->job_type() == ALTERNATIVE);
149 alternative_job_.reset(); 153 alternative_job_.reset();
154 // If ResumeMainJob() is not executed, reset |main_job_|. Otherwise,
155 // OnOrphanedJobComplete() will clean up |this| when the job completes.
156 // Use |main_job_is_blocked_| and |!main_job_wait_time_.is_zero()| instead
157 // of |main_job_|->is_waiting() because |main_job_| can be in proxy
158 // resolution step.
159 if (main_job_ && (main_job_is_blocked_ || !main_job_wait_time_.is_zero()))
160 main_job_.reset();
150 } 161 }
151 bound_job_ = nullptr; 162 bound_job_ = nullptr;
152 } 163 }
153 MaybeNotifyFactoryOfCompletion(); 164 MaybeNotifyFactoryOfCompletion();
154 } 165 }
155 166
156 int HttpStreamFactoryImpl::JobController::RestartTunnelWithProxyAuth( 167 int HttpStreamFactoryImpl::JobController::RestartTunnelWithProxyAuth(
157 const AuthCredentials& credentials) { 168 const AuthCredentials& credentials) {
158 DCHECK(bound_job_); 169 DCHECK(bound_job_);
159 return bound_job_->RestartTunnelWithProxyAuth(credentials); 170 return bound_job_->RestartTunnelWithProxyAuth(credentials);
160 } 171 }
161 172
162 void HttpStreamFactoryImpl::JobController::SetPriority( 173 void HttpStreamFactoryImpl::JobController::SetPriority(
163 RequestPriority priority) { 174 RequestPriority priority) {
164 if (main_job_) { 175 if (main_job_) {
165 main_job_->SetPriority(priority); 176 main_job_->SetPriority(priority);
166 } 177 }
167 if (alternative_job_) { 178 if (alternative_job_) {
168 alternative_job_->SetPriority(priority); 179 alternative_job_->SetPriority(priority);
169 } 180 }
170 } 181 }
171 182
172 void HttpStreamFactoryImpl::JobController::OnStreamReady( 183 void HttpStreamFactoryImpl::JobController::OnStreamReady(
173 Job* job, 184 Job* job,
174 const SSLConfig& used_ssl_config, 185 const SSLConfig& used_ssl_config,
175 const ProxyInfo& used_proxy_info) { 186 const ProxyInfo& used_proxy_info) {
176 DCHECK(job); 187 DCHECK(job);
177 188
178 if (job_bound_ && bound_job_ != job) { 189 if (IsJobOrphaned(job)) {
179 // We have bound a job to the associated Request, |job| has been orphaned. 190 // We have bound a job to the associated Request, |job| has been orphaned.
180 OnOrphanedJobComplete(job); 191 OnOrphanedJobComplete(job);
181 return; 192 return;
182 } 193 }
183 std::unique_ptr<HttpStream> stream = job->ReleaseStream(); 194 std::unique_ptr<HttpStream> stream = job->ReleaseStream();
184 DCHECK(stream); 195 DCHECK(stream);
185 196
186 MarkRequestComplete(job->was_alpn_negotiated(), job->negotiated_protocol(), 197 MarkRequestComplete(job->was_alpn_negotiated(), job->negotiated_protocol(),
187 job->using_spdy()); 198 job->using_spdy());
188 199
189 if (!request_) 200 if (!request_)
190 return; 201 return;
191 DCHECK(!factory_->for_websockets_); 202 DCHECK(!factory_->for_websockets_);
192 DCHECK_EQ(HttpStreamRequest::HTTP_STREAM, request_->stream_type()); 203 DCHECK_EQ(HttpStreamRequest::HTTP_STREAM, request_->stream_type());
193 OnJobSucceeded(job); 204 OnJobSucceeded(job);
194 request_->OnStreamReady(used_ssl_config, used_proxy_info, stream.release()); 205 request_->OnStreamReady(used_ssl_config, used_proxy_info, stream.release());
195 } 206 }
196 207
197 void HttpStreamFactoryImpl::JobController::OnBidirectionalStreamImplReady( 208 void HttpStreamFactoryImpl::JobController::OnBidirectionalStreamImplReady(
198 Job* job, 209 Job* job,
199 const SSLConfig& used_ssl_config, 210 const SSLConfig& used_ssl_config,
200 const ProxyInfo& used_proxy_info) { 211 const ProxyInfo& used_proxy_info) {
201 DCHECK(job); 212 DCHECK(job);
202 213
203 if (job_bound_ && bound_job_ != job) { 214 if (IsJobOrphaned(job)) {
204 // We have bound a job to the associated Request, |job| has been orphaned. 215 // We have bound a job to the associated Request, |job| has been orphaned.
205 OnOrphanedJobComplete(job); 216 OnOrphanedJobComplete(job);
206 return; 217 return;
207 } 218 }
208 219
209 MarkRequestComplete(job->was_alpn_negotiated(), job->negotiated_protocol(), 220 MarkRequestComplete(job->was_alpn_negotiated(), job->negotiated_protocol(),
210 job->using_spdy()); 221 job->using_spdy());
211 222
212 if (!request_) 223 if (!request_)
213 return; 224 return;
(...skipping 30 matching lines...) Expand all
244 255
245 void HttpStreamFactoryImpl::JobController::OnStreamFailed( 256 void HttpStreamFactoryImpl::JobController::OnStreamFailed(
246 Job* job, 257 Job* job,
247 int status, 258 int status,
248 const SSLConfig& used_ssl_config) { 259 const SSLConfig& used_ssl_config) {
249 if (job->job_type() == ALTERNATIVE) 260 if (job->job_type() == ALTERNATIVE)
250 OnAlternativeJobFailed(job); 261 OnAlternativeJobFailed(job);
251 262
252 MaybeResumeMainJob(job, base::TimeDelta()); 263 MaybeResumeMainJob(job, base::TimeDelta());
253 264
254 if (job_bound_ && bound_job_ != job) { 265 if (IsJobOrphaned(job)) {
255 // We have bound a job to the associated Request, |job| has been orphaned. 266 // We have bound a job to the associated Request, |job| has been orphaned.
256 OnOrphanedJobComplete(job); 267 OnOrphanedJobComplete(job);
257 return; 268 return;
258 } 269 }
259 270
260 if (!request_) 271 if (!request_)
261 return; 272 return;
262 DCHECK_NE(OK, status); 273 DCHECK_NE(OK, status);
263 DCHECK(job); 274 DCHECK(job);
264 275
(...skipping 17 matching lines...) Expand all
282 request_->OnStreamFailed(status, used_ssl_config); 293 request_->OnStreamFailed(status, used_ssl_config);
283 } 294 }
284 295
285 void HttpStreamFactoryImpl::JobController::OnCertificateError( 296 void HttpStreamFactoryImpl::JobController::OnCertificateError(
286 Job* job, 297 Job* job,
287 int status, 298 int status,
288 const SSLConfig& used_ssl_config, 299 const SSLConfig& used_ssl_config,
289 const SSLInfo& ssl_info) { 300 const SSLInfo& ssl_info) {
290 MaybeResumeMainJob(job, base::TimeDelta()); 301 MaybeResumeMainJob(job, base::TimeDelta());
291 302
292 if (job_bound_ && bound_job_ != job) { 303 if (IsJobOrphaned(job)) {
293 // We have bound a job to the associated Request, |job| has been orphaned. 304 // We have bound a job to the associated Request, |job| has been orphaned.
294 OnOrphanedJobComplete(job); 305 OnOrphanedJobComplete(job);
295 return; 306 return;
296 } 307 }
297 308
298 if (!request_) 309 if (!request_)
299 return; 310 return;
300 DCHECK_NE(OK, status); 311 DCHECK_NE(OK, status);
301 if (!bound_job_) 312 if (!bound_job_)
302 BindJob(job); 313 BindJob(job);
303 314
304 request_->OnCertificateError(status, used_ssl_config, ssl_info); 315 request_->OnCertificateError(status, used_ssl_config, ssl_info);
305 } 316 }
306 317
307 void HttpStreamFactoryImpl::JobController::OnHttpsProxyTunnelResponse( 318 void HttpStreamFactoryImpl::JobController::OnHttpsProxyTunnelResponse(
308 Job* job, 319 Job* job,
309 const HttpResponseInfo& response_info, 320 const HttpResponseInfo& response_info,
310 const SSLConfig& used_ssl_config, 321 const SSLConfig& used_ssl_config,
311 const ProxyInfo& used_proxy_info, 322 const ProxyInfo& used_proxy_info,
312 HttpStream* stream) { 323 HttpStream* stream) {
313 MaybeResumeMainJob(job, base::TimeDelta()); 324 MaybeResumeMainJob(job, base::TimeDelta());
314 325
315 if (job_bound_ && bound_job_ != job) { 326 if (IsJobOrphaned(job)) {
316 // We have bound a job to the associated Request, |job| has been orphaned. 327 // We have bound a job to the associated Request, |job| has been orphaned.
317 OnOrphanedJobComplete(job); 328 OnOrphanedJobComplete(job);
318 return; 329 return;
319 } 330 }
320 331
321 if (!bound_job_) 332 if (!bound_job_)
322 BindJob(job); 333 BindJob(job);
323 if (!request_) 334 if (!request_)
324 return; 335 return;
325 request_->OnHttpsProxyTunnelResponse(response_info, used_ssl_config, 336 request_->OnHttpsProxyTunnelResponse(response_info, used_ssl_config,
326 used_proxy_info, stream); 337 used_proxy_info, stream);
327 } 338 }
328 339
329 void HttpStreamFactoryImpl::JobController::OnNeedsClientAuth( 340 void HttpStreamFactoryImpl::JobController::OnNeedsClientAuth(
330 Job* job, 341 Job* job,
331 const SSLConfig& used_ssl_config, 342 const SSLConfig& used_ssl_config,
332 SSLCertRequestInfo* cert_info) { 343 SSLCertRequestInfo* cert_info) {
333 MaybeResumeMainJob(job, base::TimeDelta()); 344 MaybeResumeMainJob(job, base::TimeDelta());
334 345
335 if (job_bound_ && bound_job_ != job) { 346 if (IsJobOrphaned(job)) {
336 // We have bound a job to the associated Request, |job| has been orphaned. 347 // We have bound a job to the associated Request, |job| has been orphaned.
337 OnOrphanedJobComplete(job); 348 OnOrphanedJobComplete(job);
338 return; 349 return;
339 } 350 }
340 if (!request_) 351 if (!request_)
341 return; 352 return;
342 if (!bound_job_) 353 if (!bound_job_)
343 BindJob(job); 354 BindJob(job);
344 355
345 request_->OnNeedsClientAuth(used_ssl_config, cert_info); 356 request_->OnNeedsClientAuth(used_ssl_config, cert_info);
346 } 357 }
347 358
348 void HttpStreamFactoryImpl::JobController::OnNeedsProxyAuth( 359 void HttpStreamFactoryImpl::JobController::OnNeedsProxyAuth(
349 Job* job, 360 Job* job,
350 const HttpResponseInfo& proxy_response, 361 const HttpResponseInfo& proxy_response,
351 const SSLConfig& used_ssl_config, 362 const SSLConfig& used_ssl_config,
352 const ProxyInfo& used_proxy_info, 363 const ProxyInfo& used_proxy_info,
353 HttpAuthController* auth_controller) { 364 HttpAuthController* auth_controller) {
354 MaybeResumeMainJob(job, base::TimeDelta()); 365 MaybeResumeMainJob(job, base::TimeDelta());
355 366
356 if (job_bound_ && bound_job_ != job) { 367 if (IsJobOrphaned(job)) {
357 // We have bound a job to the associated Request, |job| has been orphaned. 368 // We have bound a job to the associated Request, |job| has been orphaned.
358 OnOrphanedJobComplete(job); 369 OnOrphanedJobComplete(job);
359 return; 370 return;
360 } 371 }
361 372
362 if (!request_) 373 if (!request_)
363 return; 374 return;
364 if (!bound_job_) 375 if (!bound_job_)
365 BindJob(job); 376 BindJob(job);
366 request_->OnNeedsProxyAuth(proxy_response, used_ssl_config, used_proxy_info, 377 request_->OnNeedsProxyAuth(proxy_response, used_ssl_config, used_proxy_info,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 ptr_factory_.GetWeakPtr())); 418 ptr_factory_.GetWeakPtr()));
408 } 419 }
409 420
410 void HttpStreamFactoryImpl::JobController::OnNewSpdySessionReady( 421 void HttpStreamFactoryImpl::JobController::OnNewSpdySessionReady(
411 Job* job, 422 Job* job,
412 const base::WeakPtr<SpdySession>& spdy_session, 423 const base::WeakPtr<SpdySession>& spdy_session,
413 bool direct) { 424 bool direct) {
414 DCHECK(job); 425 DCHECK(job);
415 DCHECK(job->using_spdy()); 426 DCHECK(job->using_spdy());
416 427
417 bool is_job_orphaned = job_bound_ && bound_job_ != job; 428 bool is_job_orphaned = IsJobOrphaned(job);
418 429
419 // Cache these values in case the job gets deleted. 430 // Cache these values in case the job gets deleted.
420 const SSLConfig used_ssl_config = job->server_ssl_config(); 431 const SSLConfig used_ssl_config = job->server_ssl_config();
421 const ProxyInfo used_proxy_info = job->proxy_info(); 432 const ProxyInfo used_proxy_info = job->proxy_info();
422 const bool was_alpn_negotiated = job->was_alpn_negotiated(); 433 const bool was_alpn_negotiated = job->was_alpn_negotiated();
423 const NextProto negotiated_protocol = job->negotiated_protocol(); 434 const NextProto negotiated_protocol = job->negotiated_protocol();
424 const bool using_spdy = job->using_spdy(); 435 const bool using_spdy = job->using_spdy();
425 const NetLogWithSource net_log = job->net_log(); 436 const NetLogWithSource net_log = job->net_log();
426 437
427 // Cache this so we can still use it if the JobController is deleted. 438 // Cache this so we can still use it if the JobController is deleted.
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 781
771 alternative_job_failed_ = true; 782 alternative_job_failed_ = true;
772 783
773 if (job->alternative_proxy_server().is_valid()) { 784 if (job->alternative_proxy_server().is_valid()) {
774 failed_alternative_proxy_server_ = job->alternative_proxy_server(); 785 failed_alternative_proxy_server_ = job->alternative_proxy_server();
775 } else { 786 } else {
776 DCHECK(!failed_alternative_proxy_server_.is_valid()); 787 DCHECK(!failed_alternative_proxy_server_.is_valid());
777 failed_alternative_service_ = job->alternative_service(); 788 failed_alternative_service_ = job->alternative_service();
778 } 789 }
779 790
780 if (!request_ || (job_bound_ && bound_job_ != job)) { 791 if (IsJobOrphaned(job)) {
781 // If |request_| is gone then it must have been successfully served by 792 // If |request_| is gone then it must have been successfully served by
782 // |main_job_|. 793 // |main_job_|.
783 // If |request_| is bound to a different job, then it is being 794 // If |request_| is bound to a different job, then it is being
784 // successfully serverd by the main job. 795 // successfully serverd by the main job.
785 ReportBrokenAlternativeService(); 796 ReportBrokenAlternativeService();
786 } 797 }
787 } 798 }
788 799
789 void HttpStreamFactoryImpl::JobController::ReportBrokenAlternativeService() { 800 void HttpStreamFactoryImpl::JobController::ReportBrokenAlternativeService() {
790 DCHECK(failed_alternative_service_.protocol != kProtoUnknown || 801 DCHECK(failed_alternative_service_.protocol != kProtoUnknown ||
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 proxy_server_used); 1081 proxy_server_used);
1071 } 1082 }
1072 1083
1073 void HttpStreamFactoryImpl::JobController::StartAlternativeProxyServerJob() { 1084 void HttpStreamFactoryImpl::JobController::StartAlternativeProxyServerJob() {
1074 if (!alternative_job_ || !request_) 1085 if (!alternative_job_ || !request_)
1075 return; 1086 return;
1076 DCHECK(alternative_job_->alternative_proxy_server().is_valid()); 1087 DCHECK(alternative_job_->alternative_proxy_server().is_valid());
1077 alternative_job_->Start(request_->stream_type()); 1088 alternative_job_->Start(request_->stream_type());
1078 } 1089 }
1079 1090
1091 bool HttpStreamFactoryImpl::JobController::IsJobOrphaned(Job* job) const {
1092 return !request_ || (job_bound_ && bound_job_ != job);
1093 }
1094
1080 } // namespace net 1095 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_stream_factory_impl_job_controller.h ('k') | net/http/http_stream_factory_impl_job_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698