File: download_stats.cc

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (180 lines) | stat: -rw-r--r-- 8,382 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/download/download_stats.h"

#include "base/metrics/histogram_functions.h"
#include "base/metrics/user_metrics.h"
#include "base/notreached.h"
#include "build/build_config.h"
#include "chrome/browser/download/download_ui_model.h"
#include "chrome/browser/profiles/profile.h"
#include "components/download/public/common/download_content.h"
#include "components/download/public/common/download_stats.h"
#include "components/profile_metrics/browser_profile_type.h"
#include "components/safe_browsing/buildflags.h"

#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
#include "components/safe_browsing/content/browser/download/download_stats.h"
#endif

void RecordDownloadSource(ChromeDownloadSource source) {
  base::UmaHistogramEnumeration("Download.SourcesChrome", source,
                                CHROME_DOWNLOAD_SOURCE_LAST_ENTRY);
}

void MaybeRecordDangerousDownloadWarningShown(DownloadUIModel& model) {
  if (!model.IsDangerous() ||
      model.GetState() == download::DownloadItem::DownloadState::CANCELLED) {
    return;
  }
  if (model.WasUIWarningShown()) {
    return;
  }
  base::UmaHistogramEnumeration("Download.ShowedDownloadWarning",
                                model.GetDangerType(),
                                download::DOWNLOAD_DANGER_TYPE_MAX);
#if !BUILDFLAG(IS_ANDROID)
  base::UmaHistogramEnumeration("SBClientDownload.TailoredWarningType",
                                model.GetTailoredWarningType());
#endif  // BUILDFLAG(IS_ANDROID)
#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
  safe_browsing::RecordDangerousDownloadWarningShown(
      model.GetDangerType(), model.GetTargetFilePath(),
      model.GetURL().SchemeIs(url::kHttpsScheme), model.HasUserGesture());
#endif

  model.SetWasUIWarningShown(true);
}

void RecordDownloadOpen(ChromeDownloadOpenMethod open_method,
                        const std::string& mime_type_string) {
  base::RecordAction(base::UserMetricsAction("Download.Open"));
  base::UmaHistogramEnumeration("Download.OpenMethod", open_method,
                                DOWNLOAD_OPEN_METHOD_LAST_ENTRY);
  download::DownloadContent download_content =
      download::DownloadContentFromMimeType(
          mime_type_string, /*record_content_subcategory=*/false);
  base::UmaHistogramEnumeration("Download.Open.ContentType", download_content);
}

void RecordDatabaseAvailability(bool is_available) {
  base::UmaHistogramBoolean("Download.Database.IsAvailable", is_available);
}

void RecordDownloadPathGeneration(DownloadPathGenerationEvent event,
                                  bool is_transient) {
  if (is_transient) {
    base::UmaHistogramEnumeration("Download.PathGenerationEvent.Transient",
                                  event, DownloadPathGenerationEvent::COUNT);
  } else {
    base::UmaHistogramEnumeration("Download.PathGenerationEvent.UserDownload",
                                  event, DownloadPathGenerationEvent::COUNT);
  }
}

void RecordDownloadPathValidation(download::PathValidationResult result,
                                  bool is_transient) {
  if (is_transient) {
    base::UmaHistogramEnumeration("Download.PathValidationResult.Transient",
                                  result,
                                  download::PathValidationResult::COUNT);
  } else {
    base::UmaHistogramEnumeration("Download.PathValidationResult.UserDownload",
                                  result,
                                  download::PathValidationResult::COUNT);
  }
}

void RecordDownloadCancelReason(DownloadCancelReason reason) {
  base::UmaHistogramEnumeration("Download.CancelReason", reason);
}

void RecordDownloadShelfDragInfo(DownloadDragInfo drag_info) {
  base::UmaHistogramEnumeration("Download.Shelf.DragInfo", drag_info,
                                DownloadDragInfo::COUNT);
}

void RecordDownloadStartPerProfileType(Profile* profile) {
  base::UmaHistogramEnumeration(
      "Download.Start.PerProfileType",
      profile_metrics::GetBrowserProfileType(profile));
}

#if BUILDFLAG(IS_ANDROID)
// Records whether the download dialog is shown to the user.
void RecordDownloadPromptStatus(DownloadPromptStatus status) {
  base::UmaHistogramEnumeration("MobileDownload.DownloadPromptStatus", status,
                                DownloadPromptStatus::MAX_VALUE);
}
#endif  // BUILDFLAG(IS_ANDROID)

