| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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_controller.h" | 5 #include "net/http/http_stream_factory_impl_job_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "net/base/host_mapping_rules.h" | 16 #include "net/base/host_mapping_rules.h" |
| 17 #include "net/base/proxy_delegate.h" | 17 #include "net/base/proxy_delegate.h" |
| 18 #include "net/http/bidirectional_stream_impl.h" | 18 #include "net/http/bidirectional_stream_impl.h" |
| 19 #include "net/http/transport_security_state.h" | 19 #include "net/http/transport_security_state.h" |
| 20 #include "net/log/net_log_capture_mode.h" | 20 #include "net/log/net_log_capture_mode.h" |
| 21 #include "net/log/net_log_event_type.h" | 21 #include "net/log/net_log_event_type.h" |
| 22 #include "net/log/net_log_source.h" | 22 #include "net/log/net_log_source.h" |
| 23 #include "net/log/net_log_with_source.h" | 23 #include "net/log/net_log_with_source.h" |
| 24 #include "net/proxy/proxy_server.h" | 24 #include "net/proxy/proxy_server.h" |
| 25 #include "net/spdy/spdy_session.h" | 25 #include "net/spdy/spdy_session.h" |
| 26 #include "url/url_constants.h" | 26 #include "url/url_constants.h" |
| 27 | 27 |
| 28 namespace net { | 28 namespace net { |
| 29 | 29 |
| 30 // The maximum time to wait for the alternate job to complete before resuming |
| 31 // the main job. |
| 32 const int kMaxDelayTimeForMainJobSecs = 3; |
| 33 |
| 30 // Returns parameters associated with the delay of the HTTP stream job. | 34 // Returns parameters associated with the delay of the HTTP stream job. |
| 31 std::unique_ptr<base::Value> NetLogHttpStreamJobDelayCallback( | 35 std::unique_ptr<base::Value> NetLogHttpStreamJobDelayCallback( |
| 32 base::TimeDelta delay, | 36 base::TimeDelta delay, |
| 33 NetLogCaptureMode /* capture_mode */) { | 37 NetLogCaptureMode /* capture_mode */) { |
| 34 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 38 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 35 dict->SetInteger("resume_after_ms", static_cast<int>(delay.InMilliseconds())); | 39 dict->SetInteger("resume_after_ms", static_cast<int>(delay.InMilliseconds())); |
| 36 return std::move(dict); | 40 return std::move(dict); |
| 37 } | 41 } |
| 38 | 42 |
| 39 HttpStreamFactoryImpl::JobController::JobController( | 43 HttpStreamFactoryImpl::JobController::JobController( |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 const NetLogWithSource* HttpStreamFactoryImpl::JobController::GetNetLog( | 635 const NetLogWithSource* HttpStreamFactoryImpl::JobController::GetNetLog( |
| 632 Job* job) const { | 636 Job* job) const { |
| 633 if (is_preconnect_ || (job_bound_ && bound_job_ != job)) | 637 if (is_preconnect_ || (job_bound_ && bound_job_ != job)) |
| 634 return nullptr; | 638 return nullptr; |
| 635 DCHECK(request_); | 639 DCHECK(request_); |
| 636 return &request_->net_log(); | 640 return &request_->net_log(); |
| 637 } | 641 } |
| 638 | 642 |
| 639 void HttpStreamFactoryImpl::JobController::MaybeSetWaitTimeForMainJob( | 643 void HttpStreamFactoryImpl::JobController::MaybeSetWaitTimeForMainJob( |
| 640 const base::TimeDelta& delay) { | 644 const base::TimeDelta& delay) { |
| 641 if (main_job_is_blocked_) | 645 if (main_job_is_blocked_) { |
| 642 main_job_wait_time_ = delay; | 646 main_job_wait_time_ = std::min( |
| 647 delay, base::TimeDelta::FromSeconds(kMaxDelayTimeForMainJobSecs)); |
| 648 } |
| 643 } | 649 } |
| 644 | 650 |
| 645 WebSocketHandshakeStreamBase::CreateHelper* HttpStreamFactoryImpl:: | 651 WebSocketHandshakeStreamBase::CreateHelper* HttpStreamFactoryImpl:: |
| 646 JobController::websocket_handshake_stream_create_helper() { | 652 JobController::websocket_handshake_stream_create_helper() { |
| 647 DCHECK(request_); | 653 DCHECK(request_); |
| 648 return request_->websocket_handshake_stream_create_helper(); | 654 return request_->websocket_handshake_stream_create_helper(); |
| 649 } | 655 } |
| 650 | 656 |
| 651 void HttpStreamFactoryImpl::JobController::CreateJobs( | 657 void HttpStreamFactoryImpl::JobController::CreateJobs( |
| 652 const HttpRequestInfo& request_info, | 658 const HttpRequestInfo& request_info, |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1111 return; | 1117 return; |
| 1112 DCHECK(alternative_job_->alternative_proxy_server().is_valid()); | 1118 DCHECK(alternative_job_->alternative_proxy_server().is_valid()); |
| 1113 alternative_job_->Start(request_->stream_type()); | 1119 alternative_job_->Start(request_->stream_type()); |
| 1114 } | 1120 } |
| 1115 | 1121 |
| 1116 bool HttpStreamFactoryImpl::JobController::IsJobOrphaned(Job* job) const { | 1122 bool HttpStreamFactoryImpl::JobController::IsJobOrphaned(Job* job) const { |
| 1117 return !request_ || (job_bound_ && bound_job_ != job); | 1123 return !request_ || (job_bound_ && bound_job_ != job); |
| 1118 } | 1124 } |
| 1119 | 1125 |
| 1120 } // namespace net | 1126 } // namespace net |
| OLD | NEW |