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( | |
mmenke
2011/10/12 19:41:35
nit: Fix indent.
James Simonsen
2011/10/12 21:55:51
Done.
| |
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_.reset(new HttpPipelinedConnectionImplFactory()); | |
38 } | |
39 } | |
40 | |
41 HttpPipelinedHost::~HttpPipelinedHost() { | |
42 CHECK(pipelines_.empty()); | |
43 } | |
44 | |
45 HttpPipelinedStream* HttpPipelinedHost::CreateStreamOnNewPipeline( | |
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->CreateNewStream(); | |
56 } | |
57 | |
58 HttpPipelinedStream* HttpPipelinedHost::CreateStreamOnExistingPipeline() { | |
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 if (!available_pipeline) { | |
70 return NULL; | |
71 } | |
72 return available_pipeline->CreateNewStream(); | |
73 } | |
74 | |
75 bool HttpPipelinedHost::IsExistingPipelineAvailable() { | |
76 for (std::set<HttpPipelinedConnection*>::iterator it = pipelines_.begin(); | |
77 it != pipelines_.end(); ++it) { | |
78 if ((*it)->usable() && | |
79 (*it)->active() && | |
80 (*it)->depth() < max_pipeline_depth()) { | |
81 return true; | |
82 } | |
83 } | |
84 return false; | |
85 } | |
86 | |
87 void HttpPipelinedHost::OnPipelineEmpty(HttpPipelinedConnection* pipeline) { | |
88 CHECK(ContainsKey(pipelines_, pipeline)); | |
89 pipelines_.erase(pipeline); | |
90 delete pipeline; | |
91 if (pipelines_.empty()) { | |
92 delegate_->OnHostIdle(this); | |
93 // WARNING: We'll probably be deleted here. | |
94 } | |
95 } | |
96 | |
97 void HttpPipelinedHost::OnPipelineHasCapacity( | |
98 HttpPipelinedConnection* pipeline) { | |
99 if (pipeline->usable() && pipeline->depth() < max_pipeline_depth()) { | |
100 delegate_->OnHostHasAdditionalCapacity(this); | |
101 } | |
102 if (!pipeline->depth()) { | |
103 OnPipelineEmpty(pipeline); | |
104 // WARNING: We might be deleted here. | |
105 } | |
106 } | |
107 | |
108 } // namespace net | |
OLD | NEW |