#include "chrome/browser/safe_browsing/download_protection/check_client_download_request_base.h"
#include "base/cancelable_callback.h"
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/rand_util.h"
#include "base/ranges/algorithm.h"
#include "base/strings/strcat.h"
#include "base/task/bind_post_task.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/api/safe_browsing_private/safe_browsing_private_event_router.h"
#include "chrome/browser/extensions/api/safe_browsing_private/safe_browsing_private_event_router_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/download_protection/download_protection_service.h"
#include "chrome/browser/safe_browsing/download_protection/download_protection_util.h"
#include "chrome/browser/safe_browsing/download_protection/ppapi_download_request.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/content/browser/web_ui/safe_browsing_ui.h"
#include "components/safe_browsing/content/common/file_type_policies.h"
#include "components/safe_browsing/core/browser/sync/sync_utils.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/safe_browsing/core/common/utils.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "net/base/load_flags.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_status_code.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
namespace safe_browsing {
BrowserThread;
namespace {
const char kDownloadExtensionUmaName[] = …;
void RecordFileExtensionType(const std::string& metric_name,
const base::FilePath& file) { … }
std::string SanitizeUrl(const std::string& url) { … }
}
CheckClientDownloadRequestBase::CheckClientDownloadRequestBase(
GURL source_url,
base::FilePath target_file_path,
content::BrowserContext* browser_context,
CheckDownloadCallback callback,
DownloadProtectionService* service,
scoped_refptr<SafeBrowsingDatabaseManager> database_manager,
std::unique_ptr<DownloadRequestMaker> download_request_maker)
: … { … }
CheckClientDownloadRequestBase::~CheckClientDownloadRequestBase() = default;
void CheckClientDownloadRequestBase::Start() { … }
void CheckClientDownloadRequestBase::FinishRequest(
DownloadCheckResult result,
DownloadCheckResultReason reason) { … }
bool CheckClientDownloadRequestBase::ShouldSampleAllowlistedDownload() { … }
bool CheckClientDownloadRequestBase::ShouldSampleUnsupportedFile(
const base::FilePath& filename) { … }
bool CheckClientDownloadRequestBase::IsDownloadManuallyBlocklisted(
const ClientDownloadRequest& request) { … }
void CheckClientDownloadRequestBase::OnUrlAllowlistCheckDone(
bool is_allowlisted) { … }
void CheckClientDownloadRequestBase::SanitizeRequest() { … }
void CheckClientDownloadRequestBase::GetAdditionalPromptResult(
const ClientDownloadResponse& response,
DownloadCheckResult* result,
DownloadCheckResultReason* reason,
std::string* token) const { … }
void CheckClientDownloadRequestBase::OnRequestBuilt(
std::unique_ptr<ClientDownloadRequest> request) { … }
void CheckClientDownloadRequestBase::StartTimeout() { … }
void CheckClientDownloadRequestBase::OnGotAccessToken(
const std::string& access_token) { … }
void CheckClientDownloadRequestBase::SendRequest() { … }
void CheckClientDownloadRequestBase::OnURLLoaderComplete(
std::unique_ptr<std::string> response_body) { … }
}