chromium/chrome/browser/safe_browsing/incident_reporting/download_metadata_manager.cc

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

#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 {

// The name of the metadata file in the profile directory.
const base::FilePath::CharType kDownloadMetadataBasename[] =);


// DownloadItemData ------------------------------------------------------------

// A UserData object that holds the ClientDownloadRequest for a download while
// it is in progress.
class DownloadItemData : public base::SupportsUserData::Data {};

// Make the key's value unique by setting it to its own location.
// static
const void* const DownloadItemData::kKey_ =;

// static
void DownloadItemData::SetRequestForDownload(
    download::DownloadItem* item,
    std::unique_ptr<ClientDownloadRequest> request) {}

// static
std::unique_ptr<ClientDownloadRequest> DownloadItemData::TakeRequestForDownload(
    download::DownloadItem* item) {}


// Utility functions------------------------------------------------------------

// Returns the path to the metadata file for |browser_context|.
base::FilePath GetMetadataPath(content::BrowserContext* browser_context) {}

// Returns true if |metadata| appears to be valid.
bool MetadataIsValid(const DownloadMetadata& metadata) {}

// Reads and parses a DownloadMetadata message from |metadata_path| into
// |metadata|.
void ReadMetadataInBackground(const base::FilePath& metadata_path,
                              DownloadMetadata* metadata) {}

// Writes |download_metadata| to |metadata_path|.
void WriteMetadataInBackground(const base::FilePath& metadata_path,
                               DownloadMetadata* download_metadata) {}

// Deletes |metadata_path|.
void DeleteMetadataInBackground(const base::FilePath& metadata_path) {}

// Runs |callback| with the DownloadDetails in |download_metadata|.
void ReturnResults(DownloadMetadataManager::GetDownloadDetailsCallback callback,
                   std::unique_ptr<DownloadMetadata> download_metadata) {}

}  // namespace

// Applies operations to the profile's persistent DownloadMetadata as they occur
// on its corresponding download item. An instance can be in one of three
// states: waiting for metatada load, waiting for metadata to load after its
// corresponding SimpleDownloadManagerCoordinator has gone down, and not waiting
// for metadata to load. The instance is notified on events for downloads
// belonging to its coordinator. While it is waiting for metadata to load, it
// records all operations on download items that must be reflected in the
// metadata. Once the metadata is ready, recorded operations are applied to the
// metadata. While waiting for metadata to load, an instance also tracks
// callbacks to be run to provide consumers with persisted details of a
// download.
class DownloadMetadataManager::ManagerContext {};

// DownloadMetadataManager -----------------------------------------------------

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 -------------------------------------

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) {}

}  // namespace safe_browsing