| 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.h" | 5 #include "net/http/http_stream_factory_impl.h" |
| 6 | 6 |
| 7 #include <tuple> | 7 #include <tuple> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 namespace net { | 33 namespace net { |
| 34 | 34 |
| 35 HttpStreamFactoryImpl::HttpStreamFactoryImpl(HttpNetworkSession* session, | 35 HttpStreamFactoryImpl::HttpStreamFactoryImpl(HttpNetworkSession* session, |
| 36 bool for_websockets) | 36 bool for_websockets) |
| 37 : session_(session), | 37 : session_(session), |
| 38 job_factory_(new JobFactory()), | 38 job_factory_(new JobFactory()), |
| 39 for_websockets_(for_websockets), | 39 for_websockets_(for_websockets), |
| 40 last_logged_job_controller_count_(0) {} | 40 last_logged_job_controller_count_(0) {} |
| 41 | 41 |
| 42 HttpStreamFactoryImpl::~HttpStreamFactoryImpl() { | 42 HttpStreamFactoryImpl::~HttpStreamFactoryImpl() { |
| 43 DCHECK(spdy_session_request_map_.empty()); | |
| 44 UMA_HISTOGRAM_COUNTS_1M("Net.JobControllerSet.CountOfJobControllerAtShutDown", | 43 UMA_HISTOGRAM_COUNTS_1M("Net.JobControllerSet.CountOfJobControllerAtShutDown", |
| 45 job_controller_set_.size()); | 44 job_controller_set_.size()); |
| 46 } | 45 } |
| 47 | 46 |
| 48 std::unique_ptr<HttpStreamRequest> HttpStreamFactoryImpl::RequestStream( | 47 std::unique_ptr<HttpStreamRequest> HttpStreamFactoryImpl::RequestStream( |
| 49 const HttpRequestInfo& request_info, | 48 const HttpRequestInfo& request_info, |
| 50 RequestPriority priority, | 49 RequestPriority priority, |
| 51 const SSLConfig& server_ssl_config, | 50 const SSLConfig& server_ssl_config, |
| 52 const SSLConfig& proxy_ssl_config, | 51 const SSLConfig& proxy_ssl_config, |
| 53 HttpStreamRequest::Delegate* delegate, | 52 HttpStreamRequest::Delegate* delegate, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 proxy_ssl_config); | 147 proxy_ssl_config); |
| 149 JobController* job_controller_raw_ptr = job_controller.get(); | 148 JobController* job_controller_raw_ptr = job_controller.get(); |
| 150 job_controller_set_.insert(std::move(job_controller)); | 149 job_controller_set_.insert(std::move(job_controller)); |
| 151 job_controller_raw_ptr->Preconnect(num_streams); | 150 job_controller_raw_ptr->Preconnect(num_streams); |
| 152 } | 151 } |
| 153 | 152 |
| 154 const HostMappingRules* HttpStreamFactoryImpl::GetHostMappingRules() const { | 153 const HostMappingRules* HttpStreamFactoryImpl::GetHostMappingRules() const { |
| 155 return &session_->params().host_mapping_rules; | 154 return &session_->params().host_mapping_rules; |
| 156 } | 155 } |
| 157 | 156 |
| 158 void HttpStreamFactoryImpl::OnNewSpdySessionReady( | |
| 159 const base::WeakPtr<SpdySession>& spdy_session, | |
| 160 bool direct, | |
| 161 const SSLConfig& used_ssl_config, | |
| 162 const ProxyInfo& used_proxy_info, | |
| 163 bool was_alpn_negotiated, | |
| 164 NextProto negotiated_protocol, | |
| 165 bool using_spdy, | |
| 166 NetLogSource source_dependency) { | |
| 167 while (true) { | |
| 168 if (!spdy_session) | |
| 169 break; | |
| 170 const SpdySessionKey& spdy_session_key = spdy_session->spdy_session_key(); | |
| 171 // Each iteration may empty out the RequestSet for |spdy_session_key| in | |
| 172 // |spdy_session_request_map_|. So each time, check for RequestSet and use | |
| 173 // the first one. | |
| 174 // | |
| 175 // TODO(willchan): If it's important, switch RequestSet out for a FIFO | |
| 176 // queue (Order by priority first, then FIFO within same priority). Unclear | |
| 177 // that it matters here. | |
| 178 if (!base::ContainsKey(spdy_session_request_map_, spdy_session_key)) | |
| 179 break; | |
| 180 Request* request = *spdy_session_request_map_[spdy_session_key].begin(); | |
| 181 request->Complete(was_alpn_negotiated, negotiated_protocol, using_spdy); | |
| 182 if (for_websockets_) { | |
| 183 // TODO(ricea): Restore this code path when WebSocket over SPDY | |
| 184 // implementation is ready. | |
| 185 NOTREACHED(); | |
| 186 } else if (request->stream_type() == | |
| 187 HttpStreamRequest::BIDIRECTIONAL_STREAM) { | |
| 188 request->OnBidirectionalStreamImplReady( | |
| 189 used_ssl_config, used_proxy_info, | |
| 190 new BidirectionalStreamSpdyImpl(spdy_session, source_dependency)); | |
| 191 } else { | |
| 192 bool use_relative_url = | |
| 193 direct || request->url().SchemeIs(url::kHttpsScheme); | |
| 194 request->OnStreamReady(used_ssl_config, used_proxy_info, | |
| 195 new SpdyHttpStream(spdy_session, use_relative_url, | |
| 196 source_dependency)); | |
| 197 } | |
| 198 } | |
| 199 // TODO(mbelshe): Alert other valid requests. | |
| 200 } | |
| 201 | |
| 202 void HttpStreamFactoryImpl::OnJobControllerComplete(JobController* controller) { | 157 void HttpStreamFactoryImpl::OnJobControllerComplete(JobController* controller) { |
| 203 for (auto it = job_controller_set_.begin(); it != job_controller_set_.end(); | 158 for (auto it = job_controller_set_.begin(); it != job_controller_set_.end(); |
| 204 ++it) { | 159 ++it) { |
| 205 if (it->get() == controller) { | 160 if (it->get() == controller) { |
| 206 job_controller_set_.erase(it); | 161 job_controller_set_.erase(it); |
| 207 return; | 162 return; |
| 208 } | 163 } |
| 209 } | 164 } |
| 210 NOTREACHED(); | 165 NOTREACHED(); |
| 211 } | 166 } |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 factory_dump->AddScalar("main_job_count", | 340 factory_dump->AddScalar("main_job_count", |
| 386 base::trace_event::MemoryAllocatorDump::kUnitsObjects, | 341 base::trace_event::MemoryAllocatorDump::kUnitsObjects, |
| 387 main_job_count); | 342 main_job_count); |
| 388 // The number of preconnect controllers. | 343 // The number of preconnect controllers. |
| 389 factory_dump->AddScalar("preconnect_count", | 344 factory_dump->AddScalar("preconnect_count", |
| 390 base::trace_event::MemoryAllocatorDump::kUnitsObjects, | 345 base::trace_event::MemoryAllocatorDump::kUnitsObjects, |
| 391 num_controllers_for_preconnect); | 346 num_controllers_for_preconnect); |
| 392 } | 347 } |
| 393 | 348 |
| 394 } // namespace net | 349 } // namespace net |
| OLD | NEW |