Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(355)

Side by Side Diff: net/http/http_server_properties_impl.cc

Issue 1860343002: SHP 1: Change SupportsSpdy dict to use SchemeHostPort as the key. No change to Pref data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 10 matching lines...) Expand all
21 21
22 namespace net { 22 namespace net {
23 23
24 namespace { 24 namespace {
25 25
26 const uint64_t kBrokenAlternativeProtocolDelaySecs = 300; 26 const uint64_t kBrokenAlternativeProtocolDelaySecs = 300;
27 27
28 } // namespace 28 } // namespace
29 29
30 HttpServerPropertiesImpl::HttpServerPropertiesImpl() 30 HttpServerPropertiesImpl::HttpServerPropertiesImpl()
31 : spdy_servers_map_(SpdyServerHostPortMap::NO_AUTO_EVICT), 31 : spdy_servers_map_(SpdyServerSchemeHostPortMap::NO_AUTO_EVICT),
32 alternative_service_map_(AlternativeServiceMap::NO_AUTO_EVICT), 32 alternative_service_map_(AlternativeServiceMap::NO_AUTO_EVICT),
33 spdy_settings_map_(SpdySettingsMap::NO_AUTO_EVICT), 33 spdy_settings_map_(SpdySettingsMap::NO_AUTO_EVICT),
34 server_network_stats_map_(ServerNetworkStatsMap::NO_AUTO_EVICT), 34 server_network_stats_map_(ServerNetworkStatsMap::NO_AUTO_EVICT),
35 quic_server_info_map_(QuicServerInfoMap::NO_AUTO_EVICT), 35 quic_server_info_map_(QuicServerInfoMap::NO_AUTO_EVICT),
36 max_server_configs_stored_in_properties_(kMaxQuicServersToPersist), 36 max_server_configs_stored_in_properties_(kMaxQuicServersToPersist),
37 weak_ptr_factory_(this) { 37 weak_ptr_factory_(this) {
38 canonical_suffixes_.push_back(".c.youtube.com"); 38 canonical_suffixes_.push_back(".c.youtube.com");
39 canonical_suffixes_.push_back(".googlevideo.com"); 39 canonical_suffixes_.push_back(".googlevideo.com");
40 canonical_suffixes_.push_back(".googleusercontent.com"); 40 canonical_suffixes_.push_back(".googleusercontent.com");
41 } 41 }
42 42
43 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() { 43 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() {
44 } 44 }
45 45
46 void HttpServerPropertiesImpl::InitializeSpdyServers( 46 void HttpServerPropertiesImpl::InitializeSpdyServers(
47 std::vector<std::string>* spdy_servers, 47 std::vector<std::string>* spdy_servers,
48 bool support_spdy) { 48 bool support_spdy) {
49 DCHECK(CalledOnValidThread()); 49 DCHECK(CalledOnValidThread());
50 if (!spdy_servers) 50 if (!spdy_servers)
51 return; 51 return;
52 52
53 // Add the entries from persisted data. 53 // Add the entries from persisted data.
54 SpdyServerHostPortMap spdy_servers_map(SpdyServerHostPortMap::NO_AUTO_EVICT); 54 SpdyServerSchemeHostPortMap spdy_servers_map(
55 SpdyServerSchemeHostPortMap::NO_AUTO_EVICT);
55 for (std::vector<std::string>::reverse_iterator it = spdy_servers->rbegin(); 56 for (std::vector<std::string>::reverse_iterator it = spdy_servers->rbegin();
56 it != spdy_servers->rend(); ++it) { 57 it != spdy_servers->rend(); ++it) {
57 spdy_servers_map.Put(*it, support_spdy); 58 spdy_servers_map.Put(*it, support_spdy);
58 } 59 }
59 60
60 // |spdy_servers_map| will have the memory cache. 61 // |spdy_servers_map| will have the memory cache.
61 spdy_servers_map_.Swap(spdy_servers_map); 62 spdy_servers_map_.Swap(spdy_servers_map);
62 63
63 // Add the entries from the memory cache. 64 // Add the entries from the memory cache.
64 for (SpdyServerHostPortMap::reverse_iterator it = spdy_servers_map.rbegin(); 65 for (SpdyServerSchemeHostPortMap::reverse_iterator it =
66 spdy_servers_map.rbegin();
65 it != spdy_servers_map.rend(); ++it) { 67 it != spdy_servers_map.rend(); ++it) {
66 // Add the entry if it is not in the cache, otherwise move it to the front 68 // Add the entry if it is not in the cache, otherwise move it to the front
67 // of recency list. 69 // of recency list.
68 if (spdy_servers_map_.Get(it->first) == spdy_servers_map_.end()) 70 if (spdy_servers_map_.Get(it->first) == spdy_servers_map_.end())
69 spdy_servers_map_.Put(it->first, it->second); 71 spdy_servers_map_.Put(it->first, it->second);
70 } 72 }
71 } 73 }
72 74
73 void HttpServerPropertiesImpl::InitializeAlternativeServiceServers( 75 void HttpServerPropertiesImpl::InitializeAlternativeServiceServers(
74 AlternativeServiceMap* alternative_service_map) { 76 AlternativeServiceMap* alternative_service_map) {
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 202 }
201 } 203 }
202 204
203 void HttpServerPropertiesImpl::GetSpdyServerList( 205 void HttpServerPropertiesImpl::GetSpdyServerList(
204 base::ListValue* spdy_server_list, 206 base::ListValue* spdy_server_list,
205 size_t max_size) const { 207 size_t max_size) const {
206 DCHECK(CalledOnValidThread()); 208 DCHECK(CalledOnValidThread());
207 DCHECK(spdy_server_list); 209 DCHECK(spdy_server_list);
208 spdy_server_list->Clear(); 210 spdy_server_list->Clear();
209 size_t count = 0; 211 size_t count = 0;
210 // Get the list of servers (host/port) that support SPDY. 212 // Get the list of servers (scheme/host/port) that support SPDY.
211 for (SpdyServerHostPortMap::const_iterator it = spdy_servers_map_.begin(); 213 for (SpdyServerSchemeHostPortMap::const_iterator it =
214 spdy_servers_map_.begin();
212 it != spdy_servers_map_.end() && count < max_size; ++it) { 215 it != spdy_servers_map_.end() && count < max_size; ++it) {
213 const std::string spdy_server_host_port = it->first; 216 const std::string spdy_server_scheme_host_port = it->first;
214 if (it->second) { 217 if (it->second) {
215 spdy_server_list->Append(new base::StringValue(spdy_server_host_port)); 218 spdy_server_list->Append(
219 new base::StringValue(spdy_server_scheme_host_port));
216 ++count; 220 ++count;
217 } 221 }
218 } 222 }
219 } 223 }
220 224
221 base::WeakPtr<HttpServerProperties> HttpServerPropertiesImpl::GetWeakPtr() { 225 base::WeakPtr<HttpServerProperties> HttpServerPropertiesImpl::GetWeakPtr() {
222 return weak_ptr_factory_.GetWeakPtr(); 226 return weak_ptr_factory_.GetWeakPtr();
223 } 227 }
224 228
225 void HttpServerPropertiesImpl::Clear() { 229 void HttpServerPropertiesImpl::Clear() {
226 DCHECK(CalledOnValidThread()); 230 DCHECK(CalledOnValidThread());
227 spdy_servers_map_.Clear(); 231 spdy_servers_map_.Clear();
228 alternative_service_map_.Clear(); 232 alternative_service_map_.Clear();
229 canonical_host_to_origin_map_.clear(); 233 canonical_host_to_origin_map_.clear();
230 spdy_settings_map_.Clear(); 234 spdy_settings_map_.Clear();
231 last_quic_address_ = IPAddress(); 235 last_quic_address_ = IPAddress();
232 server_network_stats_map_.Clear(); 236 server_network_stats_map_.Clear();
233 quic_server_info_map_.Clear(); 237 quic_server_info_map_.Clear();
234 } 238 }
235 239
236 bool HttpServerPropertiesImpl::SupportsRequestPriority( 240 bool HttpServerPropertiesImpl::SupportsRequestPriority(
237 const HostPortPair& host_port_pair) { 241 const url::SchemeHostPort& server) {
242 HostPortPair host_port_pair = HostPortPair::FromSchemeHostPort(server);
238 DCHECK(CalledOnValidThread()); 243 DCHECK(CalledOnValidThread());
239 if (host_port_pair.host().empty()) 244 if (server.host().empty())
240 return false; 245 return false;
241 246
242 if (GetSupportsSpdy(host_port_pair)) 247 if (GetSupportsSpdy(server))
243 return true; 248 return true;
244 249
245 const AlternativeServiceVector alternative_service_vector = 250 const AlternativeServiceVector alternative_service_vector =
246 GetAlternativeServices(host_port_pair); 251 GetAlternativeServices(host_port_pair);
247 for (const AlternativeService& alternative_service : 252 for (const AlternativeService& alternative_service :
248 alternative_service_vector) { 253 alternative_service_vector) {
249 if (alternative_service.protocol == QUIC) { 254 if (alternative_service.protocol == QUIC) {
250 return true; 255 return true;
251 } 256 }
252 } 257 }
253 return false; 258 return false;
254 } 259 }
255 260
256 bool HttpServerPropertiesImpl::GetSupportsSpdy( 261 bool HttpServerPropertiesImpl::GetSupportsSpdy(
257 const HostPortPair& host_port_pair) { 262 const url::SchemeHostPort& server) {
258 DCHECK(CalledOnValidThread()); 263 DCHECK(CalledOnValidThread());
259 if (host_port_pair.host().empty()) 264 if (server.host().empty())
260 return false; 265 return false;
261 266
262 SpdyServerHostPortMap::iterator spdy_host_port = 267 SpdyServerSchemeHostPortMap::iterator spdy_scheme_host_port =
Ryan Hamilton 2016/04/06 19:16:08 how about spdy_server?
Zhongyi Shi 2016/04/07 00:31:18 Done.
263 spdy_servers_map_.Get(host_port_pair.ToString()); 268 spdy_servers_map_.Get(server.ToString());
264 return spdy_host_port != spdy_servers_map_.end() && spdy_host_port->second; 269 return spdy_scheme_host_port != spdy_servers_map_.end() &&
270 spdy_scheme_host_port->second;
265 } 271 }
266 272
267 void HttpServerPropertiesImpl::SetSupportsSpdy( 273 void HttpServerPropertiesImpl::SetSupportsSpdy(
268 const HostPortPair& host_port_pair, 274 const url::SchemeHostPort& server,
269 bool support_spdy) { 275 bool support_spdy) {
270 DCHECK(CalledOnValidThread()); 276 DCHECK(CalledOnValidThread());
271 if (host_port_pair.host().empty()) 277 if (server.host().empty())
272 return; 278 return;
273 279
274 SpdyServerHostPortMap::iterator spdy_host_port = 280 SpdyServerSchemeHostPortMap::iterator spdy_scheme_host_port =
275 spdy_servers_map_.Get(host_port_pair.ToString()); 281 spdy_servers_map_.Get(server.ToString());
276 if ((spdy_host_port != spdy_servers_map_.end()) && 282 if ((spdy_scheme_host_port != spdy_servers_map_.end()) &&
277 (spdy_host_port->second == support_spdy)) { 283 (spdy_scheme_host_port->second == support_spdy)) {
278 return; 284 return;
279 } 285 }
280 // Cache the data. 286 // Cache the data.
281 spdy_servers_map_.Put(host_port_pair.ToString(), support_spdy); 287 spdy_servers_map_.Put(server.ToString(), support_spdy);
282 } 288 }
283 289
284 bool HttpServerPropertiesImpl::RequiresHTTP11( 290 bool HttpServerPropertiesImpl::RequiresHTTP11(
285 const HostPortPair& host_port_pair) { 291 const HostPortPair& host_port_pair) {
286 DCHECK(CalledOnValidThread()); 292 DCHECK(CalledOnValidThread());
287 if (host_port_pair.host().empty()) 293 if (host_port_pair.host().empty())
288 return false; 294 return false;
289 295
290 return (http11_servers_.find(host_port_pair) != http11_servers_.end()); 296 return (http11_servers_.find(host_port_pair) != http11_servers_.end());
291 } 297 }
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); 805 base::TimeDelta delay = when > now ? when - now : base::TimeDelta();
800 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 806 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
801 FROM_HERE, 807 FROM_HERE,
802 base::Bind( 808 base::Bind(
803 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, 809 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings,
804 weak_ptr_factory_.GetWeakPtr()), 810 weak_ptr_factory_.GetWeakPtr()),
805 delay); 811 delay);
806 } 812 }
807 813
808 } // namespace net 814 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698