OLD | NEW |
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" |
11 #include "base/debug/stack_trace.h" | 11 #include "base/debug/stack_trace.h" |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/metrics/stats_counters.h" | 15 #include "base/metrics/stats_counters.h" |
| 16 #include "base/profiler/scoped_tracker.h" |
16 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
18 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
19 #include "base/values.h" | 20 #include "base/values.h" |
20 #include "net/base/auth.h" | 21 #include "net/base/auth.h" |
21 #include "net/base/chunked_upload_data_stream.h" | 22 #include "net/base/chunked_upload_data_stream.h" |
22 #include "net/base/host_port_pair.h" | 23 #include "net/base/host_port_pair.h" |
23 #include "net/base/load_flags.h" | 24 #include "net/base/load_flags.h" |
24 #include "net/base/load_timing_info.h" | 25 #include "net/base/load_timing_info.h" |
25 #include "net/base/net_errors.h" | 26 #include "net/base/net_errors.h" |
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 is_redirecting_ = true; | 826 is_redirecting_ = true; |
826 | 827 |
827 // TODO(davidben): Pass the full RedirectInfo down to MaybeInterceptRedirect? | 828 // TODO(davidben): Pass the full RedirectInfo down to MaybeInterceptRedirect? |
828 URLRequestJob* job = | 829 URLRequestJob* job = |
829 URLRequestJobManager::GetInstance()->MaybeInterceptRedirect( | 830 URLRequestJobManager::GetInstance()->MaybeInterceptRedirect( |
830 this, network_delegate_, redirect_info.new_url); | 831 this, network_delegate_, redirect_info.new_url); |
831 if (job) { | 832 if (job) { |
832 RestartWithJob(job); | 833 RestartWithJob(job); |
833 } else if (delegate_) { | 834 } else if (delegate_) { |
834 OnCallToDelegate(); | 835 OnCallToDelegate(); |
| 836 |
| 837 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed. |
| 838 tracked_objects::ScopedTracker tracking_profile( |
| 839 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 840 "423948 URLRequest::Delegate::OnReceivedRedirect")); |
835 delegate_->OnReceivedRedirect(this, redirect_info, defer_redirect); | 841 delegate_->OnReceivedRedirect(this, redirect_info, defer_redirect); |
836 // |this| may be have been destroyed here. | 842 // |this| may be have been destroyed here. |
837 } | 843 } |
838 } | 844 } |
839 | 845 |
840 void URLRequest::NotifyBeforeNetworkStart(bool* defer) { | 846 void URLRequest::NotifyBeforeNetworkStart(bool* defer) { |
841 if (delegate_ && !notified_before_network_start_) { | 847 if (delegate_ && !notified_before_network_start_) { |
842 OnCallToDelegate(); | 848 OnCallToDelegate(); |
843 delegate_->OnBeforeNetworkStart(this, defer); | 849 { |
| 850 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is |
| 851 // fixed. |
| 852 tracked_objects::ScopedTracker tracking_profile( |
| 853 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 854 "423948 URLRequest::Delegate::OnBeforeNetworkStart")); |
| 855 delegate_->OnBeforeNetworkStart(this, defer); |
| 856 } |
844 if (!*defer) | 857 if (!*defer) |
845 OnCallToDelegateComplete(); | 858 OnCallToDelegateComplete(); |
846 notified_before_network_start_ = true; | 859 notified_before_network_start_ = true; |
847 } | 860 } |
848 } | 861 } |
849 | 862 |
850 void URLRequest::ResumeNetworkStart() { | 863 void URLRequest::ResumeNetworkStart() { |
851 DCHECK(job_.get()); | 864 DCHECK(job_.get()); |
852 DCHECK(notified_before_network_start_); | 865 DCHECK(notified_before_network_start_); |
853 | 866 |
(...skipping 20 matching lines...) Expand all Loading... |
874 if (!has_notified_completion_ && status_.is_success()) { | 887 if (!has_notified_completion_ && status_.is_success()) { |
875 if (network_delegate_) | 888 if (network_delegate_) |
876 network_delegate_->NotifyResponseStarted(this); | 889 network_delegate_->NotifyResponseStarted(this); |
877 } | 890 } |
878 | 891 |
879 // Notify in case the entire URL Request has been finished. | 892 // Notify in case the entire URL Request has been finished. |
880 if (!has_notified_completion_ && !status_.is_success()) | 893 if (!has_notified_completion_ && !status_.is_success()) |
881 NotifyRequestCompleted(); | 894 NotifyRequestCompleted(); |
882 | 895 |
883 OnCallToDelegate(); | 896 OnCallToDelegate(); |
| 897 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is |
| 898 // fixed. |
| 899 tracked_objects::ScopedTracker tracking_profile( |
| 900 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 901 "423948 URLRequest::Delegate::OnResponseStarted")); |
884 delegate_->OnResponseStarted(this); | 902 delegate_->OnResponseStarted(this); |
885 // Nothing may appear below this line as OnResponseStarted may delete | 903 // Nothing may appear below this line as OnResponseStarted may delete |
886 // |this|. | 904 // |this|. |
887 } | 905 } |
888 } | 906 } |
889 } | 907 } |
890 | 908 |
891 void URLRequest::FollowDeferredRedirect() { | 909 void URLRequest::FollowDeferredRedirect() { |
892 CHECK(job_.get()); | 910 CHECK(job_.get()); |
893 CHECK(status_.is_success()); | 911 CHECK(status_.is_success()); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1090 // so it can be reset on another round. | 1108 // so it can be reset on another round. |
1091 AuthCredentials credentials = auth_credentials_; | 1109 AuthCredentials credentials = auth_credentials_; |
1092 auth_credentials_ = AuthCredentials(); | 1110 auth_credentials_ = AuthCredentials(); |
1093 scoped_refptr<AuthChallengeInfo> auth_info; | 1111 scoped_refptr<AuthChallengeInfo> auth_info; |
1094 auth_info.swap(auth_info_); | 1112 auth_info.swap(auth_info_); |
1095 | 1113 |
1096 switch (result) { | 1114 switch (result) { |
1097 case NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION: | 1115 case NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION: |
1098 // Defer to the URLRequest::Delegate, since the NetworkDelegate | 1116 // Defer to the URLRequest::Delegate, since the NetworkDelegate |
1099 // didn't take an action. | 1117 // didn't take an action. |
1100 if (delegate_) | 1118 if (delegate_) { |
| 1119 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is |
| 1120 // fixed. |
| 1121 tracked_objects::ScopedTracker tracking_profile( |
| 1122 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1123 "423948 URLRequest::Delegate::OnAuthRequired")); |
1101 delegate_->OnAuthRequired(this, auth_info.get()); | 1124 delegate_->OnAuthRequired(this, auth_info.get()); |
| 1125 } |
1102 break; | 1126 break; |
1103 | 1127 |
1104 case NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH: | 1128 case NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH: |
1105 SetAuth(credentials); | 1129 SetAuth(credentials); |
1106 break; | 1130 break; |
1107 | 1131 |
1108 case NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH: | 1132 case NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH: |
1109 CancelAuth(); | 1133 CancelAuth(); |
1110 break; | 1134 break; |
1111 | 1135 |
1112 case NetworkDelegate::AUTH_REQUIRED_RESPONSE_IO_PENDING: | 1136 case NetworkDelegate::AUTH_REQUIRED_RESPONSE_IO_PENDING: |
1113 NOTREACHED(); | 1137 NOTREACHED(); |
1114 break; | 1138 break; |
1115 } | 1139 } |
1116 } | 1140 } |
1117 | 1141 |
1118 void URLRequest::NotifyCertificateRequested( | 1142 void URLRequest::NotifyCertificateRequested( |
1119 SSLCertRequestInfo* cert_request_info) { | 1143 SSLCertRequestInfo* cert_request_info) { |
1120 if (delegate_) | 1144 if (delegate_) { |
| 1145 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed. |
| 1146 tracked_objects::ScopedTracker tracking_profile( |
| 1147 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1148 "423948 URLRequest::Delegate::OnCertificateRequested")); |
1121 delegate_->OnCertificateRequested(this, cert_request_info); | 1149 delegate_->OnCertificateRequested(this, cert_request_info); |
| 1150 } |
1122 } | 1151 } |
1123 | 1152 |
1124 void URLRequest::NotifySSLCertificateError(const SSLInfo& ssl_info, | 1153 void URLRequest::NotifySSLCertificateError(const SSLInfo& ssl_info, |
1125 bool fatal) { | 1154 bool fatal) { |
1126 if (delegate_) | 1155 if (delegate_) { |
| 1156 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed. |
| 1157 tracked_objects::ScopedTracker tracking_profile( |
| 1158 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1159 "423948 URLRequest::Delegate::OnSSLCertificateError")); |
1127 delegate_->OnSSLCertificateError(this, ssl_info, fatal); | 1160 delegate_->OnSSLCertificateError(this, ssl_info, fatal); |
| 1161 } |
1128 } | 1162 } |
1129 | 1163 |
1130 bool URLRequest::CanGetCookies(const CookieList& cookie_list) const { | 1164 bool URLRequest::CanGetCookies(const CookieList& cookie_list) const { |
1131 DCHECK(!(load_flags_ & LOAD_DO_NOT_SEND_COOKIES)); | 1165 DCHECK(!(load_flags_ & LOAD_DO_NOT_SEND_COOKIES)); |
1132 if (network_delegate_) { | 1166 if (network_delegate_) { |
1133 return network_delegate_->CanGetCookies(*this, cookie_list); | 1167 return network_delegate_->CanGetCookies(*this, cookie_list); |
1134 } | 1168 } |
1135 return g_default_can_use_cookies; | 1169 return g_default_can_use_cookies; |
1136 } | 1170 } |
1137 | 1171 |
(...skipping 20 matching lines...) Expand all Loading... |
1158 if (bytes_read <= 0) | 1192 if (bytes_read <= 0) |
1159 NotifyRequestCompleted(); | 1193 NotifyRequestCompleted(); |
1160 | 1194 |
1161 // Notify NetworkChangeNotifier that we just received network data. | 1195 // Notify NetworkChangeNotifier that we just received network data. |
1162 // This is to identify cases where the NetworkChangeNotifier thinks we | 1196 // This is to identify cases where the NetworkChangeNotifier thinks we |
1163 // are off-line but we are still receiving network data (crbug.com/124069), | 1197 // are off-line but we are still receiving network data (crbug.com/124069), |
1164 // and to get rough network connection measurements. | 1198 // and to get rough network connection measurements. |
1165 if (bytes_read > 0 && !was_cached()) | 1199 if (bytes_read > 0 && !was_cached()) |
1166 NetworkChangeNotifier::NotifyDataReceived(*this, bytes_read); | 1200 NetworkChangeNotifier::NotifyDataReceived(*this, bytes_read); |
1167 | 1201 |
1168 if (delegate_) | 1202 if (delegate_) { |
| 1203 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed. |
| 1204 tracked_objects::ScopedTracker tracking_profile( |
| 1205 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1206 "423948 URLRequest::Delegate::OnReadCompleted")); |
1169 delegate_->OnReadCompleted(this, bytes_read); | 1207 delegate_->OnReadCompleted(this, bytes_read); |
| 1208 } |
1170 | 1209 |
1171 // Nothing below this line as OnReadCompleted may delete |this|. | 1210 // Nothing below this line as OnReadCompleted may delete |this|. |
1172 } | 1211 } |
1173 | 1212 |
1174 void URLRequest::OnHeadersComplete() { | 1213 void URLRequest::OnHeadersComplete() { |
1175 // Cache load timing information now, as information will be lost once the | 1214 // Cache load timing information now, as information will be lost once the |
1176 // socket is closed and the ClientSocketHandle is Reset, which will happen | 1215 // socket is closed and the ClientSocketHandle is Reset, which will happen |
1177 // once the body is complete. The start times should already be populated. | 1216 // once the body is complete. The start times should already be populated. |
1178 if (job_.get()) { | 1217 if (job_.get()) { |
1179 // Keep a copy of the two times the URLRequest sets. | 1218 // Keep a copy of the two times the URLRequest sets. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1226 new base::debug::StackTrace(NULL, 0); | 1265 new base::debug::StackTrace(NULL, 0); |
1227 *stack_trace_copy = stack_trace; | 1266 *stack_trace_copy = stack_trace; |
1228 stack_trace_.reset(stack_trace_copy); | 1267 stack_trace_.reset(stack_trace_copy); |
1229 } | 1268 } |
1230 | 1269 |
1231 const base::debug::StackTrace* URLRequest::stack_trace() const { | 1270 const base::debug::StackTrace* URLRequest::stack_trace() const { |
1232 return stack_trace_.get(); | 1271 return stack_trace_.get(); |
1233 } | 1272 } |
1234 | 1273 |
1235 } // namespace net | 1274 } // namespace net |
OLD | NEW |