mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Make AnalyticsRecorder available in ShareSession.
PiperOrigin-RevId: 651442133
This commit is contained in:
committed by
Copybara-Service
parent
76651429b8
commit
ca435ad75f
@@ -36,7 +36,10 @@ cc_library(
|
||||
cc_library(
|
||||
name = "mock_event_logger",
|
||||
testonly = True,
|
||||
hdrs = ["mock_event_logger.h"],
|
||||
hdrs = [
|
||||
"mock_event_logger.h",
|
||||
"sharing_log_matchers.h",
|
||||
],
|
||||
compatible_with = ["//buildenv/target:non_prod"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
// Copyright 2024 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_INTERNAL_ANALYTICS_SHARING_LOG_MATCHERS_H_
|
||||
#define THIRD_PARTY_NEARBY_INTERNAL_ANALYTICS_SHARING_LOG_MATCHERS_H_
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
namespace nearby::analytics {
|
||||
|
||||
MATCHER_P(HasCategory, category, "has category") {
|
||||
return arg.event_category() == category;
|
||||
}
|
||||
|
||||
MATCHER_P(HasEventType, event_type, "has event type") {
|
||||
return arg.event_type() == event_type;
|
||||
}
|
||||
|
||||
MATCHER_P(HasAction, action, "has action") {
|
||||
return arg.action() == action;
|
||||
}
|
||||
|
||||
MATCHER_P(HasSessionId, session_id, "has session id") {
|
||||
return arg.session_id() == session_id;
|
||||
}
|
||||
|
||||
} // namespace nearby::analytics
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_INTERNAL_ANALYTICS_SHARING_LOG_MATCHERS_H_
|
||||
@@ -206,6 +206,7 @@ cc_library(
|
||||
"//internal/base:files",
|
||||
"//internal/platform:types",
|
||||
"//proto:sharing_enums_cc_proto",
|
||||
"//sharing/analytics",
|
||||
"//sharing/certificates",
|
||||
"//sharing/common:compatible_u8_string",
|
||||
"//sharing/internal/public:logging",
|
||||
@@ -521,9 +522,11 @@ cc_test(
|
||||
":types",
|
||||
"//base:casts",
|
||||
"//internal/account",
|
||||
"//internal/analytics:mock_event_logger",
|
||||
"//internal/flags:nearby_flags",
|
||||
"//internal/platform/implementation/g3", # fixdeps: keep
|
||||
"//internal/test",
|
||||
"//sharing/analytics",
|
||||
"//sharing/certificates",
|
||||
"//sharing/certificates:test_support",
|
||||
"//sharing/common",
|
||||
@@ -727,8 +730,10 @@ cc_test(
|
||||
":test_support",
|
||||
":transfer_metadata",
|
||||
":types",
|
||||
"//internal/analytics:mock_event_logger",
|
||||
"//internal/platform/implementation/g3", # fixdeps: keep
|
||||
"//internal/test",
|
||||
"//sharing/analytics",
|
||||
"//sharing/certificates:test_support",
|
||||
"@com_github_protobuf_matchers//protobuf-matchers",
|
||||
"@com_google_absl//absl/strings:string_view",
|
||||
@@ -773,8 +778,10 @@ cc_test(
|
||||
":test_support",
|
||||
":transfer_metadata",
|
||||
":types",
|
||||
"//internal/analytics:mock_event_logger",
|
||||
"//internal/platform/implementation/g3", # fixdeps: keep
|
||||
"//internal/test",
|
||||
"//sharing/analytics",
|
||||
"//sharing/proto:wire_format_cc_proto",
|
||||
"@com_github_protobuf_matchers//protobuf-matchers",
|
||||
"@com_google_absl//absl/strings:string_view",
|
||||
@@ -796,11 +803,14 @@ cc_test(
|
||||
":test_support",
|
||||
":transfer_metadata",
|
||||
":types",
|
||||
"//internal/analytics:mock_event_logger",
|
||||
"//internal/platform/implementation/g3", # fixdeps: keep
|
||||
"//internal/test",
|
||||
"//proto:sharing_enums_cc_proto",
|
||||
"//sharing/analytics",
|
||||
"//sharing/internal/public:logging",
|
||||
"//sharing/proto:wire_format_cc_proto",
|
||||
"//sharing/proto/analytics:sharing_log_cc_proto",
|
||||
"//third_party/protobuf",
|
||||
"@com_github_protobuf_matchers//protobuf-matchers",
|
||||
"@com_google_absl//absl/strings:string_view",
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "internal/platform/clock.h"
|
||||
#include "internal/platform/task_runner.h"
|
||||
#include "sharing/analytics/analytics_recorder.h"
|
||||
#include "sharing/attachment_container.h"
|
||||
#include "sharing/common/compatible_u8_string.h"
|
||||
#include "sharing/constants.h"
|
||||
@@ -51,17 +52,20 @@ namespace {
|
||||
using ::location::nearby::proto::sharing::OSType;
|
||||
using ::nearby::sharing::service::proto::ConnectionResponseFrame;
|
||||
using ::nearby::sharing::service::proto::IntroductionFrame;
|
||||
using ::location::nearby::proto::sharing::ResponseToIntroduction;
|
||||
using ::nearby::sharing::service::proto::V1Frame;
|
||||
using ::nearby::sharing::service::proto::WifiCredentials;
|
||||
|
||||
} // namespace
|
||||
|
||||
IncomingShareSession::IncomingShareSession(
|
||||
TaskRunner& service_thread, std::string endpoint_id,
|
||||
TaskRunner& service_thread,
|
||||
analytics::AnalyticsRecorder& analytics_recorder, std::string endpoint_id,
|
||||
const ShareTarget& share_target,
|
||||
std::function<void(const IncomingShareSession&, const TransferMetadata&)>
|
||||
transfer_update_callback)
|
||||
: ShareSession(service_thread, std::move(endpoint_id), share_target),
|
||||
: ShareSession(service_thread, analytics_recorder, std::move(endpoint_id),
|
||||
share_target),
|
||||
transfer_update_callback_(std::move(transfer_update_callback)) {}
|
||||
|
||||
IncomingShareSession::IncomingShareSession(IncomingShareSession&&) = default;
|
||||
@@ -200,6 +204,9 @@ void IncomingShareSession::AcceptTransfer(
|
||||
}
|
||||
WriteResponseFrame(ConnectionResponseFrame::ACCEPT);
|
||||
NL_VLOG(1) << __func__ << ": Successfully wrote response frame";
|
||||
// Log analytics event of responding to introduction.
|
||||
analytics_recorder().NewRespondToIntroduction(
|
||||
ResponseToIntroduction::ACCEPT_INTRODUCTION, session_id());
|
||||
|
||||
UpdateTransferMetadata(
|
||||
TransferMetadataBuilder()
|
||||
@@ -214,6 +221,9 @@ void IncomingShareSession::AcceptTransfer(
|
||||
// upgrade are no longer a concern.
|
||||
NL_LOG(INFO) << __func__ << ": Upgrade bandwidth when sending accept.";
|
||||
}
|
||||
// Log analytics event of starting to receive payloads.
|
||||
analytics_recorder().NewReceiveAttachmentsStart(session_id(),
|
||||
attachment_container());
|
||||
}
|
||||
|
||||
bool IncomingShareSession::UpdateFilePayloadPaths(
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include "internal/platform/clock.h"
|
||||
#include "internal/platform/task_runner.h"
|
||||
#include "sharing/analytics/analytics_recorder.h"
|
||||
#include "sharing/nearby_connection.h"
|
||||
#include "sharing/nearby_connections_manager.h"
|
||||
#include "sharing/paired_key_verification_runner.h"
|
||||
@@ -39,7 +40,8 @@ namespace nearby::sharing {
|
||||
class IncomingShareSession : public ShareSession {
|
||||
public:
|
||||
IncomingShareSession(
|
||||
TaskRunner& service_thread, std::string endpoint_id,
|
||||
TaskRunner& service_thread,
|
||||
analytics::AnalyticsRecorder& analytics_recorder, std::string endpoint_id,
|
||||
const ShareTarget& share_target,
|
||||
std::function<void(const IncomingShareSession&, const TransferMetadata&)>
|
||||
transfer_update_callback);
|
||||
|
||||
@@ -28,9 +28,12 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/time/clock.h"
|
||||
#include "internal/analytics/mock_event_logger.h"
|
||||
#include "internal/analytics/sharing_log_matchers.h"
|
||||
#include "internal/test/fake_clock.h"
|
||||
#include "internal/test/fake_task_runner.h"
|
||||
#include "proto/sharing_enums.pb.h"
|
||||
#include "sharing/analytics/analytics_recorder.h"
|
||||
#include "sharing/attachment_compare.h" // IWYU pragma: keep
|
||||
#include "sharing/fake_nearby_connection.h"
|
||||
#include "sharing/fake_nearby_connections_manager.h"
|
||||
@@ -39,6 +42,7 @@
|
||||
#include "sharing/nearby_connections_types.h"
|
||||
#include "sharing/nearby_sharing_decoder_impl.h"
|
||||
#include "sharing/paired_key_verification_runner.h"
|
||||
#include "sharing/proto/analytics/nearby_sharing_log.pb.h"
|
||||
#include "sharing/proto/wire_format.pb.h"
|
||||
#include "sharing/share_target.h"
|
||||
#include "sharing/text_attachment.h"
|
||||
@@ -49,7 +53,15 @@
|
||||
namespace nearby::sharing {
|
||||
namespace {
|
||||
|
||||
using ::location::nearby::proto::sharing::EventCategory;
|
||||
using ::location::nearby::proto::sharing::EventType;
|
||||
using ::location::nearby::proto::sharing::OSType;
|
||||
using ::location::nearby::proto::sharing::ResponseToIntroduction;
|
||||
using ::nearby::analytics::HasAction;
|
||||
using ::nearby::analytics::HasCategory;
|
||||
using ::nearby::analytics::HasEventType;
|
||||
using ::nearby::analytics::HasSessionId;
|
||||
using ::nearby::sharing::analytics::proto::SharingLog;
|
||||
using ::nearby::sharing::service::proto::ConnectionResponseFrame;
|
||||
using ::nearby::sharing::service::proto::FileMetadata;
|
||||
using ::nearby::sharing::service::proto::Frame;
|
||||
@@ -59,12 +71,15 @@ using ::nearby::sharing::service::proto::V1Frame;
|
||||
using ::nearby::sharing::service::proto::WifiCredentials;
|
||||
using ::nearby::sharing::service::proto::WifiCredentialsMetadata;
|
||||
using ::testing::_;
|
||||
using ::testing::AllOf;
|
||||
using ::testing::Eq;
|
||||
using ::testing::Invoke;
|
||||
using ::testing::IsEmpty;
|
||||
using ::testing::IsFalse;
|
||||
using ::testing::IsTrue;
|
||||
using ::testing::Matcher;
|
||||
using ::testing::MockFunction;
|
||||
using ::testing::Property;
|
||||
using ::testing::UnorderedElementsAre;
|
||||
|
||||
constexpr absl::string_view kEndpointId = "ABCD";
|
||||
@@ -99,8 +114,8 @@ std::unique_ptr<Payload> CreateWifiCredentialsPayload(
|
||||
class IncomingShareSessionTest : public ::testing::Test {
|
||||
protected:
|
||||
IncomingShareSessionTest()
|
||||
: session_(task_runner_, std::string(kEndpointId), share_target_,
|
||||
transfer_metadata_callback_.AsStdFunction()) {
|
||||
: session_(task_runner_, analytics_recorder_, std::string(kEndpointId),
|
||||
share_target_, transfer_metadata_callback_.AsStdFunction()) {
|
||||
NL_CHECK(
|
||||
proto2::TextFormat::ParseFromString(R"pb(
|
||||
file_metadata {
|
||||
@@ -153,6 +168,9 @@ class IncomingShareSessionTest : public ::testing::Test {
|
||||
|
||||
FakeClock clock_;
|
||||
FakeTaskRunner task_runner_{&clock_, 1};
|
||||
nearby::analytics::MockEventLogger mock_event_logger_;
|
||||
analytics::AnalyticsRecorder analytics_recorder_{/*vendor_id=*/0,
|
||||
&mock_event_logger_};
|
||||
ShareTarget share_target_;
|
||||
MockFunction<void(const IncomingShareSession&, const TransferMetadata&)>
|
||||
transfer_metadata_callback_;
|
||||
@@ -574,6 +592,7 @@ TEST_F(IncomingShareSessionTest, FinalizePayloadsMissingWifiPayloads) {
|
||||
TEST_F(IncomingShareSessionTest, AcceptTransferSuccess) {
|
||||
NearbySharingDecoderImpl nearby_sharing_decoder;
|
||||
FakeNearbyConnection connection;
|
||||
session_.set_session_id(1234);
|
||||
EXPECT_TRUE(
|
||||
session_.OnConnected(nearby_sharing_decoder, absl::Now(), &connection));
|
||||
EXPECT_THAT(session_.ProcessIntroduction(introduction_frame_),
|
||||
@@ -584,6 +603,21 @@ TEST_F(IncomingShareSessionTest, AcceptTransferSuccess) {
|
||||
EXPECT_EQ(metadata.status(),
|
||||
TransferMetadata::Status::kAwaitingRemoteAcceptance);
|
||||
}));
|
||||
EXPECT_CALL(
|
||||
mock_event_logger_,
|
||||
Log(Matcher<const SharingLog&>(AllOf((
|
||||
HasCategory(EventCategory::RECEIVING_EVENT),
|
||||
HasEventType(EventType::RESPOND_TO_INTRODUCTION),
|
||||
Property(&SharingLog::respond_introduction,
|
||||
HasAction(ResponseToIntroduction::ACCEPT_INTRODUCTION)),
|
||||
Property(&SharingLog::respond_introduction,
|
||||
HasSessionId(1234)))))));
|
||||
EXPECT_CALL(mock_event_logger_,
|
||||
Log(Matcher<const SharingLog&>(
|
||||
AllOf((HasCategory(EventCategory::RECEIVING_EVENT),
|
||||
HasEventType(EventType::RECEIVE_ATTACHMENTS_START),
|
||||
Property(&SharingLog::receive_attachments_start,
|
||||
HasSessionId(1234)))))));
|
||||
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
FakeClock clock;
|
||||
|
||||
@@ -832,9 +832,6 @@ void NearbySharingServiceImpl::Accept(
|
||||
std::move(status_codes_callback)(StatusCodes::kOutOfOrderApiCall);
|
||||
return;
|
||||
}
|
||||
// Log analytics event of responding to introduction.
|
||||
analytics_recorder_->NewRespondToIntroduction(
|
||||
ResponseToIntroduction::ACCEPT_INTRODUCTION, session->session_id());
|
||||
|
||||
bool is_incoming = session->IsIncoming();
|
||||
std::optional<
|
||||
@@ -855,10 +852,6 @@ void NearbySharingServiceImpl::Accept(
|
||||
GetIncomingShareSession(share_target_id);
|
||||
mutual_acceptance_timeout_alarm_.reset();
|
||||
|
||||
// Log analytics event of starting to receive payloads.
|
||||
analytics_recorder_->NewReceiveAttachmentsStart(
|
||||
incoming_session->session_id(),
|
||||
incoming_session->attachment_container());
|
||||
incoming_session->AcceptTransfer(
|
||||
context_->GetClock(), *nearby_connections_manager_,
|
||||
absl::bind_front(
|
||||
@@ -3499,7 +3492,8 @@ IncomingShareSession& NearbySharingServiceImpl::CreateIncomingShareSession(
|
||||
std::optional<NearbyShareDecryptedPublicCertificate> certificate) {
|
||||
NL_DCHECK(share_target.is_incoming);
|
||||
auto [it, inserted] = incoming_share_session_map_.try_emplace(
|
||||
share_target.id, *service_thread_, std::string(endpoint_id), share_target,
|
||||
share_target.id, *service_thread_, *analytics_recorder_,
|
||||
std::string(endpoint_id), share_target,
|
||||
absl::bind_front(&NearbySharingServiceImpl::OnIncomingTransferUpdate,
|
||||
this));
|
||||
if (!inserted) {
|
||||
@@ -3529,7 +3523,8 @@ OutgoingShareSession& NearbySharingServiceImpl::CreateOutgoingShareSession(
|
||||
<< ") to outgoing share target map";
|
||||
outgoing_share_target_map_.insert_or_assign(endpoint_id, share_target);
|
||||
auto [it_out, inserted] = outgoing_share_session_map_.try_emplace(
|
||||
share_target.id, *service_thread_, std::string(endpoint_id), share_target,
|
||||
share_target.id, *service_thread_, *analytics_recorder_,
|
||||
std::string(endpoint_id), share_target,
|
||||
absl::bind_front(&NearbySharingServiceImpl::OnOutgoingTransferUpdate,
|
||||
this));
|
||||
auto& session = it_out->second;
|
||||
|
||||
@@ -41,11 +41,13 @@
|
||||
#include "absl/time/time.h"
|
||||
#include "absl/types/span.h"
|
||||
#include "internal/account/account_manager_impl.h"
|
||||
#include "internal/analytics/mock_event_logger.h"
|
||||
#include "internal/flags/nearby_flags.h"
|
||||
#include "internal/test/fake_account_manager.h"
|
||||
#include "internal/test/fake_device_info.h"
|
||||
#include "internal/test/fake_task_runner.h"
|
||||
#include "sharing/advertisement.h"
|
||||
#include "sharing/analytics/analytics_recorder.h"
|
||||
#include "sharing/attachment_container.h"
|
||||
#include "sharing/certificates/fake_nearby_share_certificate_manager.h"
|
||||
#include "sharing/certificates/nearby_share_certificate_manager_impl.h"
|
||||
@@ -4903,10 +4905,14 @@ TEST_F(NearbySharingServiceImplTest, RemoveIncomingPayloads) {
|
||||
EXPECT_EQ(unknown_file_paths_to_delete.size(), 2);
|
||||
EXPECT_THAT(unknown_file_paths_to_delete,
|
||||
UnorderedElementsAre("test1.txt", "test2.txt"));
|
||||
nearby::analytics::MockEventLogger mock_event_logger;
|
||||
analytics::AnalyticsRecorder analytics_recorder{/*vendor_id=*/0,
|
||||
&mock_event_logger};
|
||||
ShareTarget share_target;
|
||||
share_target.is_incoming = true;
|
||||
IncomingShareSession session(
|
||||
*sharing_service_task_runner_, "endpoint_id", share_target,
|
||||
*sharing_service_task_runner_, analytics_recorder, "endpoint_id",
|
||||
share_target,
|
||||
[](const IncomingShareSession&, const TransferMetadata&) {});
|
||||
service_->RemoveIncomingPayloads(session);
|
||||
EXPECT_EQ(
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/platform/clock.h"
|
||||
#include "internal/platform/task_runner.h"
|
||||
#include "sharing/analytics/analytics_recorder.h"
|
||||
#include "sharing/attachment_container.h"
|
||||
#include "sharing/file_attachment.h"
|
||||
#include "sharing/internal/public/logging.h"
|
||||
@@ -50,11 +51,13 @@ using ::nearby::sharing::service::proto::ProgressUpdateFrame;
|
||||
using ::nearby::sharing::service::proto::V1Frame;
|
||||
|
||||
OutgoingShareSession::OutgoingShareSession(
|
||||
TaskRunner& service_thread, std::string endpoint_id,
|
||||
TaskRunner& service_thread,
|
||||
analytics::AnalyticsRecorder& analytics_recorder, std::string endpoint_id,
|
||||
const ShareTarget& share_target,
|
||||
std::function<void(OutgoingShareSession&, const TransferMetadata&)>
|
||||
transfer_update_callback)
|
||||
: ShareSession(service_thread, std::move(endpoint_id), share_target),
|
||||
: ShareSession(service_thread, analytics_recorder, std::move(endpoint_id),
|
||||
share_target),
|
||||
transfer_update_callback_(std::move(transfer_update_callback)) {}
|
||||
|
||||
OutgoingShareSession::OutgoingShareSession(OutgoingShareSession&&) =
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "internal/platform/clock.h"
|
||||
#include "internal/platform/task_runner.h"
|
||||
#include "sharing/analytics/analytics_recorder.h"
|
||||
#include "sharing/nearby_connection.h"
|
||||
#include "sharing/nearby_connections_manager.h"
|
||||
#include "sharing/nearby_connections_types.h"
|
||||
@@ -41,7 +42,8 @@ namespace nearby::sharing {
|
||||
class OutgoingShareSession : public ShareSession {
|
||||
public:
|
||||
OutgoingShareSession(
|
||||
TaskRunner& service_thread, std::string endpoint_id,
|
||||
TaskRunner& service_thread,
|
||||
analytics::AnalyticsRecorder& analytics_recorder, std::string endpoint_id,
|
||||
const ShareTarget& share_target,
|
||||
std::function<void(OutgoingShareSession&, const TransferMetadata&)>
|
||||
transfer_update_callback);
|
||||
|
||||
@@ -26,8 +26,10 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/time/clock.h"
|
||||
#include "internal/analytics/mock_event_logger.h"
|
||||
#include "internal/test/fake_clock.h"
|
||||
#include "internal/test/fake_task_runner.h"
|
||||
#include "sharing/analytics/analytics_recorder.h"
|
||||
#include "sharing/attachment_container.h"
|
||||
#include "sharing/fake_nearby_connection.h"
|
||||
#include "sharing/fake_nearby_connections_manager.h"
|
||||
@@ -65,7 +67,8 @@ constexpr absl::string_view kEndpointId = "ABCD";
|
||||
class OutgoingShareSessionTest : public ::testing::Test {
|
||||
public:
|
||||
OutgoingShareSessionTest()
|
||||
: session_(fake_task_runner_, std::string(kEndpointId), share_target_,
|
||||
: session_(fake_task_runner_, analytics_recorder_,
|
||||
std::string(kEndpointId), share_target_,
|
||||
[](OutgoingShareSession&, const TransferMetadata&) {}),
|
||||
text1_(nearby::sharing::service::proto::TextMetadata::URL,
|
||||
"A bit of text body", "Some text title", "text/html"),
|
||||
@@ -87,6 +90,9 @@ class OutgoingShareSessionTest : public ::testing::Test {
|
||||
protected:
|
||||
FakeClock fake_clock_;
|
||||
FakeTaskRunner fake_task_runner_ {&fake_clock_, 1};
|
||||
nearby::analytics::MockEventLogger mock_event_logger_;
|
||||
analytics::AnalyticsRecorder analytics_recorder_{/*vendor_id=*/0,
|
||||
&mock_event_logger_};
|
||||
NearbySharingDecoderImpl decoder_;
|
||||
ShareTarget share_target_;
|
||||
OutgoingShareSession session_;
|
||||
@@ -99,8 +105,8 @@ class OutgoingShareSessionTest : public ::testing::Test {
|
||||
|
||||
TEST_F(OutgoingShareSessionTest, GetFilePaths) {
|
||||
OutgoingShareSession session(
|
||||
fake_task_runner_, std::string(kEndpointId), share_target_,
|
||||
[](OutgoingShareSession&, const TransferMetadata&) {});
|
||||
fake_task_runner_, analytics_recorder_, std::string(kEndpointId),
|
||||
share_target_, [](OutgoingShareSession&, const TransferMetadata&) {});
|
||||
AttachmentContainer container(std::vector<TextAttachment>{},
|
||||
std::vector<FileAttachment>{file1_, file2_},
|
||||
std::vector<WifiCredentialsAttachment>{});
|
||||
@@ -115,8 +121,8 @@ TEST_F(OutgoingShareSessionTest, GetFilePaths) {
|
||||
|
||||
TEST_F(OutgoingShareSessionTest, CreateTextPayloadsWithNoTextAttachments) {
|
||||
OutgoingShareSession session(
|
||||
fake_task_runner_, std::string(kEndpointId), share_target_,
|
||||
[](OutgoingShareSession&, const TransferMetadata&) {});
|
||||
fake_task_runner_, analytics_recorder_, std::string(kEndpointId),
|
||||
share_target_, [](OutgoingShareSession&, const TransferMetadata&) {});
|
||||
session.CreateTextPayloads();
|
||||
const std::vector<Payload>& payloads = session.text_payloads();
|
||||
|
||||
@@ -147,8 +153,8 @@ TEST_F(OutgoingShareSessionTest, CreateTextPayloads) {
|
||||
|
||||
TEST_F(OutgoingShareSessionTest, CreateFilePayloadsWithNoFileAttachments) {
|
||||
OutgoingShareSession session(
|
||||
fake_task_runner_, std::string(kEndpointId), share_target_,
|
||||
[](OutgoingShareSession&, const TransferMetadata&) {});
|
||||
fake_task_runner_, analytics_recorder_, std::string(kEndpointId),
|
||||
share_target_, [](OutgoingShareSession&, const TransferMetadata&) {});
|
||||
|
||||
EXPECT_THAT(
|
||||
session.CreateFilePayloads(std::vector<NearbyFileHandler::FileInfo>()),
|
||||
@@ -195,8 +201,8 @@ TEST_F(OutgoingShareSessionTest, CreateFilePayloads) {
|
||||
|
||||
TEST_F(OutgoingShareSessionTest, CreateWifiPayloadsWithNoWifiAttachments) {
|
||||
OutgoingShareSession session(
|
||||
fake_task_runner_, std::string(kEndpointId), share_target_,
|
||||
[](OutgoingShareSession&, const TransferMetadata&) {});
|
||||
fake_task_runner_, analytics_recorder_, std::string(kEndpointId),
|
||||
share_target_, [](OutgoingShareSession&, const TransferMetadata&) {});
|
||||
session.CreateWifiCredentialsPayloads();
|
||||
const std::vector<Payload>& payloads = session.file_payloads();
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "absl/time/time.h"
|
||||
#include "internal/platform/clock.h"
|
||||
#include "internal/platform/task_runner.h"
|
||||
#include "sharing/analytics/analytics_recorder.h"
|
||||
#include "sharing/certificates/nearby_share_certificate_manager.h"
|
||||
#include "sharing/constants.h"
|
||||
#include "sharing/incoming_frames_reader.h"
|
||||
@@ -67,9 +68,12 @@ std::string TokenToFourDigitString(const std::vector<uint8_t>& bytes) {
|
||||
|
||||
} // namespace
|
||||
|
||||
ShareSession::ShareSession(TaskRunner& service_thread, std::string endpoint_id,
|
||||
ShareSession::ShareSession(TaskRunner& service_thread,
|
||||
analytics::AnalyticsRecorder& analytics_recorder,
|
||||
std::string endpoint_id,
|
||||
const ShareTarget& share_target)
|
||||
: service_thread_(service_thread),
|
||||
analytics_recorder_(analytics_recorder),
|
||||
endpoint_id_(std::move(endpoint_id)),
|
||||
self_share_(share_target.for_self_share),
|
||||
share_target_(share_target) {}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "internal/platform/clock.h"
|
||||
#include "internal/platform/task_runner.h"
|
||||
#include "proto/sharing_enums.pb.h"
|
||||
#include "sharing/analytics/analytics_recorder.h"
|
||||
#include "sharing/attachment_container.h"
|
||||
#include "sharing/certificates/nearby_share_certificate_manager.h"
|
||||
#include "sharing/certificates/nearby_share_decrypted_public_certificate.h"
|
||||
@@ -47,8 +48,9 @@ namespace nearby::sharing {
|
||||
// This class is thread-compatible.
|
||||
class ShareSession {
|
||||
public:
|
||||
ShareSession(TaskRunner& service_thread, std::string endpoint_id,
|
||||
const ShareTarget& share_target);
|
||||
ShareSession(TaskRunner& service_thread,
|
||||
analytics::AnalyticsRecorder& analytics_recorder,
|
||||
std::string endpoint_id, const ShareTarget& share_target);
|
||||
ShareSession(ShareSession&&);
|
||||
ShareSession& operator=(ShareSession&&) = delete;
|
||||
ShareSession& operator=(const ShareSession&) = delete;
|
||||
@@ -143,6 +145,10 @@ class ShareSession {
|
||||
const TransferMetadata& metadata) = 0;
|
||||
virtual bool OnNewConnection(NearbyConnection* connection) = 0;
|
||||
|
||||
analytics::AnalyticsRecorder& analytics_recorder() {
|
||||
return analytics_recorder_;
|
||||
};
|
||||
|
||||
void SetAttachmentPayloadId(int64_t attachment_id, int64_t payload_id);
|
||||
|
||||
void set_payload_tracker(std::shared_ptr<PayloadTracker> payload_tracker) {
|
||||
@@ -161,6 +167,7 @@ class ShareSession {
|
||||
|
||||
private:
|
||||
TaskRunner& service_thread_;
|
||||
analytics::AnalyticsRecorder& analytics_recorder_;
|
||||
std::string endpoint_id_;
|
||||
std::optional<NearbyShareDecryptedPublicCertificate> certificate_;
|
||||
NearbyConnection* connection_ = nullptr;
|
||||
|
||||
@@ -25,8 +25,10 @@
|
||||
#include "absl/synchronization/notification.h"
|
||||
#include "absl/time/clock.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "internal/analytics/mock_event_logger.h"
|
||||
#include "internal/test/fake_clock.h"
|
||||
#include "internal/test/fake_task_runner.h"
|
||||
#include "sharing/analytics/analytics_recorder.h"
|
||||
#include "sharing/certificates/fake_nearby_share_certificate_manager.h"
|
||||
#include "sharing/fake_nearby_connection.h"
|
||||
#include "sharing/fake_nearby_connections_manager.h"
|
||||
@@ -51,7 +53,8 @@ constexpr absl::string_view kEndpointId = "12345";
|
||||
class TestShareSession : public ShareSession {
|
||||
public:
|
||||
TestShareSession(std::string endpoint_id, const ShareTarget& share_target)
|
||||
: ShareSession(fake_task_runner_, std::move(endpoint_id), share_target),
|
||||
: ShareSession(fake_task_runner_, analytics_recorder_,
|
||||
std::move(endpoint_id), share_target),
|
||||
is_incoming_(share_target.is_incoming) {}
|
||||
|
||||
bool IsIncoming() const override { return is_incoming_; }
|
||||
@@ -91,6 +94,9 @@ class TestShareSession : public ShareSession {
|
||||
private:
|
||||
FakeClock fake_clock_;
|
||||
FakeTaskRunner fake_task_runner_ {&fake_clock_, 1};
|
||||
nearby::analytics::MockEventLogger mock_event_logger_;
|
||||
analytics::AnalyticsRecorder analytics_recorder_{/*vendor_id=*/0,
|
||||
&mock_event_logger_};
|
||||
const bool is_incoming_;
|
||||
int transfer_update_count_ = 0;
|
||||
std::optional<TransferMetadata> last_transfer_metadata_;
|
||||
|
||||
Reference in New Issue
Block a user