#include "components/feed/core/v2/metrics_reporter.h"
#include <algorithm>
#include <cmath>
#include <memory>
#include <ratio>
#include <string>
#include <string_view>
#include "base/compiler_specific.h"
#include "base/feature_list.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/user_metrics.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/feed/core/v2/enums.h"
#include "components/feed/core/v2/feedstore_util.h"
#include "components/feed/core/v2/prefs.h"
#include "components/feed/core/v2/public/common_enums.h"
#include "components/feed/core/v2/public/feed_api.h"
#include "components/feed/core/v2/public/stream_type.h"
#include "components/feed/core/v2/public/web_feed_subscriptions.h"
#include "components/feed/feed_feature_list.h"
#ifndef OFFICIAL_BUILD
#define VVLOG …
#else
#define VVLOG …
#endif
namespace feed {
namespace {
StreamKind kStreamKinds[] = …;
FeedEngagementType;
FeedUserActionType;
const int kMaxSuggestionsTotal = …;
constexpr base::TimeDelta kLoadTimeout = …;
constexpr base::TimeDelta kOpenTimeout = …;
constexpr base::TimeDelta kTimeSpentInFeedInteractionTimeout = …;
constexpr base::TimeDelta kVisitTimeout = …;
constexpr base::TimeDelta kGoodTimeInFeed = …;
constexpr base::TimeDelta kLongOpenTime = …;
constexpr base::TimeDelta kMinStableContentSliceVisibilityTime = …;
constexpr base::TimeDelta kMaxStableContentSliceVisibilityTime = …;
std::string_view HistogramReplacement(const StreamType& stream_type) { … }
void ReportEngagementTypeHistogram(const StreamType& stream_type,
FeedEngagementType engagement_type) { … }
void ReportCombinedEngagementTypeHistogram(FeedEngagementType engagement_type) { … }
void ReportContentSuggestionsOpened(const StreamType& stream_type,
int index_in_stream) { … }
void ReportUserActionHistogram(FeedUserActionType action_type) { … }
std::string LoadLatencyStepName(LoadLatencyTimes::StepKind kind) { … }
std::string_view ContentOrderToString(ContentOrder content_order) { … }
FeedSortType GetSortTypeFromContentOrder(ContentOrder content_order) { … }
void ReportLoadLatencies(std::unique_ptr<LoadLatencyTimes> latencies) { … }
void ReportContentLifetimeStaleAge(base::TimeDelta content_lifetime_stale_age) { … }
void ReportContentLifetimeInvalidAge(
base::TimeDelta content_lifetime_invalid_age) { … }
std::string_view NetworkRequestTypeUmaName(NetworkRequestType type) { … }
std::string InfoCardActionUmaName(const StreamType& stream_type,
std::string_view action_name) { … }
UserSettingsOnStart GetUserSettingsOnStart(
bool isEnabledByEnterprisePolicy,
bool isFeedVisible,
bool isSignedIn,
bool isEnabled,
const feedstore::Metadata& metadata) { … }
void ReportSubscriptionCountAtEngagementTime(const StreamType& stream_type,
int subscription_count) { … }
void ReportCombinedSubscriptionCountAtEngagementTime(int subscription_count) { … }
bool IsGoodExplicitInteraction(FeedUserActionType action) { … }
}
MetricsReporter::LoadStreamResultSummary::LoadStreamResultSummary() = default;
MetricsReporter::LoadStreamResultSummary::LoadStreamResultSummary(
const LoadStreamResultSummary& src) = default;
MetricsReporter::LoadStreamResultSummary::~LoadStreamResultSummary() = default;
MetricsReporter::SurfaceWaiting::SurfaceWaiting() = default;
MetricsReporter::SurfaceWaiting::SurfaceWaiting(
const feed::StreamType& stream_type,
base::TimeTicks wait_start)
: … { … }
MetricsReporter::SurfaceWaiting::~SurfaceWaiting() = default;
MetricsReporter::SurfaceWaiting::SurfaceWaiting(const SurfaceWaiting&) =
default;
MetricsReporter::SurfaceWaiting::SurfaceWaiting(SurfaceWaiting&&) = default;
MetricsReporter::SurfaceWaiting& MetricsReporter::SurfaceWaiting::operator=(
const SurfaceWaiting&) = default;
MetricsReporter::SurfaceWaiting& MetricsReporter::SurfaceWaiting::operator=(
SurfaceWaiting&&) = default;
MetricsReporter::MetricsReporter(PrefService* profile_prefs)
: … { … }
MetricsReporter::~MetricsReporter() { … }
void MetricsReporter::Initialize(Delegate* delegate) { … }
void MetricsReporter::OnMetadataInitialized(
bool isEnabledByEnterprisePolicy,
bool isFeedVisible,
bool isSignedIn,
bool isEnabled,
const feedstore::Metadata& metadata) { … }
void MetricsReporter::OnEnterBackground() { … }
void MetricsReporter::RecordInteraction(const StreamType& stream_type) { … }
void MetricsReporter::LogContentStats(const StreamType& stream_type,
const ContentStats& content_stats) { … }
void MetricsReporter::TrackTimeSpentInFeed(bool interacted_or_scrolled) { … }
void MetricsReporter::FinalizeVisit() { … }
void MetricsReporter::RecordEngagement(const StreamType& stream_type,
int scroll_distance_dp,
bool interacted) { … }
void MetricsReporter::StreamScrollStart() { … }
void MetricsReporter::StreamScrolled(const StreamType& stream_type,
int distance_dp) { … }
void MetricsReporter::ContentSliceViewed(const StreamType& stream_type,
int index_in_stream,
int stream_slice_count) { … }
void MetricsReporter::FeedViewed(SurfaceId surface_id) { … }
void MetricsReporter::OpenAction(const StreamType& stream_type,
int index_in_stream,
OpenActionType action_type) { … }
void MetricsReporter::OpenVisitComplete(base::TimeDelta visit_time) { … }
void MetricsReporter::PageLoaded() { … }
void MetricsReporter::OtherUserAction(const StreamType& stream_type,
FeedUserActionType action_type) { … }
void MetricsReporter::ReportStableContentSliceVisibilityTimeForGoodVisits(
base::TimeDelta delta) { … }
void MetricsReporter::SurfaceOpened(
const StreamType& stream_type,
SurfaceId surface_id,
SingleWebFeedEntryPoint single_web_feed_entry_point) { … }
void MetricsReporter::SurfaceClosed(SurfaceId surface_id) { … }
void MetricsReporter::FinalizeMetrics() { … }
void MetricsReporter::ReportOpenFeedIfNeeded(SurfaceId surface_id,
bool success) { … }
void MetricsReporter::ReportGetMoreIfNeeded(SurfaceId surface_id,
bool success) { … }
void MetricsReporter::CardOpenBegin(const StreamType& stream_type) { … }
void MetricsReporter::CardOpenTimeout(base::TimeTicks start_ticks) { … }
void MetricsReporter::ReportCardOpenEndIfNeeded(bool success) { … }
void MetricsReporter::NetworkRefreshRequestStarted(
const StreamType& stream_type,
ContentOrder content_order) { … }
void MetricsReporter::NetworkRequestComplete(
NetworkRequestType type,
const NetworkResponseInfo& response_info) { … }
void MetricsReporter::OnLoadStream(
const StreamType& stream_type,
const LoadStreamResultSummary& result_summary,
const ContentStats& content_stats,
std::unique_ptr<LoadLatencyTimes> load_latencies) { … }
void MetricsReporter::OnBackgroundRefresh(const StreamType& stream_type,
LoadStreamStatus final_status) { … }
void MetricsReporter::OnManualRefresh(const StreamType& stream_type,
const feedstore::Metadata& metadata,
const ContentHashSet& content_hashes) { … }
void MetricsReporter::OnLoadMoreBegin(const StreamType& stream_type,
SurfaceId surface_id) { … }
void MetricsReporter::OnLoadMore(const StreamType& stream_type,
LoadStreamStatus status,
const ContentStats& content_stats) { … }
void MetricsReporter::OnImageFetched(const GURL& url,
int net_error_or_http_status) { … }
void MetricsReporter::OnResourceFetched(int net_error_or_http_status) { … }
void MetricsReporter::OnUploadActionsBatch(UploadActionsBatchStatus status) { … }
void MetricsReporter::OnUploadActions(UploadActionsStatus status) { … }
void MetricsReporter::ActivityLoggingEnabled(
bool response_has_logging_enabled) { … }
void MetricsReporter::NoticeCardFulfilled(bool response_has_notice_card) { … }
void MetricsReporter::NoticeCardFulfilledObsolete(
bool response_has_notice_card) { … }
void MetricsReporter::SurfaceReceivedContent(SurfaceId surface_id) { … }
void MetricsReporter::ReportPersistentDataIfDayIsDone() { … }
MetricsReporter::StreamStats& MetricsReporter::ForStream(
const StreamType& stream_type) { … }
void MetricsReporter::OnFollowAttempt(
bool followed_with_id,
const WebFeedSubscriptions::FollowWebFeedResult& result) { … }
void MetricsReporter::OnUnfollowAttempt(
const WebFeedSubscriptions::UnfollowWebFeedResult& result) { … }
void MetricsReporter::OnQueryAttempt(
const WebFeedSubscriptions::QueryWebFeedResult& result) { … }
void MetricsReporter::RefreshRecommendedWebFeedsAttempted(
WebFeedRefreshStatus status,
int recommended_web_feed_count) { … }
void MetricsReporter::RefreshSubscribedWebFeedsAttempted(
bool subscriptions_were_stale,
WebFeedRefreshStatus status,
int subscribed_web_feed_count) { … }
void MetricsReporter::ReportFollowCountOnLoad(bool content_shown,
int subscription_count) { … }
void MetricsReporter::OnInfoCardTrackViewStarted(const StreamType& stream_type,
int info_card_type) { … }
void MetricsReporter::OnInfoCardViewed(const StreamType& stream_type,
int info_card_type) { … }
void MetricsReporter::OnInfoCardClicked(const StreamType& stream_type,
int info_card_type) { … }
void MetricsReporter::OnInfoCardDismissedExplicitly(
const StreamType& stream_type,
int info_card_type) { … }
void MetricsReporter::OnInfoCardStateReset(const StreamType& stream_type,
int info_card_type) { … }
MetricsReporter::GoodVisitState::GoodVisitState(PersistentMetricsData& data)
: … { … }
void MetricsReporter::GoodVisitState::OnScroll() { … }
void MetricsReporter::GoodVisitState::OnGoodExplicitInteraction() { … }
void MetricsReporter::GoodVisitState::OnOpenComplete(
base::TimeDelta open_duration) { … }
void MetricsReporter::GoodVisitState::ExtendOrStartNewVisit() { … }
void MetricsReporter::GoodVisitState::AddTimeInFeed(base::TimeDelta time) { … }
void MetricsReporter::GoodVisitState::MaybeReportGoodVisit() { … }
void MetricsReporter::GoodVisitState::Reset() { … }
void MetricsReporter::ReportContentDuplication(
bool is_duplicated_at_pos_1,
bool is_duplicated_at_pos_2,
bool is_duplicated_at_pos_3,
int duplicate_percentage_for_first_10,
int duplicate_percentage_for_all) { … }
}