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

Side by Side Diff: net/url_request/url_request_http_job.cc

Issue 10299002: Stop refcounting URLRequestContext. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Initialize to NULL Created 8 years, 7 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
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/url_request/url_request_http_job.h" 5 #include "net/url_request/url_request_http_job.h"
6 6
7 #include "base/base_switches.h" 7 #include "base/base_switches.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 DoneWithRequest(FINISHED); 245 DoneWithRequest(FINISHED);
246 URLRequestJob::NotifyDone(status); 246 URLRequestJob::NotifyDone(status);
247 } 247 }
248 248
249 void URLRequestHttpJob::DestroyTransaction() { 249 void URLRequestHttpJob::DestroyTransaction() {
250 DCHECK(transaction_.get()); 250 DCHECK(transaction_.get());
251 251
252 DoneWithRequest(ABORTED); 252 DoneWithRequest(ABORTED);
253 transaction_.reset(); 253 transaction_.reset();
254 response_info_ = NULL; 254 response_info_ = NULL;
255 context_ = NULL;
256 } 255 }
257 256
258 void URLRequestHttpJob::StartTransaction() { 257 void URLRequestHttpJob::StartTransaction() {
259 if (request_->context() && request_->context()->network_delegate()) { 258 if (request_->context() && request_->context()->network_delegate()) {
260 int rv = request_->context()->network_delegate()->NotifyBeforeSendHeaders( 259 int rv = request_->context()->network_delegate()->NotifyBeforeSendHeaders(
261 request_, notify_before_headers_sent_callback_, 260 request_, notify_before_headers_sent_callback_,
262 &request_info_.extra_headers); 261 &request_info_.extra_headers);
263 // If an extension blocks the request, we rely on the callback to 262 // If an extension blocks the request, we rely on the callback to
264 // StartTransactionInternal(). 263 // StartTransactionInternal().
265 if (rv == ERR_IO_PENDING) { 264 if (rv == ERR_IO_PENDING) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 !manager->enforce_throttling() || 319 !manager->enforce_throttling() ||
321 request_->first_party_for_cookies().scheme() != "chrome-extension" || 320 request_->first_party_for_cookies().scheme() != "chrome-extension" ||
322 !throttling_entry_->ShouldRejectRequest(request_info_.load_flags)) { 321 !throttling_entry_->ShouldRejectRequest(request_info_.load_flags)) {
323 rv = transaction_->Start( 322 rv = transaction_->Start(
324 &request_info_, start_callback_, request_->net_log()); 323 &request_info_, start_callback_, request_->net_log());
325 start_time_ = base::TimeTicks::Now(); 324 start_time_ = base::TimeTicks::Now();
326 } else { 325 } else {
327 // Special error code for the exponential back-off module. 326 // Special error code for the exponential back-off module.
328 rv = ERR_TEMPORARILY_THROTTLED; 327 rv = ERR_TEMPORARILY_THROTTLED;
329 } 328 }
330 // Make sure the context is alive for the duration of the
331 // transaction.
332 context_ = request_->context();
333 } 329 }
334 } 330 }
335 331
336 if (rv == ERR_IO_PENDING) 332 if (rv == ERR_IO_PENDING)
337 return; 333 return;
338 334
339 // The transaction started synchronously, but we need to notify the 335 // The transaction started synchronously, but we need to notify the
340 // URLRequest delegate via the message loop. 336 // URLRequest delegate via the message loop.
341 MessageLoop::current()->PostTask( 337 MessageLoop::current()->PostTask(
342 FROM_HERE, 338 FROM_HERE,
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 return; 652 return;
657 653
658 // If the transaction was destroyed, then the job was cancelled, and 654 // If the transaction was destroyed, then the job was cancelled, and
659 // we can just ignore this notification. 655 // we can just ignore this notification.
660 if (!transaction_.get()) 656 if (!transaction_.get())
661 return; 657 return;
662 658
663 // Clear the IO_PENDING status 659 // Clear the IO_PENDING status
664 SetStatus(URLRequestStatus()); 660 SetStatus(URLRequestStatus());
665 661
662 const URLRequestContext* context = request_->context();
663
666 if (result == ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN && 664 if (result == ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN &&
667 transaction_->GetResponseInfo() != NULL) { 665 transaction_->GetResponseInfo() != NULL) {
668 FraudulentCertificateReporter* reporter = 666 FraudulentCertificateReporter* reporter =
669 context_->fraudulent_certificate_reporter(); 667 context->fraudulent_certificate_reporter();
670 if (reporter != NULL) { 668 if (reporter != NULL) {
671 const SSLInfo& ssl_info = transaction_->GetResponseInfo()->ssl_info; 669 const SSLInfo& ssl_info = transaction_->GetResponseInfo()->ssl_info;
672 bool sni_available = SSLConfigService::IsSNIAvailable( 670 bool sni_available = SSLConfigService::IsSNIAvailable(
673 context_->ssl_config_service()); 671 context->ssl_config_service());
674 const std::string& host = request_->url().host(); 672 const std::string& host = request_->url().host();
675 673
676 reporter->SendReport(host, ssl_info, sni_available); 674 reporter->SendReport(host, ssl_info, sni_available);
677 } 675 }
678 } 676 }
679 677
680 if (result == OK) { 678 if (result == OK) {
681 scoped_refptr<HttpResponseHeaders> headers = GetResponseHeaders(); 679 scoped_refptr<HttpResponseHeaders> headers = GetResponseHeaders();
682 if (request_->context() && request_->context()->network_delegate()) { 680 if (context && context->network_delegate()) {
683 // Note that |this| may not be deleted until 681 // Note that |this| may not be deleted until
684 // |on_headers_received_callback_| or 682 // |on_headers_received_callback_| or
685 // |NetworkDelegate::URLRequestDestroyed()| has been called. 683 // |NetworkDelegate::URLRequestDestroyed()| has been called.
686 int error = request_->context()->network_delegate()-> 684 int error = context->network_delegate()->
687 NotifyHeadersReceived(request_, on_headers_received_callback_, 685 NotifyHeadersReceived(request_, on_headers_received_callback_,
688 headers, &override_response_headers_); 686 headers, &override_response_headers_);
689 if (error != net::OK) { 687 if (error != net::OK) {
690 if (error == net::ERR_IO_PENDING) { 688 if (error == net::ERR_IO_PENDING) {
691 awaiting_callback_ = true; 689 awaiting_callback_ = true;
692 request_->net_log().BeginEvent( 690 request_->net_log().BeginEvent(
693 NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); 691 NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL);
694 } else { 692 } else {
695 request_->net_log().AddEvent(NetLog::TYPE_CANCELLED, 693 request_->net_log().AddEvent(NetLog::TYPE_CANCELLED,
696 make_scoped_refptr( 694 make_scoped_refptr(
697 new NetLogStringParameter("source", "delegate"))); 695 new NetLogStringParameter("source", "delegate")));
698 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, error)); 696 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, error));
699 } 697 }
700 return; 698 return;
701 } 699 }
702 } 700 }
703 701
704 SaveCookiesAndNotifyHeadersComplete(net::OK); 702 SaveCookiesAndNotifyHeadersComplete(net::OK);
705 } else if (IsCertificateError(result)) { 703 } else if (IsCertificateError(result)) {
706 // We encountered an SSL certificate error. Ask our delegate to decide 704 // We encountered an SSL certificate error. Ask our delegate to decide
707 // what we should do. 705 // what we should do.
708 706
709 TransportSecurityState::DomainState domain_state; 707 TransportSecurityState::DomainState domain_state;
708 const URLRequestContext* context = request_->context();
710 const bool fatal = 709 const bool fatal =
711 context_->transport_security_state() && 710 context->transport_security_state() &&
712 context_->transport_security_state()->GetDomainState( 711 context->transport_security_state()->GetDomainState(
713 request_info_.url.host(), 712 request_info_.url.host(),
714 SSLConfigService::IsSNIAvailable(context_->ssl_config_service()), 713 SSLConfigService::IsSNIAvailable(context->ssl_config_service()),
715 &domain_state); 714 &domain_state);
716 NotifySSLCertificateError(transaction_->GetResponseInfo()->ssl_info, fatal); 715 NotifySSLCertificateError(transaction_->GetResponseInfo()->ssl_info, fatal);
717 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { 716 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) {
718 NotifyCertificateRequested( 717 NotifyCertificateRequested(
719 transaction_->GetResponseInfo()->cert_request_info); 718 transaction_->GetResponseInfo()->cert_request_info);
720 } else { 719 } else {
721 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); 720 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result));
722 } 721 }
723 } 722 }
724 723
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after
1398 return override_response_headers_.get() ? 1397 return override_response_headers_.get() ?
1399 override_response_headers_ : 1398 override_response_headers_ :
1400 transaction_->GetResponseInfo()->headers; 1399 transaction_->GetResponseInfo()->headers;
1401 } 1400 }
1402 1401
1403 void URLRequestHttpJob::NotifyURLRequestDestroyed() { 1402 void URLRequestHttpJob::NotifyURLRequestDestroyed() {
1404 awaiting_callback_ = false; 1403 awaiting_callback_ = false;
1405 } 1404 }
1406 1405
1407 } // namespace net 1406 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_http_job.h ('k') | net/url_request/url_request_job_factory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698