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

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

Issue 1904483004: Change SupportsSpdy dict, SpdySettingsMap, ServerNetworkStatsMap, AlternativeServiceMap and disk da… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile after sync code, introduced by commit 388755 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 <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 10
(...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_(SpdyServersMap::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(".ggpht.com"); 38 canonical_suffixes_.push_back(".ggpht.com");
39 canonical_suffixes_.push_back(".c.youtube.com"); 39 canonical_suffixes_.push_back(".c.youtube.com");
40 canonical_suffixes_.push_back(".googlevideo.com"); 40 canonical_suffixes_.push_back(".googlevideo.com");
41 canonical_suffixes_.push_back(".googleusercontent.com"); 41 canonical_suffixes_.push_back(".googleusercontent.com");
42 } 42 }
43 43
44 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() { 44 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() {
45 } 45 }
46 46
47 void HttpServerPropertiesImpl::InitializeSpdyServers( 47 void HttpServerPropertiesImpl::InitializeSpdyServers(
48 std::vector<std::string>* spdy_servers, 48 std::vector<std::string>* spdy_servers,
49 bool support_spdy) { 49 bool support_spdy) {
50 DCHECK(CalledOnValidThread()); 50 DCHECK(CalledOnValidThread());
51 if (!spdy_servers) 51 if (!spdy_servers)
52 return; 52 return;
53 53
54 // Add the entries from persisted data. 54 // Add the entries from persisted data.
55 SpdyServerHostPortMap spdy_servers_map(SpdyServerHostPortMap::NO_AUTO_EVICT); 55 SpdyServersMap spdy_servers_map(SpdyServersMap::NO_AUTO_EVICT);
56 for (std::vector<std::string>::reverse_iterator it = spdy_servers->rbegin(); 56 for (std::vector<std::string>::reverse_iterator it = spdy_servers->rbegin();
57 it != spdy_servers->rend(); ++it) { 57 it != spdy_servers->rend(); ++it) {
58 spdy_servers_map.Put(*it, support_spdy); 58 spdy_servers_map.Put(*it, support_spdy);
59 } 59 }
60 60
61 // |spdy_servers_map| will have the memory cache. 61 // |spdy_servers_map| will have the memory cache.
62 spdy_servers_map_.Swap(spdy_servers_map); 62 spdy_servers_map_.Swap(spdy_servers_map);
63 63
64 // Add the entries from the memory cache. 64 // Add the entries from the memory cache.
65 for (SpdyServerHostPortMap::reverse_iterator it = spdy_servers_map.rbegin(); 65 for (SpdyServersMap::reverse_iterator it = spdy_servers_map.rbegin();
66 it != spdy_servers_map.rend(); ++it) { 66 it != spdy_servers_map.rend(); ++it) {
67 // Add the entry if it is not in the cache, otherwise move it to the front 67 // Add the entry if it is not in the cache, otherwise move it to the front
68 // of recency list. 68 // of recency list.
69 if (spdy_servers_map_.Get(it->first) == spdy_servers_map_.end()) 69 if (spdy_servers_map_.Get(it->first) == spdy_servers_map_.end())
70 spdy_servers_map_.Put(it->first, it->second); 70 spdy_servers_map_.Put(it->first, it->second);
71 } 71 }
72 } 72 }
73 73
74 void HttpServerPropertiesImpl::InitializeAlternativeServiceServers( 74 void HttpServerPropertiesImpl::InitializeAlternativeServiceServers(
75 AlternativeServiceMap* alternative_service_map) { 75 AlternativeServiceMap* alternative_service_map) {
(...skipping 22 matching lines...) Expand all
98 // Add the entries from the memory cache. 98 // Add the entries from the memory cache.
99 for (AlternativeServiceMap::reverse_iterator input_it = 99 for (AlternativeServiceMap::reverse_iterator input_it =
100 new_alternative_service_map.rbegin(); 100 new_alternative_service_map.rbegin();
101 input_it != new_alternative_service_map.rend(); ++input_it) { 101 input_it != new_alternative_service_map.rend(); ++input_it) {
102 if (alternative_service_map_.Get(input_it->first) == 102 if (alternative_service_map_.Get(input_it->first) ==
103 alternative_service_map_.end()) { 103 alternative_service_map_.end()) {
104 alternative_service_map_.Put(input_it->first, input_it->second); 104 alternative_service_map_.Put(input_it->first, input_it->second);
105 } 105 }
106 } 106 }
107 107
108 // Attempt to find canonical servers. 108 // Attempt to find canonical servers. Canonical suffix only apply to HTTPS.
109 uint16_t canonical_ports[] = {80, 443}; 109 uint16_t canonical_port = 443;
110 const char* canonical_scheme = "https";
110 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { 111 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) {
111 std::string canonical_suffix = canonical_suffixes_[i]; 112 std::string canonical_suffix = canonical_suffixes_[i];
112 for (size_t j = 0; j < arraysize(canonical_ports); ++j) { 113 url::SchemeHostPort canonical_server(canonical_scheme, canonical_suffix,
113 HostPortPair canonical_host(canonical_suffix, canonical_ports[j]); 114 canonical_port);
114 // If we already have a valid canonical server, we're done. 115 // If we already have a valid canonical server, we're done.
115 if (ContainsKey(canonical_host_to_origin_map_, canonical_host) && 116 if (ContainsKey(canonical_host_to_origin_map_, canonical_server) &&
116 (alternative_service_map_.Peek( 117 (alternative_service_map_.Peek(
117 canonical_host_to_origin_map_[canonical_host]) != 118 canonical_host_to_origin_map_[canonical_server]) !=
118 alternative_service_map_.end())) { 119 alternative_service_map_.end())) {
119 continue; 120 continue;
120 } 121 }
121 // Now attempt to find a server which matches this origin and set it as 122 // Now attempt to find a server which matches this origin and set it as
122 // canonical. 123 // canonical.
123 for (AlternativeServiceMap::const_iterator it = 124 for (AlternativeServiceMap::const_iterator it =
124 alternative_service_map_.begin(); 125 alternative_service_map_.begin();
125 it != alternative_service_map_.end(); ++it) { 126 it != alternative_service_map_.end(); ++it) {
126 if (base::EndsWith(it->first.host(), canonical_suffixes_[i], 127 if (base::EndsWith(it->first.host(), canonical_suffixes_[i],
127 base::CompareCase::INSENSITIVE_ASCII)) { 128 base::CompareCase::INSENSITIVE_ASCII) &&
128 canonical_host_to_origin_map_[canonical_host] = it->first; 129 it->first.scheme() == canonical_server.scheme()) {
129 break; 130 canonical_host_to_origin_map_[canonical_server] = it->first;
130 } 131 break;
131 } 132 }
132 } 133 }
133 } 134 }
134 } 135 }
135 136
136 void HttpServerPropertiesImpl::InitializeSpdySettingsServers( 137 void HttpServerPropertiesImpl::InitializeSpdySettingsServers(
137 SpdySettingsMap* spdy_settings_map) { 138 SpdySettingsMap* spdy_settings_map) {
138 // Add the entries from persisted data. 139 // Add the entries from persisted data.
139 SpdySettingsMap new_spdy_settings_map(SpdySettingsMap::NO_AUTO_EVICT); 140 SpdySettingsMap new_spdy_settings_map(SpdySettingsMap::NO_AUTO_EVICT);
140 for (SpdySettingsMap::reverse_iterator it = spdy_settings_map->rbegin(); 141 for (SpdySettingsMap::reverse_iterator it = spdy_settings_map->rbegin();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 } 202 }
202 } 203 }
203 204
204 void HttpServerPropertiesImpl::GetSpdyServerList( 205 void HttpServerPropertiesImpl::GetSpdyServerList(
205 base::ListValue* spdy_server_list, 206 base::ListValue* spdy_server_list,
206 size_t max_size) const { 207 size_t max_size) const {
207 DCHECK(CalledOnValidThread()); 208 DCHECK(CalledOnValidThread());
208 DCHECK(spdy_server_list); 209 DCHECK(spdy_server_list);
209 spdy_server_list->Clear(); 210 spdy_server_list->Clear();
210 size_t count = 0; 211 size_t count = 0;
211 // Get the list of servers (host/port) that support SPDY. 212 // Get the list of servers (scheme/host/port) that support SPDY.
212 for (SpdyServerHostPortMap::const_iterator it = spdy_servers_map_.begin(); 213 for (SpdyServersMap::const_iterator it = spdy_servers_map_.begin();
213 it != spdy_servers_map_.end() && count < max_size; ++it) { 214 it != spdy_servers_map_.end() && count < max_size; ++it) {
214 const std::string spdy_server_host_port = it->first; 215 const std::string spdy_server = it->first;
215 if (it->second) { 216 if (it->second) {
216 spdy_server_list->Append(new base::StringValue(spdy_server_host_port)); 217 spdy_server_list->Append(new base::StringValue(spdy_server));
217 ++count; 218 ++count;
218 } 219 }
219 } 220 }
220 } 221 }
221 222
222 base::WeakPtr<HttpServerProperties> HttpServerPropertiesImpl::GetWeakPtr() { 223 base::WeakPtr<HttpServerProperties> HttpServerPropertiesImpl::GetWeakPtr() {
223 return weak_ptr_factory_.GetWeakPtr(); 224 return weak_ptr_factory_.GetWeakPtr();
224 } 225 }
225 226
226 void HttpServerPropertiesImpl::Clear() { 227 void HttpServerPropertiesImpl::Clear() {
227 DCHECK(CalledOnValidThread()); 228 DCHECK(CalledOnValidThread());
228 spdy_servers_map_.Clear(); 229 spdy_servers_map_.Clear();
229 alternative_service_map_.Clear(); 230 alternative_service_map_.Clear();
230 canonical_host_to_origin_map_.clear(); 231 canonical_host_to_origin_map_.clear();
231 spdy_settings_map_.Clear(); 232 spdy_settings_map_.Clear();
232 last_quic_address_ = IPAddress(); 233 last_quic_address_ = IPAddress();
233 server_network_stats_map_.Clear(); 234 server_network_stats_map_.Clear();
234 quic_server_info_map_.Clear(); 235 quic_server_info_map_.Clear();
235 } 236 }
236 237
237 bool HttpServerPropertiesImpl::SupportsRequestPriority( 238 bool HttpServerPropertiesImpl::SupportsRequestPriority(
238 const HostPortPair& host_port_pair) { 239 const url::SchemeHostPort& server) {
239 DCHECK(CalledOnValidThread()); 240 DCHECK(CalledOnValidThread());
240 if (host_port_pair.host().empty()) 241 if (server.host().empty())
241 return false; 242 return false;
242 243
243 if (GetSupportsSpdy(host_port_pair)) 244 if (GetSupportsSpdy(server))
244 return true; 245 return true;
245
246 const AlternativeServiceVector alternative_service_vector = 246 const AlternativeServiceVector alternative_service_vector =
247 GetAlternativeServices(host_port_pair); 247 GetAlternativeServices(server);
248 for (const AlternativeService& alternative_service : 248 for (const AlternativeService& alternative_service :
249 alternative_service_vector) { 249 alternative_service_vector) {
250 if (alternative_service.protocol == QUIC) { 250 if (alternative_service.protocol == QUIC) {
251 return true; 251 return true;
252 } 252 }
253 } 253 }
254 return false; 254 return false;
255 } 255 }
256 256
257 bool HttpServerPropertiesImpl::GetSupportsSpdy( 257 bool HttpServerPropertiesImpl::GetSupportsSpdy(
258 const HostPortPair& host_port_pair) { 258 const url::SchemeHostPort& server) {
259 DCHECK(CalledOnValidThread()); 259 DCHECK(CalledOnValidThread());
260 if (host_port_pair.host().empty()) 260 if (server.host().empty())
261 return false; 261 return false;
262 262
263 SpdyServerHostPortMap::iterator spdy_host_port = 263 SpdyServersMap::iterator spdy_server =
264 spdy_servers_map_.Get(host_port_pair.ToString()); 264 spdy_servers_map_.Get(server.Serialize());
265 return spdy_host_port != spdy_servers_map_.end() && spdy_host_port->second; 265 return spdy_server != spdy_servers_map_.end() && spdy_server->second;
266 } 266 }
267 267
268 void HttpServerPropertiesImpl::SetSupportsSpdy( 268 void HttpServerPropertiesImpl::SetSupportsSpdy(
269 const HostPortPair& host_port_pair, 269 const url::SchemeHostPort& server,
270 bool support_spdy) { 270 bool support_spdy) {
271 DCHECK(CalledOnValidThread()); 271 DCHECK(CalledOnValidThread());
272 if (host_port_pair.host().empty()) 272 if (server.host().empty())
273 return; 273 return;
274 274
275 SpdyServerHostPortMap::iterator spdy_host_port = 275 SpdyServersMap::iterator spdy_server =
276 spdy_servers_map_.Get(host_port_pair.ToString()); 276 spdy_servers_map_.Get(server.Serialize());
277 if ((spdy_host_port != spdy_servers_map_.end()) && 277 if ((spdy_server != spdy_servers_map_.end()) &&
278 (spdy_host_port->second == support_spdy)) { 278 (spdy_server->second == support_spdy)) {
279 return; 279 return;
280 } 280 }
281 // Cache the data. 281 // Cache the data.
282 spdy_servers_map_.Put(host_port_pair.ToString(), support_spdy); 282 spdy_servers_map_.Put(server.Serialize(), support_spdy);
283 } 283 }
284 284
285 bool HttpServerPropertiesImpl::RequiresHTTP11( 285 bool HttpServerPropertiesImpl::RequiresHTTP11(
286 const HostPortPair& host_port_pair) { 286 const HostPortPair& host_port_pair) {
287 DCHECK(CalledOnValidThread()); 287 DCHECK(CalledOnValidThread());
288 if (host_port_pair.host().empty()) 288 if (host_port_pair.host().empty())
289 return false; 289 return false;
290 290
291 return (http11_servers_.find(host_port_pair) != http11_servers_.end()); 291 return (http11_servers_.find(host_port_pair) != http11_servers_.end());
292 } 292 }
(...skipping 22 matching lines...) Expand all
315 std::string canonical_suffix = canonical_suffixes_[i]; 315 std::string canonical_suffix = canonical_suffixes_[i];
316 if (base::EndsWith(host, canonical_suffixes_[i], 316 if (base::EndsWith(host, canonical_suffixes_[i],
317 base::CompareCase::INSENSITIVE_ASCII)) { 317 base::CompareCase::INSENSITIVE_ASCII)) {
318 return canonical_suffix; 318 return canonical_suffix;
319 } 319 }
320 } 320 }
321 return std::string(); 321 return std::string();
322 } 322 }
323 323
324 AlternativeServiceVector HttpServerPropertiesImpl::GetAlternativeServices( 324 AlternativeServiceVector HttpServerPropertiesImpl::GetAlternativeServices(
325 const HostPortPair& origin) { 325 const url::SchemeHostPort& origin) {
326 // Copy valid alternative services into |valid_alternative_services|. 326 // Copy valid alternative services into |valid_alternative_services|.
327 AlternativeServiceVector valid_alternative_services; 327 AlternativeServiceVector valid_alternative_services;
328 const base::Time now = base::Time::Now(); 328 const base::Time now = base::Time::Now();
329 AlternativeServiceMap::iterator map_it = alternative_service_map_.Get(origin); 329 AlternativeServiceMap::iterator map_it = alternative_service_map_.Get(origin);
330 if (map_it != alternative_service_map_.end()) { 330 if (map_it != alternative_service_map_.end()) {
331 HostPortPair host_port_pair(origin.host(), origin.port());
331 for (AlternativeServiceInfoVector::iterator it = map_it->second.begin(); 332 for (AlternativeServiceInfoVector::iterator it = map_it->second.begin();
332 it != map_it->second.end();) { 333 it != map_it->second.end();) {
333 if (it->expiration < now) { 334 if (it->expiration < now) {
334 it = map_it->second.erase(it); 335 it = map_it->second.erase(it);
335 continue; 336 continue;
336 } 337 }
337 AlternativeService alternative_service(it->alternative_service); 338 AlternativeService alternative_service(it->alternative_service);
338 if (alternative_service.host.empty()) { 339 if (alternative_service.host.empty()) {
339 alternative_service.host = origin.host(); 340 alternative_service.host = origin.host();
340 } 341 }
341 // If the alternative service is equivalent to the origin (same host, same 342 // If the alternative service is equivalent to the origin (same host, same
342 // port, and both TCP), then there is already a Job for it, so do not 343 // port, and both TCP), skip it.
343 // return it here. 344 if (host_port_pair.Equals(alternative_service.host_port_pair()) &&
344 if (origin.Equals(alternative_service.host_port_pair()) &&
345 NPN_SPDY_MINIMUM_VERSION <= alternative_service.protocol && 345 NPN_SPDY_MINIMUM_VERSION <= alternative_service.protocol &&
346 alternative_service.protocol <= NPN_SPDY_MAXIMUM_VERSION) { 346 alternative_service.protocol <= NPN_SPDY_MAXIMUM_VERSION) {
347 ++it; 347 ++it;
348 continue; 348 continue;
349 } 349 }
350 valid_alternative_services.push_back(alternative_service); 350 valid_alternative_services.push_back(alternative_service);
351 ++it; 351 ++it;
352 } 352 }
353 if (map_it->second.empty()) { 353 if (map_it->second.empty()) {
354 alternative_service_map_.Erase(map_it); 354 alternative_service_map_.Erase(map_it);
(...skipping 30 matching lines...) Expand all
385 valid_alternative_services.push_back(alternative_service); 385 valid_alternative_services.push_back(alternative_service);
386 ++it; 386 ++it;
387 } 387 }
388 if (map_it->second.empty()) { 388 if (map_it->second.empty()) {
389 alternative_service_map_.Erase(map_it); 389 alternative_service_map_.Erase(map_it);
390 } 390 }
391 return valid_alternative_services; 391 return valid_alternative_services;
392 } 392 }
393 393
394 bool HttpServerPropertiesImpl::SetAlternativeService( 394 bool HttpServerPropertiesImpl::SetAlternativeService(
395 const HostPortPair& origin, 395 const url::SchemeHostPort& origin,
396 const AlternativeService& alternative_service, 396 const AlternativeService& alternative_service,
397 base::Time expiration) { 397 base::Time expiration) {
398 return SetAlternativeServices( 398 return SetAlternativeServices(
399 origin, 399 origin,
400 AlternativeServiceInfoVector( 400 AlternativeServiceInfoVector(
401 /*size=*/1, AlternativeServiceInfo(alternative_service, expiration))); 401 /*size=*/1, AlternativeServiceInfo(alternative_service, expiration)));
402 } 402 }
403 403
404 bool HttpServerPropertiesImpl::SetAlternativeServices( 404 bool HttpServerPropertiesImpl::SetAlternativeServices(
405 const HostPortPair& origin, 405 const url::SchemeHostPort& origin,
406 const AlternativeServiceInfoVector& alternative_service_info_vector) { 406 const AlternativeServiceInfoVector& alternative_service_info_vector) {
407 AlternativeServiceMap::iterator it = alternative_service_map_.Peek(origin); 407 AlternativeServiceMap::iterator it = alternative_service_map_.Peek(origin);
408 408
409 if (alternative_service_info_vector.empty()) { 409 if (alternative_service_info_vector.empty()) {
410 if (it == alternative_service_map_.end()) { 410 if (it == alternative_service_map_.end()) {
411 return false; 411 return false;
412 } 412 }
413 ClearAlternativeServices(origin); 413 ClearAlternativeServices(origin);
414 return true; 414 return true;
415 } 415 }
(...skipping 15 matching lines...) Expand all
431 if (previously_no_alternative_services && 431 if (previously_no_alternative_services &&
432 !GetAlternativeServices(origin).empty()) { 432 !GetAlternativeServices(origin).empty()) {
433 // TODO(rch): Consider the case where multiple requests are started 433 // TODO(rch): Consider the case where multiple requests are started
434 // before the first completes. In this case, only one of the jobs 434 // before the first completes. In this case, only one of the jobs
435 // would reach this code, whereas all of them should should have. 435 // would reach this code, whereas all of them should should have.
436 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_MAPPING_MISSING); 436 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_MAPPING_MISSING);
437 } 437 }
438 438
439 // If this host ends with a canonical suffix, then set it as the 439 // If this host ends with a canonical suffix, then set it as the
440 // canonical host. 440 // canonical host.
441 const char* canonical_scheme = "https";
441 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { 442 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) {
442 std::string canonical_suffix = canonical_suffixes_[i]; 443 std::string canonical_suffix = canonical_suffixes_[i];
443 if (base::EndsWith(origin.host(), canonical_suffixes_[i], 444 // canonical suffixes only apply to HTTPS.
445 if (origin.scheme() == canonical_scheme &&
446 base::EndsWith(origin.host(), canonical_suffixes_[i],
444 base::CompareCase::INSENSITIVE_ASCII)) { 447 base::CompareCase::INSENSITIVE_ASCII)) {
445 HostPortPair canonical_host(canonical_suffix, origin.port()); 448 url::SchemeHostPort canonical_server(canonical_scheme, canonical_suffix,
446 canonical_host_to_origin_map_[canonical_host] = origin; 449 origin.port());
450 canonical_host_to_origin_map_[canonical_server] = origin;
447 break; 451 break;
448 } 452 }
449 } 453 }
450 454
451 return changed; 455 return changed;
452 } 456 }
453 457
454 void HttpServerPropertiesImpl::MarkAlternativeServiceBroken( 458 void HttpServerPropertiesImpl::MarkAlternativeServiceBroken(
455 const AlternativeService& alternative_service) { 459 const AlternativeService& alternative_service) {
456 // Empty host means use host of origin, callers are supposed to substitute. 460 // Empty host means use host of origin, callers are supposed to substitute.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 504
501 void HttpServerPropertiesImpl::ConfirmAlternativeService( 505 void HttpServerPropertiesImpl::ConfirmAlternativeService(
502 const AlternativeService& alternative_service) { 506 const AlternativeService& alternative_service) {
503 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) 507 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL)
504 return; 508 return;
505 broken_alternative_services_.erase(alternative_service); 509 broken_alternative_services_.erase(alternative_service);
506 recently_broken_alternative_services_.erase(alternative_service); 510 recently_broken_alternative_services_.erase(alternative_service);
507 } 511 }
508 512
509 void HttpServerPropertiesImpl::ClearAlternativeServices( 513 void HttpServerPropertiesImpl::ClearAlternativeServices(
510 const HostPortPair& origin) { 514 const url::SchemeHostPort& origin) {
511 RemoveCanonicalHost(origin); 515 RemoveCanonicalHost(origin);
512 516
513 AlternativeServiceMap::iterator it = alternative_service_map_.Peek(origin); 517 AlternativeServiceMap::iterator it = alternative_service_map_.Peek(origin);
514 if (it == alternative_service_map_.end()) { 518 if (it == alternative_service_map_.end()) {
515 return; 519 return;
516 } 520 }
517 alternative_service_map_.Erase(it); 521 alternative_service_map_.Erase(it);
518 } 522 }
519 523
520 const AlternativeServiceMap& HttpServerPropertiesImpl::alternative_service_map() 524 const AlternativeServiceMap& HttpServerPropertiesImpl::alternative_service_map()
521 const { 525 const {
522 return alternative_service_map_; 526 return alternative_service_map_;
523 } 527 }
524 528
525 std::unique_ptr<base::Value> 529 std::unique_ptr<base::Value>
526 HttpServerPropertiesImpl::GetAlternativeServiceInfoAsValue() const { 530 HttpServerPropertiesImpl::GetAlternativeServiceInfoAsValue() const {
527 std::unique_ptr<base::ListValue> dict_list(new base::ListValue); 531 std::unique_ptr<base::ListValue> dict_list(new base::ListValue);
528 for (const auto& alternative_service_map_item : alternative_service_map_) { 532 for (const auto& alternative_service_map_item : alternative_service_map_) {
529 std::unique_ptr<base::ListValue> alternative_service_list( 533 std::unique_ptr<base::ListValue> alternative_service_list(
530 new base::ListValue); 534 new base::ListValue);
531 const HostPortPair& host_port_pair = alternative_service_map_item.first; 535 const url::SchemeHostPort& server = alternative_service_map_item.first;
532 for (const AlternativeServiceInfo& alternative_service_info : 536 for (const AlternativeServiceInfo& alternative_service_info :
533 alternative_service_map_item.second) { 537 alternative_service_map_item.second) {
534 std::string alternative_service_string( 538 std::string alternative_service_string(
535 alternative_service_info.ToString()); 539 alternative_service_info.ToString());
536 AlternativeService alternative_service( 540 AlternativeService alternative_service(
537 alternative_service_info.alternative_service); 541 alternative_service_info.alternative_service);
538 if (alternative_service.host.empty()) { 542 if (alternative_service.host.empty()) {
539 alternative_service.host = host_port_pair.host(); 543 alternative_service.host = server.host();
540 } 544 }
541 if (IsAlternativeServiceBroken(alternative_service)) { 545 if (IsAlternativeServiceBroken(alternative_service)) {
542 alternative_service_string.append(" (broken)"); 546 alternative_service_string.append(" (broken)");
543 } 547 }
544 alternative_service_list->Append( 548 alternative_service_list->Append(
545 new base::StringValue(alternative_service_string)); 549 new base::StringValue(alternative_service_string));
546 } 550 }
547 if (alternative_service_list->empty()) 551 if (alternative_service_list->empty())
548 continue; 552 continue;
549 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 553 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
550 dict->SetString("host_port_pair", host_port_pair.ToString()); 554 dict->SetString("server", server.Serialize());
551 dict->Set("alternative_service", std::unique_ptr<base::Value>( 555 dict->Set("alternative_service", std::unique_ptr<base::Value>(
552 std::move(alternative_service_list))); 556 std::move(alternative_service_list)));
553 dict_list->Append(std::move(dict)); 557 dict_list->Append(std::move(dict));
554 } 558 }
555 return std::move(dict_list); 559 return std::move(dict_list);
556 } 560 }
557 561
558 const SettingsMap& HttpServerPropertiesImpl::GetSpdySettings( 562 const SettingsMap& HttpServerPropertiesImpl::GetSpdySettings(
559 const HostPortPair& host_port_pair) { 563 const url::SchemeHostPort& server) {
560 SpdySettingsMap::iterator it = spdy_settings_map_.Get(host_port_pair); 564 SpdySettingsMap::iterator it = spdy_settings_map_.Get(server);
561 if (it == spdy_settings_map_.end()) { 565 if (it == spdy_settings_map_.end()) {
562 CR_DEFINE_STATIC_LOCAL(SettingsMap, kEmptySettingsMap, ()); 566 CR_DEFINE_STATIC_LOCAL(SettingsMap, kEmptySettingsMap, ());
563 return kEmptySettingsMap; 567 return kEmptySettingsMap;
564 } 568 }
565 return it->second; 569 return it->second;
566 } 570 }
567 571
568 bool HttpServerPropertiesImpl::SetSpdySetting( 572 bool HttpServerPropertiesImpl::SetSpdySetting(const url::SchemeHostPort& server,
569 const HostPortPair& host_port_pair, 573 SpdySettingsIds id,
570 SpdySettingsIds id, 574 SpdySettingsFlags flags,
571 SpdySettingsFlags flags, 575 uint32_t value) {
572 uint32_t value) {
573 if (!(flags & SETTINGS_FLAG_PLEASE_PERSIST)) 576 if (!(flags & SETTINGS_FLAG_PLEASE_PERSIST))
574 return false; 577 return false;
575 578
576 SettingsFlagsAndValue flags_and_value(SETTINGS_FLAG_PERSISTED, value); 579 SettingsFlagsAndValue flags_and_value(SETTINGS_FLAG_PERSISTED, value);
577 SpdySettingsMap::iterator it = spdy_settings_map_.Get(host_port_pair); 580 SpdySettingsMap::iterator it = spdy_settings_map_.Get(server);
578 if (it == spdy_settings_map_.end()) { 581 if (it == spdy_settings_map_.end()) {
579 SettingsMap settings_map; 582 SettingsMap settings_map;
580 settings_map[id] = flags_and_value; 583 settings_map[id] = flags_and_value;
581 spdy_settings_map_.Put(host_port_pair, settings_map); 584 spdy_settings_map_.Put(server, settings_map);
582 } else { 585 } else {
583 SettingsMap& settings_map = it->second; 586 SettingsMap& settings_map = it->second;
584 settings_map[id] = flags_and_value; 587 settings_map[id] = flags_and_value;
585 } 588 }
586 return true; 589 return true;
587 } 590 }
588 591
589 void HttpServerPropertiesImpl::ClearSpdySettings( 592 void HttpServerPropertiesImpl::ClearSpdySettings(
590 const HostPortPair& host_port_pair) { 593 const url::SchemeHostPort& server) {
591 SpdySettingsMap::iterator it = spdy_settings_map_.Peek(host_port_pair); 594 SpdySettingsMap::iterator it = spdy_settings_map_.Peek(server);
592 if (it != spdy_settings_map_.end()) 595 if (it != spdy_settings_map_.end())
593 spdy_settings_map_.Erase(it); 596 spdy_settings_map_.Erase(it);
594 } 597 }
595 598
596 void HttpServerPropertiesImpl::ClearAllSpdySettings() { 599 void HttpServerPropertiesImpl::ClearAllSpdySettings() {
597 spdy_settings_map_.Clear(); 600 spdy_settings_map_.Clear();
598 } 601 }
599 602
600 const SpdySettingsMap& 603 const SpdySettingsMap&
601 HttpServerPropertiesImpl::spdy_settings_map() const { 604 HttpServerPropertiesImpl::spdy_settings_map() const {
(...skipping 11 matching lines...) Expand all
613 void HttpServerPropertiesImpl::SetSupportsQuic(bool used_quic, 616 void HttpServerPropertiesImpl::SetSupportsQuic(bool used_quic,
614 const IPAddress& address) { 617 const IPAddress& address) {
615 if (!used_quic) { 618 if (!used_quic) {
616 last_quic_address_ = IPAddress(); 619 last_quic_address_ = IPAddress();
617 } else { 620 } else {
618 last_quic_address_ = address; 621 last_quic_address_ = address;
619 } 622 }
620 } 623 }
621 624
622 void HttpServerPropertiesImpl::SetServerNetworkStats( 625 void HttpServerPropertiesImpl::SetServerNetworkStats(
623 const HostPortPair& host_port_pair, 626 const url::SchemeHostPort& server,
624 ServerNetworkStats stats) { 627 ServerNetworkStats stats) {
625 server_network_stats_map_.Put(host_port_pair, stats); 628 server_network_stats_map_.Put(server, stats);
626 } 629 }
627 630
628 const ServerNetworkStats* HttpServerPropertiesImpl::GetServerNetworkStats( 631 const ServerNetworkStats* HttpServerPropertiesImpl::GetServerNetworkStats(
629 const HostPortPair& host_port_pair) { 632 const url::SchemeHostPort& server) {
630 ServerNetworkStatsMap::iterator it = 633 ServerNetworkStatsMap::iterator it = server_network_stats_map_.Get(server);
631 server_network_stats_map_.Get(host_port_pair);
632 if (it == server_network_stats_map_.end()) { 634 if (it == server_network_stats_map_.end()) {
633 return NULL; 635 return NULL;
634 } 636 }
635 return &it->second; 637 return &it->second;
636 } 638 }
637 639
638 const ServerNetworkStatsMap& 640 const ServerNetworkStatsMap&
639 HttpServerPropertiesImpl::server_network_stats_map() const { 641 HttpServerPropertiesImpl::server_network_stats_map() const {
640 return server_network_stats_map_; 642 return server_network_stats_map_;
641 } 643 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 for (QuicServerInfoMap::reverse_iterator it = quic_server_info_map_.rbegin(); 682 for (QuicServerInfoMap::reverse_iterator it = quic_server_info_map_.rbegin();
681 it != quic_server_info_map_.rend(); ++it) { 683 it != quic_server_info_map_.rend(); ++it) {
682 temp_map.Put(it->first, it->second); 684 temp_map.Put(it->first, it->second);
683 } 685 }
684 686
685 quic_server_info_map_.Swap(temp_map); 687 quic_server_info_map_.Swap(temp_map);
686 } 688 }
687 689
688 AlternativeServiceMap::const_iterator 690 AlternativeServiceMap::const_iterator
689 HttpServerPropertiesImpl::GetAlternateProtocolIterator( 691 HttpServerPropertiesImpl::GetAlternateProtocolIterator(
690 const HostPortPair& server) { 692 const url::SchemeHostPort& server) {
691 AlternativeServiceMap::const_iterator it = 693 AlternativeServiceMap::const_iterator it =
692 alternative_service_map_.Get(server); 694 alternative_service_map_.Get(server);
693 if (it != alternative_service_map_.end()) 695 if (it != alternative_service_map_.end())
694 return it; 696 return it;
695 697
696 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(server); 698 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(server);
697 if (canonical == canonical_host_to_origin_map_.end()) { 699 if (canonical == canonical_host_to_origin_map_.end()) {
698 return alternative_service_map_.end(); 700 return alternative_service_map_.end();
699 } 701 }
700 702
701 const HostPortPair canonical_host_port = canonical->second; 703 const url::SchemeHostPort canonical_server = canonical->second;
702 it = alternative_service_map_.Get(canonical_host_port); 704 it = alternative_service_map_.Get(canonical_server);
703 if (it == alternative_service_map_.end()) { 705 if (it == alternative_service_map_.end()) {
704 return alternative_service_map_.end(); 706 return alternative_service_map_.end();
705 } 707 }
706 708
707 for (const AlternativeServiceInfo& alternative_service_info : it->second) { 709 for (const AlternativeServiceInfo& alternative_service_info : it->second) {
708 AlternativeService alternative_service( 710 AlternativeService alternative_service(
709 alternative_service_info.alternative_service); 711 alternative_service_info.alternative_service);
710 if (alternative_service.host.empty()) { 712 if (alternative_service.host.empty()) {
711 alternative_service.host = canonical_host_port.host(); 713 alternative_service.host = canonical_server.host();
712 } 714 }
713 if (!IsAlternativeServiceBroken(alternative_service)) { 715 if (!IsAlternativeServiceBroken(alternative_service)) {
714 return it; 716 return it;
715 } 717 }
716 } 718 }
717 719
718 RemoveCanonicalHost(canonical_host_port); 720 RemoveCanonicalHost(canonical_server);
719 return alternative_service_map_.end(); 721 return alternative_service_map_.end();
720 } 722 }
721 723
722 HttpServerPropertiesImpl::CanonicalHostMap::const_iterator 724 HttpServerPropertiesImpl::CanonicalHostMap::const_iterator
723 HttpServerPropertiesImpl::GetCanonicalHost(HostPortPair server) const { 725 HttpServerPropertiesImpl::GetCanonicalHost(
726 const url::SchemeHostPort& server) const {
727 const char* canonical_scheme = "https";
728 if (server.scheme() != canonical_scheme)
729 return canonical_host_to_origin_map_.end();
730
724 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { 731 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) {
725 std::string canonical_suffix = canonical_suffixes_[i]; 732 std::string canonical_suffix = canonical_suffixes_[i];
726 if (base::EndsWith(server.host(), canonical_suffixes_[i], 733 if (base::EndsWith(server.host(), canonical_suffixes_[i],
727 base::CompareCase::INSENSITIVE_ASCII)) { 734 base::CompareCase::INSENSITIVE_ASCII)) {
728 HostPortPair canonical_host(canonical_suffix, server.port()); 735 url::SchemeHostPort canonical_server(canonical_scheme, canonical_suffix,
729 return canonical_host_to_origin_map_.find(canonical_host); 736 server.port());
737 return canonical_host_to_origin_map_.find(canonical_server);
730 } 738 }
731 } 739 }
732 740
733 return canonical_host_to_origin_map_.end(); 741 return canonical_host_to_origin_map_.end();
734 } 742 }
735 743
736 void HttpServerPropertiesImpl::RemoveCanonicalHost( 744 void HttpServerPropertiesImpl::RemoveCanonicalHost(
737 const HostPortPair& server) { 745 const url::SchemeHostPort& server) {
738 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(server); 746 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(server);
739 if (canonical == canonical_host_to_origin_map_.end()) 747 if (canonical == canonical_host_to_origin_map_.end())
740 return; 748 return;
741 749
742 if (!canonical->second.Equals(server)) 750 if (!canonical->second.Equals(server))
743 return; 751 return;
744 752
745 canonical_host_to_origin_map_.erase(canonical->first); 753 canonical_host_to_origin_map_.erase(canonical->first);
746 } 754 }
747 755
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); 808 base::TimeDelta delay = when > now ? when - now : base::TimeDelta();
801 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 809 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
802 FROM_HERE, 810 FROM_HERE,
803 base::Bind( 811 base::Bind(
804 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, 812 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings,
805 weak_ptr_factory_.GetWeakPtr()), 813 weak_ptr_factory_.GetWeakPtr()),
806 delay); 814 delay);
807 } 815 }
808 816
809 } // namespace net 817 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_server_properties_impl.h ('k') | net/http/http_server_properties_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698