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

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

Issue 10532121: NetLogEventParameter to Callback refactoring 6. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Update includes Created 8 years, 6 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.h" 5 #include "net/url_request/url_request.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 DCHECK(!job_); 415 DCHECK(!job_);
416 DCHECK_NE(ERR_IO_PENDING, error); 416 DCHECK_NE(ERR_IO_PENDING, error);
417 417
418 // Check that there are no callbacks to already canceled requests. 418 // Check that there are no callbacks to already canceled requests.
419 DCHECK_NE(URLRequestStatus::CANCELED, status_.status()); 419 DCHECK_NE(URLRequestStatus::CANCELED, status_.status());
420 420
421 if (blocked_on_delegate_) 421 if (blocked_on_delegate_)
422 SetUnblockedOnDelegate(); 422 SetUnblockedOnDelegate();
423 423
424 if (error != OK) { 424 if (error != OK) {
425 std::string source("delegate");
425 net_log_.AddEvent(NetLog::TYPE_CANCELLED, 426 net_log_.AddEvent(NetLog::TYPE_CANCELLED,
426 make_scoped_refptr(new NetLogStringParameter("source", "delegate"))); 427 NetLog::StringCallback("source", &source));
eroman 2012/06/13 18:48:11 I wander if we want to introduce a: NetLog::CSt
mmenke 2012/06/13 19:32:09 I don't think we need it yet, though don't feel st
427 StartJob(new URLRequestErrorJob(this, error)); 428 StartJob(new URLRequestErrorJob(this, error));
428 } else if (!delegate_redirect_url_.is_empty()) { 429 } else if (!delegate_redirect_url_.is_empty()) {
429 GURL new_url; 430 GURL new_url;
430 new_url.Swap(&delegate_redirect_url_); 431 new_url.Swap(&delegate_redirect_url_);
431 432
432 URLRequestRedirectJob* job = new URLRequestRedirectJob(this, new_url); 433 URLRequestRedirectJob* job = new URLRequestRedirectJob(this, new_url);
433 // Use status code 307 to preserve the method, so POST requests work. 434 // Use status code 307 to preserve the method, so POST requests work.
434 job->set_redirect_code( 435 job->set_redirect_code(
435 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT); 436 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT);
436 StartJob(job); 437 StartJob(job);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 URLRequestJobManager::GetInstance()->MaybeInterceptRedirect(this, 560 URLRequestJobManager::GetInstance()->MaybeInterceptRedirect(this,
560 location); 561 location);
561 if (job) { 562 if (job) {
562 RestartWithJob(job); 563 RestartWithJob(job);
563 } else if (delegate_) { 564 } else if (delegate_) {
564 delegate_->OnReceivedRedirect(this, location, defer_redirect); 565 delegate_->OnReceivedRedirect(this, location, defer_redirect);
565 } 566 }
566 } 567 }
567 568
568 void URLRequest::NotifyResponseStarted() { 569 void URLRequest::NotifyResponseStarted() {
569 scoped_refptr<NetLog::EventParameters> params; 570 int net_error = OK;
570 if (!status_.is_success()) 571 if (!status_.is_success())
571 params = new NetLogIntegerParameter("net_error", status_.error()); 572 net_error = status_.error();
572 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_START_JOB, params); 573 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_URL_REQUEST_START_JOB,
574 net_error);
573 575
574 URLRequestJob* job = 576 URLRequestJob* job =
575 URLRequestJobManager::GetInstance()->MaybeInterceptResponse(this); 577 URLRequestJobManager::GetInstance()->MaybeInterceptResponse(this);
576 if (job) { 578 if (job) {
577 RestartWithJob(job); 579 RestartWithJob(job);
578 } else { 580 } else {
579 if (delegate_) { 581 if (delegate_) {
580 // In some cases (e.g. an event was canceled), we might have sent the 582 // In some cases (e.g. an event was canceled), we might have sent the
581 // completion event and receive a NotifyResponseStarted() later. 583 // completion event and receive a NotifyResponseStarted() later.
582 if (!has_notified_completion_ && status_.is_success()) { 584 if (!has_notified_completion_ && status_.is_success()) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 DCHECK(job_); 628 DCHECK(job_);
627 629
628 job_->ContinueDespiteLastError(); 630 job_->ContinueDespiteLastError();
629 } 631 }
630 632
631 void URLRequest::PrepareToRestart() { 633 void URLRequest::PrepareToRestart() {
632 DCHECK(job_); 634 DCHECK(job_);
633 635
634 // Close the current URL_REQUEST_START_JOB, since we will be starting a new 636 // Close the current URL_REQUEST_START_JOB, since we will be starting a new
635 // one. 637 // one.
636 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_START_JOB, NULL); 638 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_START_JOB);
637 639
638 OrphanJob(); 640 OrphanJob();
639 641
640 response_info_ = HttpResponseInfo(); 642 response_info_ = HttpResponseInfo();
641 response_info_.request_time = Time::Now(); 643 response_info_.request_time = Time::Now();
642 status_ = URLRequestStatus(); 644 status_ = URLRequestStatus();
643 is_pending_ = false; 645 is_pending_ = false;
644 } 646 }
645 647
646 void URLRequest::OrphanJob() { 648 void URLRequest::OrphanJob() {
647 // When calling this function, please check that URLRequestHttpJob is 649 // When calling this function, please check that URLRequestHttpJob is
648 // not in between calling NetworkDelegate::NotifyHeadersReceived receiving 650 // not in between calling NetworkDelegate::NotifyHeadersReceived receiving
649 // the call back. This is currently guaranteed by the following strategies: 651 // the call back. This is currently guaranteed by the following strategies:
650 // - OrphanJob is called on JobRestart, in this case the URLRequestJob cannot 652 // - OrphanJob is called on JobRestart, in this case the URLRequestJob cannot
651 // be receiving any headers at that time. 653 // be receiving any headers at that time.
652 // - OrphanJob is called in ~URLRequest, in this case 654 // - OrphanJob is called in ~URLRequest, in this case
653 // NetworkDelegate::NotifyURLRequestDestroyed notifies the NetworkDelegate 655 // NetworkDelegate::NotifyURLRequestDestroyed notifies the NetworkDelegate
654 // that the callback becomes invalid. 656 // that the callback becomes invalid.
655 job_->Kill(); 657 job_->Kill();
656 job_->DetachRequest(); // ensures that the job will not call us again 658 job_->DetachRequest(); // ensures that the job will not call us again
657 job_ = NULL; 659 job_ = NULL;
658 } 660 }
659 661
660 int URLRequest::Redirect(const GURL& location, int http_status_code) { 662 int URLRequest::Redirect(const GURL& location, int http_status_code) {
661 if (net_log_.IsLoggingAllEvents()) { 663 if (net_log_.IsLoggingAllEvents()) {
662 net_log_.AddEvent( 664 net_log_.AddEvent(
663 NetLog::TYPE_URL_REQUEST_REDIRECTED, 665 NetLog::TYPE_URL_REQUEST_REDIRECTED,
664 make_scoped_refptr(new NetLogStringParameter( 666 NetLog::StringCallback("location", &location.possibly_invalid_spec()));
665 "location", location.possibly_invalid_spec())));
666 } 667 }
667 668
668 if (context_ && context_->network_delegate()) 669 if (context_ && context_->network_delegate())
669 context_->network_delegate()->NotifyBeforeRedirect(this, location); 670 context_->network_delegate()->NotifyBeforeRedirect(this, location);
670 671
671 if (redirect_limit_ <= 0) { 672 if (redirect_limit_ <= 0) {
672 DVLOG(1) << "disallowing redirect: exceeds limit"; 673 DVLOG(1) << "disallowing redirect: exceeds limit";
673 return ERR_TOO_MANY_REDIRECTS; 674 return ERR_TOO_MANY_REDIRECTS;
674 } 675 }
675 676
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 // Log error only on failure, not cancellation, as even successful requests 751 // Log error only on failure, not cancellation, as even successful requests
751 // are "cancelled" on destruction. 752 // are "cancelled" on destruction.
752 if (status_.status() == URLRequestStatus::FAILED) 753 if (status_.status() == URLRequestStatus::FAILED)
753 net_error = status_.error(); 754 net_error = status_.error();
754 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_REQUEST_ALIVE, net_error); 755 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_REQUEST_ALIVE, net_error);
755 net_log_ = BoundNetLog(); 756 net_log_ = BoundNetLog();
756 757
757 if (context) { 758 if (context) {
758 net_log_ = BoundNetLog::Make(context->net_log(), 759 net_log_ = BoundNetLog::Make(context->net_log(),
759 NetLog::SOURCE_URL_REQUEST); 760 NetLog::SOURCE_URL_REQUEST);
760 net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE, NULL); 761 net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE);
761 } 762 }
762 } 763 }
763 } 764 }
764 765
765 int64 URLRequest::GetExpectedContentSize() const { 766 int64 URLRequest::GetExpectedContentSize() const {
766 int64 expected_content_size = -1; 767 int64 expected_content_size = -1;
767 if (job_) 768 if (job_)
768 expected_content_size = job_->expected_content_size(); 769 expected_content_size = job_->expected_content_size();
769 770
770 return expected_content_size; 771 return expected_content_size;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 return; 900 return;
900 901
901 is_pending_ = false; 902 is_pending_ = false;
902 has_notified_completion_ = true; 903 has_notified_completion_ = true;
903 if (context_ && context_->network_delegate()) 904 if (context_ && context_->network_delegate())
904 context_->network_delegate()->NotifyCompleted(this, job_ != NULL); 905 context_->network_delegate()->NotifyCompleted(this, job_ != NULL);
905 } 906 }
906 907
907 void URLRequest::SetBlockedOnDelegate() { 908 void URLRequest::SetBlockedOnDelegate() {
908 blocked_on_delegate_ = true; 909 blocked_on_delegate_ = true;
909 net_log_.BeginEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); 910 net_log_.BeginEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE);
910 } 911 }
911 912
912 void URLRequest::SetUnblockedOnDelegate() { 913 void URLRequest::SetUnblockedOnDelegate() {
913 if (!blocked_on_delegate_) 914 if (!blocked_on_delegate_)
914 return; 915 return;
915 blocked_on_delegate_ = false; 916 blocked_on_delegate_ = false;
916 load_state_param_.clear(); 917 load_state_param_.clear();
917 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); 918 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE);
918 } 919 }
919 920
920 void URLRequest::set_stack_trace(const base::debug::StackTrace& stack_trace) { 921 void URLRequest::set_stack_trace(const base::debug::StackTrace& stack_trace) {
921 base::debug::StackTrace* stack_trace_copy = 922 base::debug::StackTrace* stack_trace_copy =
922 new base::debug::StackTrace(NULL, 0); 923 new base::debug::StackTrace(NULL, 0);
923 *stack_trace_copy = stack_trace; 924 *stack_trace_copy = stack_trace;
924 stack_trace_.reset(stack_trace_copy); 925 stack_trace_.reset(stack_trace_copy);
925 } 926 }
926 927
927 const base::debug::StackTrace* URLRequest::stack_trace() const { 928 const base::debug::StackTrace* URLRequest::stack_trace() const {
928 return stack_trace_.get(); 929 return stack_trace_.get();
929 } 930 }
930 931
931 } // namespace net 932 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/url_request/url_request_http_job.cc » ('j') | net/url_request/url_request_http_job.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698