#include "chrome/browser/safe_browsing/incident_reporting/last_download_finder.h"
#include <stddef.h>
#include <stdint.h>
#include <algorithm>
#include <functional>
#include <memory>
#include <tuple>
#include <utility>
#include "base/functional/bind.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/safe_browsing/incident_reporting/incident_reporting_service.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/safe_browsing/download_type_util.h"
#include "components/history/core/browser/download_constants.h"
#include "components/language/core/browser/pref_names.h"
#include "components/language/core/common/locale_util.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/content/common/file_type_policies.h"
#include "components/safe_browsing/core/common/proto/csd.pb.h"
#include "crypto/sha2.h"
#include "extensions/buildflags/buildflags.h"
namespace safe_browsing {
namespace {
int64_t GetEndTime(const history::DownloadRow& row) { … }
int64_t GetEndTime(const ClientIncidentReport_DownloadDetails& details) { … }
bool IsBinaryDownloadForCurrentOS(
ClientDownloadRequest::DownloadType download_type) { … }
bool IsBinaryDownload(const history::DownloadRow& row) { … }
bool IsNonBinaryDownload(const history::DownloadRow& row) { … }
bool IsBinaryDownload(const ClientIncidentReport_DownloadDetails& details) { … }
bool HasBeenOpened(const history::DownloadRow& row) { … }
bool HasBeenOpened(const ClientIncidentReport_DownloadDetails& details) { … }
template <class A, class B>
bool IsMoreInterestingBinaryThan(const A& first, const B& second) { … }
bool IsMoreInterestingNonBinaryThan(const history::DownloadRow& first,
const history::DownloadRow& second) { … }
const history::DownloadRow* FindMostInteresting(
const std::vector<history::DownloadRow>& downloads,
bool is_binary) { … }
template <class D>
bool IsMostInterestingBinary(
const D& candidate,
const ClientIncidentReport_DownloadDetails* details,
const history::DownloadRow& best_row) { … }
void PopulateDetailsFromRow(const history::DownloadRow& download,
ClientIncidentReport_DownloadDetails* details) { … }
void PopulateNonBinaryDetailsFromRow(
const history::DownloadRow& download,
ClientIncidentReport_NonBinaryDownloadDetails* details) { … }
}
LastDownloadFinder::~LastDownloadFinder() { … }
std::unique_ptr<LastDownloadFinder> LastDownloadFinder::Create(
DownloadDetailsGetter download_details_getter,
LastDownloadCallback callback) { … }
LastDownloadFinder::LastDownloadFinder() = default;
LastDownloadFinder::LastDownloadFinder(
DownloadDetailsGetter download_details_getter,
LastDownloadCallback callback)
: … { … }
LastDownloadFinder::PendingProfileData::PendingProfileData(
LastDownloadFinder* finder,
Profile* profile,
State state)
: … { … }
LastDownloadFinder::PendingProfileData::~PendingProfileData() = default;
LastDownloadFinder::ProfileKey LastDownloadFinder::KeyForProfile(
Profile* profile) { … }
void LastDownloadFinder::SearchInProfile(Profile* profile) { … }
void LastDownloadFinder::OnMetadataQuery(
ProfileKey profile_key,
std::unique_ptr<ClientIncidentReport_DownloadDetails> details) { … }
void LastDownloadFinder::OnDownloadQuery(
ProfileKey profile_key,
std::vector<history::DownloadRow> downloads) { … }
void LastDownloadFinder::RemoveProfileAndReportIfDone(
PendingProfilesMap::iterator iter) { … }
void LastDownloadFinder::ReportResults() { … }
void LastDownloadFinder::OnProfileAdded(Profile* profile) { … }
void LastDownloadFinder::OnProfileWillBeDestroyed(Profile* profile) { … }
void LastDownloadFinder::OnHistoryServiceLoaded(
history::HistoryService* history_service) { … }
void LastDownloadFinder::HistoryServiceBeingDeleted(
history::HistoryService* history_service) { … }
}