Commit 60cf50e0 authored by rtenneti@chromium.org's avatar rtenneti@chromium.org

QUIC - Minor clean up of QUIC Server Info memory cache.

R=wtc@chromium.org

Review URL: https://codereview.chromium.org/255783002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266684 0039d316-1c4b-4281-b951-d872f2087c98
parent 4d20337d
...@@ -899,16 +899,16 @@ void BrowsingDataRemover::DoClearCache(int rv) { ...@@ -899,16 +899,16 @@ void BrowsingDataRemover::DoClearCache(int rv) {
(next_cache_state_ == STATE_CREATE_MAIN) (next_cache_state_ == STATE_CREATE_MAIN)
? main_context_getter_.get() ? main_context_getter_.get()
: media_context_getter_.get(); : media_context_getter_.get();
net::HttpTransactionFactory* factory = net::HttpCache* http_cache =
getter->GetURLRequestContext()->http_transaction_factory(); getter->GetURLRequestContext()->http_transaction_factory()->
GetCache();
// Clear QUIC server information from memory.
net::HttpCache* http_cache = factory->GetCache();
http_cache->GetSession()->quic_stream_factory()->ClearCachedStates();
next_cache_state_ = (next_cache_state_ == STATE_CREATE_MAIN) ? next_cache_state_ = (next_cache_state_ == STATE_CREATE_MAIN) ?
STATE_DELETE_MAIN : STATE_DELETE_MEDIA; STATE_DELETE_MAIN : STATE_DELETE_MEDIA;
// Clear QUIC server information from memory and the disk cache.
http_cache->GetSession()->quic_stream_factory()->
ClearCachedStatesInCryptoConfig();
rv = http_cache->GetBackend( rv = http_cache->GetBackend(
&cache_, base::Bind(&BrowsingDataRemover::DoClearCache, &cache_, base::Bind(&BrowsingDataRemover::DoClearCache,
base::Unretained(this))); base::Unretained(this)));
......
...@@ -149,6 +149,17 @@ void QuicCryptoClientConfig::CachedState::SetProof(const vector<string>& certs, ...@@ -149,6 +149,17 @@ void QuicCryptoClientConfig::CachedState::SetProof(const vector<string>& certs,
server_config_sig_ = signature.as_string(); server_config_sig_ = signature.as_string();
} }
void QuicCryptoClientConfig::CachedState::Clear() {
server_config_.clear();
source_address_token_.clear();
certs_.clear();
server_config_sig_.clear();
server_config_valid_ = false;
proof_verify_details_.reset();
scfg_.reset();
++generation_counter_;
}
void QuicCryptoClientConfig::CachedState::ClearProof() { void QuicCryptoClientConfig::CachedState::ClearProof() {
SetProofInvalid(); SetProofInvalid();
certs_.clear(); certs_.clear();
...@@ -274,9 +285,7 @@ QuicCryptoClientConfig::CachedState* QuicCryptoClientConfig::LookupOrCreate( ...@@ -274,9 +285,7 @@ QuicCryptoClientConfig::CachedState* QuicCryptoClientConfig::LookupOrCreate(
void QuicCryptoClientConfig::ClearCachedStates() { void QuicCryptoClientConfig::ClearCachedStates() {
for (CachedStateMap::const_iterator it = cached_states_.begin(); for (CachedStateMap::const_iterator it = cached_states_.begin();
it != cached_states_.end(); ++it) { it != cached_states_.end(); ++it) {
CachedState* cached = it->second; it->second->Clear();
cached->ClearProof();
cached->InvalidateServerConfig();
} }
} }
......
...@@ -64,6 +64,9 @@ class NET_EXPORT_PRIVATE QuicCryptoClientConfig : public QuicCryptoConfig { ...@@ -64,6 +64,9 @@ class NET_EXPORT_PRIVATE QuicCryptoClientConfig : public QuicCryptoConfig {
void SetProof(const std::vector<std::string>& certs, void SetProof(const std::vector<std::string>& certs,
base::StringPiece signature); base::StringPiece signature);
// Clears all the data.
void Clear();
// Clears the certificate chain and signature and invalidates the proof. // Clears the certificate chain and signature and invalidates the proof.
void ClearProof(); void ClearProof();
......
...@@ -229,43 +229,35 @@ TEST(QuicCryptoClientConfigTest, CanonicalNotUsedIfNotValid) { ...@@ -229,43 +229,35 @@ TEST(QuicCryptoClientConfigTest, CanonicalNotUsedIfNotValid) {
TEST(QuicCryptoClientConfigTest, ClearCachedStates) { TEST(QuicCryptoClientConfigTest, ClearCachedStates) {
QuicCryptoClientConfig config; QuicCryptoClientConfig config;
QuicServerId canonical_server_id("www.google.com", 80, false, QuicServerId server_id("www.google.com", 80, false, PRIVACY_MODE_DISABLED);
PRIVACY_MODE_DISABLED); QuicCryptoClientConfig::CachedState* state = config.LookupOrCreate(server_id);
QuicCryptoClientConfig::CachedState* state =
config.LookupOrCreate(canonical_server_id);
// TODO(rch): Populate other fields of |state|. // TODO(rch): Populate other fields of |state|.
vector<string> certs(1); vector<string> certs(1);
certs[0] = "Hello Cert"; certs[0] = "Hello Cert";
state->SetProof(certs, "signature"); state->SetProof(certs, "signature");
state->set_source_address_token("TOKEN"); state->set_source_address_token("TOKEN");
state->SetProofValid(); state->SetProofValid();
EXPECT_EQ(1u, state->generation_counter());
// Verify LookupOrCreate returns the same data. // Verify LookupOrCreate returns the same data.
QuicServerId other_server_id("www.google.com", 80, false, QuicCryptoClientConfig::CachedState* other = config.LookupOrCreate(server_id);
PRIVACY_MODE_DISABLED);
QuicCryptoClientConfig::CachedState* other = EXPECT_EQ(state, other);
config.LookupOrCreate(other_server_id);
EXPECT_TRUE(other->proof_valid());
EXPECT_EQ(state->server_config(), other->server_config());
EXPECT_EQ(state->signature(), other->signature());
EXPECT_EQ(state->certs(), other->certs());
EXPECT_EQ(state->source_address_token(), other->source_address_token());
EXPECT_EQ(1u, other->generation_counter()); EXPECT_EQ(1u, other->generation_counter());
// Clear the cached state. // Clear the cached states.
config.ClearCachedStates(); config.ClearCachedStates();
// Verify LookupOrCreate doesn't have any data. // Verify LookupOrCreate doesn't have any data.
QuicCryptoClientConfig::CachedState* cleared_cache = QuicCryptoClientConfig::CachedState* cleared_cache =
config.LookupOrCreate(other_server_id); config.LookupOrCreate(server_id);
EXPECT_EQ(state, cleared_cache);
EXPECT_FALSE(cleared_cache->proof_valid()); EXPECT_FALSE(cleared_cache->proof_valid());
EXPECT_TRUE(cleared_cache->server_config().empty()); EXPECT_TRUE(cleared_cache->server_config().empty());
EXPECT_TRUE(cleared_cache->certs().empty()); EXPECT_TRUE(cleared_cache->certs().empty());
EXPECT_TRUE(cleared_cache->signature().empty()); EXPECT_TRUE(cleared_cache->signature().empty());
EXPECT_LT(1u, cleared_cache->generation_counter()); EXPECT_EQ(2u, cleared_cache->generation_counter());
} }
} // namespace test } // namespace test
......
...@@ -648,7 +648,7 @@ base::Value* QuicStreamFactory::QuicStreamFactoryInfoToValue() const { ...@@ -648,7 +648,7 @@ base::Value* QuicStreamFactory::QuicStreamFactoryInfoToValue() const {
return list; return list;
} }
void QuicStreamFactory::ClearCachedStates() { void QuicStreamFactory::ClearCachedStatesInCryptoConfig() {
crypto_config_.ClearCachedStates(); crypto_config_.ClearCachedStates();
} }
...@@ -754,7 +754,7 @@ int QuicStreamFactory::CreateSession( ...@@ -754,7 +754,7 @@ int QuicStreamFactory::CreateSession(
writer->SetConnection(connection); writer->SetConnection(connection);
connection->options()->max_packet_length = max_packet_length_; connection->options()->max_packet_length = max_packet_length_;
InitializeCachedState(server_id, server_info); InitializeCachedStateInCryptoConfig(server_id, server_info);
QuicConfig config = config_; QuicConfig config = config_;
if (http_server_properties_) { if (http_server_properties_) {
...@@ -790,7 +790,7 @@ void QuicStreamFactory::ActivateSession( ...@@ -790,7 +790,7 @@ void QuicStreamFactory::ActivateSession(
ip_aliases_[ip_alias_key].insert(session); ip_aliases_[ip_alias_key].insert(session);
} }
void QuicStreamFactory::InitializeCachedState( void QuicStreamFactory::InitializeCachedStateInCryptoConfig(
const QuicServerId& server_id, const QuicServerId& server_id,
const scoped_ptr<QuicServerInfo>& server_info) { const scoped_ptr<QuicServerInfo>& server_info) {
if (!server_info) if (!server_info)
......
...@@ -133,7 +133,7 @@ class NET_EXPORT_PRIVATE QuicStreamFactory ...@@ -133,7 +133,7 @@ class NET_EXPORT_PRIVATE QuicStreamFactory
base::Value* QuicStreamFactoryInfoToValue() const; base::Value* QuicStreamFactoryInfoToValue() const;
// Delete all cached state objects in |crypto_config_|. // Delete all cached state objects in |crypto_config_|.
void ClearCachedStates(); void ClearCachedStatesInCryptoConfig();
// NetworkChangeNotifier::IPAddressObserver methods: // NetworkChangeNotifier::IPAddressObserver methods:
...@@ -215,8 +215,9 @@ class NET_EXPORT_PRIVATE QuicStreamFactory ...@@ -215,8 +215,9 @@ class NET_EXPORT_PRIVATE QuicStreamFactory
// Initializes the cached state associated with |server_id| in // Initializes the cached state associated with |server_id| in
// |crypto_config_| with the information in |server_info|. // |crypto_config_| with the information in |server_info|.
void InitializeCachedState(const QuicServerId& server_id, void InitializeCachedStateInCryptoConfig(
const scoped_ptr<QuicServerInfo>& server_info); const QuicServerId& server_id,
const scoped_ptr<QuicServerInfo>& server_info);
bool require_confirmation_; bool require_confirmation_;
HostResolver* host_resolver_; HostResolver* host_resolver_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment