chromium/components/download/internal/common/download_stats.cc

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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"

// TODO(crbug.com/40120259): Launch this on Fuchsia. We should also consider
// serving an empty FileTypePolicies to platforms without Safe Browsing to
// remove the BUILDFLAGs and nogncheck here.
#if (BUILDFLAG(FULL_SAFE_BROWSING) || BUILDFLAG(SAFE_BROWSING_DB_REMOTE)) && \
    !BUILDFLAG(IS_FUCHSIA)
#include "components/safe_browsing/content/common/file_type_policies.h"  // nogncheck
#endif

namespace download {
namespace {

// All possible error codes from the network module. Note that the error codes
// are all positive (since histograms expect positive sample values).
const int kAllInterruptReasonCodes[] =;

// These values are based on net::HttpContentDisposition::ParseResult values.
// Values other than HEADER_PRESENT and IS_VALID are only measured if |IS_VALID|
// is true.
enum ContentDispositionCountTypes {};

// Helper method to calculate the bandwidth given the data length and time.
int64_t CalculateBandwidthBytesPerSecond(size_t length,
                                         base::TimeDelta elapsed_time) {}

// Records a histogram with download source suffix.
std::string CreateHistogramNameWithSuffix(const std::string& name,
                                          DownloadSource download_source) {}

void RecordConnectionType(
    const std::string& name,
    net::NetworkChangeNotifier::ConnectionType connection_type,
    DownloadSource download_source) {}

}  // namespace

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() {}

// NOTE: Keep in sync with DownloadImageType in
// tools/metrics/histograms/enums.xml.
enum DownloadImage {};

static std::map<std::string, int> getMimeTypeToDownloadImageMap() {}

void RecordDownloadImageType(const std::string& mime_type_string) {}

/** Text categories **/

// NOTE: Keep in sync with DownloadTextType in
// tools/metrics/histograms/enums.xml.
enum DownloadText {};

static std::map<std::string, int> getMimeTypeToDownloadTextMap() {}

void RecordDownloadTextType(const std::string& mime_type_string) {}

/* Audio categories */

// NOTE: Keep in sync with DownloadAudioType in
// tools/metrics/histograms/enums.xml.
enum DownloadAudio {};

static std::map<std::string, int> getMimeTypeToDownloadAudioMap() {}

void RecordDownloadAudioType(const std::string& mime_type_string) {}

/* Video categories */

// NOTE: Keep in sync with DownloadVideoType in
// tools/metrics/histograms/enums.xml.
enum DownloadVideo {};

static std::map<std::string, int> getMimeTypeToDownloadVideoMap() {}

void RecordDownloadVideoType(const std::string& mime_type_string) {}

// These histograms summarize download mime-types. The same data is recorded in
// a few places, as they exist to sanity-check and understand other metrics.
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) {}

}  // namespace

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  // BUILDFLAG(IS_ANDROID)

}  // namespace download