#include "components/download/public/common/download_stats.h"
#include <map>
#include "base/files/file_path.h"
#include "base/functional/callback.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_util.h"
#include "build/build_config.h"
#include "components/download/public/common/download_danger_type.h"
#include "components/download/public/common/download_interrupt_reasons.h"
#include "components/safe_browsing/buildflags.h"
#include "net/http/http_content_disposition.h"
#include "net/http/http_util.h"
#if (BUILDFLAG(FULL_SAFE_BROWSING) || BUILDFLAG(SAFE_BROWSING_DB_REMOTE)) && \
!BUILDFLAG(IS_FUCHSIA)
#include "components/safe_browsing/content/common/file_type_policies.h"
#endif
namespace download {
namespace {
const int kAllInterruptReasonCodes[] = …;
enum ContentDispositionCountTypes { … };
int64_t CalculateBandwidthBytesPerSecond(size_t length,
base::TimeDelta elapsed_time) { … }
std::string CreateHistogramNameWithSuffix(const std::string& name,
DownloadSource download_source) { … }
void RecordConnectionType(
const std::string& name,
net::NetworkChangeNotifier::ConnectionType connection_type,
DownloadSource download_source) { … }
}
void RecordDownloadCount(DownloadCountTypes type) { … }
void RecordDownloadCountWithSource(DownloadCountTypes type,
DownloadSource download_source) { … }
void RecordNewDownloadStarted(
net::NetworkChangeNotifier::ConnectionType connection_type,
DownloadSource download_source) { … }
void RecordDownloadCompleted(
int64_t download_len,
bool is_parallelizable,
net::NetworkChangeNotifier::ConnectionType connection_type,
DownloadSource download_source) { … }
void RecordDownloadInterrupted(DownloadInterruptReason reason,
int64_t received,
int64_t total,
bool is_parallelizable,
bool is_parallel_download_enabled,
DownloadSource download_source) { … }
void RecordDownloadRetry(DownloadInterruptReason reason) { … }
void RecordDangerousDownloadAccept(DownloadDangerType danger_type,
const base::FilePath& file_path) { … }
namespace {
int GetMimeTypeMatch(const std::string& mime_type_string,
std::map<std::string, int> mime_type_map) { … }
static std::map<std::string, DownloadContent>
getMimeTypeToDownloadContentMap() { … }
enum DownloadImage { … };
static std::map<std::string, int> getMimeTypeToDownloadImageMap() { … }
void RecordDownloadImageType(const std::string& mime_type_string) { … }
enum DownloadText { … };
static std::map<std::string, int> getMimeTypeToDownloadTextMap() { … }
void RecordDownloadTextType(const std::string& mime_type_string) { … }
enum DownloadAudio { … };
static std::map<std::string, int> getMimeTypeToDownloadAudioMap() { … }
void RecordDownloadAudioType(const std::string& mime_type_string) { … }
enum DownloadVideo { … };
static std::map<std::string, int> getMimeTypeToDownloadVideoMap() { … }
void RecordDownloadVideoType(const std::string& mime_type_string) { … }
const char* const kDownloadMetricsVerificationNameItemSecure = …;
const char* const kDownloadMetricsVerificationNameItemInsecure = …;
const char* const kDownloadMetricsVerificationNameItemOther = …;
const char* const kDownloadMetricsVerificationNameManagerSecure = …;
const char* const kDownloadMetricsVerificationNameManagerInsecure = …;
const char* const kDownloadMetricsVerificationNameManagerOther = …;
const char* GetDownloadValidationMetricName(
const DownloadMetricsCallsite& callsite,
const DownloadConnectionSecurity& state) { … }
}
DownloadContent DownloadContentFromMimeType(const std::string& mime_type_string,
bool record_content_subcategory) { … }
void RecordDownloadMimeType(const std::string& mime_type_string,
bool is_transient) { … }
void RecordDownloadMimeTypeForNormalProfile(const std::string& mime_type_string,
bool is_transient) { … }
void RecordFileBandwidth(size_t length,
base::TimeDelta elapsed_time) { … }
void RecordParallelizableDownloadCount(DownloadCountTypes type,
bool is_parallel_download_enabled) { … }
namespace {
int g_parallel_download_creation_failure_count_ = …;
}
void RecordParallelRequestCreationFailure(DownloadInterruptReason reason) { … }
int GetParallelRequestCreationFailureCountForTesting() { … }
DownloadConnectionSecurity CheckDownloadConnectionSecurity(
const GURL& download_url,
const std::vector<GURL>& url_chain) { … }
void RecordDownloadValidationMetrics(DownloadMetricsCallsite callsite,
DownloadConnectionSecurity state,
DownloadContent file_type) { … }
void RecordDownloadHttpResponseCode(int response_code,
bool is_background_mode) { … }
void RecordInputStreamReadError(MojoResult mojo_result) { … }
#if BUILDFLAG(IS_ANDROID)
void RecordDuplicatePdfDownloadTriggered(bool open_inline) {
base::UmaHistogramBoolean("Download.DuplicatePdfDownloadTriggered",
open_inline);
}
#endif
}