OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/quic/crypto/quic_crypto_client_config.h" | 5 #include "net/quic/crypto/quic_crypto_client_config.h" |
6 | 6 |
7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "net/quic/crypto/cert_compressor.h" | 8 #include "net/quic/crypto/cert_compressor.h" |
9 #include "net/quic/crypto/channel_id.h" | 9 #include "net/quic/crypto/channel_id.h" |
10 #include "net/quic/crypto/common_cert_set.h" | 10 #include "net/quic/crypto/common_cert_set.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "base/win/windows_version.h" | 22 #include "base/win/windows_version.h" |
23 #endif | 23 #endif |
24 | 24 |
25 using base::StringPiece; | 25 using base::StringPiece; |
26 using std::map; | 26 using std::map; |
27 using std::string; | 27 using std::string; |
28 using std::vector; | 28 using std::vector; |
29 | 29 |
30 namespace net { | 30 namespace net { |
31 | 31 |
32 QuicCryptoClientConfig::QuicCryptoClientConfig() | 32 QuicCryptoClientConfig::QuicCryptoClientConfig() { |
33 : quic_server_info_factory_(NULL) { | |
34 } | 33 } |
35 | 34 |
36 QuicCryptoClientConfig::QuicCryptoClientConfig( | 35 QuicCryptoClientConfig::QuicCryptoClientConfig( |
37 QuicServerInfoFactory* quic_server_info_factory) | 36 scoped_ptr<QuicServerInfo> quic_server_info) |
38 : quic_server_info_factory_(quic_server_info_factory) { | 37 : quic_server_info_(quic_server_info.Pass()) { |
39 } | 38 } |
40 | 39 |
41 QuicCryptoClientConfig::~QuicCryptoClientConfig() { | 40 QuicCryptoClientConfig::~QuicCryptoClientConfig() { |
42 STLDeleteValues(&cached_states_); | 41 STLDeleteValues(&cached_states_); |
43 } | 42 } |
44 | 43 |
45 QuicCryptoClientConfig::CachedState::CachedState() | 44 QuicCryptoClientConfig::CachedState::CachedState() |
46 : server_config_valid_(false), | 45 : server_config_valid_(false), |
47 generation_counter_(0) {} | 46 generation_counter_(0) {} |
48 | 47 |
| 48 QuicCryptoClientConfig::CachedState::CachedState( |
| 49 scoped_ptr<QuicServerInfo> quic_server_info) |
| 50 : server_config_valid_(false), |
| 51 generation_counter_(0), |
| 52 quic_server_info_(quic_server_info.Pass()) {} |
| 53 |
49 QuicCryptoClientConfig::CachedState::~CachedState() {} | 54 QuicCryptoClientConfig::CachedState::~CachedState() {} |
50 | 55 |
51 void QuicCryptoClientConfig::CachedState::LoadFromDiskCache( | |
52 QuicServerInfoFactory* quic_server_info_factory, | |
53 const string& server_hostname) { | |
54 DCHECK(quic_server_info_factory); | |
55 quic_server_info_.reset( | |
56 quic_server_info_factory->GetForHost(server_hostname)); | |
57 | |
58 // TODO(rtenneti): Need to flesh out reading data from disk cache. | |
59 } | |
60 | |
61 bool QuicCryptoClientConfig::CachedState::IsComplete(QuicWallTime now) const { | 56 bool QuicCryptoClientConfig::CachedState::IsComplete(QuicWallTime now) const { |
62 if (server_config_.empty() || !server_config_valid_) { | 57 if (server_config_.empty() || !server_config_valid_) { |
63 return false; | 58 return false; |
64 } | 59 } |
65 | 60 |
66 const CryptoHandshakeMessage* scfg = GetServerConfig(); | 61 const CryptoHandshakeMessage* scfg = GetServerConfig(); |
67 if (!scfg) { | 62 if (!scfg) { |
68 // Should be impossible short of cache corruption. | 63 // Should be impossible short of cache corruption. |
69 DCHECK(false); | 64 DCHECK(false); |
70 return false; | 65 return false; |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 } | 235 } |
241 | 236 |
242 QuicCryptoClientConfig::CachedState* QuicCryptoClientConfig::LookupOrCreate( | 237 QuicCryptoClientConfig::CachedState* QuicCryptoClientConfig::LookupOrCreate( |
243 const string& server_hostname) { | 238 const string& server_hostname) { |
244 map<string, CachedState*>::const_iterator it = | 239 map<string, CachedState*>::const_iterator it = |
245 cached_states_.find(server_hostname); | 240 cached_states_.find(server_hostname); |
246 if (it != cached_states_.end()) { | 241 if (it != cached_states_.end()) { |
247 return it->second; | 242 return it->second; |
248 } | 243 } |
249 | 244 |
250 CachedState* cached = new CachedState; | 245 CachedState* cached = new CachedState(quic_server_info_.Pass()); |
251 if (quic_server_info_factory_) { | |
252 cached->LoadFromDiskCache(quic_server_info_factory_, server_hostname); | |
253 } | |
254 cached_states_.insert(make_pair(server_hostname, cached)); | 246 cached_states_.insert(make_pair(server_hostname, cached)); |
255 return cached; | 247 return cached; |
256 } | 248 } |
257 | 249 |
258 void QuicCryptoClientConfig::FillInchoateClientHello( | 250 void QuicCryptoClientConfig::FillInchoateClientHello( |
259 const string& server_hostname, | 251 const string& server_hostname, |
260 const QuicVersion preferred_version, | 252 const QuicVersion preferred_version, |
261 const CachedState* cached, | 253 const CachedState* cached, |
262 QuicCryptoNegotiatedParameters* out_params, | 254 QuicCryptoNegotiatedParameters* out_params, |
263 CryptoHandshakeMessage* out) const { | 255 CryptoHandshakeMessage* out) const { |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 CachedState* canonical_cached = | 659 CachedState* canonical_cached = |
668 canonical_crypto_config->LookupOrCreate(canonical_server_hostname); | 660 canonical_crypto_config->LookupOrCreate(canonical_server_hostname); |
669 if (!canonical_cached->proof_valid()) { | 661 if (!canonical_cached->proof_valid()) { |
670 return; | 662 return; |
671 } | 663 } |
672 CachedState* cached = LookupOrCreate(server_hostname); | 664 CachedState* cached = LookupOrCreate(server_hostname); |
673 cached->InitializeFrom(*canonical_cached); | 665 cached->InitializeFrom(*canonical_cached); |
674 } | 666 } |
675 | 667 |
676 } // namespace net | 668 } // namespace net |
OLD | NEW |