Uniquify ChannelIDSource handling

gfe-relnote: Use unique_ptr for memory management rather than bare pointer. No functional change intended, not flag-protected.
PiperOrigin-RevId: 238496581
Change-Id: Ic0c57d6419bc30db89e803cb92d84cbdf1bea5c6
diff --git a/quic/core/crypto/quic_crypto_client_config.cc b/quic/core/crypto/quic_crypto_client_config.cc
index 4400fea..3da127a 100644
--- a/quic/core/crypto/quic_crypto_client_config.cc
+++ b/quic/core/crypto/quic_crypto_client_config.cc
@@ -959,8 +959,9 @@
   return ssl_ctx_.get();
 }
 
-void QuicCryptoClientConfig::SetChannelIDSource(ChannelIDSource* source) {
-  channel_id_source_.reset(source);
+void QuicCryptoClientConfig::SetChannelIDSource(
+    std::unique_ptr<ChannelIDSource> source) {
+  channel_id_source_ = std::move(source);
 }
 
 void QuicCryptoClientConfig::InitializeFrom(
diff --git a/quic/core/crypto/quic_crypto_client_config.h b/quic/core/crypto/quic_crypto_client_config.h
index c50c97d..d4b7150 100644
--- a/quic/core/crypto/quic_crypto_client_config.h
+++ b/quic/core/crypto/quic_crypto_client_config.h
@@ -318,9 +318,8 @@
 
   // SetChannelIDSource sets a ChannelIDSource that will be called, when the
   // server supports channel IDs, to obtain a channel ID for signing a message
-  // proving possession of the channel ID. This object takes ownership of
-  // |source|.
-  void SetChannelIDSource(ChannelIDSource* source);
+  // proving possession of the channel ID.
+  void SetChannelIDSource(std::unique_ptr<ChannelIDSource> source);
 
   // Initialize the CachedState from |canonical_crypto_config| for the
   // |canonical_server_id| as the initial CachedState for |server_id|. We will
diff --git a/quic/test_tools/crypto_test_utils.cc b/quic/test_tools/crypto_test_utils.cc
index f20878f..78bbc4e 100644
--- a/quic/test_tools/crypto_test_utils.cc
+++ b/quic/test_tools/crypto_test_utils.cc
@@ -211,9 +211,10 @@
 // argument to GetChannelIDKey is nullptr.
 class AsyncTestChannelIDSource : public ChannelIDSource, public CallbackSource {
  public:
-  // Takes ownership of |sync_source|, a synchronous ChannelIDSource.
-  explicit AsyncTestChannelIDSource(ChannelIDSource* sync_source)
-      : sync_source_(sync_source) {}
+  // |sync_source| is a synchronous ChannelIDSource.
+  explicit AsyncTestChannelIDSource(
+      std::unique_ptr<ChannelIDSource> sync_source)
+      : sync_source_(std::move(sync_source)) {}
   ~AsyncTestChannelIDSource() override {}
 
   // ChannelIDSource implementation.
@@ -447,12 +448,13 @@
                                        TlsClientHandshaker::CreateSslCtx());
   AsyncTestChannelIDSource* async_channel_id_source = nullptr;
   if (options.channel_id_enabled) {
-    ChannelIDSource* source = ChannelIDSourceForTesting();
+    std::unique_ptr<ChannelIDSource> source = ChannelIDSourceForTesting();
     if (options.channel_id_source_async) {
-      async_channel_id_source = new AsyncTestChannelIDSource(source);
-      source = async_channel_id_source;
+      auto temp = QuicMakeUnique<AsyncTestChannelIDSource>(std::move(source));
+      async_channel_id_source = temp.get();
+      source = std::move(temp);
     }
-    crypto_config.SetChannelIDSource(source);
+    crypto_config.SetChannelIDSource(std::move(source));
   }
   if (!options.token_binding_params.empty()) {
     crypto_config.tb_key_params = options.token_binding_params;
@@ -919,8 +921,8 @@
   return *parsed;
 }
 
-ChannelIDSource* ChannelIDSourceForTesting() {
-  return new TestChannelIDSource();
+std::unique_ptr<ChannelIDSource> ChannelIDSourceForTesting() {
+  return QuicMakeUnique<TestChannelIDSource>();
 }
 
 void MovePackets(PacketSavingConnection* source_conn,
diff --git a/quic/test_tools/crypto_test_utils.h b/quic/test_tools/crypto_test_utils.h
index c70747f..5bb4b4e 100644
--- a/quic/test_tools/crypto_test_utils.h
+++ b/quic/test_tools/crypto_test_utils.h
@@ -226,7 +226,7 @@
 // deterministically based on the hostname given in the GetChannelIDKey call.
 // This ChannelIDSource works in synchronous mode, i.e., its GetChannelIDKey
 // method never returns QUIC_PENDING.
-ChannelIDSource* ChannelIDSourceForTesting();
+std::unique_ptr<ChannelIDSource> ChannelIDSourceForTesting();
 
 // MovePackets parses crypto handshake messages from packet number
 // |*inout_packet_index| through to the last packet (or until a packet fails
diff --git a/quic/tools/quic_client_base.h b/quic/tools/quic_client_base.h
index 261fc2b..6ad326e 100644
--- a/quic/tools/quic_client_base.h
+++ b/quic/tools/quic_client_base.h
@@ -133,10 +133,9 @@
 
   // SetChannelIDSource sets a ChannelIDSource that will be called, when the
   // server supports channel IDs, to obtain a channel ID for signing a message
-  // proving possession of the channel ID. This object takes ownership of
-  // |source|.
-  void SetChannelIDSource(ChannelIDSource* source) {
-    crypto_config_.SetChannelIDSource(source);
+  // proving possession of the channel ID.
+  void SetChannelIDSource(std::unique_ptr<ChannelIDSource> source) {
+    crypto_config_.SetChannelIDSource(std::move(source));
   }
 
   const ParsedQuicVersionVector& supported_versions() const {