Commit 3a08c5cc authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Download source enum for download better metrics.

This CL introduces a new enum that track the download source.

Currently it lives in content/public/browser, and passed in from
content::DownloadUrlParameters. In components/download, there is a one
to one mapping enum for usage in download in progress db, which can not
depend on content/public.

This enum is supposed to used in UMA as suffix for several key metrics
and UKM as Components, and saved in the new in progress level db.

Bug: 786482
Change-Id: I19a2f959eb9e7b0787087cad6c9519acbde13281
Reviewed-on: https://chromium-review.googlesource.com/777548
Commit-Queue: Xing Liu <xingliu@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#519928}
parent 872446d6
...@@ -9,6 +9,7 @@ DownloadServiceEntryUtilsTest.* ...@@ -9,6 +9,7 @@ DownloadServiceEntryUtilsTest.*
DownloadServiceModelImplTest.* DownloadServiceModelImplTest.*
DownloadStoreTest.* DownloadStoreTest.*
FileMonitorTest.* FileMonitorTest.*
InProgressConversionsTest.*
NavigationMonitorImplTest.* NavigationMonitorImplTest.*
NetworkListenerTest.* NetworkListenerTest.*
ProtoConversionsTest.* ProtoConversionsTest.*
......
...@@ -11,6 +11,7 @@ static_library("in_progress") { ...@@ -11,6 +11,7 @@ static_library("in_progress") {
sources = [ sources = [
"download_entry.cc", "download_entry.cc",
"download_entry.h", "download_entry.h",
"download_source.h",
"in_progress_cache.cc", "in_progress_cache.cc",
"in_progress_cache.h", "in_progress_cache.h",
"in_progress_conversions.cc", "in_progress_conversions.cc",
......
...@@ -11,13 +11,17 @@ DownloadEntry::DownloadEntry() = default; ...@@ -11,13 +11,17 @@ DownloadEntry::DownloadEntry() = default;
DownloadEntry::DownloadEntry(const DownloadEntry& other) = default; DownloadEntry::DownloadEntry(const DownloadEntry& other) = default;
DownloadEntry::DownloadEntry(const std::string& guid, DownloadEntry::DownloadEntry(const std::string& guid,
const std::string& request_origin) const std::string& request_origin,
: guid(guid), request_origin(request_origin){}; DownloadSource download_source)
: guid(guid),
request_origin(request_origin),
download_source(download_source) {}
DownloadEntry::~DownloadEntry() = default; DownloadEntry::~DownloadEntry() = default;
bool DownloadEntry::operator==(const DownloadEntry& other) const { bool DownloadEntry::operator==(const DownloadEntry& other) const {
return guid == other.guid && request_origin == other.request_origin; return guid == other.guid && request_origin == other.request_origin &&
download_source == other.download_source;
} }
} // namespace download } // namespace download
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include <string> #include <string>
#include "components/download/downloader/in_progress/download_source.h"
namespace download { namespace download {
// Contains various in-progress information related to a download. // Contains various in-progress information related to a download.
...@@ -14,7 +16,9 @@ struct DownloadEntry { ...@@ -14,7 +16,9 @@ struct DownloadEntry {
public: public:
DownloadEntry(); DownloadEntry();
DownloadEntry(const DownloadEntry& other); DownloadEntry(const DownloadEntry& other);
DownloadEntry(const std::string& guid, const std::string& request_origin); DownloadEntry(const std::string& guid,
const std::string& request_origin,
DownloadSource download_source);
~DownloadEntry(); ~DownloadEntry();
bool operator==(const DownloadEntry& other) const; bool operator==(const DownloadEntry& other) const;
...@@ -24,6 +28,9 @@ struct DownloadEntry { ...@@ -24,6 +28,9 @@ struct DownloadEntry {
// Represents the origin information for this download. Used by offline pages. // Represents the origin information for this download. Used by offline pages.
std::string request_origin; std::string request_origin;
// The source that triggered the download.
DownloadSource download_source = DownloadSource::UNKNOWN;
}; };
} // namespace download } // namespace download
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_DOWNLOAD_DOWNLOADER_IN_PROGRESS_DOWNLOAD_SOURCE_H_
#define COMPONENTS_DOWNLOAD_DOWNLOADER_IN_PROGRESS_DOWNLOAD_SOURCE_H_
#include <string>
namespace download {
// The source of download.
// This enum should match content::DownloadSource in
// content/public/browser/download_source.h.
// Any changes here should also apply to download_source.proto.
enum class DownloadSource {
UNKNOWN = 0,
NAVIGATION = 1,
DRAG_AND_DROP = 2,
MANUAL_RESUMPTION = 3,
AUTO_RESUMPTION = 4,
FROM_RENDERER = 5,
EXTENSION_API = 6,
EXTENSION_INSTALLER = 7,
PLUGIN = 8,
PLUGIN_INSTALLER = 9,
INTERNAL_API = 10,
SAVE_PACKAGE = 11,
OFFLINE_PAGE = 12,
COUNT = 13
};
} // namespace download
#endif // COMPONENTS_DOWNLOAD_DOWNLOADER_IN_PROGRESS_DOWNLOAD_SOURCE_H_
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "components/download/downloader/in_progress/in_progress_conversions.h" #include "components/download/downloader/in_progress/in_progress_conversions.h"
#include <utility> #include <utility>
#include "base/logging.h"
// TODO(jming): Write unit tests for conversion methods. // TODO(jming): Write unit tests for conversion methods.
namespace download { namespace download {
...@@ -14,6 +15,7 @@ DownloadEntry InProgressConversions::DownloadEntryFromProto( ...@@ -14,6 +15,7 @@ DownloadEntry InProgressConversions::DownloadEntryFromProto(
DownloadEntry entry; DownloadEntry entry;
entry.guid = proto.guid(); entry.guid = proto.guid();
entry.request_origin = proto.request_origin(); entry.request_origin = proto.request_origin();
entry.download_source = DownloadSourceFromProto(proto.download_source());
return entry; return entry;
} }
...@@ -22,9 +24,83 @@ metadata_pb::DownloadEntry InProgressConversions::DownloadEntryToProto( ...@@ -22,9 +24,83 @@ metadata_pb::DownloadEntry InProgressConversions::DownloadEntryToProto(
metadata_pb::DownloadEntry proto; metadata_pb::DownloadEntry proto;
proto.set_guid(entry.guid); proto.set_guid(entry.guid);
proto.set_request_origin(entry.request_origin); proto.set_request_origin(entry.request_origin);
proto.set_download_source(DownloadSourceToProto(entry.download_source));
return proto; return proto;
} }
// static
DownloadSource InProgressConversions::DownloadSourceFromProto(
metadata_pb::DownloadSource download_source) {
switch (download_source) {
case metadata_pb::DownloadSource::UNKNOWN:
return DownloadSource::UNKNOWN;
case metadata_pb::DownloadSource::NAVIGATION:
return DownloadSource::NAVIGATION;
case metadata_pb::DownloadSource::DRAG_AND_DROP:
return DownloadSource::DRAG_AND_DROP;
case metadata_pb::DownloadSource::MANUAL_RESUMPTION:
return DownloadSource::MANUAL_RESUMPTION;
case metadata_pb::DownloadSource::AUTO_RESUMPTION:
return DownloadSource::AUTO_RESUMPTION;
case metadata_pb::DownloadSource::FROM_RENDERER:
return DownloadSource::FROM_RENDERER;
case metadata_pb::DownloadSource::EXTENSION_API:
return DownloadSource::EXTENSION_API;
case metadata_pb::DownloadSource::EXTENSION_INSTALLER:
return DownloadSource::EXTENSION_INSTALLER;
case metadata_pb::DownloadSource::PLUGIN:
return DownloadSource::PLUGIN;
case metadata_pb::DownloadSource::PLUGIN_INSTALLER:
return DownloadSource::PLUGIN_INSTALLER;
case metadata_pb::DownloadSource::INTERNAL_API:
return DownloadSource::INTERNAL_API;
case metadata_pb::DownloadSource::SAVE_PACKAGE:
return DownloadSource::SAVE_PACKAGE;
case metadata_pb::DownloadSource::OFFLINE_PAGE:
return DownloadSource::OFFLINE_PAGE;
}
NOTREACHED();
return DownloadSource::UNKNOWN;
}
// static
metadata_pb::DownloadSource InProgressConversions::DownloadSourceToProto(
DownloadSource download_source) {
switch (download_source) {
case DownloadSource::UNKNOWN:
return metadata_pb::DownloadSource::UNKNOWN;
case DownloadSource::NAVIGATION:
return metadata_pb::DownloadSource::NAVIGATION;
case DownloadSource::DRAG_AND_DROP:
return metadata_pb::DownloadSource::DRAG_AND_DROP;
case DownloadSource::MANUAL_RESUMPTION:
return metadata_pb::DownloadSource::MANUAL_RESUMPTION;
case DownloadSource::AUTO_RESUMPTION:
return metadata_pb::DownloadSource::AUTO_RESUMPTION;
case DownloadSource::FROM_RENDERER:
return metadata_pb::DownloadSource::FROM_RENDERER;
case DownloadSource::EXTENSION_API:
return metadata_pb::DownloadSource::EXTENSION_API;
case DownloadSource::EXTENSION_INSTALLER:
return metadata_pb::DownloadSource::EXTENSION_INSTALLER;
case DownloadSource::PLUGIN:
return metadata_pb::DownloadSource::PLUGIN;
case DownloadSource::PLUGIN_INSTALLER:
return metadata_pb::DownloadSource::PLUGIN_INSTALLER;
case DownloadSource::INTERNAL_API:
return metadata_pb::DownloadSource::INTERNAL_API;
case DownloadSource::SAVE_PACKAGE:
return metadata_pb::DownloadSource::SAVE_PACKAGE;
case DownloadSource::OFFLINE_PAGE:
return metadata_pb::DownloadSource::OFFLINE_PAGE;
case DownloadSource::COUNT:
break;
}
NOTREACHED();
return metadata_pb::DownloadSource::UNKNOWN;
}
std::vector<DownloadEntry> InProgressConversions::DownloadEntriesFromProto( std::vector<DownloadEntry> InProgressConversions::DownloadEntriesFromProto(
const metadata_pb::DownloadEntries& proto) { const metadata_pb::DownloadEntries& proto) {
std::vector<DownloadEntry> entries; std::vector<DownloadEntry> entries;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "components/download/downloader/in_progress/download_entry.h" #include "components/download/downloader/in_progress/download_entry.h"
#include "components/download/downloader/in_progress/proto/download_entry.pb.h" #include "components/download/downloader/in_progress/proto/download_entry.pb.h"
#include "components/download/downloader/in_progress/proto/download_source.pb.h"
namespace download { namespace download {
...@@ -19,6 +20,12 @@ class InProgressConversions { ...@@ -19,6 +20,12 @@ class InProgressConversions {
static metadata_pb::DownloadEntry DownloadEntryToProto( static metadata_pb::DownloadEntry DownloadEntryToProto(
const DownloadEntry& entry); const DownloadEntry& entry);
static DownloadSource DownloadSourceFromProto(
metadata_pb::DownloadSource download_source);
static metadata_pb::DownloadSource DownloadSourceToProto(
DownloadSource download_source);
static std::vector<DownloadEntry> DownloadEntriesFromProto( static std::vector<DownloadEntry> DownloadEntriesFromProto(
const metadata_pb::DownloadEntries& proto); const metadata_pb::DownloadEntries& proto);
......
...@@ -18,9 +18,10 @@ TEST_F(InProgressConversionsTest, DownloadEntry) { ...@@ -18,9 +18,10 @@ TEST_F(InProgressConversionsTest, DownloadEntry) {
DownloadEntry entry; DownloadEntry entry;
EXPECT_EQ(entry, DownloadEntryFromProto(DownloadEntryToProto(entry))); EXPECT_EQ(entry, DownloadEntryFromProto(DownloadEntryToProto(entry)));
// Entry with guid and request origin. // Entry with guid, request origin and download source.
entry.guid = "guid"; entry.guid = "guid";
entry.request_origin = "request origin"; entry.request_origin = "request origin";
entry.download_source = DownloadSource::DRAG_AND_DROP;
EXPECT_EQ(entry, DownloadEntryFromProto(DownloadEntryToProto(entry))); EXPECT_EQ(entry, DownloadEntryFromProto(DownloadEntryToProto(entry)));
} }
...@@ -30,12 +31,29 @@ TEST_F(InProgressConversionsTest, DownloadEntries) { ...@@ -30,12 +31,29 @@ TEST_F(InProgressConversionsTest, DownloadEntries) {
EXPECT_EQ(entries, DownloadEntriesFromProto(DownloadEntriesToProto(entries))); EXPECT_EQ(entries, DownloadEntriesFromProto(DownloadEntriesToProto(entries)));
// Entries vector with one entry. // Entries vector with one entry.
entries.push_back(DownloadEntry("guid", "request origin")); entries.push_back(
DownloadEntry("guid", "request origin", DownloadSource::UNKNOWN));
EXPECT_EQ(entries, DownloadEntriesFromProto(DownloadEntriesToProto(entries))); EXPECT_EQ(entries, DownloadEntriesFromProto(DownloadEntriesToProto(entries)));
// Entries vector with multiple entries. // Entries vector with multiple entries.
entries.push_back(DownloadEntry("guid2", "request origin")); entries.push_back(
DownloadEntry("guid2", "request origin", DownloadSource::UNKNOWN));
EXPECT_EQ(entries, DownloadEntriesFromProto(DownloadEntriesToProto(entries))); EXPECT_EQ(entries, DownloadEntriesFromProto(DownloadEntriesToProto(entries)));
} }
TEST_F(InProgressConversionsTest, DownloadSource) {
DownloadSource sources[] = {
DownloadSource::UNKNOWN, DownloadSource::NAVIGATION,
DownloadSource::DRAG_AND_DROP, DownloadSource::MANUAL_RESUMPTION,
DownloadSource::AUTO_RESUMPTION, DownloadSource::FROM_RENDERER,
DownloadSource::EXTENSION_API, DownloadSource::EXTENSION_INSTALLER,
DownloadSource::PLUGIN, DownloadSource::PLUGIN_INSTALLER,
DownloadSource::INTERNAL_API, DownloadSource::SAVE_PACKAGE,
DownloadSource::OFFLINE_PAGE};
for (auto source : sources) {
EXPECT_EQ(source, DownloadSourceFromProto(DownloadSourceToProto(source)));
}
}
} // namespace download } // namespace download
...@@ -9,5 +9,6 @@ proto_library("proto") { ...@@ -9,5 +9,6 @@ proto_library("proto") {
sources = [ sources = [
"download_entry.proto", "download_entry.proto",
"download_source.proto",
] ]
} }
...@@ -8,10 +8,13 @@ option optimize_for = LITE_RUNTIME; ...@@ -8,10 +8,13 @@ option optimize_for = LITE_RUNTIME;
package metadata_pb; package metadata_pb;
import "download_source.proto";
// Stores various in-progress metadata related to a download. // Stores various in-progress metadata related to a download.
message DownloadEntry { message DownloadEntry {
optional string guid = 1; optional string guid = 1;
optional string request_origin = 2; optional string request_origin = 2;
optional DownloadSource download_source = 3;
} }
// Contains a list of entries. // Contains a list of entries.
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
syntax = "proto2";
option optimize_for = LITE_RUNTIME;
package metadata_pb;
// This should stay in sync with the download::DownloadSource enum in
// components/download/downloader/in_progress/download_source.h.
enum DownloadSource {
UNKNOWN = 0;
NAVIGATION = 1;
DRAG_AND_DROP = 2;
MANUAL_RESUMPTION = 3;
AUTO_RESUMPTION = 4;
FROM_RENDERER = 5;
EXTENSION_API = 6;
EXTENSION_INSTALLER = 7;
PLUGIN = 8;
PLUGIN_INSTALLER = 9;
INTERNAL_API = 10;
SAVE_PACKAGE = 11;
OFFLINE_PAGE = 12;
}
...@@ -980,8 +980,9 @@ void DownloadManagerImpl::BeginDownloadInternal( ...@@ -980,8 +980,9 @@ void DownloadManagerImpl::BeginDownloadInternal(
download::InProgressCache* in_progress_cache = download::InProgressCache* in_progress_cache =
GetBrowserContext()->GetDownloadManagerDelegate()->GetInProgressCache(); GetBrowserContext()->GetDownloadManagerDelegate()->GetInProgressCache();
if (in_progress_cache) { if (in_progress_cache) {
in_progress_cache->AddOrReplaceEntry(download::DownloadEntry( in_progress_cache->AddOrReplaceEntry(
params.get()->guid(), params.get()->request_origin())); download::DownloadEntry(params->guid(), params->request_origin(),
ToDownloadSource(params->download_source())));
} }
if (base::FeatureList::IsEnabled(features::kNetworkService)) { if (base::FeatureList::IsEnabled(features::kNetworkService)) {
......
...@@ -273,7 +273,7 @@ void RecordDownloadCount(DownloadCountTypes type) { ...@@ -273,7 +273,7 @@ void RecordDownloadCount(DownloadCountTypes type) {
"Download.Counts", type, DOWNLOAD_COUNT_TYPES_LAST_ENTRY); "Download.Counts", type, DOWNLOAD_COUNT_TYPES_LAST_ENTRY);
} }
void RecordDownloadSource(DownloadSource source) { void RecordDownloadSource(DownloadTriggerSource source) {
UMA_HISTOGRAM_ENUMERATION( UMA_HISTOGRAM_ENUMERATION(
"Download.Sources", source, DOWNLOAD_SOURCE_LAST_ENTRY); "Download.Sources", source, DOWNLOAD_SOURCE_LAST_ENTRY);
} }
......
...@@ -123,7 +123,8 @@ enum DownloadCountTypes { ...@@ -123,7 +123,8 @@ enum DownloadCountTypes {
DOWNLOAD_COUNT_TYPES_LAST_ENTRY DOWNLOAD_COUNT_TYPES_LAST_ENTRY
}; };
enum DownloadSource { // TODO(xingliu): Deprecate this enum.
enum DownloadTriggerSource {
// The download was initiated when the SavePackage system rejected // The download was initiated when the SavePackage system rejected
// a Save Page As ... by returning false from // a Save Page As ... by returning false from
// SavePackage::IsSaveableContents(). // SavePackage::IsSaveableContents().
...@@ -205,7 +206,7 @@ enum class ParallelDownloadCreationEvent { ...@@ -205,7 +206,7 @@ enum class ParallelDownloadCreationEvent {
void RecordDownloadCount(DownloadCountTypes type); void RecordDownloadCount(DownloadCountTypes type);
// Record initiation of a download from a specific source. // Record initiation of a download from a specific source.
void RecordDownloadSource(DownloadSource source); void RecordDownloadSource(DownloadTriggerSource source);
// Record COMPLETED_COUNT and how long the download took. // Record COMPLETED_COUNT and how long the download took.
void RecordDownloadCompleted(const base::TimeTicks& start, void RecordDownloadCompleted(const base::TimeTicks& start,
......
...@@ -405,4 +405,40 @@ void HandleResponseHeaders(const net::HttpResponseHeaders* headers, ...@@ -405,4 +405,40 @@ void HandleResponseHeaders(const net::HttpResponseHeaders* headers,
headers->response_code() == net::HTTP_PARTIAL_CONTENT); headers->response_code() == net::HTTP_PARTIAL_CONTENT);
} }
download::DownloadSource ToDownloadSource(
content::DownloadSource download_source) {
switch (download_source) {
case DownloadSource::UNKNOWN:
return download::DownloadSource::UNKNOWN;
case DownloadSource::NAVIGATION:
return download::DownloadSource::NAVIGATION;
case DownloadSource::DRAG_AND_DROP:
return download::DownloadSource::DRAG_AND_DROP;
case DownloadSource::MANUAL_RESUMPTION:
return download::DownloadSource::MANUAL_RESUMPTION;
case DownloadSource::AUTO_RESUMPTION:
return download::DownloadSource::AUTO_RESUMPTION;
case DownloadSource::FROM_RENDERER:
return download::DownloadSource::FROM_RENDERER;
case DownloadSource::EXTENSION_API:
return download::DownloadSource::EXTENSION_API;
case DownloadSource::EXTENSION_INSTALLER:
return download::DownloadSource::EXTENSION_INSTALLER;
case DownloadSource::PLUGIN:
return download::DownloadSource::PLUGIN;
case DownloadSource::PLUGIN_INSTALLER:
return download::DownloadSource::PLUGIN_INSTALLER;
case DownloadSource::INTERNAL_API:
return download::DownloadSource::INTERNAL_API;
case DownloadSource::SAVE_PACKAGE:
return download::DownloadSource::SAVE_PACKAGE;
case DownloadSource::OFFLINE_PAGE:
return download::DownloadSource::OFFLINE_PAGE;
case DownloadSource::COUNT:
break;
}
NOTREACHED();
return download::DownloadSource::UNKNOWN;
}
} // namespace content } // namespace content
...@@ -5,7 +5,9 @@ ...@@ -5,7 +5,9 @@
#ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_UTILS_H_ #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_UTILS_H_
#define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_UTILS_H_ #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_UTILS_H_
#include "components/download/downloader/in_progress/download_source.h"
#include "content/public/browser/download_interrupt_reasons.h" #include "content/public/browser/download_interrupt_reasons.h"
#include "content/public/browser/download_source.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "net/cert/cert_status_flags.h" #include "net/cert/cert_status_flags.h"
#include "net/http/http_response_headers.h" #include "net/http/http_response_headers.h"
...@@ -48,6 +50,10 @@ CONTENT_EXPORT void HandleResponseHeaders( ...@@ -48,6 +50,10 @@ CONTENT_EXPORT void HandleResponseHeaders(
const net::HttpResponseHeaders* headers, const net::HttpResponseHeaders* headers,
DownloadCreateInfo* create_info); DownloadCreateInfo* create_info);
// Converts content::DownloadSource to download::DownloadSource.
CONTENT_EXPORT download::DownloadSource ToDownloadSource(
content::DownloadSource download_source);
} // namespace content } // namespace content
#endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_UTILS_H_ #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_UTILS_H_
...@@ -118,6 +118,7 @@ source_set("browser_sources") { ...@@ -118,6 +118,7 @@ source_set("browser_sources") {
"download_request_utils.h", "download_request_utils.h",
"download_save_info.cc", "download_save_info.cc",
"download_save_info.h", "download_save_info.h",
"download_source.h",
"download_url_parameters.cc", "download_url_parameters.cc",
"download_url_parameters.h", "download_url_parameters.h",
"favicon_status.cc", "favicon_status.cc",
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_PUBLIC_BROWSER_DOWNLOAD_SOURCE_H_
#define CONTENT_PUBLIC_BROWSER_DOWNLOAD_SOURCE_H_
namespace content {
// The source of download.
// Used in UMA metrics and persisted to disk.
// Entries in this enum can only be appended instead of being deleted or reused.
// Any changes here also needs to apply to enums.xml.
enum class DownloadSource {
// The source is unknown.
UNKNOWN = 0,
// Download is triggered from navigation request.
NAVIGATION = 1,
// Drag and drop.
DRAG_AND_DROP = 2,
// User manually resume the download.
MANUAL_RESUMPTION = 3,
// Auto resumption in download system.
AUTO_RESUMPTION = 4,
// Renderer initiated download, mostly from Javascript or HTML <a> tag.
FROM_RENDERER = 5,
// Extension download API.
EXTENSION_API = 6,
// Extension web store installer.
EXTENSION_INSTALLER = 7,
// Plugin triggered download.
PLUGIN = 8,
// Plugin installer download.
PLUGIN_INSTALLER = 9,
// Download service API background download.
INTERNAL_API = 10,
// Save package download.
SAVE_PACKAGE = 11,
// Offline page download.
OFFLINE_PAGE = 12,
COUNT = 13
};
} // namespace content
#endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_SOURCE_H_
...@@ -47,7 +47,8 @@ DownloadUrlParameters::DownloadUrlParameters( ...@@ -47,7 +47,8 @@ DownloadUrlParameters::DownloadUrlParameters(
do_not_prompt_for_login_(false), do_not_prompt_for_login_(false),
fetch_error_body_(false), fetch_error_body_(false),
transient_(false), transient_(false),
traffic_annotation_(traffic_annotation) {} traffic_annotation_(traffic_annotation),
download_source_(DownloadSource::UNKNOWN) {}
DownloadUrlParameters::~DownloadUrlParameters() { DownloadUrlParameters::~DownloadUrlParameters() {
} }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "base/optional.h" #include "base/optional.h"
#include "content/public/browser/download_interrupt_reasons.h" #include "content/public/browser/download_interrupt_reasons.h"
#include "content/public/browser/download_save_info.h" #include "content/public/browser/download_save_info.h"
#include "content/public/browser/download_source.h"
#include "content/public/common/referrer.h" #include "content/public/common/referrer.h"
#include "net/traffic_annotation/network_traffic_annotation.h" #include "net/traffic_annotation/network_traffic_annotation.h"
#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_context_getter.h"
...@@ -244,6 +245,11 @@ class CONTENT_EXPORT DownloadUrlParameters { ...@@ -244,6 +245,11 @@ class CONTENT_EXPORT DownloadUrlParameters {
request_origin_ = origin; request_origin_ = origin;
} }
// Sets the download source, which will be used in metrics recording.
void set_download_source(DownloadSource download_source) {
download_source_ = download_source;
}
const OnStartedCallback& callback() const { return callback_; } const OnStartedCallback& callback() const { return callback_; }
bool content_initiated() const { return content_initiated_; } bool content_initiated() const { return content_initiated_; }
const std::string& last_modified() const { return last_modified_; } const std::string& last_modified() const { return last_modified_; }
...@@ -301,6 +307,8 @@ class CONTENT_EXPORT DownloadUrlParameters { ...@@ -301,6 +307,8 @@ class CONTENT_EXPORT DownloadUrlParameters {
return traffic_annotation_; return traffic_annotation_;
} }
DownloadSource download_source() const { return download_source_; }
private: private:
OnStartedCallback callback_; OnStartedCallback callback_;
bool content_initiated_; bool content_initiated_;
...@@ -328,6 +336,7 @@ class CONTENT_EXPORT DownloadUrlParameters { ...@@ -328,6 +336,7 @@ class CONTENT_EXPORT DownloadUrlParameters {
std::unique_ptr<storage::BlobDataHandle> blob_data_handle_; std::unique_ptr<storage::BlobDataHandle> blob_data_handle_;
const net::NetworkTrafficAnnotationTag traffic_annotation_; const net::NetworkTrafficAnnotationTag traffic_annotation_;
std::string request_origin_; std::string request_origin_;
DownloadSource download_source_;
DISALLOW_COPY_AND_ASSIGN(DownloadUrlParameters); DISALLOW_COPY_AND_ASSIGN(DownloadUrlParameters);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment