OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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_pipelined_host_pool.h" | 5 #include "net/http/http_pipelined_host_pool.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "net/http/http_pipelined_host_capability.h" | 10 #include "net/http/http_pipelined_host_capability.h" |
| 11 #include "net/http/http_pipelined_host_forced.h" |
11 #include "net/http/http_pipelined_host_impl.h" | 12 #include "net/http/http_pipelined_host_impl.h" |
12 #include "net/http/http_server_properties.h" | 13 #include "net/http/http_server_properties.h" |
13 | 14 |
14 using base::ListValue; | 15 using base::ListValue; |
15 using base::Value; | 16 using base::Value; |
16 | 17 |
17 namespace net { | 18 namespace net { |
18 | 19 |
19 class HttpPipelinedHostImplFactory : public HttpPipelinedHost::Factory { | 20 class HttpPipelinedHostImplFactory : public HttpPipelinedHost::Factory { |
20 public: | 21 public: |
21 virtual HttpPipelinedHost* CreateNewHost( | 22 virtual HttpPipelinedHost* CreateNewHost( |
22 HttpPipelinedHost::Delegate* delegate, const HostPortPair& origin, | 23 HttpPipelinedHost::Delegate* delegate, |
| 24 const HttpPipelinedHost::Key& key, |
23 HttpPipelinedConnection::Factory* factory, | 25 HttpPipelinedConnection::Factory* factory, |
24 HttpPipelinedHostCapability capability) OVERRIDE { | 26 HttpPipelinedHostCapability capability) OVERRIDE { |
25 return new HttpPipelinedHostImpl(delegate, origin, factory, capability); | 27 if (key.force_pipelining()) { |
| 28 return new HttpPipelinedHostForced(delegate, key, factory); |
| 29 } else { |
| 30 return new HttpPipelinedHostImpl(delegate, key, factory, capability); |
| 31 } |
26 } | 32 } |
27 }; | 33 }; |
28 | 34 |
29 HttpPipelinedHostPool::HttpPipelinedHostPool( | 35 HttpPipelinedHostPool::HttpPipelinedHostPool( |
30 Delegate* delegate, | 36 Delegate* delegate, |
31 HttpPipelinedHost::Factory* factory, | 37 HttpPipelinedHost::Factory* factory, |
32 HttpServerProperties* http_server_properties) | 38 HttpServerProperties* http_server_properties) |
33 : delegate_(delegate), | 39 : delegate_(delegate), |
34 factory_(factory), | 40 factory_(factory), |
35 http_server_properties_(http_server_properties) { | 41 http_server_properties_(http_server_properties) { |
36 if (!factory) { | 42 if (!factory) { |
37 factory_.reset(new HttpPipelinedHostImplFactory); | 43 factory_.reset(new HttpPipelinedHostImplFactory); |
38 } | 44 } |
39 } | 45 } |
40 | 46 |
41 HttpPipelinedHostPool::~HttpPipelinedHostPool() { | 47 HttpPipelinedHostPool::~HttpPipelinedHostPool() { |
42 CHECK(host_map_.empty()); | 48 CHECK(host_map_.empty()); |
43 } | 49 } |
44 | 50 |
45 bool HttpPipelinedHostPool::IsHostEligibleForPipelining( | 51 bool HttpPipelinedHostPool::IsKeyEligibleForPipelining( |
46 const HostPortPair& origin) { | 52 const HttpPipelinedHost::Key& key) { |
47 HttpPipelinedHostCapability capability = | 53 HttpPipelinedHostCapability capability = |
48 http_server_properties_->GetPipelineCapability(origin); | 54 http_server_properties_->GetPipelineCapability(key.origin()); |
49 return capability != PIPELINE_INCAPABLE; | 55 return capability != PIPELINE_INCAPABLE; |
50 } | 56 } |
51 | 57 |
52 HttpPipelinedStream* HttpPipelinedHostPool::CreateStreamOnNewPipeline( | 58 HttpPipelinedStream* HttpPipelinedHostPool::CreateStreamOnNewPipeline( |
53 const HostPortPair& origin, | 59 const HttpPipelinedHost::Key& key, |
54 ClientSocketHandle* connection, | 60 ClientSocketHandle* connection, |
55 const SSLConfig& used_ssl_config, | 61 const SSLConfig& used_ssl_config, |
56 const ProxyInfo& used_proxy_info, | 62 const ProxyInfo& used_proxy_info, |
57 const BoundNetLog& net_log, | 63 const BoundNetLog& net_log, |
58 bool was_npn_negotiated, | 64 bool was_npn_negotiated, |
59 SSLClientSocket::NextProto protocol_negotiated) { | 65 SSLClientSocket::NextProto protocol_negotiated) { |
60 HttpPipelinedHost* host = GetPipelinedHost(origin, true); | 66 HttpPipelinedHost* host = GetPipelinedHost(key, true); |
61 if (!host) { | 67 if (!host) { |
62 return NULL; | 68 return NULL; |
63 } | 69 } |
64 return host->CreateStreamOnNewPipeline(connection, used_ssl_config, | 70 return host->CreateStreamOnNewPipeline(connection, used_ssl_config, |
65 used_proxy_info, net_log, | 71 used_proxy_info, net_log, |
66 was_npn_negotiated, | 72 was_npn_negotiated, |
67 protocol_negotiated); | 73 protocol_negotiated); |
68 } | 74 } |
69 | 75 |
70 HttpPipelinedStream* HttpPipelinedHostPool::CreateStreamOnExistingPipeline( | 76 HttpPipelinedStream* HttpPipelinedHostPool::CreateStreamOnExistingPipeline( |
71 const HostPortPair& origin) { | 77 const HttpPipelinedHost::Key& key) { |
72 HttpPipelinedHost* host = GetPipelinedHost(origin, false); | 78 HttpPipelinedHost* host = GetPipelinedHost(key, false); |
73 if (!host) { | 79 if (!host) { |
74 return NULL; | 80 return NULL; |
75 } | 81 } |
76 return host->CreateStreamOnExistingPipeline(); | 82 return host->CreateStreamOnExistingPipeline(); |
77 } | 83 } |
78 | 84 |
79 bool HttpPipelinedHostPool::IsExistingPipelineAvailableForOrigin( | 85 bool HttpPipelinedHostPool::IsExistingPipelineAvailableForKey( |
80 const HostPortPair& origin) { | 86 const HttpPipelinedHost::Key& key) { |
81 HttpPipelinedHost* host = GetPipelinedHost(origin, false); | 87 HttpPipelinedHost* host = GetPipelinedHost(key, false); |
82 if (!host) { | 88 if (!host) { |
83 return false; | 89 return false; |
84 } | 90 } |
85 return host->IsExistingPipelineAvailable(); | 91 return host->IsExistingPipelineAvailable(); |
86 } | 92 } |
87 | 93 |
88 HttpPipelinedHost* HttpPipelinedHostPool::GetPipelinedHost( | 94 HttpPipelinedHost* HttpPipelinedHostPool::GetPipelinedHost( |
89 const HostPortPair& origin, bool create_if_not_found) { | 95 const HttpPipelinedHost::Key& key, bool create_if_not_found) { |
90 HostMap::iterator host_it = host_map_.find(origin); | 96 HostMap::iterator host_it = host_map_.find(key); |
91 if (host_it != host_map_.end()) { | 97 if (host_it != host_map_.end()) { |
92 CHECK(host_it->second); | 98 CHECK(host_it->second); |
93 return host_it->second; | 99 return host_it->second; |
94 } else if (!create_if_not_found) { | 100 } else if (!create_if_not_found) { |
95 return NULL; | 101 return NULL; |
96 } | 102 } |
97 | 103 |
98 HttpPipelinedHostCapability capability = | 104 HttpPipelinedHostCapability capability = |
99 http_server_properties_->GetPipelineCapability(origin); | 105 http_server_properties_->GetPipelineCapability(key.origin()); |
100 if (capability == PIPELINE_INCAPABLE) { | 106 if (capability == PIPELINE_INCAPABLE) { |
101 return NULL; | 107 return NULL; |
102 } | 108 } |
103 | 109 |
104 HttpPipelinedHost* host = factory_->CreateNewHost( | 110 HttpPipelinedHost* host = factory_->CreateNewHost( |
105 this, origin, NULL, capability); | 111 this, key, NULL, capability); |
106 host_map_[origin] = host; | 112 host_map_[key] = host; |
107 return host; | 113 return host; |
108 } | 114 } |
109 | 115 |
110 void HttpPipelinedHostPool::OnHostIdle(HttpPipelinedHost* host) { | 116 void HttpPipelinedHostPool::OnHostIdle(HttpPipelinedHost* host) { |
111 const HostPortPair& origin = host->origin(); | 117 const HttpPipelinedHost::Key& key = host->key(); |
112 CHECK(ContainsKey(host_map_, origin)); | 118 CHECK(ContainsKey(host_map_, key)); |
113 host_map_.erase(origin); | 119 host_map_.erase(key); |
114 delete host; | 120 delete host; |
115 } | 121 } |
116 | 122 |
117 void HttpPipelinedHostPool::OnHostHasAdditionalCapacity( | 123 void HttpPipelinedHostPool::OnHostHasAdditionalCapacity( |
118 HttpPipelinedHost* host) { | 124 HttpPipelinedHost* host) { |
119 delegate_->OnHttpPipelinedHostHasAdditionalCapacity(host->origin()); | 125 delegate_->OnHttpPipelinedHostHasAdditionalCapacity(host); |
120 } | 126 } |
121 | 127 |
122 void HttpPipelinedHostPool::OnHostDeterminedCapability( | 128 void HttpPipelinedHostPool::OnHostDeterminedCapability( |
123 HttpPipelinedHost* host, | 129 HttpPipelinedHost* host, |
124 HttpPipelinedHostCapability capability) { | 130 HttpPipelinedHostCapability capability) { |
125 http_server_properties_->SetPipelineCapability(host->origin(), capability); | 131 http_server_properties_->SetPipelineCapability(host->key().origin(), |
| 132 capability); |
126 } | 133 } |
127 | 134 |
128 Value* HttpPipelinedHostPool::PipelineInfoToValue() const { | 135 Value* HttpPipelinedHostPool::PipelineInfoToValue() const { |
129 ListValue* list = new ListValue(); | 136 ListValue* list = new ListValue(); |
130 for (HostMap::const_iterator it = host_map_.begin(); | 137 for (HostMap::const_iterator it = host_map_.begin(); |
131 it != host_map_.end(); ++it) { | 138 it != host_map_.end(); ++it) { |
132 Value* value = it->second->PipelineInfoToValue(); | 139 Value* value = it->second->PipelineInfoToValue(); |
133 list->Append(value); | 140 list->Append(value); |
134 } | 141 } |
135 return list; | 142 return list; |
136 } | 143 } |
137 | 144 |
138 } // namespace net | 145 } // namespace net |
OLD | NEW |