#include "chrome/browser/download/download_offline_content_provider.h"
#include <memory>
#include <utility>
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/download/offline_item_utils.h"
#include "chrome/browser/offline_items_collection/offline_content_aggregator_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/thumbnail/generator/image_thumbnail_request.h"
#include "components/download/public/common/download_features.h"
#include "components/download/public/common/download_item.h"
#include "content/public/browser/browser_context.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/android/build_info.h"
#include "chrome/browser/download/android/download_controller.h"
#include "chrome/browser/download/android/download_manager_bridge.h"
#include "chrome/browser/download/android/download_manager_service.h"
#include "chrome/browser/download/android/download_utils.h"
#include "chrome/browser/download/android/open_download_dialog_bridge_delegate.h"
#include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/flags/android/chrome_feature_list.h"
#include "components/pdf/common/constants.h"
#include "content/public/browser/download_item_utils.h"
#include "content/public/browser/download_manager_delegate.h"
#include "content/public/common/content_features.h"
#include "ui/base/device_form_factor.h"
#endif
OfflineItemFilter;
OfflineItemState;
OfflineItemProgressUnit;
OfflineItemShareInfo;
OfflineItemVisuals;
UpdateDelta;
namespace {
const int kThumbnailSizeInDP = …;
const base::TimeDelta kCheckExternallyRemovedDownloadsDelay = …;
#if BUILDFLAG(IS_ANDROID)
const int kInvalidSystemDownloadId = -1;
#endif
bool ShouldShowDownloadItem(const DownloadItem* item) { … }
std::unique_ptr<OfflineItemShareInfo> CreateShareInfo(
const DownloadItem* item) { … }
class AllDownloadObserver
: public download::AllDownloadEventNotifier::Observer { … };
AllDownloadObserver::AllDownloadObserver(
DownloadOfflineContentProvider* provider)
: … { … }
AllDownloadObserver::~AllDownloadObserver() { … }
void AllDownloadObserver::OnDownloadUpdated(
SimpleDownloadManagerCoordinator* manager,
DownloadItem* item) { … }
void AllDownloadObserver::OnDownloadRemoved(
SimpleDownloadManagerCoordinator* manager,
DownloadItem* item) { … }
void AllDownloadObserver::DeleteDownloadItem(
SimpleDownloadManagerCoordinator* manager,
const std::string& guid) { … }
}
DownloadOfflineContentProvider::DownloadOfflineContentProvider(
OfflineContentAggregator* aggregator,
const std::string& name_space)
: … { … }
DownloadOfflineContentProvider::~DownloadOfflineContentProvider() { … }
void DownloadOfflineContentProvider::SetSimpleDownloadManagerCoordinator(
SimpleDownloadManagerCoordinator* manager) { … }
void DownloadOfflineContentProvider::OnDownloadsInitialized(
bool active_downloads_only) { … }
void DownloadOfflineContentProvider::OpenItem(const OpenParams& open_params,
const ContentId& id) { … }
void DownloadOfflineContentProvider::RemoveItem(const ContentId& id) { … }
void DownloadOfflineContentProvider::CancelDownload(const ContentId& id) { … }
void DownloadOfflineContentProvider::PauseDownload(const ContentId& id) { … }
void DownloadOfflineContentProvider::ResumeDownload(const ContentId& id) { … }
void DownloadOfflineContentProvider::GetItemById(
const ContentId& id,
OfflineContentProvider::SingleItemCallback callback) { … }
void DownloadOfflineContentProvider::GetAllItems(
OfflineContentProvider::MultipleItemCallback callback) { … }
void DownloadOfflineContentProvider::GetVisualsForItem(
const ContentId& id,
GetVisualsOptions options,
VisualsCallback callback) { … }
void DownloadOfflineContentProvider::GetShareInfoForItem(
const ContentId& id,
ShareCallback callback) { … }
void DownloadOfflineContentProvider::OnThumbnailRetrieved(
const ContentId& id,
VisualsCallback callback,
const SkBitmap& bitmap) { … }
void DownloadOfflineContentProvider::RenameItem(const ContentId& id,
const std::string& name,
RenameCallback callback) { … }
void DownloadOfflineContentProvider::OnRenameDownloadCallbackDone(
RenameCallback callback,
DownloadItem* item,
DownloadItem::DownloadRenameResult result) { … }
void DownloadOfflineContentProvider::OnManagerGoingDown(
SimpleDownloadManagerCoordinator* manager) { … }
void DownloadOfflineContentProvider::OnDownloadStarted(DownloadItem* item) { … }
void DownloadOfflineContentProvider::OnDownloadUpdated(DownloadItem* item) { … }
void DownloadOfflineContentProvider::OnDownloadRemoved(DownloadItem* item) { … }
void DownloadOfflineContentProvider::OnProfileCreated(Profile* profile) { … }
void DownloadOfflineContentProvider::AddCompletedDownload(DownloadItem* item) { … }
void DownloadOfflineContentProvider::AddCompletedDownloadDone(
const std::string& download_guid,
int64_t system_download_id) { … }
DownloadItem* DownloadOfflineContentProvider::GetDownload(
const std::string& download_guid) { … }
void DownloadOfflineContentProvider::GetAllDownloads(
std::vector<raw_ptr<DownloadItem, VectorExperimental>>* all_items) { … }
void DownloadOfflineContentProvider::UpdateObservers(
const OfflineItem& item,
const std::optional<UpdateDelta>& update_delta) { … }
void DownloadOfflineContentProvider::CheckForExternallyRemovedDownloads() { … }
void DownloadOfflineContentProvider::EnsureDownloadCoreServiceStarted() { … }
void DownloadOfflineContentProvider::RunGetAllItemsCallback(
OfflineContentProvider::MultipleItemCallback callback) { … }
void DownloadOfflineContentProvider::RunGetItemByIdCallback(
const ContentId& id,
OfflineContentProvider::SingleItemCallback callback) { … }