mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
Change Open to accept AttachmentContainer.
PiperOrigin-RevId: 640278287
This commit is contained in:
committed by
Copybara-Service
parent
98dc739a8a
commit
37327e79f3
@@ -172,7 +172,8 @@ bool FakeNearbySharingService::DidLocalUserCancelTransfer(
|
||||
|
||||
// Opens attachments from the remote |share_target|.
|
||||
void FakeNearbySharingService::Open(
|
||||
const ShareTarget& share_target,
|
||||
ShareTarget share_target,
|
||||
std::unique_ptr<AttachmentContainer> attachment_container,
|
||||
std::function<void(StatusCodes status_codes)> status_codes_callback) {
|
||||
status_codes_callback(StatusCodes::kOk);
|
||||
}
|
||||
|
||||
@@ -120,7 +120,8 @@ class FakeNearbySharingService : public NearbySharingService {
|
||||
bool DidLocalUserCancelTransfer(int64_t share_target_id) override;
|
||||
|
||||
// Opens attachments from the remote |share_target|.
|
||||
void Open(const ShareTarget& share_target,
|
||||
void Open(ShareTarget share_target,
|
||||
std::unique_ptr<AttachmentContainer> attachment_container,
|
||||
std::function<void(StatusCodes status_codes)> status_codes_callback)
|
||||
override;
|
||||
|
||||
|
||||
@@ -236,9 +236,12 @@ class NearbySharingService {
|
||||
// |share_target|.
|
||||
virtual bool DidLocalUserCancelTransfer(int64_t share_target_id) = 0;
|
||||
|
||||
// Opens attachments from the remote |share_target|.
|
||||
// Opens attachments in |attachment_container| from the remote |share_target|.
|
||||
// If |attachment_container| is null, or the container is empty, the status
|
||||
// code will be set to kInvalidArgument.
|
||||
virtual void Open(
|
||||
const ShareTarget& share_target,
|
||||
ShareTarget share_target,
|
||||
std::unique_ptr<AttachmentContainer> attachment_container,
|
||||
std::function<void(StatusCodes status_codes)> status_codes_callback) = 0;
|
||||
|
||||
// Opens an url target on a browser instance.
|
||||
|
||||
@@ -971,22 +971,24 @@ bool NearbySharingServiceImpl::DidLocalUserCancelTransfer(
|
||||
}
|
||||
|
||||
void NearbySharingServiceImpl::Open(
|
||||
const ShareTarget& share_target,
|
||||
ShareTarget share_target,
|
||||
std::unique_ptr<AttachmentContainer> attachment_container,
|
||||
std::function<void(StatusCodes status_codes)> status_codes_callback) {
|
||||
RunOnAnyThread(
|
||||
"api_open", [this, share_target,
|
||||
"api_open", [this, share_target = std::move(share_target),
|
||||
attachment_container = std::move(attachment_container),
|
||||
status_codes_callback = std::move(status_codes_callback)]() {
|
||||
if (!attachment_container || !attachment_container->HasAttachments()) {
|
||||
status_codes_callback(StatusCodes::kInvalidArgument);
|
||||
return;
|
||||
}
|
||||
NL_LOG(INFO) << __func__ << ": Open is called for share_target: "
|
||||
<< share_target.ToString();
|
||||
|
||||
// Log analytics event of opening received attachments.
|
||||
ShareTargetInfo* info = GetShareTargetInfo(share_target.id);
|
||||
analytics_recorder_->NewOpenReceivedAttachments(
|
||||
share_target.attachment_container,
|
||||
info != nullptr ? info->session_id() : 0);
|
||||
|
||||
status_codes_callback(
|
||||
service_extension_->Open(share_target.attachment_container));
|
||||
*attachment_container, info != nullptr ? info->session_id() : 0);
|
||||
status_codes_callback(service_extension_->Open(*attachment_container));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -175,7 +175,8 @@ class NearbySharingServiceImpl
|
||||
std::function<void(StatusCodes status_codes)>
|
||||
status_codes_callback) override;
|
||||
bool DidLocalUserCancelTransfer(int64_t share_target_id) override;
|
||||
void Open(const ShareTarget& share_target,
|
||||
void Open(ShareTarget share_target,
|
||||
std::unique_ptr<AttachmentContainer> attachment_container,
|
||||
std::function<void(StatusCodes status_codes)> status_codes_callback)
|
||||
override;
|
||||
void OpenUrl(const ::nearby::network::Url& url) override;
|
||||
|
||||
@@ -4494,14 +4494,30 @@ TEST_F(NearbySharingServiceImplTest, OpenSharedTarget) {
|
||||
TextAttachment(TextMetadata::TEXT, "body", "title", "mime"));
|
||||
NearbySharingService::StatusCodes result;
|
||||
absl::Notification notification;
|
||||
service_->Open(share_target,
|
||||
service_->Open(
|
||||
share_target,
|
||||
std::make_unique<AttachmentContainer>(share_target.attachment_container),
|
||||
[&](NearbySharingService::StatusCodes status_code) {
|
||||
result = status_code;
|
||||
notification.Notify();
|
||||
});
|
||||
|
||||
ASSERT_TRUE(notification.WaitForNotificationWithTimeout(kWaitTimeout));
|
||||
EXPECT_EQ(result, NearbySharingService::StatusCodes::kOk);
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, OpenSharedTargetWithEmptyAttachments) {
|
||||
ShareTarget share_target;
|
||||
NearbySharingService::StatusCodes result;
|
||||
absl::Notification notification;
|
||||
service_->Open(share_target, std::make_unique<AttachmentContainer>(),
|
||||
[&](NearbySharingService::StatusCodes status_code) {
|
||||
result = status_code;
|
||||
notification.Notify();
|
||||
});
|
||||
|
||||
ASSERT_TRUE(notification.WaitForNotificationWithTimeout(kWaitTimeout));
|
||||
EXPECT_EQ(result, NearbySharingService::StatusCodes::kOk);
|
||||
EXPECT_EQ(result, NearbySharingService::StatusCodes::kInvalidArgument);
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
Reference in New Issue
Block a user