1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_DOWNLOAD_PUBLIC_BACKGROUND_SERVICE_DOWNLOAD_METADATA_H_
#define COMPONENTS_DOWNLOAD_PUBLIC_BACKGROUND_SERVICE_DOWNLOAD_METADATA_H_
#include <optional>
#include <vector>
#include "base/component_export.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_refptr.h"
#include "build/blink_buildflags.h"
#include "build/build_config.h"
#include "components/download/public/background_service/download_params.h"
#include "net/http/http_response_headers.h"
#include "url/gurl.h"
#if BUILDFLAG(USE_BLINK)
#include "storage/browser/blob/blob_data_handle.h"
#endif
namespace download {
// Struct that contains information about successfully completed downloads.
struct COMPONENT_EXPORT(COMPONENTS_DOWNLOAD_PUBLIC_BACKGROUND_SERVICE)
CompletionInfo {
// The file path for the download file. In incognito mode, use |blob_handle_|
// to retrieve data.
base::FilePath path;
#if BUILDFLAG(USE_BLINK)
// The blob data handle that contains download data.
// Will be available after the download is completed in incognito mode.
std::optional<storage::BlobDataHandle> blob_handle;
#endif
// Download file size in bytes.
uint64_t bytes_downloaded = 0u;
// The url chain of the download. Download may encounter redirects, and
// fetches the content from the last url in the chain.
// This will reflect the initial request's chain and does not take into
// account changed values during retries/resumptions.
std::vector<GURL> url_chain;
// The response headers for the download request.
// This will reflect the initial response's headers and does not take into
// account changed values during retries/resumptions.
scoped_refptr<const net::HttpResponseHeaders> response_headers;
// An optional base::HexEncoded SHA-256 hash (if available) of the file
// contents. If empty there is no available hash value.
std::string hash256;
// The custom data sent back to clients when download is completed or failed.
DownloadParams::CustomData custom_data;
CompletionInfo();
CompletionInfo(
const base::FilePath& path,
uint64_t bytes_downloaded,
const std::vector<GURL>& url_chain,
scoped_refptr<const net::HttpResponseHeaders> response_headers);
CompletionInfo(const base::FilePath& path, uint64_t bytes_downloaded);
CompletionInfo(const CompletionInfo& other);
~CompletionInfo();
bool operator==(const CompletionInfo& other) const;
};
// Struct to describe general download status.
struct COMPONENT_EXPORT(COMPONENTS_DOWNLOAD_PUBLIC_BACKGROUND_SERVICE)
DownloadMetaData {
// The GUID of the download.
std::string guid;
// Data that has been fetched. Can be used to get the current size of
// uncompleted download.
uint64_t current_size;
// Whether the entry is currently paused by the client.
bool paused;
// Info about successfully completed download, or null for in-progress
// download. Failed download will not be persisted and exposed as meta data.
std::optional<CompletionInfo> completion_info;
DownloadMetaData();
~DownloadMetaData();
DownloadMetaData(const DownloadMetaData& other);
bool operator==(const DownloadMetaData& other) const;
};
} // namespace download
#endif // COMPONENTS_DOWNLOAD_PUBLIC_BACKGROUND_SERVICE_DOWNLOAD_METADATA_H_
|