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/http/http_stream_factory_impl_job.h" | 5 #include "net/http/http_stream_factory_impl_job.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 69 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
70 if (source.IsValid()) | 70 if (source.IsValid()) |
71 source.AddToEventParameters(dict.get()); | 71 source.AddToEventParameters(dict.get()); |
72 dict->SetString("original_url", original_url->GetOrigin().spec()); | 72 dict->SetString("original_url", original_url->GetOrigin().spec()); |
73 dict->SetString("url", url->GetOrigin().spec()); | 73 dict->SetString("url", url->GetOrigin().spec()); |
74 dict->SetString("alternative_service", alternative_service->ToString()); | 74 dict->SetString("alternative_service", alternative_service->ToString()); |
75 dict->SetString("priority", RequestPriorityToString(priority)); | 75 dict->SetString("priority", RequestPriorityToString(priority)); |
76 return std::move(dict); | 76 return std::move(dict); |
77 } | 77 } |
78 | 78 |
79 // Returns parameters associated with the delay of the HTTP stream job. | |
80 scoped_ptr<base::Value> NetLogHttpStreamJobDelayCallback( | |
81 base::TimeDelta delay, | |
82 NetLogCaptureMode /* capture_mode */) { | |
83 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | |
84 dict->SetInteger("resume_after_ms", static_cast<int>(delay.InMilliseconds())); | |
85 return std::move(dict); | |
86 } | |
87 | |
79 // Returns parameters associated with the Proto (with NPN negotiation) of a HTTP | 88 // Returns parameters associated with the Proto (with NPN negotiation) of a HTTP |
80 // stream. | 89 // stream. |
81 scoped_ptr<base::Value> NetLogHttpStreamProtoCallback( | 90 scoped_ptr<base::Value> NetLogHttpStreamProtoCallback( |
82 const SSLClientSocket::NextProtoStatus status, | 91 const SSLClientSocket::NextProtoStatus status, |
83 const std::string* proto, | 92 const std::string* proto, |
84 NetLogCaptureMode /* capture_mode */) { | 93 NetLogCaptureMode /* capture_mode */) { |
85 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 94 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
86 | 95 |
87 dict->SetString("next_proto_status", | 96 dict->SetString("next_proto_status", |
88 SSLClientSocket::NextProtoStatusToString(status)); | 97 SSLClientSocket::NextProtoStatusToString(status)); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 DCHECK(!blocking_job_); | 236 DCHECK(!blocking_job_); |
228 DCHECK(!job->waiting_job_); | 237 DCHECK(!job->waiting_job_); |
229 | 238 |
230 // Never share connection with other jobs for FTP requests. | 239 // Never share connection with other jobs for FTP requests. |
231 DCHECK(!request_info_.url.SchemeIs("ftp")); | 240 DCHECK(!request_info_.url.SchemeIs("ftp")); |
232 | 241 |
233 blocking_job_ = job; | 242 blocking_job_ = job; |
234 job->waiting_job_ = this; | 243 job->waiting_job_ = this; |
235 } | 244 } |
236 | 245 |
246 void HttpStreamFactoryImpl::Job::ResumeWaitingJobAfterDelay( | |
Ryan Hamilton
2016/01/19 23:23:27
Does this resume the current job, or a job which i
ramant (doing other things)
2016/01/20 04:37:52
You are right.
Done.
| |
247 const base::TimeDelta& delay) { | |
Ryan Hamilton
2016/01/19 23:23:27
Instead if passing in delay here, an alternative w
ramant (doing other things)
2016/01/20 04:37:52
Done.
| |
248 DCHECK(!blocking_job_); | |
249 DCHECK_EQ(STATE_WAIT_FOR_JOB_COMPLETE, next_state_); | |
250 | |
251 net_log_.AddEvent(NetLog::TYPE_HTTP_STREAM_JOB_DELAYED, | |
252 base::Bind(&NetLogHttpStreamJobDelayCallback, delay)); | |
253 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
254 FROM_HERE, base::Bind(&HttpStreamFactoryImpl::Job::OnIOComplete, | |
255 ptr_factory_.GetWeakPtr(), OK), | |
256 delay); | |
257 wait_time_ = base::TimeDelta(); | |
258 } | |
259 | |
237 void HttpStreamFactoryImpl::Job::Resume(Job* job, | 260 void HttpStreamFactoryImpl::Job::Resume(Job* job, |
238 const base::TimeDelta& delay) { | 261 const base::TimeDelta& delay) { |
239 DCHECK_EQ(blocking_job_, job); | 262 DCHECK_EQ(blocking_job_, job); |
240 blocking_job_ = NULL; | 263 blocking_job_ = NULL; |
241 | 264 |
265 // If the job hasn't started, delay that job by |wait_time_| when it starts. | |
Ryan Hamilton
2016/01/19 23:23:27
"that job" or "this job"?
ramant (doing other things)
2016/01/20 04:37:52
:-). It is |this| job. Updated the comment.
| |
266 if (next_state_ == STATE_NONE && !delay.is_zero()) { | |
267 wait_time_ = delay; | |
268 return; | |
269 } | |
270 | |
242 // We know we're blocked if the next_state_ is STATE_WAIT_FOR_JOB_COMPLETE. | 271 // We know we're blocked if the next_state_ is STATE_WAIT_FOR_JOB_COMPLETE. |
243 // Unblock |this|. | 272 // Unblock |this|. |
244 if (next_state_ == STATE_WAIT_FOR_JOB_COMPLETE) { | 273 if (next_state_ == STATE_WAIT_FOR_JOB_COMPLETE) |
245 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 274 ResumeWaitingJobAfterDelay(delay); |
Ryan Hamilton
2016/01/19 23:23:27
Is the only case we need to schedule a future wait
ramant (doing other things)
2016/01/20 04:37:52
+1 to the above and thanks for the very good point
| |
246 FROM_HERE, base::Bind(&HttpStreamFactoryImpl::Job::OnIOComplete, | |
247 ptr_factory_.GetWeakPtr(), OK), | |
248 delay); | |
249 } | |
250 } | 275 } |
251 | 276 |
252 void HttpStreamFactoryImpl::Job::Orphan(const Request* request) { | 277 void HttpStreamFactoryImpl::Job::Orphan(const Request* request) { |
253 DCHECK_EQ(request_, request); | 278 DCHECK_EQ(request_, request); |
254 request_ = NULL; | 279 request_ = NULL; |
255 net_log_.AddEvent(NetLog::TYPE_HTTP_STREAM_JOB_ORPHANED); | 280 net_log_.AddEvent(NetLog::TYPE_HTTP_STREAM_JOB_ORPHANED); |
256 if (blocking_job_) { | 281 if (blocking_job_) { |
257 // We've been orphaned, but there's a job we're blocked on. Don't bother | 282 // We've been orphaned, but there's a job we're blocked on. Don't bother |
258 // racing, just cancel ourself. | 283 // racing, just cancel ourself. |
259 DCHECK(blocking_job_->waiting_job_); | 284 DCHECK(blocking_job_->waiting_job_); |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
820 } | 845 } |
821 | 846 |
822 if (result != OK) { | 847 if (result != OK) { |
823 if (waiting_job_) { | 848 if (waiting_job_) { |
824 waiting_job_->Resume(this, base::TimeDelta()); | 849 waiting_job_->Resume(this, base::TimeDelta()); |
825 waiting_job_ = NULL; | 850 waiting_job_ = NULL; |
826 } | 851 } |
827 return result; | 852 return result; |
828 } | 853 } |
829 | 854 |
830 if (blocking_job_) | 855 if (blocking_job_ || !wait_time_.is_zero()) |
Ryan Hamilton
2016/01/19 23:23:27
Alternatively, we could always move to the WAIT_FO
ramant (doing other things)
2016/01/20 04:37:52
Done.
| |
831 next_state_ = STATE_WAIT_FOR_JOB; | 856 next_state_ = STATE_WAIT_FOR_JOB; |
832 else | 857 else |
833 next_state_ = STATE_INIT_CONNECTION; | 858 next_state_ = STATE_INIT_CONNECTION; |
834 return OK; | 859 return OK; |
835 } | 860 } |
836 | 861 |
837 bool HttpStreamFactoryImpl::Job::ShouldForceQuic() const { | 862 bool HttpStreamFactoryImpl::Job::ShouldForceQuic() const { |
838 return session_->params().enable_quic && | 863 return session_->params().enable_quic && |
839 session_->params().origin_to_force_quic_on.Equals(server_) && | 864 session_->params().origin_to_force_quic_on.Equals(server_) && |
840 proxy_info_.is_direct() && origin_url_.SchemeIs("https"); | 865 proxy_info_.is_direct() && origin_url_.SchemeIs("https"); |
841 } | 866 } |
842 | 867 |
843 int HttpStreamFactoryImpl::Job::DoWaitForJob() { | 868 int HttpStreamFactoryImpl::Job::DoWaitForJob() { |
844 DCHECK(blocking_job_); | |
845 next_state_ = STATE_WAIT_FOR_JOB_COMPLETE; | 869 next_state_ = STATE_WAIT_FOR_JOB_COMPLETE; |
870 if (wait_time_.is_zero()) { | |
871 DCHECK(blocking_job_); | |
872 } else { | |
873 // If there is a waiting_time, then resume the job after the wait_time_. | |
874 DCHECK(!blocking_job_); | |
875 ResumeWaitingJobAfterDelay(wait_time_); | |
876 } | |
877 | |
846 return ERR_IO_PENDING; | 878 return ERR_IO_PENDING; |
847 } | 879 } |
848 | 880 |
849 int HttpStreamFactoryImpl::Job::DoWaitForJobComplete(int result) { | 881 int HttpStreamFactoryImpl::Job::DoWaitForJobComplete(int result) { |
850 DCHECK(!blocking_job_); | 882 DCHECK(!blocking_job_); |
851 DCHECK_EQ(OK, result); | 883 DCHECK_EQ(OK, result); |
852 next_state_ = STATE_INIT_CONNECTION; | 884 next_state_ = STATE_INIT_CONNECTION; |
853 return OK; | 885 return OK; |
854 } | 886 } |
855 | 887 |
(...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1690 if (connection_->socket()) { | 1722 if (connection_->socket()) { |
1691 ConnectionAttempts socket_attempts; | 1723 ConnectionAttempts socket_attempts; |
1692 connection_->socket()->GetConnectionAttempts(&socket_attempts); | 1724 connection_->socket()->GetConnectionAttempts(&socket_attempts); |
1693 request_->AddConnectionAttempts(socket_attempts); | 1725 request_->AddConnectionAttempts(socket_attempts); |
1694 } else { | 1726 } else { |
1695 request_->AddConnectionAttempts(connection_->connection_attempts()); | 1727 request_->AddConnectionAttempts(connection_->connection_attempts()); |
1696 } | 1728 } |
1697 } | 1729 } |
1698 | 1730 |
1699 } // namespace net | 1731 } // namespace net |
OLD | NEW |