| 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/spdy/spdy_session_pool.h" | 5 #include "net/spdy/spdy_session_pool.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/stringprintf.h" |
| 9 #include "base/values.h" | 10 #include "base/values.h" |
| 10 #include "net/base/address_list.h" | 11 #include "net/base/address_list.h" |
| 11 #include "net/base/sys_addrinfo.h" | 12 #include "net/base/sys_addrinfo.h" |
| 12 #include "net/http/http_network_session.h" | 13 #include "net/http/http_network_session.h" |
| 13 #include "net/spdy/spdy_session.h" | 14 #include "net/spdy/spdy_session.h" |
| 14 | 15 |
| 15 | 16 |
| 16 namespace net { | 17 namespace net { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 33 } | 34 } |
| 34 | 35 |
| 35 // The maximum number of sessions to open to a single domain. | 36 // The maximum number of sessions to open to a single domain. |
| 36 static const size_t kMaxSessionsPerDomain = 1; | 37 static const size_t kMaxSessionsPerDomain = 1; |
| 37 | 38 |
| 38 size_t SpdySessionPool::g_max_sessions_per_domain = kMaxSessionsPerDomain; | 39 size_t SpdySessionPool::g_max_sessions_per_domain = kMaxSessionsPerDomain; |
| 39 bool SpdySessionPool::g_force_single_domain = false; | 40 bool SpdySessionPool::g_force_single_domain = false; |
| 40 bool SpdySessionPool::g_enable_ip_pooling = true; | 41 bool SpdySessionPool::g_enable_ip_pooling = true; |
| 41 | 42 |
| 42 SpdySessionPool::SpdySessionPool(HostResolver* resolver, | 43 SpdySessionPool::SpdySessionPool(HostResolver* resolver, |
| 44 SpdyConfigService* spdy_config_service, |
| 43 SSLConfigService* ssl_config_service) | 45 SSLConfigService* ssl_config_service) |
| 44 : ssl_config_service_(ssl_config_service), | 46 : spdy_config_service_(spdy_config_service), |
| 47 ssl_config_service_(ssl_config_service), |
| 45 resolver_(resolver), | 48 resolver_(resolver), |
| 46 verify_domain_authentication_(true) { | 49 verify_domain_authentication_(true) { |
| 47 NetworkChangeNotifier::AddIPAddressObserver(this); | 50 NetworkChangeNotifier::AddIPAddressObserver(this); |
| 48 if (ssl_config_service_) | 51 if (ssl_config_service_) |
| 49 ssl_config_service_->AddObserver(this); | 52 ssl_config_service_->AddObserver(this); |
| 50 CertDatabase::AddObserver(this); | 53 CertDatabase::AddObserver(this); |
| 51 } | 54 } |
| 52 | 55 |
| 53 SpdySessionPool::~SpdySessionPool() { | 56 SpdySessionPool::~SpdySessionPool() { |
| 54 CloseAllSessions(); | 57 CloseAllSessions(); |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 return rv == OK; | 352 return rv == OK; |
| 350 } | 353 } |
| 351 | 354 |
| 352 void SpdySessionPool::AddAlias(const addrinfo* address, | 355 void SpdySessionPool::AddAlias(const addrinfo* address, |
| 353 const HostPortProxyPair& pair) { | 356 const HostPortProxyPair& pair) { |
| 354 DCHECK(g_enable_ip_pooling); | 357 DCHECK(g_enable_ip_pooling); |
| 355 DCHECK(address); | 358 DCHECK(address); |
| 356 IPEndPoint endpoint; | 359 IPEndPoint endpoint; |
| 357 endpoint.FromSockAddr(address->ai_addr, address->ai_addrlen); | 360 endpoint.FromSockAddr(address->ai_addr, address->ai_addrlen); |
| 358 aliases_[endpoint] = pair; | 361 aliases_[endpoint] = pair; |
| 362 |
| 363 // Walk the aliases map and persist the spdy server names. |
| 364 if (spdy_config_service_) { |
| 365 std::string spdy_server; |
| 366 const HostPortPair& host_port_pair = pair.first; |
| 367 spdy_server.append(host_port_pair.host()); |
| 368 spdy_server.append(":"); |
| 369 base::StringAppendF(&spdy_server, "%d", host_port_pair.port()); |
| 370 spdy_server.append(";"); |
| 371 spdy_config_service_->AddSpdyServer(spdy_server); |
| 372 } |
| 359 } | 373 } |
| 360 | 374 |
| 361 void SpdySessionPool::RemoveAliases(const HostPortProxyPair& pair) { | 375 void SpdySessionPool::RemoveAliases(const HostPortProxyPair& pair) { |
| 362 // Walk the aliases map, find references to this pair. | 376 // Walk the aliases map, find references to this pair. |
| 363 // TODO(mbelshe): Figure out if this is too expensive. | 377 // TODO(mbelshe): Figure out if this is too expensive. |
| 364 SpdyAliasMap::iterator alias_it = aliases_.begin(); | 378 SpdyAliasMap::iterator alias_it = aliases_.begin(); |
| 365 while (alias_it != aliases_.end()) { | 379 while (alias_it != aliases_.end()) { |
| 366 if (HostPortProxyPairsAreEqual(alias_it->second, pair)) { | 380 if (HostPortProxyPairsAreEqual(alias_it->second, pair)) { |
| 367 aliases_.erase(alias_it); | 381 aliases_.erase(alias_it); |
| 368 alias_it = aliases_.begin(); // Iterator was invalidated. | 382 alias_it = aliases_.begin(); // Iterator was invalidated. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 delete list; | 421 delete list; |
| 408 RemoveAliases(old_map.begin()->first); | 422 RemoveAliases(old_map.begin()->first); |
| 409 old_map.erase(old_map.begin()->first); | 423 old_map.erase(old_map.begin()->first); |
| 410 } | 424 } |
| 411 } | 425 } |
| 412 DCHECK(sessions_.empty()); | 426 DCHECK(sessions_.empty()); |
| 413 DCHECK(aliases_.empty()); | 427 DCHECK(aliases_.empty()); |
| 414 } | 428 } |
| 415 | 429 |
| 416 } // namespace net | 430 } // namespace net |
| OLD | NEW |