DownloadShelfContextMenuAction DownloadCommandToShelfAction(
    DownloadCommands::Command download_command,
    bool clicked) {
  switch (download_command) {
    case DownloadCommands::Command::SHOW_IN_FOLDER:
      return clicked ? DownloadShelfContextMenuAction::kShowInFolderClicked
                     : DownloadShelfContextMenuAction::kShowInFolderEnabled;
    case DownloadCommands::Command::OPEN_WHEN_COMPLETE:
      return clicked ? DownloadShelfContextMenuAction::kOpenWhenCompleteClicked
                     : DownloadShelfContextMenuAction::kOpenWhenCompleteEnabled;
    case DownloadCommands::Command::ALWAYS_OPEN_TYPE:
      return clicked ? DownloadShelfContextMenuAction::kAlwaysOpenTypeClicked
                     : DownloadShelfContextMenuAction::kAlwaysOpenTypeEnabled;
    case DownloadCommands::Command::PLATFORM_OPEN:
      return clicked ? DownloadShelfContextMenuAction::kPlatformOpenClicked
                     : DownloadShelfContextMenuAction::kPlatformOpenEnabled;
    case DownloadCommands::Command::CANCEL:
      return clicked ? DownloadShelfContextMenuAction::kCancelClicked
                     : DownloadShelfContextMenuAction::kCancelEnabled;
    case DownloadCommands::Command::PAUSE:
      return clicked ? DownloadShelfContextMenuAction::kPauseClicked
                     : DownloadShelfContextMenuAction::kPauseEnabled;
    case DownloadCommands::Command::RESUME:
      return clicked ? DownloadShelfContextMenuAction::kResumeClicked
                     : DownloadShelfContextMenuAction::kResumeEnabled;
    case DownloadCommands::Command::DISCARD:
      return clicked ? DownloadShelfContextMenuAction::kDiscardClicked
                     : DownloadShelfContextMenuAction::kDiscardEnabled;
    case DownloadCommands::Command::KEEP:
      return clicked ? DownloadShelfContextMenuAction::kKeepClicked
                     : DownloadShelfContextMenuAction::kKeepEnabled;
    case DownloadCommands::Command::LEARN_MORE_SCANNING:
      return clicked
                 ? DownloadShelfContextMenuAction::kLearnMoreScanningClicked
                 : DownloadShelfContextMenuAction::kLearnMoreScanningEnabled;
    case DownloadCommands::Command::LEARN_MORE_INTERRUPTED:
      return clicked
                 ? DownloadShelfContextMenuAction::kLearnMoreInterruptedClicked
                 : DownloadShelfContextMenuAction::kLearnMoreInterruptedEnabled;
    case DownloadCommands::Command::LEARN_MORE_INSECURE_DOWNLOAD:
      return clicked ? DownloadShelfContextMenuAction::
                           kLearnMoreInsecureDownloadClicked
                     : DownloadShelfContextMenuAction::
                           kLearnMoreInsecureDownloadEnabled;
    case DownloadCommands::Command::COPY_TO_CLIPBOARD:
      return clicked ? DownloadShelfContextMenuAction::kCopyToClipboardClicked
                     : DownloadShelfContextMenuAction::kCopyToClipboardEnabled;
    case DownloadCommands::Command::DEEP_SCAN:
      return clicked ? DownloadShelfContextMenuAction::kDeepScanClicked
                     : DownloadShelfContextMenuAction::kDeepScanEnabled;
    case DownloadCommands::BYPASS_DEEP_SCANNING_AND_OPEN:
      return clicked
                 ? DownloadShelfContextMenuAction::kBypassDeepScanningClicked
                 : DownloadShelfContextMenuAction::kBypassDeepScanningEnabled;

    // The following are not actually visible in the context menu so should
    // never be logged.
    case DownloadCommands::Command::REVIEW:
    case DownloadCommands::Command::RETRY:
    case DownloadCommands::Command::CANCEL_DEEP_SCAN:
    case DownloadCommands::Command::LEARN_MORE_DOWNLOAD_BLOCKED:
    case DownloadCommands::Command::OPEN_SAFE_BROWSING_SETTING:
    case DownloadCommands::Command::BYPASS_DEEP_SCANNING:
    case DownloadCommands::Command::OPEN_WITH_MEDIA_APP:
    case DownloadCommands::Command::EDIT_WITH_MEDIA_APP:
      NOTREACHED();
  }
}