#include "content/public/test/test_file_error_injector.h"
#include <utility>
#include <vector>
#include "base/check_op.h"
#include "base/compiler_specific.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "components/download/public/common/download_file_factory.h"
#include "components/download/public/common/download_file_impl.h"
#include "components/download/public/common/download_interrupt_reasons_utils.h"
#include "components/download/public/common/download_task_runner.h"
#include "content/browser/download/download_manager_impl.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "url/gurl.h"
namespace net {
class NetLogWithSource;
}
namespace content {
class ByteStreamReader;
namespace {
class DownloadFileWithError : public download::DownloadFileImpl { … };
static void InitializeErrorCallback(
download::DownloadFile::InitializeCallback original_callback,
download::DownloadInterruptReason overwrite_error,
download::DownloadInterruptReason original_error,
int64_t bytes_wasted) { … }
static void RenameErrorCallback(
download::DownloadFile::RenameCompletionCallback original_callback,
download::DownloadInterruptReason overwrite_error,
download::DownloadInterruptReason original_error,
const base::FilePath& path_result) { … }
DownloadFileWithError::DownloadFileWithError(
std::unique_ptr<download::DownloadSaveInfo> save_info,
const base::FilePath& default_download_directory,
std::unique_ptr<download::InputStream> stream,
uint32_t download_id,
base::WeakPtr<download::DownloadDestinationObserver> observer,
const TestFileErrorInjector::FileErrorInfo& error_info,
base::OnceClosure ctor_callback,
base::OnceClosure dtor_callback)
: … { … }
DownloadFileWithError::~DownloadFileWithError() { … }
void DownloadFileWithError::Initialize(
InitializeCallback initialize_callback,
CancelRequestCallback cancel_request_callback,
const download::DownloadItem::ReceivedSlices& received_slices) { … }
download::DownloadInterruptReason
DownloadFileWithError::ValidateAndWriteDataToFile(int64_t offset,
const char* data,
size_t bytes_to_validate,
size_t bytes_to_write) { … }
download::DownloadInterruptReason
DownloadFileWithError::HandleStreamCompletionStatus(
SourceStream* source_stream) { … }
void DownloadFileWithError::RenameAndUniquify(
const base::FilePath& full_path,
RenameCompletionCallback callback) { … }
void DownloadFileWithError::RenameAndAnnotate(
const base::FilePath& full_path,
const std::string& client_guid,
const GURL& source_url,
const GURL& referrer_url,
mojo::PendingRemote<quarantine::mojom::Quarantine> remote_quarantine,
RenameCompletionCallback callback) { … }
bool DownloadFileWithError::OverwriteError(
TestFileErrorInjector::FileOperationCode code,
download::DownloadInterruptReason* output_error) { … }
download::DownloadInterruptReason DownloadFileWithError::ShouldReturnError(
TestFileErrorInjector::FileOperationCode code,
download::DownloadInterruptReason original_error) { … }
}
class DownloadFileWithErrorFactory : public download::DownloadFileFactory { … };
DownloadFileWithErrorFactory::DownloadFileWithErrorFactory(
base::RepeatingClosure ctor_callback,
base::RepeatingClosure dtor_callback)
: … { … }
DownloadFileWithErrorFactory::~DownloadFileWithErrorFactory() { … }
download::DownloadFile* DownloadFileWithErrorFactory::CreateFile(
std::unique_ptr<download::DownloadSaveInfo> save_info,
const base::FilePath& default_download_directory,
std::unique_ptr<download::InputStream> stream,
uint32_t download_id,
const base::FilePath& duplicate_download_file_path,
base::WeakPtr<download::DownloadDestinationObserver> observer) { … }
bool DownloadFileWithErrorFactory::SetError(
TestFileErrorInjector::FileErrorInfo error) { … }
TestFileErrorInjector::FileErrorInfo::FileErrorInfo()
: … { … }
TestFileErrorInjector::FileErrorInfo::FileErrorInfo(
FileOperationCode code,
int operation_instance,
download::DownloadInterruptReason error)
: … { … }
TestFileErrorInjector::TestFileErrorInjector(DownloadManager* download_manager)
: … { … }
TestFileErrorInjector::~TestFileErrorInjector() { … }
void TestFileErrorInjector::ClearError() { … }
bool TestFileErrorInjector::InjectError(const FileErrorInfo& error_info) { … }
size_t TestFileErrorInjector::CurrentFileCount() const { … }
size_t TestFileErrorInjector::TotalFileCount() const { … }
void TestFileErrorInjector::ClearTotalFileCount() { … }
void TestFileErrorInjector::DownloadFileCreated() { … }
void TestFileErrorInjector::DestroyingDownloadFile() { … }
void TestFileErrorInjector::RecordDownloadFileConstruction() { … }
void TestFileErrorInjector::RecordDownloadFileDestruction() { … }
scoped_refptr<TestFileErrorInjector> TestFileErrorInjector::Create(
DownloadManager* download_manager) { … }
std::string TestFileErrorInjector::DebugString(FileOperationCode code) { … }
}