#include "components/safe_browsing/core/browser/ping_manager.h"
#include <memory>
#include <utility>
#include <vector>
#include "base/base64url.h"
#include "base/check.h"
#include "base/containers/contains.h"
#include "base/containers/fixed_flat_set.h"
#include "base/files/file_enumerator.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_functions.h"
#include "base/not_fatal_until.h"
#include "base/notreached.h"
#include "base/rand_util.h"
#include "base/strings/escape.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "components/safe_browsing/core/browser/db/v4_protocol_manager_util.h"
#include "components/safe_browsing/core/browser/safe_browsing_hats_delegate.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/safe_browsing/core/common/proto/csd.pb.h"
#include "components/safe_browsing/core/common/utils.h"
#include "google_apis/google_api_keys.h"
#include "net/base/load_flags.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "url/gurl.h"
namespace {
WriteResult;
base::TimeDelta kReadPersistedReportsDelay = …;
GURL GetSanitizedUrl(const GURL& url) { … }
std::string GetSanitizedUrl(const std::string& url_spec) { … }
bool IsDownloadReport(
safe_browsing::ClientSafeBrowsingReportRequest::ReportType type) { … }
std::string GetRandFileName() { … }
void RecordPersisterWriteResult(WriteResult write_result) { … }
const net::NetworkTrafficAnnotationTag kTrafficAnnotation = …;
}
namespace safe_browsing {
PingManager::Persister::Persister(const base::FilePath& persister_root_path) { … }
void PingManager::Persister::WriteReport(const std::string& serialized_report) { … }
std::vector<std::string> PingManager::Persister::ReadAndDeleteReports() { … }
std::unique_ptr<PingManager> PingManager::Create(
const V4ProtocolConfig& config,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
std::unique_ptr<SafeBrowsingTokenFetcher> token_fetcher,
base::RepeatingCallback<bool()> get_should_fetch_access_token,
WebUIDelegate* webui_delegate,
scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
base::RepeatingCallback<ChromeUserPopulation()>
get_user_population_callback,
base::RepeatingCallback<ChromeUserPopulation::PageLoadToken(GURL)>
get_page_load_token_callback,
std::unique_ptr<SafeBrowsingHatsDelegate> hats_delegate,
const base::FilePath& persister_root_path,
base::RepeatingCallback<bool()> get_should_send_persisted_report) { … }
PingManager::PingManager(
const V4ProtocolConfig& config,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
std::unique_ptr<SafeBrowsingTokenFetcher> token_fetcher,
base::RepeatingCallback<bool()> get_should_fetch_access_token,
WebUIDelegate* webui_delegate,
scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
base::RepeatingCallback<ChromeUserPopulation()>
get_user_population_callback,
base::RepeatingCallback<ChromeUserPopulation::PageLoadToken(GURL)>
get_page_load_token_callback,
std::unique_ptr<SafeBrowsingHatsDelegate> hats_delegate,
const base::FilePath& persister_root_path,
base::RepeatingCallback<bool()> get_should_send_persisted_report)
: … { … }
PingManager::~PingManager() { … }
void PingManager::OnURLLoaderComplete(
network::SimpleURLLoader* source,
std::unique_ptr<std::string> response_body) { … }
void PingManager::OnThreatDetailsReportURLLoaderComplete(
network::SimpleURLLoader* source,
bool has_access_token,
std::unique_ptr<std::string> response_body) { … }
void PingManager::ReportSafeBrowsingHit(
std::unique_ptr<safe_browsing::HitReport> hit_report) { … }
PingManager::ReportThreatDetailsResult PingManager::ReportThreatDetails(
std::unique_ptr<ClientSafeBrowsingReportRequest> report) { … }
PingManager::PersistThreatDetailsResult
PingManager::PersistThreatDetailsAndReportOnNextStartup(
std::unique_ptr<ClientSafeBrowsingReportRequest> report) { … }
void PingManager::ReadPersistedReports() { … }
void PingManager::OnReadPersistedReportsDone(
std::vector<std::string> serialized_reports) { … }
void PingManager::AttachThreatDetailsAndLaunchSurvey(
std::unique_ptr<ClientSafeBrowsingReportRequest> report) { … }
void PingManager::ReportThreatDetailsOnGotAccessToken(
const std::string& serialized_report,
const std::string& access_token) { … }
GURL PingManager::SafeBrowsingHitUrl(
safe_browsing::HitReport* hit_report) const { … }
GURL PingManager::ThreatDetailsUrl() const { … }
void PingManager::SanitizeThreatDetailsReport(
ClientSafeBrowsingReportRequest* report) { … }
void PingManager::SanitizeHitReport(HitReport* hit_report) { … }
void PingManager::SetURLLoaderFactoryForTesting(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) { … }
void PingManager::SetTokenFetcherForTesting(
std::unique_ptr<SafeBrowsingTokenFetcher> token_fetcher) { … }
void PingManager::SetHatsDelegateForTesting(
std::unique_ptr<SafeBrowsingHatsDelegate> hats_delegate) { … }
}