chromium/components/safe_browsing/core/browser/password_protection/metrics_util.h

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_SAFE_BROWSING_CORE_BROWSER_PASSWORD_PROTECTION_METRICS_UTIL_H_
#define COMPONENTS_SAFE_BROWSING_CORE_BROWSER_PASSWORD_PROTECTION_METRICS_UTIL_H_

#include "components/safe_browsing/core/common/proto/csd.pb.h"

namespace base {
class TimeTicks;
}

namespace safe_browsing {

// UMA metrics
extern const char kAnyPasswordEntryRequestOutcomeHistogram[];
extern const char kAnyPasswordEntryVerdictHistogram[];
extern const char kEnterprisePasswordEntryRequestOutcomeHistogram[];
extern const char kEnterprisePasswordEntryVerdictHistogram[];
extern const char kEnterprisePasswordInterstitialHistogram[];
extern const char kEnterprisePasswordPageInfoHistogram[];
extern const char kEnterprisePasswordWarningDialogHistogram[];
extern const char kSavedPasswordPageInfoHistogram[];
extern const char kGmailNonSyncPasswordInterstitialHistogram[];
extern const char kGmailSyncPasswordPageInfoHistogram[];
extern const char kGmailNonSyncPasswordPageInfoHistogram[];
extern const char kGmailSyncPasswordWarningDialogHistogram[];
extern const char kGmailNonSyncPasswordWarningDialogHistogram[];
extern const char kNonSyncPasswordInterstitialHistogram[];
extern const char kNonSyncPasswordPageInfoHistogram[];
extern const char kGmailSyncPasswordEntryRequestOutcomeHistogram[];
extern const char kGmailNonSyncPasswordEntryRequestOutcomeHistogram[];
extern const char kGSuiteNonSyncPasswordEntryRequestOutcomeHistogram[];
extern const char kGSuiteSyncPasswordEntryVerdictHistogram[];

extern const char kGSuiteSyncPasswordEntryRequestOutcomeHistogram[];
extern const char kGSuiteNonSyncPasswordEntryVerdictHistogram[];
extern const char kGmailSyncPasswordEntryVerdictHistogram[];
extern const char kGmailNonSyncPasswordEntryVerdictHistogram[];
extern const char kGSuiteSyncPasswordInterstitialHistogram[];
extern const char kGSuiteNonSyncPasswordInterstitialHistogram[];
extern const char kGSuiteSyncPasswordPageInfoHistogram[];
extern const char kGSuiteNonSyncPasswordPageInfoHistogram[];
extern const char kGSuiteSyncPasswordWarningDialogHistogram[];
extern const char kGSuiteNonSyncPasswordWarningDialogHistogram[];
extern const char kPasswordOnFocusRequestOutcomeHistogram[];
extern const char kPasswordOnFocusVerdictHistogram[];
extern const char kNonSyncPasswordEntryRequestOutcomeHistogram[];
extern const char kNonSyncPasswordEntryVerdictHistogram[];
extern const char kSyncPasswordChromeSettingsHistogram[];
extern const char kSyncPasswordEntryRequestOutcomeHistogram[];
extern const char kSyncPasswordEntryVerdictHistogram[];
extern const char kSyncPasswordInterstitialHistogram[];
extern const char kSyncPasswordPageInfoHistogram[];
extern const char kSyncPasswordWarningDialogHistogram[];
extern const char kEnterprisePasswordAlertHistogram[];
extern const char kGsuiteSyncPasswordAlertHistogram[];
extern const char kGsuiteNonSyncPasswordAlertHistogram[];

extern const char kPasswordOnFocusRequestWithTokenHistogram[];
extern const char kAnyPasswordEntryRequestWithTokenHistogram[];

ReusedPasswordAccountType;
SyncAccountType;
VerdictType;

// The outcome of the request. These values are used for UMA.
// DO NOT CHANGE THE ORDERING OF THESE VALUES.
enum class RequestOutcome {};

// Enum values indicates if a password protection warning is shown or
// represents user's action on warnings. These values are used for UMA.
// DO NOT CHANGE THE ORDERING OF THESE VALUES.
enum class WarningAction {};

// Type of password protection warning UI.
enum class WarningUIType {};

// Logs whether an access_token was sent or not, for the appropriate
// |trigger_type| metric.
void LogPasswordProtectionRequestTokenHistogram(
    LoginReputationClientRequest::TriggerType trigger_type,
    bool has_access_token);

// Logs the |outcome| to several UMA metrics, depending on the value
// of |password_type| and |sync_account_type|.
void LogPasswordEntryRequestOutcome(
    RequestOutcome outcome,
    ReusedPasswordAccountType password_account_type);

// Logs the |outcome| to several UMA metrics for password on focus pings.
void LogPasswordOnFocusRequestOutcome(RequestOutcome outcome);

// Logs the |outcome| to several UMA metrics for password alert mode.
void LogPasswordAlertModeOutcome(
    RequestOutcome outcome,
    ReusedPasswordAccountType password_account_type);

// Logs password protection verdict based on |trigger_type|, |password_type|,
// and |sync_account_type|.
void LogPasswordProtectionVerdict(
    LoginReputationClientRequest::TriggerType trigger_type,
    ReusedPasswordAccountType password_account_type,
    VerdictType verdict_type);

// Logs |reason| for why there's no ping sent out.
void LogNoPingingReason(LoginReputationClientRequest::TriggerType trigger_type,
                        RequestOutcome reason,
                        ReusedPasswordAccountType password_account_type);

// Logs the type of sync account.
void LogSyncAccountType(SyncAccountType sync_account_type);

// Logs the network response and duration of a password protection ping.
void LogPasswordProtectionNetworkResponseAndDuration(
    int response_code,
    int net_error,
    const base::TimeTicks& request_start_time);

// Logs when a sample ping of allowlist URLs is sent to Safe Browsing.
void LogPasswordProtectionSampleReportSent();

// Records user action on warnings to corresponding UMA histograms.
void LogWarningAction(WarningUIType ui_type,
                      WarningAction action,
                      ReusedPasswordAccountType password_account_type);

// Logs the number of verdict migrated to the new caching structure.
void LogNumberOfVerdictMigrated(size_t verdicts_migrated);

// Logs the size of referrer chain by |verdict_type|.
void LogReferrerChainSize(
    LoginReputationClientResponse::VerdictType verdict_type,
    int referrer_chain_size);

// Logs the interval between when the modal warning is constructed and when it
// is destructed.
void LogModalWarningDialogLifetime(
    base::TimeTicks modal_construction_start_time);

}  // namespace safe_browsing

#endif  // COMPONENTS_SAFE_BROWSING_CORE_BROWSER_PASSWORD_PROTECTION_METRICS_UTIL_H_