#include "chrome/browser/safe_browsing/incident_reporting/download_metadata_manager.h"
#include <limits.h>
#include <stdint.h>
#include <list>
#include <memory>
#include <utility>
#include "base/check.h"
#include "base/containers/heap_array.h"
#include "base/files/file.h"
#include "base/files/file_util.h"
#include "base/files/important_file_writer.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ref.h"
#include "base/metrics/histogram_macros.h"
#include "base/notreached.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/time/time.h"
#include "chrome/browser/download/simple_download_manager_coordinator_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_key.h"
#include "components/download/public/common/download_item.h"
#include "components/download/public/common/simple_download_manager_coordinator.h"
#include "components/safe_browsing/core/common/proto/csd.pb.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/download_item_utils.h"
#include "content/public/browser/download_manager.h"
namespace safe_browsing {
namespace {
const base::FilePath::CharType kDownloadMetadataBasename[] = …);
class DownloadItemData : public base::SupportsUserData::Data { … };
const void* const DownloadItemData::kKey_ = …;
void DownloadItemData::SetRequestForDownload(
download::DownloadItem* item,
std::unique_ptr<ClientDownloadRequest> request) { … }
std::unique_ptr<ClientDownloadRequest> DownloadItemData::TakeRequestForDownload(
download::DownloadItem* item) { … }
base::FilePath GetMetadataPath(content::BrowserContext* browser_context) { … }
bool MetadataIsValid(const DownloadMetadata& metadata) { … }
void ReadMetadataInBackground(const base::FilePath& metadata_path,
DownloadMetadata* metadata) { … }
void WriteMetadataInBackground(const base::FilePath& metadata_path,
DownloadMetadata* download_metadata) { … }
void DeleteMetadataInBackground(const base::FilePath& metadata_path) { … }
void ReturnResults(DownloadMetadataManager::GetDownloadDetailsCallback callback,
std::unique_ptr<DownloadMetadata> download_metadata) { … }
}
class DownloadMetadataManager::ManagerContext { … };
DownloadMetadataManager::DownloadMetadataManager()
: … { … }
DownloadMetadataManager::~DownloadMetadataManager() { … }
void DownloadMetadataManager::AddDownloadManager(
content::DownloadManager* download_manager) { … }
void DownloadMetadataManager::SetRequest(download::DownloadItem* item,
const ClientDownloadRequest* request) { … }
void DownloadMetadataManager::GetDownloadDetails(
content::BrowserContext* browser_context,
GetDownloadDetailsCallback callback) { … }
void DownloadMetadataManager::OnManagerGoingDown(
download::SimpleDownloadManagerCoordinator* coordinator) { … }
void DownloadMetadataManager::OnDownloadUpdated(
download::SimpleDownloadManagerCoordinator* coordinator,
download::DownloadItem* download) { … }
void DownloadMetadataManager::OnDownloadOpened(
download::SimpleDownloadManagerCoordinator* coordinator,
download::DownloadItem* download) { … }
void DownloadMetadataManager::OnDownloadRemoved(
download::SimpleDownloadManagerCoordinator* coordinator,
download::DownloadItem* download) { … }
download::SimpleDownloadManagerCoordinator*
DownloadMetadataManager::GetCoordinatorForBrowserContext(
content::BrowserContext* context) { … }
DownloadMetadataManager::ManagerContext::ManagerContext(
scoped_refptr<base::SequencedTaskRunner> task_runner,
content::BrowserContext& browser_context)
: … { … }
void DownloadMetadataManager::ManagerContext::Detach() { … }
void DownloadMetadataManager::ManagerContext::SetRequest(
download::DownloadItem* download,
std::unique_ptr<ClientDownloadRequest> request) { … }
void DownloadMetadataManager::ManagerContext::GetDownloadDetails(
GetDownloadDetailsCallback callback) { … }
void DownloadMetadataManager::ManagerContext::OnDownloadUpdated(
download::DownloadItem* download) { … }
void DownloadMetadataManager::ManagerContext::OnDownloadOpened(
download::DownloadItem* download) { … }
void DownloadMetadataManager::ManagerContext::OnDownloadRemoved(
download::DownloadItem* download) { … }
DownloadMetadataManager::ManagerContext::~ManagerContext() { … }
void DownloadMetadataManager::ManagerContext::CommitRequest(
download::DownloadItem* item,
std::unique_ptr<ClientDownloadRequest> request) { … }
void DownloadMetadataManager::ManagerContext::ReadMetadata() { … }
void DownloadMetadataManager::ManagerContext::WriteMetadata() { … }
void DownloadMetadataManager::ManagerContext::RemoveMetadata() { … }
void DownloadMetadataManager::ManagerContext::ClearPendingItems() { … }
void DownloadMetadataManager::ManagerContext::RunCallbacks() { … }
bool DownloadMetadataManager::ManagerContext::HasMetadataFor(
const download::DownloadItem* item) const { … }
void DownloadMetadataManager::ManagerContext::OnMetadataReady(
std::unique_ptr<DownloadMetadata> download_metadata) { … }
void DownloadMetadataManager::ManagerContext::UpdateLastOpenedTime(
const base::Time& last_opened_time) { … }
}