Chromium Code Reviews| 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" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 base::AutoLock lock(g_next_url_request_identifier_lock.Get()); | 67 base::AutoLock lock(g_next_url_request_identifier_lock.Get()); |
| 68 return g_next_url_request_identifier++; | 68 return g_next_url_request_identifier++; |
| 69 } | 69 } |
| 70 | 70 |
| 71 // True once the first URLRequest was started. | 71 // True once the first URLRequest was started. |
| 72 bool g_url_requests_started = false; | 72 bool g_url_requests_started = false; |
| 73 | 73 |
| 74 // True if cookies are accepted by default. | 74 // True if cookies are accepted by default. |
| 75 bool g_default_can_use_cookies = true; | 75 bool g_default_can_use_cookies = true; |
| 76 | 76 |
| 77 // When the URLRequest first assempts load timing information, it has the times | |
| 78 // at which each event occurred. The API requires the time which the request | |
| 79 // was blocked on each phase. This function handles the conversion. | |
| 80 // | |
| 81 // In the case of reusing a SPDY session or HTTP pipeline, old proxy results may | |
| 82 // have been reused, so proxy resolution times may be before the request was | |
| 83 // started. | |
| 84 // | |
| 85 // Due to preconnect and late binding, it is also possible for the connection | |
| 86 // attempt to start before a request has been started, or proxy resolution | |
| 87 // completed. | |
| 88 // | |
| 89 // This functions fixes both those cases. | |
| 90 void FixupLoadTimingInfo(net::LoadTimingInfo* load_timing_info) { | |
|
eroman
2013/04/06 01:02:02
The description is pretty clear on what this does,
mmenke
2013/04/08 15:31:24
Renamed to "ConvertRealLoadTimesToBlockingTimes".
| |
| 91 DCHECK(!load_timing_info->request_start.is_null()); | |
| 92 | |
| 93 // Earliest time possible for the request to be blocking on connect events. | |
| 94 base::TimeTicks block_on_connect = load_timing_info->request_start; | |
| 95 | |
| 96 if (!load_timing_info->proxy_resolve_start.is_null()) { | |
| 97 DCHECK(!load_timing_info->proxy_resolve_end.is_null()); | |
| 98 | |
| 99 // Make sure the proxy times are after request start. | |
| 100 if (load_timing_info->proxy_resolve_start < load_timing_info->request_start) | |
| 101 load_timing_info->proxy_resolve_start = load_timing_info->request_start; | |
| 102 if (load_timing_info->proxy_resolve_end < load_timing_info->request_start) | |
| 103 load_timing_info->proxy_resolve_end = load_timing_info->request_start; | |
| 104 | |
| 105 // Connect times must also be after the proxy times. | |
| 106 block_on_connect = load_timing_info->proxy_resolve_end; | |
| 107 } | |
| 108 | |
| 109 // Make sure connection times are after start and proxy times. | |
| 110 | |
| 111 net::LoadTimingInfo::ConnectTiming* connect_timing = | |
| 112 &load_timing_info->connect_timing; | |
| 113 if (!connect_timing->dns_start.is_null()) { | |
| 114 DCHECK(!connect_timing->dns_end.is_null()); | |
| 115 if (connect_timing->dns_start < block_on_connect) | |
| 116 connect_timing->dns_start = block_on_connect; | |
| 117 if (connect_timing->dns_end < block_on_connect) | |
| 118 connect_timing->dns_end = block_on_connect; | |
| 119 } | |
| 120 | |
| 121 if (!connect_timing->connect_start.is_null()) { | |
| 122 DCHECK(!connect_timing->connect_end.is_null()); | |
| 123 if (connect_timing->connect_start < block_on_connect) | |
| 124 connect_timing->connect_start = block_on_connect; | |
| 125 if (connect_timing->connect_end < block_on_connect) | |
| 126 connect_timing->connect_end = block_on_connect; | |
| 127 } | |
| 128 | |
| 129 if (!connect_timing->ssl_start.is_null()) { | |
| 130 DCHECK(!connect_timing->ssl_end.is_null()); | |
| 131 if (connect_timing->ssl_start < block_on_connect) | |
| 132 connect_timing->ssl_start = block_on_connect; | |
| 133 if (connect_timing->ssl_end < block_on_connect) | |
| 134 connect_timing->ssl_end = block_on_connect; | |
| 135 } | |
| 136 } | |
| 137 | |
| 77 } // namespace | 138 } // namespace |
| 78 | 139 |
| 79 URLRequest::ProtocolFactory* | 140 URLRequest::ProtocolFactory* |
| 80 URLRequest::Deprecated::RegisterProtocolFactory(const std::string& scheme, | 141 URLRequest::Deprecated::RegisterProtocolFactory(const std::string& scheme, |
| 81 ProtocolFactory* factory) { | 142 ProtocolFactory* factory) { |
| 82 return URLRequest::RegisterProtocolFactory(scheme, factory); | 143 return URLRequest::RegisterProtocolFactory(scheme, factory); |
| 83 } | 144 } |
| 84 | 145 |
| 85 void URLRequest::Deprecated::RegisterRequestInterceptor( | 146 void URLRequest::Deprecated::RegisterRequestInterceptor( |
| 86 Interceptor* interceptor) { | 147 Interceptor* interceptor) { |
| (...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 966 if (delegate_) | 1027 if (delegate_) |
| 967 delegate_->OnReadCompleted(this, bytes_read); | 1028 delegate_->OnReadCompleted(this, bytes_read); |
| 968 | 1029 |
| 969 // Nothing below this line as OnReadCompleted may delete |this|. | 1030 // Nothing below this line as OnReadCompleted may delete |this|. |
| 970 } | 1031 } |
| 971 | 1032 |
| 972 void URLRequest::OnHeadersComplete() { | 1033 void URLRequest::OnHeadersComplete() { |
| 973 // Cache load timing information now, as information will be lost once the | 1034 // Cache load timing information now, as information will be lost once the |
| 974 // socket is closed and the ClientSocketHandle is Reset, which will happen | 1035 // socket is closed and the ClientSocketHandle is Reset, which will happen |
| 975 // once the body is complete. The start times should already be populated. | 1036 // once the body is complete. The start times should already be populated. |
| 976 if (job_) | 1037 if (job_) { |
| 977 job_->GetLoadTimingInfo(&load_timing_info_); | 1038 job_->GetLoadTimingInfo(&load_timing_info_); |
| 1039 FixupLoadTimingInfo(&load_timing_info_); | |
|
eroman
2013/04/06 01:02:02
This seems fragile (different meanings at differen
mmenke
2013/04/06 01:35:24
I agree... Since we dig down all the way to the s
| |
| 1040 } | |
| 978 } | 1041 } |
| 979 | 1042 |
| 980 void URLRequest::NotifyRequestCompleted() { | 1043 void URLRequest::NotifyRequestCompleted() { |
| 981 // TODO(battre): Get rid of this check, according to willchan it should | 1044 // TODO(battre): Get rid of this check, according to willchan it should |
| 982 // not be needed. | 1045 // not be needed. |
| 983 if (has_notified_completion_) | 1046 if (has_notified_completion_) |
| 984 return; | 1047 return; |
| 985 | 1048 |
| 986 is_pending_ = false; | 1049 is_pending_ = false; |
| 987 is_redirecting_ = false; | 1050 is_redirecting_ = false; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1013 new base::debug::StackTrace(NULL, 0); | 1076 new base::debug::StackTrace(NULL, 0); |
| 1014 *stack_trace_copy = stack_trace; | 1077 *stack_trace_copy = stack_trace; |
| 1015 stack_trace_.reset(stack_trace_copy); | 1078 stack_trace_.reset(stack_trace_copy); |
| 1016 } | 1079 } |
| 1017 | 1080 |
| 1018 const base::debug::StackTrace* URLRequest::stack_trace() const { | 1081 const base::debug::StackTrace* URLRequest::stack_trace() const { |
| 1019 return stack_trace_.get(); | 1082 return stack_trace_.get(); |
| 1020 } | 1083 } |
| 1021 | 1084 |
| 1022 } // namespace net | 1085 } // namespace net |
| OLD | NEW |