Commit 162c484a authored by Eugene But's avatar Eugene But Committed by Commit Bot

Add Download.IOSDownloadFileResult UMA to New Download Manager.

This is an existing histogram logged for the Old Download Manager.
The histogram is already a part of histograms.xml file.

Bug: 791806
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I93c0d84e91622654245b7dca88f06c5771e42b65
Reviewed-on: https://chromium-review.googlesource.com/973945Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Commit-Queue: Eugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545071}
parent 9d8520be
......@@ -22,4 +22,19 @@ enum class DownloadedFileAction {
Count,
};
// Values of the UMA Download.IOSDownloadFileResult histogram. This action is
// reported only for started downloads.
enum class DownloadFileResult {
// Download has successfully completed.
Completed = 0,
// In progress download was cancelled by the user.
Cancelled = 1,
// Download has completed with error.
Failure = 2,
// In progress download did no finish because the tab was closed or user has
// quit the app.
Other = 3,
Count
};
#endif // IOS_CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_METRIC_NAMES_H_
......@@ -41,10 +41,25 @@ class UnopenedDownloadsTracker : public web::DownloadTaskObserver {
// Stops tracking this download task.
void Remove(web::DownloadTask* task) { task->RemoveObserver(this); }
// DownloadTaskObserver overrides:
void OnDownloadUpdated(web::DownloadTask* task) override {
if (task->IsDone()) {
UMA_HISTOGRAM_ENUMERATION("Download.IOSDownloadFileResult",
task->GetErrorCode()
? DownloadFileResult::Failure
: DownloadFileResult::Completed,
DownloadFileResult::Count);
}
}
void OnDownloadDestroyed(web::DownloadTask* task) override {
// This download task was never open by the user.
task->RemoveObserver(this);
if (task->GetState() == web::DownloadTask::State::kInProgress) {
UMA_HISTOGRAM_ENUMERATION("Download.IOSDownloadFileResult",
DownloadFileResult::Other,
DownloadFileResult::Count);
}
if (task->IsDone() && task->GetErrorCode() == net::OK) {
UMA_HISTOGRAM_ENUMERATION("Download.IOSDownloadedFileAction",
DownloadedFileAction::NoAction,
......@@ -206,6 +221,11 @@ class UnopenedDownloadsTracker : public web::DownloadTaskObserver {
message:nil
completionHandler:^(BOOL confirmed) {
if (confirmed) {
UMA_HISTOGRAM_ENUMERATION(
"Download.IOSDownloadFileResult",
DownloadFileResult::Cancelled,
DownloadFileResult::Count);
[weakSelf cancelDownload];
}
}];
......
......@@ -403,12 +403,41 @@ TEST_F(DownloadManagerCoordinatorTest, OpenIn) {
// Download task is destroyed without opening the file.
task = nullptr;
histogram_tester_.ExpectUniqueSample(
"Download.IOSDownloadFileResult",
static_cast<base::HistogramBase::Sample>(DownloadFileResult::Completed),
1);
histogram_tester_.ExpectUniqueSample(
"Download.IOSDownloadedFileAction",
static_cast<base::HistogramBase::Sample>(DownloadedFileAction::NoAction),
1);
}
// Tests destroying download task for in progress download.
TEST_F(DownloadManagerCoordinatorTest, DestroyInProgressDownload) {
auto task = CreateTestTask();
coordinator_.downloadTask = task.get();
[coordinator_ start];
EXPECT_EQ(1U, base_view_controller_.childViewControllers.count);
DownloadManagerViewController* viewController =
base_view_controller_.childViewControllers.firstObject;
ASSERT_EQ([DownloadManagerViewController class], [viewController class]);
// Start and the download.
base::FilePath path;
ASSERT_TRUE(base::GetTempDir(&path));
task->Start(std::make_unique<net::URLFetcherFileWriter>(
base::ThreadTaskRunnerHandle::Get(), path));
// Download task is destroyed before the download is complete.
task = nullptr;
histogram_tester_.ExpectTotalCount("Download.IOSDownloadedFileAction", 0);
histogram_tester_.ExpectUniqueSample(
"Download.IOSDownloadFileResult",
static_cast<base::HistogramBase::Sample>(DownloadFileResult::Other), 1);
}
// Tests opening the download in Google Drive app.
TEST_F(DownloadManagerCoordinatorTest, OpenInDrive) {
web::FakeDownloadTask task(GURL(kTestUrl), kTestMimeType);
......@@ -451,6 +480,7 @@ TEST_F(DownloadManagerCoordinatorTest, OpenInDrive) {
willBeginSendingToApplication:kGoogleDriveAppBundleID];
}
histogram_tester_.ExpectTotalCount("Download.IOSDownloadFileResult", 0);
histogram_tester_.ExpectUniqueSample("Download.IOSDownloadedFileAction",
static_cast<base::HistogramBase::Sample>(
DownloadedFileAction::OpenedInDrive),
......@@ -499,6 +529,7 @@ TEST_F(DownloadManagerCoordinatorTest, OpenInOtherApp) {
willBeginSendingToApplication:@"foo-app-id"];
}
histogram_tester_.ExpectTotalCount("Download.IOSDownloadFileResult", 0);
histogram_tester_.ExpectUniqueSample(
"Download.IOSDownloadedFileAction",
static_cast<base::HistogramBase::Sample>(
......@@ -613,10 +644,11 @@ TEST_F(DownloadManagerCoordinatorTest, StartDownload) {
TEST_F(DownloadManagerCoordinatorTest, RetryingDownload) {
web::FakeDownloadTask task(GURL(kTestUrl), kTestMimeType);
task.SetSuggestedFilename(base::SysNSStringToUTF16(kTestSuggestedFileName));
task.SetErrorCode(net::ERR_INTERNET_DISCONNECTED);
web::DownloadTask* task_ptr = &task;
coordinator_.downloadTask = &task;
[coordinator_ start];
task.SetErrorCode(net::ERR_INTERNET_DISCONNECTED);
task.SetDone(true);
DownloadManagerViewController* viewController =
base_view_controller_.childViewControllers.firstObject;
......@@ -633,6 +665,9 @@ TEST_F(DownloadManagerCoordinatorTest, RetryingDownload) {
return task_ptr->GetState() == web::DownloadTask::State::kInProgress;
}));
histogram_tester_.ExpectUniqueSample(
"Download.IOSDownloadFileResult",
static_cast<base::HistogramBase::Sample>(DownloadFileResult::Failure), 1);
ASSERT_EQ(1,
user_action_tester_.GetActionCount("MobileDownloadRetryDownload"));
}
......
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