#include "components/safe_browsing/core/browser/safe_browsing_metrics_collector.h"
#include "base/json/values_util.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "base/time/time.h"
#include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/safe_browsing/core/browser/db/hit_report.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
namespace {
EventType;
UserState;
SafeBrowsingState;
const int kMetricsLoggingIntervalDay = …;
const int kTimestampsMaxLength = …;
const int kEsbDisabledMetricsQuota = …;
const int kEventMaxDurationDay = …;
const int kEsbShortEnabledUpperBoundHours = …;
const int kEsbLongEnabledLowerBoundHours = …;
std::string EventTypeToPrefKey(const EventType& type) { … }
std::string UserStateToPrefKey(const UserState& user_state) { … }
base::Value TimeToPrefValue(const base::Time& time) { … }
base::Time PrefValueToTime(const base::Value& value) { … }
}
namespace safe_browsing {
SafeBrowsingMetricsCollector::SafeBrowsingMetricsCollector(
PrefService* pref_service)
: … { … }
void SafeBrowsingMetricsCollector::Shutdown() { … }
void SafeBrowsingMetricsCollector::StartLogging() { … }
void SafeBrowsingMetricsCollector::LogMetricsAndScheduleNextLogging() { … }
void SafeBrowsingMetricsCollector::MaybeLogDailyEsbProtegoPingSent() { … }
void SafeBrowsingMetricsCollector::ScheduleNextLoggingAfterInterval(
base::TimeDelta interval) { … }
void SafeBrowsingMetricsCollector::LogDailyOptInMetrics() { … }
void SafeBrowsingMetricsCollector::LogDailyEventMetrics() { … }
void SafeBrowsingMetricsCollector::RemoveOldEventsFromPref() { … }
void SafeBrowsingMetricsCollector::AddSafeBrowsingEventToPref(
EventType event_type) { … }
void SafeBrowsingMetricsCollector::AddBypassEventToPref(
ThreatSource threat_source) { … }
std::optional<base::Time> SafeBrowsingMetricsCollector::GetLatestEventTimestamp(
EventType event_type) { … }
std::optional<base::Time> SafeBrowsingMetricsCollector::GetLatestEventTimestamp(
EventTypeFilter event_type_filter) { … }
std::optional<base::Time>
SafeBrowsingMetricsCollector::GetLatestSecuritySensitiveEventTimestamp() { … }
void SafeBrowsingMetricsCollector::AddSafeBrowsingEventAndUserStateToPref(
UserState user_state,
EventType event_type) { … }
void SafeBrowsingMetricsCollector::OnEnhancedProtectionPrefChanged() { … }
const base::Value::Dict*
SafeBrowsingMetricsCollector::GetSafeBrowsingEventDictionary(
UserState user_state) { … }
std::optional<SafeBrowsingMetricsCollector::Event>
SafeBrowsingMetricsCollector::GetLatestEventFromEventType(
UserState user_state,
EventType event_type) { … }
std::optional<SafeBrowsingMetricsCollector::Event>
SafeBrowsingMetricsCollector::GetLatestEventFromEventTypeFilter(
UserState user_state,
EventTypeFilter event_type_filter) { … }
void SafeBrowsingMetricsCollector::LogEnhancedProtectionDisabledMetrics() { … }
void SafeBrowsingMetricsCollector::
LogThrottledEnhancedProtectionDisabledMetrics() { … }
int SafeBrowsingMetricsCollector::GetEventCountSince(UserState user_state,
EventType event_type,
base::Time since_time) { … }
UserState SafeBrowsingMetricsCollector::GetUserState() { … }
bool SafeBrowsingMetricsCollector::IsBypassEventType(const EventType& type) { … }
bool SafeBrowsingMetricsCollector::IsSecuritySensitiveEventType(
const EventType& type) { … }
std::string SafeBrowsingMetricsCollector::GetUserStateMetricSuffix(
const UserState& user_state) { … }
std::string SafeBrowsingMetricsCollector::GetTimesDisabledSuffix() { … }
SafeBrowsingMetricsCollector::Event::Event(EventType type, base::Time timestamp)
: … { … }
}