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

Side by Side Diff: content/browser/renderer_host/resource_loader.cc

Issue 11275088: Remove implicit scoped_refptr operator T* Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 8 years, 1 month 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 "content/browser/renderer_host/resource_loader.h" 5 #include "content/browser/renderer_host/resource_loader.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/time.h" 8 #include "base/time.h"
9 #include "content/browser/child_process_security_policy_impl.h" 9 #include "content/browser/child_process_security_policy_impl.h"
10 #include "content/browser/renderer_host/doomed_resource_handler.h" 10 #include "content/browser/renderer_host/doomed_resource_handler.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 delegate_(delegate), 59 delegate_(delegate),
60 last_upload_position_(0), 60 last_upload_position_(0),
61 waiting_for_upload_progress_ack_(false), 61 waiting_for_upload_progress_ack_(false),
62 is_transferring_(false), 62 is_transferring_(false),
63 weak_ptr_factory_(this) { 63 weak_ptr_factory_(this) {
64 request_->set_delegate(this); 64 request_->set_delegate(this);
65 handler_->SetController(this); 65 handler_->SetController(this);
66 } 66 }
67 67
68 ResourceLoader::~ResourceLoader() { 68 ResourceLoader::~ResourceLoader() {
69 if (login_delegate_) 69 if (login_delegate_.get())
70 login_delegate_->OnRequestCancelled(); 70 login_delegate_->OnRequestCancelled();
71 if (ssl_client_auth_handler_) 71 if (ssl_client_auth_handler_.get())
72 ssl_client_auth_handler_->OnRequestCancelled(); 72 ssl_client_auth_handler_->OnRequestCancelled();
73 73
74 // Run ResourceHandler destructor before we tear-down the rest of our state 74 // Run ResourceHandler destructor before we tear-down the rest of our state
75 // as the ResourceHandler may want to inspect the URLRequest and other state. 75 // as the ResourceHandler may want to inspect the URLRequest and other state.
76 handler_.reset(); 76 handler_.reset();
77 } 77 }
78 78
79 void ResourceLoader::StartRequest() { 79 void ResourceLoader::StartRequest() {
80 if (delegate_->HandleExternalProtocol(this, request_->url())) { 80 if (delegate_->HandleExternalProtocol(this, request_->url())) {
81 CancelAndIgnore(); 81 CancelAndIgnore();
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 213
214 delegate_->DidReceiveRedirect(this, new_url); 214 delegate_->DidReceiveRedirect(this, new_url);
215 215
216 if (delegate_->HandleExternalProtocol(this, new_url)) { 216 if (delegate_->HandleExternalProtocol(this, new_url)) {
217 // The request is complete so we can remove it. 217 // The request is complete so we can remove it.
218 CancelAndIgnore(); 218 CancelAndIgnore();
219 return; 219 return;
220 } 220 }
221 221
222 scoped_refptr<ResourceResponse> response(new ResourceResponse()); 222 scoped_refptr<ResourceResponse> response(new ResourceResponse());
223 PopulateResourceResponse(request_.get(), response); 223 PopulateResourceResponse(request_.get(), response.get());
224 224
225 if (!handler_->OnRequestRedirected(info->GetRequestID(), new_url, response, 225 if (
226 defer)) { 226 !handler_->
227 OnRequestRedirected(info->GetRequestID(), new_url, response.get(),
228 defer)) {
227 Cancel(); 229 Cancel();
228 } else if (*defer) { 230 } else if (*defer) {
229 deferred_stage_ = DEFERRED_REDIRECT; // Follow redirect when resumed. 231 deferred_stage_ = DEFERRED_REDIRECT; // Follow redirect when resumed.
230 } 232 }
231 } 233 }
232 234
233 void ResourceLoader::OnAuthRequired(net::URLRequest* unused, 235 void ResourceLoader::OnAuthRequired(net::URLRequest* unused,
234 net::AuthChallengeInfo* auth_info) { 236 net::AuthChallengeInfo* auth_info) {
235 DCHECK_EQ(request_.get(), unused); 237 DCHECK_EQ(request_.get(), unused);
236 238
237 if (request_->load_flags() & net::LOAD_DO_NOT_PROMPT_FOR_LOGIN) { 239 if (request_->load_flags() & net::LOAD_DO_NOT_PROMPT_FOR_LOGIN) {
238 request_->CancelAuth(); 240 request_->CancelAuth();
239 return; 241 return;
240 } 242 }
241 243
242 if (!delegate_->AcceptAuthRequest(this, auth_info)) { 244 if (!delegate_->AcceptAuthRequest(this, auth_info)) {
243 request_->CancelAuth(); 245 request_->CancelAuth();
244 return; 246 return;
245 } 247 }
246 248
247 // Create a login dialog on the UI thread to get authentication data, or pull 249 // Create a login dialog on the UI thread to get authentication data, or pull
248 // from cache and continue on the IO thread. 250 // from cache and continue on the IO thread.
249 251
250 DCHECK(!login_delegate_) << 252 DCHECK(!login_delegate_.get()) <<
251 "OnAuthRequired called with login_delegate pending"; 253 "OnAuthRequired called with login_delegate pending";
252 login_delegate_ = delegate_->CreateLoginDelegate(this, auth_info); 254 login_delegate_ = delegate_->CreateLoginDelegate(this, auth_info);
253 if (!login_delegate_) 255 if (!login_delegate_.get())
254 request_->CancelAuth(); 256 request_->CancelAuth();
255 } 257 }
256 258
257 void ResourceLoader::OnCertificateRequested( 259 void ResourceLoader::OnCertificateRequested(
258 net::URLRequest* unused, 260 net::URLRequest* unused,
259 net::SSLCertRequestInfo* cert_info) { 261 net::SSLCertRequestInfo* cert_info) {
260 DCHECK_EQ(request_.get(), unused); 262 DCHECK_EQ(request_.get(), unused);
261 263
262 if (!delegate_->AcceptSSLClientCertificateRequest(this, cert_info)) { 264 if (!delegate_->AcceptSSLClientCertificateRequest(this, cert_info)) {
263 request_->Cancel(); 265 request_->Cancel();
264 return; 266 return;
265 } 267 }
266 268
267 if (cert_info->client_certs.empty()) { 269 if (cert_info->client_certs.empty()) {
268 // No need to query the user if there are no certs to choose from. 270 // No need to query the user if there are no certs to choose from.
269 request_->ContinueWithCertificate(NULL); 271 request_->ContinueWithCertificate(NULL);
270 return; 272 return;
271 } 273 }
272 274
273 DCHECK(!ssl_client_auth_handler_) << 275 DCHECK(!ssl_client_auth_handler_.get()) <<
274 "OnCertificateRequested called with ssl_client_auth_handler pending"; 276 "OnCertificateRequested called with ssl_client_auth_handler pending";
275 ssl_client_auth_handler_ = new SSLClientAuthHandler(request_.get(), 277 ssl_client_auth_handler_ = new SSLClientAuthHandler(request_.get(),
276 cert_info); 278 cert_info);
277 ssl_client_auth_handler_->SelectCertificate(); 279 ssl_client_auth_handler_->SelectCertificate();
278 } 280 }
279 281
280 void ResourceLoader::OnSSLCertificateError(net::URLRequest* request, 282 void ResourceLoader::OnSSLCertificateError(net::URLRequest* request,
281 const net::SSLInfo& ssl_info, 283 const net::SSLInfo& ssl_info,
282 bool fatal) { 284 bool fatal) {
283 ResourceRequestInfoImpl* info = GetRequestInfo(); 285 ResourceRequestInfoImpl* info = GetRequestInfo();
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 // WebKit will send us a cancel for downloads since it no longer handles 427 // WebKit will send us a cancel for downloads since it no longer handles
426 // them. In this case, ignore the cancel since we handle downloads in the 428 // them. In this case, ignore the cancel since we handle downloads in the
427 // browser. 429 // browser.
428 if (from_renderer && info->is_download()) 430 if (from_renderer && info->is_download())
429 return; 431 return;
430 432
431 // TODO(darin): Perhaps we should really be looking to see if the status is 433 // TODO(darin): Perhaps we should really be looking to see if the status is
432 // IO_PENDING? 434 // IO_PENDING?
433 bool was_pending = request_->is_pending(); 435 bool was_pending = request_->is_pending();
434 436
435 if (login_delegate_) { 437 if (login_delegate_.get()) {
436 login_delegate_->OnRequestCancelled(); 438 login_delegate_->OnRequestCancelled();
437 login_delegate_ = NULL; 439 login_delegate_ = NULL;
438 } 440 }
439 if (ssl_client_auth_handler_) { 441 if (ssl_client_auth_handler_.get()) {
440 ssl_client_auth_handler_->OnRequestCancelled(); 442 ssl_client_auth_handler_->OnRequestCancelled();
441 ssl_client_auth_handler_ = NULL; 443 ssl_client_auth_handler_ = NULL;
442 } 444 }
443 445
444 request_->CancelWithError(error); 446 request_->CancelWithError(error);
445 447
446 if (!was_pending) { 448 if (!was_pending) {
447 // If the request isn't in flight, then we won't get an asynchronous 449 // If the request isn't in flight, then we won't get an asynchronous
448 // notification from the request, so we have to signal ourselves to finish 450 // notification from the request, so we have to signal ourselves to finish
449 // this request. 451 // this request.
450 MessageLoop::current()->PostTask( 452 MessageLoop::current()->PostTask(
451 FROM_HERE, base::Bind(&ResourceLoader::ResponseCompleted, 453 FROM_HERE, base::Bind(&ResourceLoader::ResponseCompleted,
452 weak_ptr_factory_.GetWeakPtr())); 454 weak_ptr_factory_.GetWeakPtr()));
453 } 455 }
454 } 456 }
455 457
456 void ResourceLoader::CompleteResponseStarted() { 458 void ResourceLoader::CompleteResponseStarted() {
457 ResourceRequestInfoImpl* info = GetRequestInfo(); 459 ResourceRequestInfoImpl* info = GetRequestInfo();
458 460
459 scoped_refptr<ResourceResponse> response(new ResourceResponse()); 461 scoped_refptr<ResourceResponse> response(new ResourceResponse());
460 PopulateResourceResponse(request_.get(), response); 462 PopulateResourceResponse(request_.get(), response.get());
461 463
462 if (request_->ssl_info().cert) { 464 if (request_->ssl_info().cert.get()) {
463 int cert_id = 465 int cert_id =
464 CertStore::GetInstance()->StoreCert(request_->ssl_info().cert, 466 CertStore::GetInstance()->StoreCert(request_->ssl_info().cert.get(),
465 info->GetChildID()); 467 info->GetChildID());
466 response->head.security_info = SerializeSecurityInfo( 468 response->head.security_info = SerializeSecurityInfo(
467 cert_id, 469 cert_id,
468 request_->ssl_info().cert_status, 470 request_->ssl_info().cert_status,
469 request_->ssl_info().security_bits, 471 request_->ssl_info().security_bits,
470 request_->ssl_info().connection_status); 472 request_->ssl_info().connection_status);
471 } else { 473 } else {
472 // We should not have any SSL state. 474 // We should not have any SSL state.
473 DCHECK(!request_->ssl_info().cert_status && 475 DCHECK(!request_->ssl_info().cert_status &&
474 request_->ssl_info().security_bits == -1 && 476 request_->ssl_info().security_bits == -1 &&
475 !request_->ssl_info().connection_status); 477 !request_->ssl_info().connection_status);
476 } 478 }
477 479
478 delegate_->DidReceiveResponse(this); 480 delegate_->DidReceiveResponse(this);
479 481
480 bool defer = false; 482 bool defer = false;
481 if (!handler_->OnResponseStarted(info->GetRequestID(), response, &defer)) { 483 if (
484 !handler_->
485 OnResponseStarted(info->GetRequestID(), response.get(), &defer)) {
482 Cancel(); 486 Cancel();
483 } else if (defer) { 487 } else if (defer) {
484 deferred_stage_ = DEFERRED_READ; // Read first chunk when resumed. 488 deferred_stage_ = DEFERRED_READ; // Read first chunk when resumed.
485 } 489 }
486 } 490 }
487 491
488 void ResourceLoader::StartReading(bool is_continuation) { 492 void ResourceLoader::StartReading(bool is_continuation) {
489 int bytes_read = 0; 493 int bytes_read = 0;
490 ReadMore(&bytes_read); 494 ReadMore(&bytes_read);
491 495
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 deferred_stage_ = DEFERRED_READ; // Read next chunk when resumed. 553 deferred_stage_ = DEFERRED_READ; // Read next chunk when resumed.
550 } 554 }
551 } 555 }
552 556
553 void ResourceLoader::ResponseCompleted() { 557 void ResourceLoader::ResponseCompleted() {
554 VLOG(1) << "ResponseCompleted: " << request_->url().spec(); 558 VLOG(1) << "ResponseCompleted: " << request_->url().spec();
555 ResourceRequestInfoImpl* info = GetRequestInfo(); 559 ResourceRequestInfoImpl* info = GetRequestInfo();
556 560
557 std::string security_info; 561 std::string security_info;
558 const net::SSLInfo& ssl_info = request_->ssl_info(); 562 const net::SSLInfo& ssl_info = request_->ssl_info();
559 if (ssl_info.cert != NULL) { 563 if (ssl_info.cert.get() != NULL) {
560 int cert_id = CertStore::GetInstance()->StoreCert(ssl_info.cert, 564 int cert_id = CertStore::GetInstance()->StoreCert(ssl_info.cert.get(),
561 info->GetChildID()); 565 info->GetChildID());
562 security_info = SerializeSecurityInfo( 566 security_info = SerializeSecurityInfo(
563 cert_id, ssl_info.cert_status, ssl_info.security_bits, 567 cert_id, ssl_info.cert_status, ssl_info.security_bits,
564 ssl_info.connection_status); 568 ssl_info.connection_status);
565 } 569 }
566 570
567 if (handler_->OnResponseCompleted(info->GetRequestID(), request_->status(), 571 if (handler_->OnResponseCompleted(info->GetRequestID(), request_->status(),
568 security_info)) { 572 security_info)) {
569 // This will result in our destruction. 573 // This will result in our destruction.
570 CallDidFinishLoading(); 574 CallDidFinishLoading();
571 } else { 575 } else {
572 // The handler is not ready to die yet. We will call DidFinishLoading when 576 // The handler is not ready to die yet. We will call DidFinishLoading when
573 // we resume. 577 // we resume.
574 deferred_stage_ = DEFERRED_FINISH; 578 deferred_stage_ = DEFERRED_FINISH;
575 } 579 }
576 } 580 }
577 581
578 void ResourceLoader::CallDidFinishLoading() { 582 void ResourceLoader::CallDidFinishLoading() {
579 delegate_->DidFinishLoading(this); 583 delegate_->DidFinishLoading(this);
580 } 584 }
581 585
582 } // namespace content 586 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_view_host_impl.cc ('k') | content/browser/site_instance_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698