Commit d8bbe351 authored by Ryan Hansberry's avatar Ryan Hansberry Committed by Commit Bot

[Nearby] Remove surprising use of unique_ptr for CorePayload.

Discovered while debugging crbug.com/2393616.

The code in question moves the wrapped CorePayload of a
std::unique_ptr<CorePayload>, instead of moving the entire smart
pointer. Resolved by simply not using std::unique_ptr in the first
place.

Also fix a minor typo discovered while debugging.

Bug: 2393616
Change-Id: I518230bd2ced6735d13f4fc8fbee54758ceec1e5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2398952
Commit-Queue: Ryan Hansberry <hansberry@chromium.org>
Reviewed-by: default avatarJames Vecore <vecore@google.com>
Cr-Commit-Position: refs/heads/master@{#805154}
parent 594aaf47
...@@ -468,7 +468,7 @@ void NearbyConnectionsManagerImpl::OnConnectionInitiated( ...@@ -468,7 +468,7 @@ void NearbyConnectionsManagerImpl::OnConnectionInitiated(
[](const std::string& endpoint_id, ConnectionsStatus status) { [](const std::string& endpoint_id, ConnectionsStatus status) {
NS_LOG(VERBOSE) NS_LOG(VERBOSE)
<< __func__ << ": Accept connection attempted to endpoint " << __func__ << ": Accept connection attempted to endpoint "
<< endpoint_id << "over Nearby Connections with result: " << endpoint_id << " over Nearby Connections with result: "
<< ConnectionsStatusToString(status); << ConnectionsStatusToString(status);
}, },
endpoint_id)); endpoint_id));
......
...@@ -362,12 +362,12 @@ void NearbyConnections::SendPayload( ...@@ -362,12 +362,12 @@ void NearbyConnections::SendPayload(
const std::vector<std::string>& endpoint_ids, const std::vector<std::string>& endpoint_ids,
mojom::PayloadPtr payload, mojom::PayloadPtr payload,
SendPayloadCallback callback) { SendPayloadCallback callback) {
std::unique_ptr<Payload> core_payload; Payload core_payload;
switch (payload->content->which()) { switch (payload->content->which()) {
case mojom::PayloadContent::Tag::BYTES: case mojom::PayloadContent::Tag::BYTES:
core_payload = std::make_unique<Payload>( core_payload =
payload->id, Payload(payload->id,
ByteArrayFromMojom(payload->content->get_bytes()->bytes)); ByteArrayFromMojom(payload->content->get_bytes()->bytes));
break; break;
case mojom::PayloadContent::Tag::FILE: case mojom::PayloadContent::Tag::FILE:
int64_t file_size = payload->content->get_file()->file.GetLength(); int64_t file_size = payload->content->get_file()->file.GetLength();
...@@ -376,12 +376,11 @@ void NearbyConnections::SendPayload( ...@@ -376,12 +376,11 @@ void NearbyConnections::SendPayload(
input_file_map_.insert_or_assign( input_file_map_.insert_or_assign(
payload->id, std::move(payload->content->get_file()->file)); payload->id, std::move(payload->content->get_file()->file));
} }
core_payload = std::make_unique<Payload>( core_payload = Payload(payload->id, InputFile(payload->id, file_size));
payload->id, InputFile(payload->id, file_size));
break; break;
} }
core_->SendPayload(absl::MakeSpan(endpoint_ids), std::move(*core_payload), core_->SendPayload(absl::MakeSpan(endpoint_ids), std::move(core_payload),
ResultCallbackFromMojom(std::move(callback))); ResultCallbackFromMojom(std::move(callback)));
} }
......
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