Remove AttachmentInfo.

PiperOrigin-RevId: 644459879
This commit is contained in:
Francis Tsui
2024-06-18 11:38:14 -07:00
committed by Copybara-Service
parent abaf7718e2
commit 02379cc0a8
19 changed files with 75 additions and 178 deletions
-2
View File
@@ -67,12 +67,10 @@ cc_library(
name = "types",
srcs = [
"advertisement.cc",
"attachment_info.cc",
"share_target.cc",
],
hdrs = [
"advertisement.h",
"attachment_info.h",
"constants.h",
"nearby_connection.h",
"nearby_connections_manager.h",
-27
View File
@@ -1,27 +0,0 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "sharing/attachment_info.h"
namespace nearby::sharing {
AttachmentInfo::AttachmentInfo() = default;
AttachmentInfo::~AttachmentInfo() = default;
AttachmentInfo::AttachmentInfo(const AttachmentInfo&) = default;
AttachmentInfo& AttachmentInfo::operator=(const AttachmentInfo&) = default;
AttachmentInfo::AttachmentInfo(AttachmentInfo&&) = default;
AttachmentInfo& AttachmentInfo::operator=(AttachmentInfo&&) = default;
} // namespace nearby::sharing
-43
View File
@@ -1,43 +0,0 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef THIRD_PARTY_NEARBY_SHARING_ATTACHMENT_INFO_H_
#define THIRD_PARTY_NEARBY_SHARING_ATTACHMENT_INFO_H_
#include <stdint.h>
#include <filesystem> // NOLINT(build/c++17)
#include <optional>
#include <string>
namespace nearby::sharing {
// Ties associated information to an Attachment.
struct AttachmentInfo {
AttachmentInfo();
~AttachmentInfo();
AttachmentInfo(const AttachmentInfo&);
AttachmentInfo& operator=(const AttachmentInfo&);
AttachmentInfo(AttachmentInfo&&);
AttachmentInfo& operator=(AttachmentInfo&&);
std::optional<int64_t> payload_id;
std::string text_body;
std::filesystem::path file_path;
};
} // namespace nearby::sharing
#endif // THIRD_PARTY_NEARBY_SHARING_ATTACHMENT_INFO_H_
+2 -1
View File
@@ -139,7 +139,8 @@ void FakeNearbyConnectionsManager::RegisterPayloadStatusListener(
payload_status_listeners_[payload_id] = listener;
}
Payload* FakeNearbyConnectionsManager::GetIncomingPayload(int64_t payload_id) {
const Payload* FakeNearbyConnectionsManager::GetIncomingPayload(
int64_t payload_id) const {
NL_DCHECK(!is_shutdown());
absl::MutexLock lock(&incoming_payloads_mutex_);
auto it = incoming_payloads_.find(payload_id);
+2 -2
View File
@@ -66,7 +66,7 @@ class FakeNearbyConnectionsManager : public NearbyConnectionsManager {
void RegisterPayloadStatusListener(
int64_t payload_id,
std::weak_ptr<PayloadStatusListener> listener) override;
Payload* GetIncomingPayload(int64_t payload_id) override;
const Payload* GetIncomingPayload(int64_t payload_id) const override;
void Cancel(int64_t payload_id) override;
void ClearIncomingPayloads() override;
std::optional<std::vector<uint8_t>> GetRawAuthenticationToken(
@@ -171,7 +171,7 @@ class FakeNearbyConnectionsManager : public NearbyConnectionsManager {
std::map<int64_t, std::weak_ptr<PayloadStatusListener>>
payload_status_listeners_;
absl::Mutex incoming_payloads_mutex_;
mutable absl::Mutex incoming_payloads_mutex_;
std::map<int64_t, std::unique_ptr<Payload>> incoming_payloads_
ABSL_GUARDED_BY(incoming_payloads_mutex_);
absl::flat_hash_set<std::filesystem::path> file_paths_to_delete_;
+6 -6
View File
@@ -180,17 +180,17 @@ TEST_F(IncomingShareTargetInfoTest, ProcessIntroductionSuccess) {
UnorderedElementsAre(text1, text2));
EXPECT_THAT(info_.attachment_container().GetWifiCredentialsAttachments(),
UnorderedElementsAre(wifi1, wifi2));
EXPECT_THAT(info_.attachment_payload_map().at(filemeta1.id()).payload_id,
EXPECT_THAT(info_.attachment_payload_map().at(filemeta1.id()),
Eq(filemeta1.payload_id()));
EXPECT_THAT(info_.attachment_payload_map().at(filemeta2.id()).payload_id,
EXPECT_THAT(info_.attachment_payload_map().at(filemeta2.id()),
Eq(filemeta2.payload_id()));
EXPECT_THAT(info_.attachment_payload_map().at(textmeta1.id()).payload_id,
EXPECT_THAT(info_.attachment_payload_map().at(textmeta1.id()),
Eq(textmeta1.payload_id()));
EXPECT_THAT(info_.attachment_payload_map().at(textmeta2.id()).payload_id,
EXPECT_THAT(info_.attachment_payload_map().at(textmeta2.id()),
Eq(textmeta2.payload_id()));
EXPECT_THAT(info_.attachment_payload_map().at(wifimeta1.id()).payload_id,
EXPECT_THAT(info_.attachment_payload_map().at(wifimeta1.id()),
Eq(wifimeta1.payload_id()));
EXPECT_THAT(info_.attachment_payload_map().at(wifimeta2.id()).payload_id,
EXPECT_THAT(info_.attachment_payload_map().at(wifimeta2.id()),
Eq(wifimeta2.payload_id()));
}
} // namespace
+1 -1
View File
@@ -143,7 +143,7 @@ class NearbyConnectionsManager {
int64_t payload_id, std::weak_ptr<PayloadStatusListener> listener) = 0;
// Gets the payload associated with `payload_id` if available.
virtual Payload* GetIncomingPayload(int64_t payload_id) = 0;
virtual const Payload* GetIncomingPayload(int64_t payload_id) const = 0;
// Cancels a Payload currently in-flight to or from remote endpoints.
virtual void Cancel(int64_t payload_id) = 0;
+3 -2
View File
@@ -554,9 +554,10 @@ void NearbyConnectionsManagerImpl::RegisterPayloadStatusListener(
payload_status_listeners_.insert_or_assign(payload_id, listener);
}
Payload* NearbyConnectionsManagerImpl::GetIncomingPayload(int64_t payload_id) {
const Payload* NearbyConnectionsManagerImpl::GetIncomingPayload(
int64_t payload_id) const {
MutexLock lock(&mutex_);
auto it = incoming_payloads_.find(payload_id);
const auto it = incoming_payloads_.find(payload_id);
if (it == incoming_payloads_.end()) return nullptr;
return &it->second;
+1 -1
View File
@@ -78,7 +78,7 @@ class NearbyConnectionsManagerImpl : public NearbyConnectionsManager {
void RegisterPayloadStatusListener(
int64_t payload_id,
std::weak_ptr<PayloadStatusListener> listener) override;
Payload* GetIncomingPayload(int64_t payload_id) override;
const Payload* GetIncomingPayload(int64_t payload_id) const override;
void Cancel(int64_t payload_id) override;
void ClearIncomingPayloads() override;
std::optional<std::vector<uint8_t>> GetRawAuthenticationToken(
@@ -1427,7 +1427,7 @@ TEST_F(NearbyConnectionsManagerImplTest, IncomingBytesPayload) {
EXPECT_TRUE(payload_notification.WaitForNotificationWithTimeout(
kSynchronizationTimeOut));
Payload* payload =
const Payload* payload =
nearby_connections_manager_->GetIncomingPayload(kPayloadId);
ASSERT_NE(payload, nullptr);
ASSERT_TRUE(payload->content.is_bytes());
@@ -1472,7 +1472,7 @@ TEST_F(NearbyConnectionsManagerImplTest, IncomingFilePayload) {
EXPECT_TRUE(payload_notification.WaitForNotificationWithTimeout(
kSynchronizationTimeOut));
Payload* payload =
const Payload* payload =
nearby_connections_manager_->GetIncomingPayload(kPayloadId);
ASSERT_NE(payload, nullptr);
ASSERT_TRUE(payload->content.is_file());
+3 -3
View File
@@ -420,9 +420,9 @@ struct PayloadContent {
FilePayload file_payload;
enum class Type { kUnknown = 0, kBytes = 1, kStream = 2, kFile = 3 };
Type type;
bool is_bytes() { return type == Type::kBytes; }
bool is_file() { return type == Type::kFile; }
bool is_stream() { return type == Type::kStream; }
bool is_bytes() const { return type == Type::kBytes; }
bool is_file() const { return type == Type::kFile; }
bool is_stream() const { return type == Type::kStream; }
};
// A Payload sent between devices. Payloads sent with a particular content type
+26 -36
View File
@@ -54,7 +54,6 @@
#include "sharing/analytics/analytics_information.h"
#include "sharing/analytics/analytics_recorder.h"
#include "sharing/attachment_container.h"
#include "sharing/attachment_info.h"
#include "sharing/certificates/common.h"
#include "sharing/certificates/nearby_share_certificate_manager.h"
#include "sharing/certificates/nearby_share_certificate_manager_impl.h"
@@ -353,7 +352,7 @@ void NearbySharingServiceImpl::Cleanup() {
last_incoming_metadata_.reset();
last_outgoing_metadata_.reset();
attachment_info_map_.clear();
attachment_payload_map_.clear();
locally_cancelled_share_target_ids_.clear();
mutual_acceptance_timeout_alarm_->Stop();
@@ -2547,11 +2546,6 @@ void NearbySharingServiceImpl::ReceivePayloads(
<< file.id();
continue;
}
std::filesystem::path file_path =
download_path / std::filesystem::u8path(file.file_name().cbegin(),
file.file_name().cend());
attachment_info_map_[file.id()].file_path = std::move(file_path);
}
OnPayloadPathsRegistered(share_target_info, std::move(status_codes_callback));
}
@@ -2599,7 +2593,7 @@ void NearbySharingServiceImpl::OnPayloadPathsRegistered(
int64_t share_target_id = info.share_target().id;
info.set_payload_tracker(std::make_shared<PayloadTracker>(
context_, share_target_id, info.attachment_container(),
attachment_info_map_,
attachment_payload_map_,
absl::bind_front(&NearbySharingServiceImpl::OnPayloadTransferUpdate,
this)));
@@ -2794,7 +2788,7 @@ void NearbySharingServiceImpl::CreatePayloads(
return;
}
bool result = info->CreateFilePayloads(file_infos);
attachment_info_map_ = info->attachment_payload_map();
attachment_payload_map_ = info->attachment_payload_map();
std::move(callback)(*info, result);
});
});
@@ -3378,7 +3372,7 @@ void NearbySharingServiceImpl::OnReceivedIntroduction(
Fail(share_target_id, *status);
return;
}
attachment_info_map_ = info->attachment_payload_map();
attachment_payload_map_ = info->attachment_payload_map();
// Log analytics event of receiving introduction.
analytics_recorder_->NewReceiveIntroduction(
@@ -3474,7 +3468,7 @@ void NearbySharingServiceImpl::OnReceiveConnectionResponse(
info->set_payload_tracker(std::make_unique<PayloadTracker>(
context_, share_target_id, info->attachment_container(),
attachment_info_map_,
attachment_payload_map_,
absl::bind_front(&NearbySharingServiceImpl::OnPayloadTransferUpdate,
this)));
@@ -3883,15 +3877,14 @@ bool NearbySharingServiceImpl::OnIncomingPayloadsComplete(
AttachmentContainer& container = info->mutable_attachment_container();
for (int i = 0; i < container.GetTextAttachments().size(); ++i) {
TextAttachment& text = container.GetMutableTextAttachment(i);
AttachmentInfo& attachment_info = attachment_info_map_[text.id()];
std::optional<int64_t> payload_id = attachment_info.payload_id;
if (!payload_id) {
const auto it = attachment_payload_map_.find(text.id());
if (it == attachment_payload_map_.end()) {
NL_LOG(WARNING) << __func__ << ": No payload id found for text - "
<< text.id();
return false;
}
Payload* incoming_payload =
nearby_connections_manager_->GetIncomingPayload(*payload_id);
const Payload* incoming_payload =
nearby_connections_manager_->GetIncomingPayload(it->second);
if (!incoming_payload || !incoming_payload->content.is_bytes()) {
NL_LOG(WARNING) << __func__ << ": No payload found for text - "
<< text.id();
@@ -3903,31 +3896,28 @@ bool NearbySharingServiceImpl::OnIncomingPayloadsComplete(
NL_LOG(WARNING)
<< __func__
<< ": Incoming bytes is empty for text payload with payload_id - "
<< *payload_id;
<< it->second;
return false;
}
std::string text_body(bytes.begin(), bytes.end());
text.set_text_body(text_body);
attachment_info.text_body = std::move(text_body);
}
for (int i = 0; i < container.GetWifiCredentialsAttachments().size(); ++i) {
WifiCredentialsAttachment& wifi_credentials_attachment =
container.GetMutableWifiCredentialsAttachment(i);
AttachmentInfo& attachment_info =
attachment_info_map_[wifi_credentials_attachment.id()];
std::optional<int64_t> payload_id = attachment_info.payload_id;
if (!payload_id) {
const auto it =
attachment_payload_map_.find(wifi_credentials_attachment.id());
if (it == attachment_payload_map_.end()) {
NL_LOG(WARNING) << __func__
<< ": No payload id found for WiFi credentials - "
<< wifi_credentials_attachment.id();
return false;
}
Payload* incoming_payload =
nearby_connections_manager_->GetIncomingPayload(*payload_id);
const Payload* incoming_payload =
nearby_connections_manager_->GetIncomingPayload(it->second);
if (!incoming_payload || !incoming_payload->content.is_bytes()) {
NL_LOG(WARNING) << __func__
<< ": No payload found for WiFi credentials - "
@@ -3940,7 +3930,7 @@ bool NearbySharingServiceImpl::OnIncomingPayloadsComplete(
NL_LOG(WARNING) << __func__
<< ": Incoming bytes is empty for WiFi credentials "
"payload with payload_id - "
<< *payload_id;
<< it->second;
return false;
}
@@ -3950,7 +3940,7 @@ bool NearbySharingServiceImpl::OnIncomingPayloadsComplete(
NL_LOG(WARNING) << __func__
<< ": Incoming bytes is invalid for WiFi credentials "
"payload with payload_id - "
<< *payload_id;
<< it->second;
return false;
}
@@ -3969,16 +3959,15 @@ void NearbySharingServiceImpl::UpdateFilePath(
if (file.file_path().has_value()) {
continue;
}
AttachmentInfo& attachment_info = attachment_info_map_[file.id()];
std::optional<int64_t> payload_id = attachment_info.payload_id;
if (!payload_id) {
const auto it = attachment_payload_map_.find(file.id());
if (it == attachment_payload_map_.end()) {
NL_LOG(WARNING) << __func__ << ": No payload id found for file - "
<< file.id();
continue;
}
Payload* incoming_payload =
nearby_connections_manager_->GetIncomingPayload(*payload_id);
const Payload* incoming_payload =
nearby_connections_manager_->GetIncomingPayload(it->second);
if (!incoming_payload || !incoming_payload->content.is_file()) {
NL_LOG(WARNING) << __func__ << ": No payload found for file - "
<< file.id();
@@ -4015,7 +4004,8 @@ void NearbySharingServiceImpl::RemoveIncomingPayloads(
auto file_path = *file.file_path();
NL_VLOG(1) << __func__
<< ": file_path=" << GetCompatibleU8String(file_path.u8string());
if (attachment_info_map_.find(file.id()) == attachment_info_map_.end()) {
if (attachment_payload_map_.find(file.id()) ==
attachment_payload_map_.end()) {
continue;
}
files_for_deletion.push_back(file_path);
@@ -4186,10 +4176,10 @@ void NearbySharingServiceImpl::ClearOutgoingShareTargetInfoMap() {
std::optional<int64_t> NearbySharingServiceImpl::GetAttachmentPayloadId(
int64_t attachment_id) {
auto it = attachment_info_map_.find(attachment_id);
if (it == attachment_info_map_.end()) return std::nullopt;
const auto it = attachment_payload_map_.find(attachment_id);
if (it == attachment_payload_map_.end()) return std::nullopt;
return it->second.payload_id;
return it->second;
}
void NearbySharingServiceImpl::UnregisterShareTarget(int64_t share_target_id) {
+2 -4
View File
@@ -45,7 +45,6 @@
#include "sharing/advertisement.h"
#include "sharing/analytics/analytics_recorder.h"
#include "sharing/attachment_container.h"
#include "sharing/attachment_info.h"
#include "sharing/certificates/nearby_share_certificate_manager.h"
#include "sharing/certificates/nearby_share_decrypted_public_certificate.h"
#include "sharing/certificates/nearby_share_private_certificate.h"
@@ -580,9 +579,8 @@ class NearbySharingServiceImpl
// unnecessary backend API call.
absl::flat_hash_set<std::string> discovered_advertisements_retried_set_;
// A mapping of Attachment ID to additional AttachmentInfo related to the
// Attachment.
absl::flat_hash_map<int64_t, AttachmentInfo> attachment_info_map_;
// A mapping of Attachment ID to payload ID .
absl::flat_hash_map<int64_t, int64_t> attachment_payload_map_;
// This alarm is used to disconnect the sharing connection if both sides do
// not press accept within the timeout.
+8 -20
View File
@@ -121,15 +121,9 @@ TEST_F(OutgoingShareTargetInfoTest, CreateTextPayloads) {
ASSERT_THAT(attachment_payload_map, SizeIs(2));
ASSERT_THAT(attachment_payload_map.contains(text1_.id()), IsTrue());
ASSERT_THAT(attachment_payload_map.at(text1_.id()).payload_id.has_value(),
IsTrue());
EXPECT_THAT(attachment_payload_map.at(text1_.id()).payload_id.value(),
Eq(payloads[0].id));
EXPECT_THAT(attachment_payload_map.at(text1_.id()), Eq(payloads[0].id));
ASSERT_THAT(attachment_payload_map.contains(text2_.id()), IsTrue());
ASSERT_THAT(attachment_payload_map.at(text2_.id()).payload_id.has_value(),
IsTrue());
EXPECT_THAT(attachment_payload_map.at(text2_.id()).payload_id.value(),
Eq(payloads[1].id));
EXPECT_THAT(attachment_payload_map.at(text2_.id()), Eq(payloads[1].id));
}
TEST_F(OutgoingShareTargetInfoTest, CreateFilePayloadsWithNoFileAttachments) {
@@ -157,8 +151,8 @@ TEST_F(OutgoingShareTargetInfoTest, CreateFilePayloadsWithWrongFileInfo) {
TEST_F(OutgoingShareTargetInfoTest, CreateFilePayloads) {
std::vector<NearbyFileHandler::FileInfo> file_infos;
file_infos.push_back({
.size = 12355L,
.file_path = file1_.file_path().value(),
.size = 12355L,
.file_path = file1_.file_path().value(),
});
info_.CreateFilePayloads(file_infos);
const std::vector<Payload>& payloads = info_.file_payloads();
@@ -174,10 +168,7 @@ TEST_F(OutgoingShareTargetInfoTest, CreateFilePayloads) {
EXPECT_THAT(attachment_payload_map, SizeIs(1));
ASSERT_THAT(attachment_payload_map.contains(file1_.id()), IsTrue());
ASSERT_THAT(attachment_payload_map.at(file1_.id()).payload_id.has_value(),
IsTrue());
EXPECT_THAT(attachment_payload_map.at(file1_.id()).payload_id.value(),
Eq(payloads[0].id));
EXPECT_THAT(attachment_payload_map.at(file1_.id()), Eq(payloads[0].id));
EXPECT_THAT(info_.attachment_container().GetFileAttachments()[0].size(),
Eq(12355L));
@@ -210,10 +201,7 @@ TEST_F(OutgoingShareTargetInfoTest, CreateWifiCredentialsPayloads) {
ASSERT_THAT(attachment_payload_map, SizeIs(1));
ASSERT_THAT(attachment_payload_map.contains(wifi1_.id()), IsTrue());
ASSERT_THAT(attachment_payload_map.at(wifi1_.id()).payload_id.has_value(),
IsTrue());
EXPECT_THAT(attachment_payload_map.at(wifi1_.id()).payload_id.value(),
Eq(payloads[0].id));
EXPECT_THAT(attachment_payload_map.at(wifi1_.id()), Eq(payloads[0].id));
}
TEST_F(OutgoingShareTargetInfoTest, CreateIntroductionFrameWithoutPayloads) {
@@ -223,8 +211,8 @@ TEST_F(OutgoingShareTargetInfoTest, CreateIntroductionFrameWithoutPayloads) {
TEST_F(OutgoingShareTargetInfoTest, CreateIntroductionFrameSuccess) {
std::vector<NearbyFileHandler::FileInfo> file_infos;
file_infos.push_back({
.size = 12355L,
.file_path = file1_.file_path().value(),
.size = 12355L,
.file_path = file1_.file_path().value(),
});
info_.CreateFilePayloads(file_infos);
info_.CreateTextPayloads();
+10 -14
View File
@@ -26,7 +26,6 @@
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "sharing/attachment_container.h"
#include "sharing/attachment_info.h"
#include "sharing/constants.h"
#include "sharing/file_attachment.h"
#include "sharing/internal/public/context.h"
@@ -43,7 +42,7 @@ namespace sharing {
PayloadTracker::PayloadTracker(
Context* context, int64_t share_target_id,
const AttachmentContainer& container,
const absl::flat_hash_map<int64_t, AttachmentInfo>& attachment_info_map,
const absl::flat_hash_map<int64_t, int64_t>& attachment_payload_map,
std::function<void(int64_t, TransferMetadata)> update_callback)
: context_(context),
share_target_id_(share_target_id),
@@ -52,8 +51,8 @@ PayloadTracker::PayloadTracker(
confirmed_transfer_size_ = 0;
for (const auto& file : container.GetFileAttachments()) {
auto it = attachment_info_map.find(file.id());
if (it == attachment_info_map.end() || !it->second.payload_id) {
auto it = attachment_payload_map.find(file.id());
if (it == attachment_payload_map.end()) {
NL_LOG(WARNING)
<< __func__
<< ": Failed to retrieve payload for file attachment id - "
@@ -61,15 +60,14 @@ PayloadTracker::PayloadTracker(
continue;
}
payload_state_.emplace(*it->second.payload_id,
State(file.id(), file.size()));
payload_state_.emplace(it->second, State(file.id(), file.size()));
++num_file_attachments_;
total_transfer_size_ += file.size();
}
for (const auto& text : container.GetTextAttachments()) {
auto it = attachment_info_map.find(text.id());
if (it == attachment_info_map.end() || !it->second.payload_id) {
auto it = attachment_payload_map.find(text.id());
if (it == attachment_payload_map.end()) {
NL_LOG(WARNING)
<< __func__
<< ": Failed to retrieve payload for text attachment id - "
@@ -77,16 +75,15 @@ PayloadTracker::PayloadTracker(
continue;
}
payload_state_.emplace(*it->second.payload_id,
State(text.id(), text.size()));
payload_state_.emplace(it->second, State(text.id(), text.size()));
++num_text_attachments_;
total_transfer_size_ += text.size();
}
for (const auto& wifi_credentials :
container.GetWifiCredentialsAttachments()) {
auto it = attachment_info_map.find(wifi_credentials.id());
if (it == attachment_info_map.end() || !it->second.payload_id) {
auto it = attachment_payload_map.find(wifi_credentials.id());
if (it == attachment_payload_map.end()) {
NL_LOG(WARNING) << __func__
<< ": Failed to retrieve payload for WiFi credentials "
"attachment id - "
@@ -95,8 +92,7 @@ PayloadTracker::PayloadTracker(
}
payload_state_.emplace(
*it->second.payload_id,
State(wifi_credentials.id(), wifi_credentials.size()));
it->second, State(wifi_credentials.id(), wifi_credentials.size()));
++num_wifi_credentials_attachments_;
total_transfer_size_ += wifi_credentials.size();
}
+1 -2
View File
@@ -26,7 +26,6 @@
#include "absl/container/flat_hash_map.h"
#include "absl/time/time.h"
#include "sharing/attachment_container.h"
#include "sharing/attachment_info.h"
#include "sharing/internal/public/context.h"
#include "sharing/nearby_connections_manager.h"
#include "sharing/nearby_connections_types.h"
@@ -42,7 +41,7 @@ class PayloadTracker : public NearbyConnectionsManager::PayloadStatusListener {
PayloadTracker(
Context* context, int64_t share_target_id,
const AttachmentContainer& container,
const absl::flat_hash_map<int64_t, AttachmentInfo>& attachment_info_map,
const absl::flat_hash_map<int64_t, int64_t>& attachment_payload_map,
std::function<void(int64_t, TransferMetadata)> update_callback);
~PayloadTracker() override;
+5 -8
View File
@@ -27,7 +27,6 @@
#include "absl/time/time.h"
#include "internal/test/fake_clock.h"
#include "sharing/attachment_container.h"
#include "sharing/attachment_info.h"
#include "sharing/file_attachment.h"
#include "sharing/internal/test/fake_context.h"
#include "sharing/nearby_connections_types.h"
@@ -50,13 +49,11 @@ class PayloadTrackerTest : public ::testing::Test {
container_.AddFileAttachment(FileAttachment(
kFileId, kFileSize, std::string(kFileName), std::string(kMimeType),
service::proto::FileMetadata::IMAGE));
attachment_info_map_.clear();
AttachmentInfo attachment_info;
attachment_info.payload_id = kFileId;
attachment_info_map_.emplace(container_.GetFileAttachments()[0].id(),
std::move(attachment_info));
attachment_payload_map_.clear();
attachment_payload_map_.emplace(container_.GetFileAttachments()[0].id(),
kFileId);
payload_tracker_ = std::make_unique<PayloadTracker>(
context(), kShareTargetId, container_, attachment_info_map_,
context(), kShareTargetId, container_, attachment_payload_map_,
[&](int64_t share_target_id, TransferMetadata transfer_metadata) {
current_percentage_ = transfer_metadata.progress();
});
@@ -84,7 +81,7 @@ class PayloadTrackerTest : public ::testing::Test {
std::unique_ptr<PayloadTracker> payload_tracker_ = nullptr;
float current_percentage_ = 0.0;
AttachmentContainer container_;
absl::flat_hash_map<int64_t, AttachmentInfo> attachment_info_map_;
absl::flat_hash_map<int64_t, int64_t> attachment_payload_map_;
};
TEST_F(PayloadTrackerTest, StatusUpdateWithoutTimeUpdate) {
+1 -1
View File
@@ -128,7 +128,7 @@ void ShareTargetInfo::OnDisconnect() {
void ShareTargetInfo::SetAttachmentPayloadId(int64_t attachment_id,
int64_t payload_id) {
attachment_payload_map_[attachment_id].payload_id = payload_id;
attachment_payload_map_[attachment_id] = payload_id;
}
} // namespace nearby::sharing
+2 -3
View File
@@ -27,7 +27,6 @@
#include "absl/time/time.h"
#include "proto/sharing_enums.pb.h"
#include "sharing/attachment_container.h"
#include "sharing/attachment_info.h"
#include "sharing/certificates/nearby_share_certificate_manager.h"
#include "sharing/certificates/nearby_share_decrypted_public_certificate.h"
#include "sharing/incoming_frames_reader.h"
@@ -137,7 +136,7 @@ class ShareTargetInfo {
return attachment_container_;
}
const absl::flat_hash_map<int64_t, AttachmentInfo>& attachment_payload_map()
const absl::flat_hash_map<int64_t, int64_t>& attachment_payload_map()
const {
return attachment_payload_map_;
}
@@ -169,7 +168,7 @@ class ShareTargetInfo {
TransferMetadata::Status disconnect_status_ =
TransferMetadata::Status::kUnknown;
AttachmentContainer attachment_container_;
absl::flat_hash_map<int64_t, AttachmentInfo> attachment_payload_map_;
absl::flat_hash_map<int64_t, int64_t> attachment_payload_map_;
};
} // namespace nearby::sharing