Refactor EndpointChannel ownership to use shared_ptr.

PiperOrigin-RevId: 907278448
This commit is contained in:
Edwin Wu
2026-04-28 18:15:46 -07:00
committed by Copybara-Service
parent 3fd8fbf2f1
commit 4ae41f4cdf
15 changed files with 546 additions and 438 deletions
+14 -11
View File
@@ -476,11 +476,11 @@ class BasePcpHandler : public PcpHandler,
// Only (possibly) vector for incoming connections.
std::vector<location::nearby::proto::connections::Medium> supported_mediums;
// Keep track of a channel before we pass it to EndpointChannelManager. This
// is owned until the call to OnEncryptionSuccessRunnableV3 or
// OnEncryptionSuccessRunnable when ownership is transferred to the
// EndpointManager.
std::unique_ptr<EndpointChannel> channel;
// Keep track of a channel before it is registered with the
// EndpointManager. This reference is held during the handshake phase and
// passed to the EndpointManager upon successful encryption
// (OnEncryptionSuccessRunnableV3 or OnEncryptionSuccessRunnable).
std::shared_ptr<EndpointChannel> channel;
// Crypto context; initially empty; established first thing after channel
// creation by running UKey2 session. While it is in progress, we keep track
@@ -509,24 +509,27 @@ class BasePcpHandler : public PcpHandler,
void OnEncryptionFailureImpl(const std::string& endpoint_id,
EndpointChannel* channel);
EncryptionRunner::ResultListener GetResultListener();
EncryptionRunner::ResultListener GetResultListener(
std::shared_ptr<EndpointChannel> endpoint_channel);
EncryptionRunner::ResultListener GetResultListenerV3(
const NearbyDeviceProvider& device_provider,
const NearbyDevice& remote_device,
const EndpointChannel& endpoint_channel);
std::shared_ptr<EndpointChannel> endpoint_channel);
void OnEncryptionSuccessRunnable(
const std::string& endpoint_id,
std::unique_ptr<securegcm::UKey2Handshake> ukey2,
const std::string& auth_token, const ByteArray& raw_auth_token);
const std::string& auth_token, const ByteArray& raw_auth_token,
std::shared_ptr<EndpointChannel> endpoint_channel);
void OnEncryptionSuccessRunnableV3(
const NearbyDevice& remote_device,
std::unique_ptr<::securegcm::UKey2Handshake> ukey2,
absl::string_view auth_token, const ByteArray& raw_auth_token,
const EndpointChannel& endpoint_channel,
std::shared_ptr<EndpointChannel> endpoint_channel,
const NearbyDeviceProvider& device_provider);
void OnEncryptionFailureRunnable(const std::string& endpoint_id,
EndpointChannel* endpoint_channel);
void OnEncryptionFailureRunnable(
const std::string& endpoint_id,
std::shared_ptr<EndpointChannel> endpoint_channel);
void RegisterDeviceAfterEncryptionSuccess(
std::string_view endpoint_id,
std::unique_ptr<::securegcm::UKey2Handshake> ukey2,