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_server_properties_impl.h" | 5 #include "net/http/http_server_properties_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 for (SpdyServerHostPortMap::const_iterator it = spdy_servers_map_.begin(); | 120 for (SpdyServerHostPortMap::const_iterator it = spdy_servers_map_.begin(); |
121 it != spdy_servers_map_.end() && count < max_size; ++it) { | 121 it != spdy_servers_map_.end() && count < max_size; ++it) { |
122 const std::string spdy_server_host_port = it->first; | 122 const std::string spdy_server_host_port = it->first; |
123 if (it->second) { | 123 if (it->second) { |
124 spdy_server_list->Append(new base::StringValue(spdy_server_host_port)); | 124 spdy_server_list->Append(new base::StringValue(spdy_server_host_port)); |
125 ++count; | 125 ++count; |
126 } | 126 } |
127 } | 127 } |
128 } | 128 } |
129 | 129 |
130 // static | |
131 std::string HttpServerPropertiesImpl::GetFlattenedSpdyServer( | |
132 const net::HostPortPair& host_port_pair) { | |
133 std::string spdy_server; | |
134 spdy_server.append(host_port_pair.host()); | |
135 spdy_server.append(":"); | |
136 base::StringAppendF(&spdy_server, "%d", host_port_pair.port()); | |
137 return spdy_server; | |
138 } | |
139 | |
140 static const AlternateProtocolInfo* g_forced_alternate_protocol = NULL; | 130 static const AlternateProtocolInfo* g_forced_alternate_protocol = NULL; |
141 | 131 |
142 // static | 132 // static |
143 void HttpServerPropertiesImpl::ForceAlternateProtocol( | 133 void HttpServerPropertiesImpl::ForceAlternateProtocol( |
144 const AlternateProtocolInfo& info) { | 134 const AlternateProtocolInfo& info) { |
145 // Note: we're going to leak this. | 135 // Note: we're going to leak this. |
146 if (g_forced_alternate_protocol) | 136 if (g_forced_alternate_protocol) |
147 delete g_forced_alternate_protocol; | 137 delete g_forced_alternate_protocol; |
148 g_forced_alternate_protocol = new AlternateProtocolInfo(info); | 138 g_forced_alternate_protocol = new AlternateProtocolInfo(info); |
149 } | 139 } |
(...skipping 15 matching lines...) Expand all Loading... |
165 canonical_host_to_origin_map_.clear(); | 155 canonical_host_to_origin_map_.clear(); |
166 spdy_settings_map_.Clear(); | 156 spdy_settings_map_.Clear(); |
167 supports_quic_map_.clear(); | 157 supports_quic_map_.clear(); |
168 } | 158 } |
169 | 159 |
170 bool HttpServerPropertiesImpl::SupportsSpdy( | 160 bool HttpServerPropertiesImpl::SupportsSpdy( |
171 const net::HostPortPair& host_port_pair) { | 161 const net::HostPortPair& host_port_pair) { |
172 DCHECK(CalledOnValidThread()); | 162 DCHECK(CalledOnValidThread()); |
173 if (host_port_pair.host().empty()) | 163 if (host_port_pair.host().empty()) |
174 return false; | 164 return false; |
175 std::string spdy_server = GetFlattenedSpdyServer(host_port_pair); | |
176 | 165 |
177 SpdyServerHostPortMap::iterator spdy_host_port = | 166 SpdyServerHostPortMap::iterator spdy_host_port = |
178 spdy_servers_map_.Get(spdy_server); | 167 spdy_servers_map_.Get(host_port_pair.ToString()); |
179 if (spdy_host_port != spdy_servers_map_.end()) | 168 if (spdy_host_port != spdy_servers_map_.end()) |
180 return spdy_host_port->second; | 169 return spdy_host_port->second; |
181 return false; | 170 return false; |
182 } | 171 } |
183 | 172 |
184 void HttpServerPropertiesImpl::SetSupportsSpdy( | 173 void HttpServerPropertiesImpl::SetSupportsSpdy( |
185 const net::HostPortPair& host_port_pair, | 174 const net::HostPortPair& host_port_pair, |
186 bool support_spdy) { | 175 bool support_spdy) { |
187 DCHECK(CalledOnValidThread()); | 176 DCHECK(CalledOnValidThread()); |
188 if (host_port_pair.host().empty()) | 177 if (host_port_pair.host().empty()) |
189 return; | 178 return; |
190 std::string spdy_server = GetFlattenedSpdyServer(host_port_pair); | |
191 | 179 |
192 SpdyServerHostPortMap::iterator spdy_host_port = | 180 SpdyServerHostPortMap::iterator spdy_host_port = |
193 spdy_servers_map_.Get(spdy_server); | 181 spdy_servers_map_.Get(host_port_pair.ToString()); |
194 if ((spdy_host_port != spdy_servers_map_.end()) && | 182 if ((spdy_host_port != spdy_servers_map_.end()) && |
195 (spdy_host_port->second == support_spdy)) { | 183 (spdy_host_port->second == support_spdy)) { |
196 return; | 184 return; |
197 } | 185 } |
198 // Cache the data. | 186 // Cache the data. |
199 spdy_servers_map_.Put(spdy_server, support_spdy); | 187 spdy_servers_map_.Put(host_port_pair.ToString(), support_spdy); |
200 } | 188 } |
201 | 189 |
202 bool HttpServerPropertiesImpl::HasAlternateProtocol( | 190 bool HttpServerPropertiesImpl::HasAlternateProtocol( |
203 const HostPortPair& server) { | 191 const HostPortPair& server) { |
204 if (g_forced_alternate_protocol) | 192 if (g_forced_alternate_protocol) |
205 return true; | 193 return true; |
206 AlternateProtocolMap::const_iterator it = alternate_protocol_map_.Get(server); | 194 AlternateProtocolMap::const_iterator it = alternate_protocol_map_.Get(server); |
207 if (it != alternate_protocol_map_.end() && | 195 if (it != alternate_protocol_map_.end()) |
208 it->second.probability >= alternate_protocol_probability_threshold_) { | 196 return it->second.probability >= alternate_protocol_probability_threshold_; |
209 return true; | 197 |
| 198 auto canonical = GetCanonicalHost(server); |
| 199 if (canonical == canonical_host_to_origin_map_.end() || |
| 200 canonical->second.Equals(server)) { |
| 201 return false; |
210 } | 202 } |
211 | 203 |
212 return GetCanonicalHost(server) != canonical_host_to_origin_map_.end(); | 204 return HasAlternateProtocol(canonical->second); |
213 } | 205 } |
214 | 206 |
215 std::string HttpServerPropertiesImpl::GetCanonicalSuffix( | 207 std::string HttpServerPropertiesImpl::GetCanonicalSuffix( |
216 const HostPortPair& server) { | 208 const HostPortPair& server) { |
217 // If this host ends with a canonical suffix, then return the canonical | 209 // If this host ends with a canonical suffix, then return the canonical |
218 // suffix. | 210 // suffix. |
219 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { | 211 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { |
220 std::string canonical_suffix = canonical_suffixes_[i]; | 212 std::string canonical_suffix = canonical_suffixes_[i]; |
221 if (EndsWith(server.host(), canonical_suffixes_[i], false)) { | 213 if (EndsWith(server.host(), canonical_suffixes_[i], false)) { |
222 return canonical_suffix; | 214 return canonical_suffix; |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); | 489 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
498 base::MessageLoop::current()->PostDelayedTask( | 490 base::MessageLoop::current()->PostDelayedTask( |
499 FROM_HERE, | 491 FROM_HERE, |
500 base::Bind( | 492 base::Bind( |
501 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 493 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
502 weak_ptr_factory_.GetWeakPtr()), | 494 weak_ptr_factory_.GetWeakPtr()), |
503 delay); | 495 delay); |
504 } | 496 } |
505 | 497 |
506 } // namespace net | 498 } // namespace net |
OLD | NEW |