OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "net/http/http_pipelined_host.h" | |
6 | |
7 #include "base/stl_util.h" | |
8 #include "net/http/http_pipelined_connection_impl.h" | |
9 #include "net/http/http_pipelined_stream.h" | |
10 | |
11 namespace net { | |
12 | |
13 class HttpPipelinedConnectionImplFactory : | |
14 public HttpPipelinedConnection::Factory { | |
15 public: | |
16 HttpPipelinedConnection* CreateNewPipeline( | |
17 ClientSocketHandle* connection, | |
18 HttpPipelinedConnection::Delegate* delegate, | |
19 const SSLConfig& used_ssl_config, | |
20 const ProxyInfo& used_proxy_info, | |
21 const BoundNetLog& net_log, | |
22 bool was_npn_negotiated) OVERRIDE { | |
23 return new HttpPipelinedConnectionImpl(connection, delegate, | |
24 used_ssl_config, used_proxy_info, | |
25 net_log, was_npn_negotiated); | |
26 } | |
27 }; | |
28 | |
29 HttpPipelinedHost::HttpPipelinedHost( | |
30 HttpPipelinedHost::Delegate* delegate, | |
31 const HostPortPair& origin, | |
32 HttpPipelinedConnection::Factory* factory) | |
33 : delegate_(delegate), | |
34 origin_(origin), | |
35 factory_(factory) { | |
36 if (!factory_) { | |
37 factory_ = new HttpPipelinedConnectionImplFactory(); | |
willchan no longer on Chromium
2011/09/26 23:49:20
Who owns this? Where is this deleted?
James Simonsen
2011/09/29 02:39:31
Done.
| |
38 } | |
39 } | |
40 | |
41 HttpPipelinedHost::~HttpPipelinedHost() { | |
42 DCHECK(pipelines_.empty()); | |
43 } | |
44 | |
45 HttpPipelinedConnection* HttpPipelinedHost::CreateNewPipeline( | |
46 ClientSocketHandle* connection, | |
47 const SSLConfig& used_ssl_config, | |
48 const ProxyInfo& used_proxy_info, | |
49 const BoundNetLog& net_log, | |
50 bool was_npn_negotiated) { | |
51 HttpPipelinedConnection* pipeline = factory_->CreateNewPipeline( | |
52 connection, this, used_ssl_config, used_proxy_info, net_log, | |
53 was_npn_negotiated); | |
54 pipelines_.insert(pipeline); | |
55 return pipeline; | |
56 } | |
57 | |
58 HttpPipelinedConnection* HttpPipelinedHost::FindAvailablePipeline() { | |
59 HttpPipelinedConnection* available_pipeline = NULL; | |
60 for (std::set<HttpPipelinedConnection*>::iterator it = pipelines_.begin(); | |
61 it != pipelines_.end(); ++it) { | |
62 if ((*it)->usable() && | |
63 (*it)->active() && | |
64 (*it)->depth() < max_pipeline_depth() && | |
65 (!available_pipeline || (*it)->depth() < available_pipeline->depth())) { | |
66 available_pipeline = *it; | |
67 } | |
68 } | |
69 return available_pipeline; | |
70 } | |
71 | |
72 void HttpPipelinedHost::OnPipelineEmpty(HttpPipelinedConnection* pipeline) { | |
73 DCHECK(ContainsKey(pipelines_, pipeline)); | |
74 pipelines_.erase(pipeline); | |
75 delete pipeline; | |
76 if (pipelines_.empty()) { | |
77 delegate_->OnHostIdle(this); | |
78 // WARNING: We'll probably be deleted here. | |
79 } | |
80 } | |
81 | |
82 void HttpPipelinedHost::OnPipelineHasCapacity( | |
83 HttpPipelinedConnection* pipeline) { | |
84 if (pipeline->usable() && pipeline->depth() < max_pipeline_depth()) { | |
85 delegate_->OnHostHasAdditionalCapacity(this); | |
86 } | |
87 if (!pipeline->depth()) { | |
88 OnPipelineEmpty(pipeline); | |
89 // WARNING: We'll probably be deleted here. | |
willchan no longer on Chromium
2011/09/26 23:49:20
Interesting. So when pipelines go empty, we don't
James Simonsen
2011/09/29 02:39:31
Done. Yeah, I definitely intend to track what we l
| |
90 } | |
91 } | |
92 | |
93 } // namespace net | |
OLD | NEW |