Uniquify QuicCryptoServerConfig::Add[Default]Config gfe-relnote: Use unique_ptr for memory management rather than bare pointer. No functional change intended, not flag-protected. PiperOrigin-RevId: 238574036 Change-Id: I0bb803fb9d68925ecbfdf113ba70335a66b3f099
diff --git a/quic/core/crypto/crypto_server_test.cc b/quic/core/crypto/crypto_server_test.cc index d654c4a..3b5a8f6 100644 --- a/quic/core/crypto/crypto_server_test.cc +++ b/quic/core/crypto/crypto_server_test.cc
@@ -133,7 +133,7 @@ void SetUp() override { QuicCryptoServerConfig::ConfigOptions old_config_options; old_config_options.id = kOldConfigId; - delete config_.AddDefaultConfig(rand_, &clock_, old_config_options); + config_.AddDefaultConfig(rand_, &clock_, old_config_options); clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1000)); std::unique_ptr<QuicServerConfigProtobuf> primary_config( config_.GenerateConfig(rand_, &clock_, config_options_));
diff --git a/quic/core/crypto/quic_crypto_server_config.cc b/quic/core/crypto/quic_crypto_server_config.cc index e1386b4..ccb7691 100644 --- a/quic/core/crypto/quic_crypto_server_config.cc +++ b/quic/core/crypto/quic_crypto_server_config.cc
@@ -340,11 +340,11 @@ return config; } -CryptoHandshakeMessage* QuicCryptoServerConfig::AddConfig( +std::unique_ptr<CryptoHandshakeMessage> QuicCryptoServerConfig::AddConfig( std::unique_ptr<QuicServerConfigProtobuf> protobuf, const QuicWallTime now) { - std::unique_ptr<CryptoHandshakeMessage> msg( - CryptoFramer::ParseMessage(protobuf->config())); + std::unique_ptr<CryptoHandshakeMessage> msg = + CryptoFramer::ParseMessage(protobuf->config()); if (!msg.get()) { QUIC_LOG(WARNING) << "Failed to parse server config message"; @@ -373,13 +373,13 @@ primary_config_.get()); } - return msg.release(); + return msg; } -CryptoHandshakeMessage* QuicCryptoServerConfig::AddDefaultConfig( - QuicRandom* rand, - const QuicClock* clock, - const ConfigOptions& options) { +std::unique_ptr<CryptoHandshakeMessage> +QuicCryptoServerConfig::AddDefaultConfig(QuicRandom* rand, + const QuicClock* clock, + const ConfigOptions& options) { return AddConfig(GenerateConfig(rand, clock, options), clock->WallNow()); }
diff --git a/quic/core/crypto/quic_crypto_server_config.h b/quic/core/crypto/quic_crypto_server_config.h index 546b0e7..fc05fb3 100644 --- a/quic/core/crypto/quic_crypto_server_config.h +++ b/quic/core/crypto/quic_crypto_server_config.h
@@ -209,8 +209,8 @@ // |server_nonce_entropy|: an entropy source used to generate the orbit and // key for server nonces, which are always local to a given instance of a // server. Not owned. - // |proof_source|: provides certificate chains and signatures. This class - // takes ownership of |proof_source|. + // |proof_source|: provides certificate chains and signatures. + // |key_exchange_source|: provides key-exchange functionality. // |ssl_ctx|: The SSL_CTX used for doing TLS handshakes. QuicCryptoServerConfig(QuicStringPiece source_address_token_secret, QuicRandom* server_nonce_entropy, @@ -232,20 +232,20 @@ const ConfigOptions& options); // AddConfig adds a QuicServerConfigProtobuf to the available configurations. - // It returns the SCFG message from the config if successful. The caller - // takes ownership of the CryptoHandshakeMessage. |now| is used in + // It returns the SCFG message from the config if successful. |now| is used in // conjunction with |protobuf->primary_time()| to determine whether the // config should be made primary. - CryptoHandshakeMessage* AddConfig( + std::unique_ptr<CryptoHandshakeMessage> AddConfig( std::unique_ptr<QuicServerConfigProtobuf> protobuf, QuicWallTime now); // AddDefaultConfig calls DefaultConfig to create a config and then calls // AddConfig to add it. See the comment for |DefaultConfig| for details of // the arguments. - CryptoHandshakeMessage* AddDefaultConfig(QuicRandom* rand, - const QuicClock* clock, - const ConfigOptions& options); + std::unique_ptr<CryptoHandshakeMessage> AddDefaultConfig( + QuicRandom* rand, + const QuicClock* clock, + const ConfigOptions& options); // SetConfigs takes a vector of config protobufs and the current time. // Configs are assumed to be uniquely identified by their server config ID.
diff --git a/quic/core/crypto/quic_crypto_server_config_test.cc b/quic/core/crypto/quic_crypto_server_config_test.cc index 7f9c3fe..f8e4861 100644 --- a/quic/core/crypto/quic_crypto_server_config_test.cc +++ b/quic/core/crypto/quic_crypto_server_config_test.cc
@@ -158,8 +158,8 @@ clock_.AdvanceTime(QuicTime::Delta::FromSeconds(1000000)); original_time_ = clock_.WallNow(); - primary_config_.reset(server_.AddDefaultConfig( - rand_, &clock_, QuicCryptoServerConfig::ConfigOptions())); + primary_config_ = server_.AddDefaultConfig( + rand_, &clock_, QuicCryptoServerConfig::ConfigOptions()); } std::string NewSourceAddressToken(std::string config_id,
diff --git a/quic/core/http/quic_server_session_base_test.cc b/quic/core/http/quic_server_session_base_test.cc index a6fb4e2..ed375fa 100644 --- a/quic/core/http/quic_server_session_base_test.cc +++ b/quic/core/http/quic_server_session_base_test.cc
@@ -147,9 +147,9 @@ config_, connection_, &owner_, &stream_helper_, &crypto_config_, &compressed_certs_cache_, &memory_cache_backend_); MockClock clock; - handshake_message_.reset(crypto_config_.AddDefaultConfig( + handshake_message_ = crypto_config_.AddDefaultConfig( QuicRandom::GetInstance(), &clock, - QuicCryptoServerConfig::ConfigOptions())); + QuicCryptoServerConfig::ConfigOptions()); session_->Initialize(); QuicSessionPeer::GetMutableCryptoStream(session_.get()) ->OnSuccessfulVersionNegotiation(supported_versions.front());