Skip to content

Commit

Permalink
Keep management of outgoing_share_target_map_ and outgoing_share_sess…
Browse files Browse the repository at this point in the history
…ion_map_ together.

PiperOrigin-RevId: 721886250
  • Loading branch information
ftsui authored and copybara-github committed Jan 31, 2025
1 parent 0575cbd commit 4dabf9e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
4 changes: 1 addition & 3 deletions sharing/nearby_sharing_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1790,7 +1790,6 @@ void NearbySharingServiceImpl::OnOutgoingDecryptedCertificate(
VLOG(1) << __func__ << ": Adding (endpoint_id=" << endpoint_id
<< ", share_target_id=" << share_target->id
<< ") to outgoing share target map";
outgoing_share_target_map_.insert_or_assign(endpoint_id, *share_target);
CreateOutgoingShareSession(*share_target, endpoint_id,
std::move(certificate));

Expand Down Expand Up @@ -3229,7 +3228,6 @@ bool NearbySharingServiceImpl::FindDuplicateInDiscoveryCache(
<< it->second.share_target.id;
share_target.id = it->second.share_target.id;
discovery_cache_.erase(it);
outgoing_share_target_map_.insert_or_assign(endpoint_id, share_target);
return true;
}

Expand All @@ -3244,7 +3242,6 @@ bool NearbySharingServiceImpl::FindDuplicateInDiscoveryCache(
// Copy only the id field from cache entry,
share_target.id = it->second.share_target.id;
discovery_cache_.erase(it);
outgoing_share_target_map_.insert_or_assign(endpoint_id, share_target);
return true;
}
}
Expand Down Expand Up @@ -3379,6 +3376,7 @@ void NearbySharingServiceImpl::MoveToDiscoveryCache(std::string endpoint_id,
void NearbySharingServiceImpl::CreateOutgoingShareSession(
const ShareTarget& share_target, absl::string_view endpoint_id,
std::optional<NearbyShareDecryptedPublicCertificate> certificate) {
outgoing_share_target_map_.insert_or_assign(endpoint_id, share_target);
auto [it_out, inserted] = outgoing_share_session_map_.try_emplace(
share_target.id, context_->GetClock(), *service_thread_,
nearby_connections_manager_.get(), analytics_recorder_,
Expand Down
8 changes: 4 additions & 4 deletions sharing/nearby_sharing_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ class NearbySharingServiceImpl
const ShareTarget& share_target, absl::string_view endpoint_id,
std::optional<NearbyShareDecryptedPublicCertificate> certificate);

// Add an entry to the outgoing_share_session_map_
// and OnShareTargetUpdated is called.
// Add an entry to the outgoing_share_session_map_ and
// outgoing_share_target_map_ and OnShareTargetUpdated is called.
void DeDuplicateInDiscoveryCache(
const ShareTarget& share_target, absl::string_view endpoint_id,
std::optional<NearbyShareDecryptedPublicCertificate> certificate);
Expand All @@ -395,8 +395,8 @@ class NearbySharingServiceImpl
ShareTarget& share_target);

// Looks for a duplicate of the share target in the discovery cache.
// If found, move the share target to the outgoing share target map.
// The share target's id is updated to match the cached entry.
// If found, the share target is removed from the discovery cache and its
// id is copied into `share_target`.
// Returns true if the duplicate is found.
bool FindDuplicateInDiscoveryCache(absl::string_view endpoint_id,
ShareTarget& share_target);
Expand Down

0 comments on commit 4dabf9e

Please sign in to comment.