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

Side by Side Diff: net/http/http_stream_factory_impl_job.cc

Issue 1586513002: QUIC - Whne alternate job decides to delay the main(TCP) job and if the (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and fix comments Created 4 years, 11 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
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/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
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
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::ResumeAfterDelay() {
247 DCHECK(!blocking_job_);
248 DCHECK_EQ(STATE_WAIT_FOR_JOB_COMPLETE, next_state_);
249
250 net_log_.AddEvent(NetLog::TYPE_HTTP_STREAM_JOB_DELAYED,
251 base::Bind(&NetLogHttpStreamJobDelayCallback, wait_time_));
252 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
253 FROM_HERE, base::Bind(&HttpStreamFactoryImpl::Job::OnIOComplete,
254 ptr_factory_.GetWeakPtr(), OK),
255 wait_time_);
256 }
257
237 void HttpStreamFactoryImpl::Job::Resume(Job* job, 258 void HttpStreamFactoryImpl::Job::Resume(Job* job,
238 const base::TimeDelta& delay) { 259 const base::TimeDelta& delay) {
239 DCHECK_EQ(blocking_job_, job); 260 DCHECK_EQ(blocking_job_, job);
240 blocking_job_ = NULL; 261 blocking_job_ = NULL;
241 262
263 // If |this| job is not past STATE_WAIT_FOR_JOB_COMPLETE state, then it will
264 // be delayed by the |wait_time_| when it resumes.
265 if (next_state_ == STATE_NONE || next_state_ <= STATE_WAIT_FOR_JOB_COMPLETE)
266 wait_time_ = delay;
267
242 // We know we're blocked if the next_state_ is STATE_WAIT_FOR_JOB_COMPLETE. 268 // We know we're blocked if the next_state_ is STATE_WAIT_FOR_JOB_COMPLETE.
243 // Unblock |this|. 269 // Unblock |this|.
244 if (next_state_ == STATE_WAIT_FOR_JOB_COMPLETE) { 270 if (next_state_ == STATE_WAIT_FOR_JOB_COMPLETE)
245 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 271 ResumeAfterDelay();
246 FROM_HERE, base::Bind(&HttpStreamFactoryImpl::Job::OnIOComplete,
247 ptr_factory_.GetWeakPtr(), OK),
248 delay);
249 }
250 } 272 }
251 273
252 void HttpStreamFactoryImpl::Job::Orphan(const Request* request) { 274 void HttpStreamFactoryImpl::Job::Orphan(const Request* request) {
253 DCHECK_EQ(request_, request); 275 DCHECK_EQ(request_, request);
254 request_ = NULL; 276 request_ = NULL;
255 net_log_.AddEvent(NetLog::TYPE_HTTP_STREAM_JOB_ORPHANED); 277 net_log_.AddEvent(NetLog::TYPE_HTTP_STREAM_JOB_ORPHANED);
256 if (blocking_job_) { 278 if (blocking_job_) {
257 // We've been orphaned, but there's a job we're blocked on. Don't bother 279 // We've been orphaned, but there's a job we're blocked on. Don't bother
258 // racing, just cancel ourself. 280 // racing, just cancel ourself.
259 DCHECK(blocking_job_->waiting_job_); 281 DCHECK(blocking_job_->waiting_job_);
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 } 842 }
821 843
822 if (result != OK) { 844 if (result != OK) {
823 if (waiting_job_) { 845 if (waiting_job_) {
824 waiting_job_->Resume(this, base::TimeDelta()); 846 waiting_job_->Resume(this, base::TimeDelta());
825 waiting_job_ = NULL; 847 waiting_job_ = NULL;
826 } 848 }
827 return result; 849 return result;
828 } 850 }
829 851
830 if (blocking_job_) 852 next_state_ = STATE_WAIT_FOR_JOB;
831 next_state_ = STATE_WAIT_FOR_JOB;
832 else
833 next_state_ = STATE_INIT_CONNECTION;
834 return OK; 853 return OK;
835 } 854 }
836 855
837 bool HttpStreamFactoryImpl::Job::ShouldForceQuic() const { 856 bool HttpStreamFactoryImpl::Job::ShouldForceQuic() const {
838 return session_->params().enable_quic && 857 return session_->params().enable_quic &&
839 session_->params().origin_to_force_quic_on.Equals(server_) && 858 session_->params().origin_to_force_quic_on.Equals(server_) &&
840 proxy_info_.is_direct() && origin_url_.SchemeIs("https"); 859 proxy_info_.is_direct() && origin_url_.SchemeIs("https");
841 } 860 }
842 861
843 int HttpStreamFactoryImpl::Job::DoWaitForJob() { 862 int HttpStreamFactoryImpl::Job::DoWaitForJob() {
844 DCHECK(blocking_job_); 863 if (!blocking_job_ && wait_time_.is_zero()) {
864 // There is no |blocking_job_| and there is no |wait_time_|.
865 next_state_ = STATE_INIT_CONNECTION;
866 return OK;
867 }
868
845 next_state_ = STATE_WAIT_FOR_JOB_COMPLETE; 869 next_state_ = STATE_WAIT_FOR_JOB_COMPLETE;
870 if (!wait_time_.is_zero()) {
871 // If there is a waiting_time, then resume the job after the wait_time_.
872 DCHECK(!blocking_job_);
873 ResumeAfterDelay();
874 }
875
846 return ERR_IO_PENDING; 876 return ERR_IO_PENDING;
847 } 877 }
848 878
849 int HttpStreamFactoryImpl::Job::DoWaitForJobComplete(int result) { 879 int HttpStreamFactoryImpl::Job::DoWaitForJobComplete(int result) {
850 DCHECK(!blocking_job_); 880 DCHECK(!blocking_job_);
851 DCHECK_EQ(OK, result); 881 DCHECK_EQ(OK, result);
882 wait_time_ = base::TimeDelta();
852 next_state_ = STATE_INIT_CONNECTION; 883 next_state_ = STATE_INIT_CONNECTION;
853 return OK; 884 return OK;
854 } 885 }
855 886
856 int HttpStreamFactoryImpl::Job::DoInitConnection() { 887 int HttpStreamFactoryImpl::Job::DoInitConnection() {
857 // TODO(pkasting): Remove ScopedTracker below once crbug.com/462812 is fixed. 888 // TODO(pkasting): Remove ScopedTracker below once crbug.com/462812 is fixed.
858 tracked_objects::ScopedTracker tracking_profile( 889 tracked_objects::ScopedTracker tracking_profile(
859 FROM_HERE_WITH_EXPLICIT_FUNCTION( 890 FROM_HERE_WITH_EXPLICIT_FUNCTION(
860 "462812 HttpStreamFactoryImpl::Job::DoInitConnection")); 891 "462812 HttpStreamFactoryImpl::Job::DoInitConnection"));
861 DCHECK(!blocking_job_); 892 DCHECK(!blocking_job_);
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after
1690 if (connection_->socket()) { 1721 if (connection_->socket()) {
1691 ConnectionAttempts socket_attempts; 1722 ConnectionAttempts socket_attempts;
1692 connection_->socket()->GetConnectionAttempts(&socket_attempts); 1723 connection_->socket()->GetConnectionAttempts(&socket_attempts);
1693 request_->AddConnectionAttempts(socket_attempts); 1724 request_->AddConnectionAttempts(socket_attempts);
1694 } else { 1725 } else {
1695 request_->AddConnectionAttempts(connection_->connection_attempts()); 1726 request_->AddConnectionAttempts(connection_->connection_attempts());
1696 } 1727 }
1697 } 1728 }
1698 1729
1699 } // namespace net 1730 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_stream_factory_impl_job.h ('k') | net/http/http_stream_factory_impl_request_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698