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 30 matching lines...) Expand all Loading... |
41 } | 41 } |
42 | 42 |
43 void HttpServerPropertiesImpl::InitializeSpdyServers( | 43 void HttpServerPropertiesImpl::InitializeSpdyServers( |
44 std::vector<std::string>* spdy_servers, | 44 std::vector<std::string>* spdy_servers, |
45 bool support_spdy) { | 45 bool support_spdy) { |
46 DCHECK(CalledOnValidThread()); | 46 DCHECK(CalledOnValidThread()); |
47 if (!spdy_servers) | 47 if (!spdy_servers) |
48 return; | 48 return; |
49 // Add the entries from persisted data. | 49 // Add the entries from persisted data. |
50 for (std::vector<std::string>::reverse_iterator it = spdy_servers->rbegin(); | 50 for (std::vector<std::string>::reverse_iterator it = spdy_servers->rbegin(); |
51 it != spdy_servers->rend(); ++it) { | 51 it != spdy_servers->rend(); |
| 52 ++it) { |
52 spdy_servers_map_.Put(*it, support_spdy); | 53 spdy_servers_map_.Put(*it, support_spdy); |
53 } | 54 } |
54 } | 55 } |
55 | 56 |
56 void HttpServerPropertiesImpl::InitializeAlternateProtocolServers( | 57 void HttpServerPropertiesImpl::InitializeAlternateProtocolServers( |
57 AlternateProtocolMap* alternate_protocol_map) { | 58 AlternateProtocolMap* alternate_protocol_map) { |
58 // Keep all the ALTERNATE_PROTOCOL_BROKEN ones since those don't | 59 // Keep all the ALTERNATE_PROTOCOL_BROKEN ones since those don't |
59 // get persisted. | 60 // get persisted. |
60 for (AlternateProtocolMap::iterator it = alternate_protocol_map_.begin(); | 61 for (AlternateProtocolMap::iterator it = alternate_protocol_map_.begin(); |
61 it != alternate_protocol_map_.end();) { | 62 it != alternate_protocol_map_.end();) { |
62 AlternateProtocolMap::iterator old_it = it; | 63 AlternateProtocolMap::iterator old_it = it; |
63 ++it; | 64 ++it; |
64 if (old_it->second.protocol != ALTERNATE_PROTOCOL_BROKEN) { | 65 if (old_it->second.protocol != ALTERNATE_PROTOCOL_BROKEN) { |
65 alternate_protocol_map_.Erase(old_it); | 66 alternate_protocol_map_.Erase(old_it); |
66 } | 67 } |
67 } | 68 } |
68 | 69 |
69 // Add the entries from persisted data. | 70 // Add the entries from persisted data. |
70 for (AlternateProtocolMap::reverse_iterator it = | 71 for (AlternateProtocolMap::reverse_iterator it = |
71 alternate_protocol_map->rbegin(); | 72 alternate_protocol_map->rbegin(); |
72 it != alternate_protocol_map->rend(); ++it) { | 73 it != alternate_protocol_map->rend(); |
| 74 ++it) { |
73 alternate_protocol_map_.Put(it->first, it->second); | 75 alternate_protocol_map_.Put(it->first, it->second); |
74 } | 76 } |
75 | 77 |
76 // Attempt to find canonical servers. | 78 // Attempt to find canonical servers. |
77 int canonical_ports[] = { 80, 443 }; | 79 int canonical_ports[] = {80, 443}; |
78 for (size_t i = 0; i < canoncial_suffixes_.size(); ++i) { | 80 for (size_t i = 0; i < canoncial_suffixes_.size(); ++i) { |
79 std::string canonical_suffix = canoncial_suffixes_[i]; | 81 std::string canonical_suffix = canoncial_suffixes_[i]; |
80 for (size_t j = 0; j < arraysize(canonical_ports); ++j) { | 82 for (size_t j = 0; j < arraysize(canonical_ports); ++j) { |
81 HostPortPair canonical_host(canonical_suffix, canonical_ports[j]); | 83 HostPortPair canonical_host(canonical_suffix, canonical_ports[j]); |
82 // If we already have a valid canonical server, we're done. | 84 // If we already have a valid canonical server, we're done. |
83 if (ContainsKey(canonical_host_to_origin_map_, canonical_host) && | 85 if (ContainsKey(canonical_host_to_origin_map_, canonical_host) && |
84 (alternate_protocol_map_.Peek(canonical_host_to_origin_map_[ | 86 (alternate_protocol_map_.Peek( |
85 canonical_host]) != alternate_protocol_map_.end())) { | 87 canonical_host_to_origin_map_[canonical_host]) != |
| 88 alternate_protocol_map_.end())) { |
86 continue; | 89 continue; |
87 } | 90 } |
88 // Now attempt to find a server which matches this origin and set it as | 91 // Now attempt to find a server which matches this origin and set it as |
89 // canonical . | 92 // canonical . |
90 for (AlternateProtocolMap::const_iterator it = | 93 for (AlternateProtocolMap::const_iterator it = |
91 alternate_protocol_map_.begin(); | 94 alternate_protocol_map_.begin(); |
92 it != alternate_protocol_map_.end(); ++it) { | 95 it != alternate_protocol_map_.end(); |
| 96 ++it) { |
93 if (EndsWith(it->first.host(), canoncial_suffixes_[i], false)) { | 97 if (EndsWith(it->first.host(), canoncial_suffixes_[i], false)) { |
94 canonical_host_to_origin_map_[canonical_host] = it->first; | 98 canonical_host_to_origin_map_[canonical_host] = it->first; |
95 break; | 99 break; |
96 } | 100 } |
97 } | 101 } |
98 } | 102 } |
99 } | 103 } |
100 } | 104 } |
101 | 105 |
102 void HttpServerPropertiesImpl::InitializeSpdySettingsServers( | 106 void HttpServerPropertiesImpl::InitializeSpdySettingsServers( |
103 SpdySettingsMap* spdy_settings_map) { | 107 SpdySettingsMap* spdy_settings_map) { |
104 for (SpdySettingsMap::reverse_iterator it = spdy_settings_map->rbegin(); | 108 for (SpdySettingsMap::reverse_iterator it = spdy_settings_map->rbegin(); |
105 it != spdy_settings_map->rend(); ++it) { | 109 it != spdy_settings_map->rend(); |
| 110 ++it) { |
106 spdy_settings_map_.Put(it->first, it->second); | 111 spdy_settings_map_.Put(it->first, it->second); |
107 } | 112 } |
108 } | 113 } |
109 | 114 |
110 void HttpServerPropertiesImpl::InitializePipelineCapabilities( | 115 void HttpServerPropertiesImpl::InitializePipelineCapabilities( |
111 const PipelineCapabilityMap* pipeline_capability_map) { | 116 const PipelineCapabilityMap* pipeline_capability_map) { |
112 PipelineCapabilityMap::const_iterator it; | 117 PipelineCapabilityMap::const_iterator it; |
113 pipeline_capability_map_->Clear(); | 118 pipeline_capability_map_->Clear(); |
114 for (it = pipeline_capability_map->begin(); | 119 for (it = pipeline_capability_map->begin(); |
115 it != pipeline_capability_map->end(); ++it) { | 120 it != pipeline_capability_map->end(); |
| 121 ++it) { |
116 pipeline_capability_map_->Put(it->first, it->second); | 122 pipeline_capability_map_->Put(it->first, it->second); |
117 } | 123 } |
118 } | 124 } |
119 | 125 |
120 void HttpServerPropertiesImpl::SetNumPipelinedHostsToRemember(int max_size) { | 126 void HttpServerPropertiesImpl::SetNumPipelinedHostsToRemember(int max_size) { |
121 DCHECK(pipeline_capability_map_->empty()); | 127 DCHECK(pipeline_capability_map_->empty()); |
122 pipeline_capability_map_.reset(new CachedPipelineCapabilityMap(max_size)); | 128 pipeline_capability_map_.reset(new CachedPipelineCapabilityMap(max_size)); |
123 } | 129 } |
124 | 130 |
125 void HttpServerPropertiesImpl::GetSpdyServerList( | 131 void HttpServerPropertiesImpl::GetSpdyServerList( |
126 base::ListValue* spdy_server_list, | 132 base::ListValue* spdy_server_list, |
127 size_t max_size) const { | 133 size_t max_size) const { |
128 DCHECK(CalledOnValidThread()); | 134 DCHECK(CalledOnValidThread()); |
129 DCHECK(spdy_server_list); | 135 DCHECK(spdy_server_list); |
130 spdy_server_list->Clear(); | 136 spdy_server_list->Clear(); |
131 size_t count = 0; | 137 size_t count = 0; |
132 // Get the list of servers (host/port) that support SPDY. | 138 // Get the list of servers (host/port) that support SPDY. |
133 for (SpdyServerHostPortMap::const_iterator it = spdy_servers_map_.begin(); | 139 for (SpdyServerHostPortMap::const_iterator it = spdy_servers_map_.begin(); |
134 it != spdy_servers_map_.end() && count < max_size; ++it) { | 140 it != spdy_servers_map_.end() && count < max_size; |
| 141 ++it) { |
135 const std::string spdy_server_host_port = it->first; | 142 const std::string spdy_server_host_port = it->first; |
136 if (it->second) { | 143 if (it->second) { |
137 spdy_server_list->Append(new base::StringValue(spdy_server_host_port)); | 144 spdy_server_list->Append(new base::StringValue(spdy_server_host_port)); |
138 ++count; | 145 ++count; |
139 } | 146 } |
140 } | 147 } |
141 } | 148 } |
142 | 149 |
143 // static | 150 // static |
144 std::string HttpServerPropertiesImpl::GetFlattenedSpdyServer( | 151 std::string HttpServerPropertiesImpl::GetFlattenedSpdyServer( |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 | 220 |
214 bool HttpServerPropertiesImpl::HasAlternateProtocol( | 221 bool HttpServerPropertiesImpl::HasAlternateProtocol( |
215 const HostPortPair& server) { | 222 const HostPortPair& server) { |
216 if (alternate_protocol_map_.Get(server) != alternate_protocol_map_.end() || | 223 if (alternate_protocol_map_.Get(server) != alternate_protocol_map_.end() || |
217 g_forced_alternate_protocol) | 224 g_forced_alternate_protocol) |
218 return true; | 225 return true; |
219 | 226 |
220 return GetCanonicalHost(server) != canonical_host_to_origin_map_.end(); | 227 return GetCanonicalHost(server) != canonical_host_to_origin_map_.end(); |
221 } | 228 } |
222 | 229 |
223 PortAlternateProtocolPair | 230 PortAlternateProtocolPair HttpServerPropertiesImpl::GetAlternateProtocol( |
224 HttpServerPropertiesImpl::GetAlternateProtocol( | |
225 const HostPortPair& server) { | 231 const HostPortPair& server) { |
226 DCHECK(HasAlternateProtocol(server)); | 232 DCHECK(HasAlternateProtocol(server)); |
227 | 233 |
228 // First check the map. | 234 // First check the map. |
229 AlternateProtocolMap::iterator it = alternate_protocol_map_.Get(server); | 235 AlternateProtocolMap::iterator it = alternate_protocol_map_.Get(server); |
230 if (it != alternate_protocol_map_.end()) | 236 if (it != alternate_protocol_map_.end()) |
231 return it->second; | 237 return it->second; |
232 | 238 |
233 // Next check the canonical host. | 239 // Next check the canonical host. |
234 CanonicalHostMap::const_iterator canonical_host = GetCanonicalHost(server); | 240 CanonicalHostMap::const_iterator canonical_host = GetCanonicalHost(server); |
(...skipping 26 matching lines...) Expand all Loading... |
261 return; | 267 return; |
262 } | 268 } |
263 | 269 |
264 if (alternate_protocol != ALTERNATE_PROTOCOL_BROKEN && | 270 if (alternate_protocol != ALTERNATE_PROTOCOL_BROKEN && |
265 !existing_alternate.Equals(alternate)) { | 271 !existing_alternate.Equals(alternate)) { |
266 LOG(WARNING) << "Changing the alternate protocol for: " | 272 LOG(WARNING) << "Changing the alternate protocol for: " |
267 << server.ToString() | 273 << server.ToString() |
268 << " from [Port: " << existing_alternate.port | 274 << " from [Port: " << existing_alternate.port |
269 << ", Protocol: " << existing_alternate.protocol | 275 << ", Protocol: " << existing_alternate.protocol |
270 << "] to [Port: " << alternate_port | 276 << "] to [Port: " << alternate_port |
271 << ", Protocol: " << alternate_protocol | 277 << ", Protocol: " << alternate_protocol << "]."; |
272 << "]."; | |
273 } | 278 } |
274 } else { | 279 } else { |
275 // TODO(rch): Consider the case where multiple requests are started | 280 // TODO(rch): Consider the case where multiple requests are started |
276 // before the first completes. In this case, only one of the jobs | 281 // before the first completes. In this case, only one of the jobs |
277 // would reach this code, whereas all of them should should have. | 282 // would reach this code, whereas all of them should should have. |
278 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_MAPPING_MISSING); | 283 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_MAPPING_MISSING); |
279 } | 284 } |
280 | 285 |
281 alternate_protocol_map_.Put(server, alternate); | 286 alternate_protocol_map_.Put(server, alternate); |
282 | 287 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 broken_alternate_protocol_map_.erase(server); | 333 broken_alternate_protocol_map_.erase(server); |
329 } | 334 } |
330 | 335 |
331 void HttpServerPropertiesImpl::ClearAlternateProtocol( | 336 void HttpServerPropertiesImpl::ClearAlternateProtocol( |
332 const HostPortPair& server) { | 337 const HostPortPair& server) { |
333 AlternateProtocolMap::iterator it = alternate_protocol_map_.Peek(server); | 338 AlternateProtocolMap::iterator it = alternate_protocol_map_.Peek(server); |
334 if (it != alternate_protocol_map_.end()) | 339 if (it != alternate_protocol_map_.end()) |
335 alternate_protocol_map_.Erase(it); | 340 alternate_protocol_map_.Erase(it); |
336 } | 341 } |
337 | 342 |
338 const AlternateProtocolMap& | 343 const AlternateProtocolMap& HttpServerPropertiesImpl::alternate_protocol_map() |
339 HttpServerPropertiesImpl::alternate_protocol_map() const { | 344 const { |
340 return alternate_protocol_map_; | 345 return alternate_protocol_map_; |
341 } | 346 } |
342 | 347 |
343 const SettingsMap& HttpServerPropertiesImpl::GetSpdySettings( | 348 const SettingsMap& HttpServerPropertiesImpl::GetSpdySettings( |
344 const HostPortPair& host_port_pair) { | 349 const HostPortPair& host_port_pair) { |
345 SpdySettingsMap::iterator it = spdy_settings_map_.Get(host_port_pair); | 350 SpdySettingsMap::iterator it = spdy_settings_map_.Get(host_port_pair); |
346 if (it == spdy_settings_map_.end()) { | 351 if (it == spdy_settings_map_.end()) { |
347 CR_DEFINE_STATIC_LOCAL(SettingsMap, kEmptySettingsMap, ()); | 352 CR_DEFINE_STATIC_LOCAL(SettingsMap, kEmptySettingsMap, ()); |
348 return kEmptySettingsMap; | 353 return kEmptySettingsMap; |
349 } | 354 } |
350 return it->second; | 355 return it->second; |
351 } | 356 } |
352 | 357 |
353 bool HttpServerPropertiesImpl::SetSpdySetting( | 358 bool HttpServerPropertiesImpl::SetSpdySetting( |
354 const HostPortPair& host_port_pair, | 359 const HostPortPair& host_port_pair, |
355 SpdySettingsIds id, | 360 SpdySettingsIds id, |
356 SpdySettingsFlags flags, | 361 SpdySettingsFlags flags, |
357 uint32 value) { | 362 uint32 value) { |
358 if (!(flags & SETTINGS_FLAG_PLEASE_PERSIST)) | 363 if (!(flags & SETTINGS_FLAG_PLEASE_PERSIST)) |
359 return false; | 364 return false; |
360 | 365 |
361 SettingsFlagsAndValue flags_and_value(SETTINGS_FLAG_PERSISTED, value); | 366 SettingsFlagsAndValue flags_and_value(SETTINGS_FLAG_PERSISTED, value); |
362 SpdySettingsMap::iterator it = spdy_settings_map_.Get(host_port_pair); | 367 SpdySettingsMap::iterator it = spdy_settings_map_.Get(host_port_pair); |
363 if (it == spdy_settings_map_.end()) { | 368 if (it == spdy_settings_map_.end()) { |
364 SettingsMap settings_map; | 369 SettingsMap settings_map; |
365 settings_map[id] = flags_and_value; | 370 settings_map[id] = flags_and_value; |
366 spdy_settings_map_.Put(host_port_pair, settings_map); | 371 spdy_settings_map_.Put(host_port_pair, settings_map); |
367 } else { | 372 } else { |
368 SettingsMap& settings_map = it->second; | 373 SettingsMap& settings_map = it->second; |
369 settings_map[id] = flags_and_value; | 374 settings_map[id] = flags_and_value; |
370 } | 375 } |
371 return true; | 376 return true; |
372 } | 377 } |
373 | 378 |
374 void HttpServerPropertiesImpl::ClearSpdySettings( | 379 void HttpServerPropertiesImpl::ClearSpdySettings( |
375 const HostPortPair& host_port_pair) { | 380 const HostPortPair& host_port_pair) { |
376 SpdySettingsMap::iterator it = spdy_settings_map_.Peek(host_port_pair); | 381 SpdySettingsMap::iterator it = spdy_settings_map_.Peek(host_port_pair); |
377 if (it != spdy_settings_map_.end()) | 382 if (it != spdy_settings_map_.end()) |
378 spdy_settings_map_.Erase(it); | 383 spdy_settings_map_.Erase(it); |
379 } | 384 } |
380 | 385 |
381 void HttpServerPropertiesImpl::ClearAllSpdySettings() { | 386 void HttpServerPropertiesImpl::ClearAllSpdySettings() { |
382 spdy_settings_map_.Clear(); | 387 spdy_settings_map_.Clear(); |
383 } | 388 } |
384 | 389 |
385 const SpdySettingsMap& | 390 const SpdySettingsMap& HttpServerPropertiesImpl::spdy_settings_map() const { |
386 HttpServerPropertiesImpl::spdy_settings_map() const { | |
387 return spdy_settings_map_; | 391 return spdy_settings_map_; |
388 } | 392 } |
389 | 393 |
390 void HttpServerPropertiesImpl::SetServerNetworkStats( | 394 void HttpServerPropertiesImpl::SetServerNetworkStats( |
391 const HostPortPair& host_port_pair, | 395 const HostPortPair& host_port_pair, |
392 NetworkStats stats) { | 396 NetworkStats stats) { |
393 server_network_stats_map_[host_port_pair] = stats; | 397 server_network_stats_map_[host_port_pair] = stats; |
394 } | 398 } |
395 | 399 |
396 const HttpServerProperties::NetworkStats* | 400 const HttpServerProperties::NetworkStats* |
(...skipping 12 matching lines...) Expand all Loading... |
409 HttpPipelinedHostCapability capability = PIPELINE_UNKNOWN; | 413 HttpPipelinedHostCapability capability = PIPELINE_UNKNOWN; |
410 CachedPipelineCapabilityMap::const_iterator it = | 414 CachedPipelineCapabilityMap::const_iterator it = |
411 pipeline_capability_map_->Get(origin); | 415 pipeline_capability_map_->Get(origin); |
412 if (it != pipeline_capability_map_->end()) { | 416 if (it != pipeline_capability_map_->end()) { |
413 capability = it->second; | 417 capability = it->second; |
414 } | 418 } |
415 return capability; | 419 return capability; |
416 } | 420 } |
417 | 421 |
418 void HttpServerPropertiesImpl::SetPipelineCapability( | 422 void HttpServerPropertiesImpl::SetPipelineCapability( |
419 const HostPortPair& origin, | 423 const HostPortPair& origin, |
420 HttpPipelinedHostCapability capability) { | 424 HttpPipelinedHostCapability capability) { |
421 CachedPipelineCapabilityMap::iterator it = | 425 CachedPipelineCapabilityMap::iterator it = |
422 pipeline_capability_map_->Peek(origin); | 426 pipeline_capability_map_->Peek(origin); |
423 if (it == pipeline_capability_map_->end() || | 427 if (it == pipeline_capability_map_->end() || |
424 it->second != PIPELINE_INCAPABLE) { | 428 it->second != PIPELINE_INCAPABLE) { |
425 pipeline_capability_map_->Put(origin, capability); | 429 pipeline_capability_map_->Put(origin, capability); |
426 } | 430 } |
427 } | 431 } |
428 | 432 |
429 void HttpServerPropertiesImpl::ClearPipelineCapabilities() { | 433 void HttpServerPropertiesImpl::ClearPipelineCapabilities() { |
430 pipeline_capability_map_->Clear(); | 434 pipeline_capability_map_->Clear(); |
431 } | 435 } |
432 | 436 |
433 PipelineCapabilityMap | 437 PipelineCapabilityMap HttpServerPropertiesImpl::GetPipelineCapabilityMap() |
434 HttpServerPropertiesImpl::GetPipelineCapabilityMap() const { | 438 const { |
435 PipelineCapabilityMap result; | 439 PipelineCapabilityMap result; |
436 CachedPipelineCapabilityMap::const_iterator it; | 440 CachedPipelineCapabilityMap::const_iterator it; |
437 for (it = pipeline_capability_map_->begin(); | 441 for (it = pipeline_capability_map_->begin(); |
438 it != pipeline_capability_map_->end(); ++it) { | 442 it != pipeline_capability_map_->end(); |
| 443 ++it) { |
439 result[it->first] = it->second; | 444 result[it->first] = it->second; |
440 } | 445 } |
441 return result; | 446 return result; |
442 } | 447 } |
443 | 448 |
444 HttpServerPropertiesImpl::CanonicalHostMap::const_iterator | 449 HttpServerPropertiesImpl::CanonicalHostMap::const_iterator |
445 HttpServerPropertiesImpl::GetCanonicalHost(HostPortPair server) const { | 450 HttpServerPropertiesImpl::GetCanonicalHost(HostPortPair server) const { |
446 for (size_t i = 0; i < canoncial_suffixes_.size(); ++i) { | 451 for (size_t i = 0; i < canoncial_suffixes_.size(); ++i) { |
447 std::string canonical_suffix = canoncial_suffixes_[i]; | 452 std::string canonical_suffix = canoncial_suffixes_[i]; |
448 if (EndsWith(server.host(), canoncial_suffixes_[i], false)) { | 453 if (EndsWith(server.host(), canoncial_suffixes_[i], false)) { |
(...skipping 30 matching lines...) Expand all Loading... |
479 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); | 484 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
480 base::MessageLoop::current()->PostDelayedTask( | 485 base::MessageLoop::current()->PostDelayedTask( |
481 FROM_HERE, | 486 FROM_HERE, |
482 base::Bind( | 487 base::Bind( |
483 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 488 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
484 weak_ptr_factory_.GetWeakPtr()), | 489 weak_ptr_factory_.GetWeakPtr()), |
485 delay); | 490 delay); |
486 } | 491 } |
487 | 492 |
488 } // namespace net | 493 } // namespace net |
OLD | NEW |