#include "chrome/browser/ui/webui/downloads/downloads_list_tracker.h"
#include <iterator>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/i18n/rtl.h"
#include "base/i18n/unicodestring.h"
#include "base/metrics/histogram_functions.h"
#include "base/ranges/algorithm.h"
#include "base/strings/escape.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "chrome/browser/download/download_crx_util.h"
#include "chrome/browser/download/download_item_model.h"
#include "chrome/browser/download/download_item_warning_data.h"
#include "chrome/browser/download/download_query.h"
#include "chrome/browser/download/download_stats.h"
#include "chrome/browser/download/download_ui_safe_browsing_util.h"
#include "chrome/browser/enterprise/connectors/common.h"
#include "chrome/browser/extensions/api/downloads/downloads_api.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/ui/webui/downloads/downloads.mojom.h"
#include "components/download/public/common/download_danger_type.h"
#include "components/download/public/common/download_item.h"
#include "components/download/public/common/download_item_rename_handler.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/url_formatter/elide_url.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/download_item_utils.h"
#include "content/public/browser/download_manager.h"
#include "extensions/browser/extension_registry.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/base/filename_util.h"
#include "third_party/icu/source/i18n/unicode/datefmt.h"
#include "ui/base/l10n/time_format.h"
#include "url/url_constants.h"
#if BUILDFLAG(FULL_SAFE_BROWSING)
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#endif
BrowserContext;
DownloadManager;
DownloadItem;
TailoredWarningType;
DownloadVector;
namespace {
downloads::mojom::DangerType GetDangerType(
download::DownloadDangerType danger_type) { … }
downloads::mojom::TailoredWarningType GetTailoredWarningType(
TailoredWarningType tailored_warning_type) { … }
downloads::mojom::SafeBrowsingState GetSafeBrowsingState(Profile* profile) { … }
std::string TimeFormatLongDate(const base::Time& time) { … }
std::u16string GetFormattedDisplayUrl(const GURL& url) { … }
void FillUrlFields(const GURL& url,
std::optional<GURL>& data_url,
std::u16string& display_url_out) { … }
}
DownloadsListTracker::DownloadsListTracker(
DownloadManager* download_manager,
mojo::PendingRemote<downloads::mojom::Page> page)
: … { … }
DownloadsListTracker::~DownloadsListTracker() { … }
void DownloadsListTracker::Reset() { … }
bool DownloadsListTracker::SetSearchTerms(
const std::vector<std::string>& search_terms) { … }
void DownloadsListTracker::StartAndSendChunk() { … }
void DownloadsListTracker::Stop() { … }
int DownloadsListTracker::NumDangerousItemsSent() const { … }
download::DownloadItem* DownloadsListTracker::GetFirstActiveWarningItem() { … }
DownloadManager* DownloadsListTracker::GetMainNotifierManager() const { … }
DownloadManager* DownloadsListTracker::GetOriginalNotifierManager() const { … }
void DownloadsListTracker::OnDownloadCreated(DownloadManager* manager,
DownloadItem* download_item) { … }
void DownloadsListTracker::OnDownloadUpdated(DownloadManager* manager,
DownloadItem* download_item) { … }
void DownloadsListTracker::OnDownloadRemoved(DownloadManager* manager,
DownloadItem* download_item) { … }
DownloadsListTracker::DownloadsListTracker(
DownloadManager* download_manager,
mojo::PendingRemote<downloads::mojom::Page> page,
base::RepeatingCallback<bool(const DownloadItem&)> should_show)
: … { … }
downloads::mojom::DataPtr DownloadsListTracker::CreateDownloadData(
download::DownloadItem* download_item) const { … }
bool DownloadsListTracker::IsIncognito(const DownloadItem& item) const { … }
const DownloadItem* DownloadsListTracker::GetItemForTesting(
size_t index) const { … }
void DownloadsListTracker::SetChunkSizeForTesting(size_t chunk_size) { … }
bool DownloadsListTracker::ShouldShow(const DownloadItem& item) const { … }
bool DownloadsListTracker::StartTimeComparator::operator()(
const download::DownloadItem* a,
const download::DownloadItem* b) const { … }
void DownloadsListTracker::Init() { … }
void DownloadsListTracker::RebuildSortedItems() { … }
void DownloadsListTracker::InsertItem(const SortedSet::iterator& insert) { … }
void DownloadsListTracker::UpdateItem(const SortedSet::iterator& update) { … }
size_t DownloadsListTracker::GetIndex(const SortedSet::iterator& item) const { … }
void DownloadsListTracker::RemoveItem(const SortedSet::iterator& remove) { … }
int DownloadsListTracker::GetPercentComplete(
download::DownloadItem* download_item) const { … }