Commit 17a73537 authored by Min Qin's avatar Min Qin Committed by Commit Bot

Add UMA to track how many downloads are resumed when browser process is not running

Bug: 906287
Change-Id: Ia3b48e13ac444d7569333141c6bba0c7dc14302e
Reviewed-on: https://chromium-review.googlesource.com/c/1340806
Commit-Queue: Min Qin <qinmin@chromium.org>
Reviewed-by: default avatarShakti Sahu <shaktisahu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609563}
parent d2eae8d5
......@@ -31,9 +31,11 @@ import com.google.ipc.invalidation.util.Preconditions;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.library_loader.LibraryProcessType;
import org.chromium.base.library_loader.ProcessInitException;
import org.chromium.chrome.browser.ChromeApplication;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.download.DownloadNotificationUmaHelper.UmaDownloadResumption;
import org.chromium.chrome.browser.download.items.OfflineContentAggregatorNotificationBridgeUiFactory;
import org.chromium.chrome.browser.init.BrowserParts;
import org.chromium.chrome.browser.init.ChromeBrowserInitializer;
......@@ -43,6 +45,7 @@ import org.chromium.chrome.browser.util.IntentUtils;
import org.chromium.components.offline_items_collection.ContentId;
import org.chromium.components.offline_items_collection.LegacyHelpers;
import org.chromium.components.offline_items_collection.PendingState;
import org.chromium.content_public.browser.BrowserStartupController;
/**
* Class that spins up native when an interaction with a notification happens and passes the
......@@ -170,12 +173,20 @@ public class DownloadBroadcastManager extends Service {
*/
@VisibleForTesting
void loadNativeAndPropagateInteraction(final Intent intent) {
final boolean browserStarted =
BrowserStartupController.get(LibraryProcessType.PROCESS_BROWSER)
.isStartupSuccessfullyCompleted();
final BrowserParts parts = new EmptyBrowserParts() {
@Override
public void finishNativeInitialization() {
// Delay the stop of the service by WAIT_TIME_MS after native library is loaded.
mHandler.postDelayed(mStopSelfRunnable, WAIT_TIME_MS);
if (ACTION_DOWNLOAD_RESUME.equals(intent.getAction())) {
DownloadNotificationUmaHelper.recordDownloadResumptionHistogram(browserStarted
? UmaDownloadResumption.BROWSER_RUNNING
: UmaDownloadResumption.BROWSER_NOT_RUNNING);
}
propagateInteraction(intent);
}
......
......@@ -32,6 +32,7 @@ import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.task.AsyncTask;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.download.DownloadMetrics.DownloadOpenSource;
import org.chromium.chrome.browser.download.DownloadNotificationUmaHelper.UmaDownloadResumption;
import org.chromium.chrome.browser.download.ui.BackendProvider;
import org.chromium.chrome.browser.externalnav.ExternalNavigationDelegateImpl;
import org.chromium.chrome.browser.feature_engagement.TrackerFactory;
......@@ -108,20 +109,6 @@ public class DownloadManagerService
private static final String PREF_IS_DOWNLOAD_HOME_ENABLED =
"org.chromium.chrome.browser.download.IS_DOWNLOAD_HOME_ENABLED";
// Values for the histogram MobileDownloadResumptionCount.
@IntDef({UmaDownloadResumption.MANUAL_PAUSE, UmaDownloadResumption.BROWSER_KILLED,
UmaDownloadResumption.CLICKED, UmaDownloadResumption.FAILED,
UmaDownloadResumption.AUTO_STARTED})
@Retention(RetentionPolicy.SOURCE)
private @interface UmaDownloadResumption {
int MANUAL_PAUSE = 0;
int BROWSER_KILLED = 1;
int CLICKED = 2;
int FAILED = 3;
int AUTO_STARTED = 4;
int NUM_ENTRIES = 5;
}
// Set will be more expensive to initialize, so use an ArrayList here.
private static final List<String> MIME_TYPES_TO_OPEN = new ArrayList<String>(Arrays.asList(
OMADownloadHandler.OMA_DOWNLOAD_DESCRIPTOR_MIME,
......@@ -498,7 +485,8 @@ public class DownloadManagerService
case DownloadStatus.IN_PROGRESS:
if (info.isPaused()) {
mDownloadNotifier.notifyDownloadPaused(info);
recordDownloadResumption(UmaDownloadResumption.MANUAL_PAUSE);
DownloadNotificationUmaHelper.recordDownloadResumptionHistogram(
UmaDownloadResumption.MANUAL_PAUSE);
} else {
mDownloadNotifier.notifyDownloadProgress(
info, progress.mStartTimeInMillis, progress.mCanDownloadWhileMetered);
......@@ -973,14 +961,15 @@ public class DownloadManagerService
}
int uma =
hasUserGesture ? UmaDownloadResumption.CLICKED : UmaDownloadResumption.AUTO_STARTED;
recordDownloadResumption(uma);
DownloadNotificationUmaHelper.recordDownloadResumptionHistogram(uma);
if (progress == null) {
assert !item.getDownloadInfo().isPaused();
// If the download was not resumed before, the browser must have been killed while the
// download is active.
if (!sFirstSeenDownloadIds.contains(item.getId())) {
sFirstSeenDownloadIds.add(item.getId());
recordDownloadResumption(UmaDownloadResumption.BROWSER_KILLED);
DownloadNotificationUmaHelper.recordDownloadResumptionHistogram(
UmaDownloadResumption.BROWSER_KILLED);
}
updateDownloadProgress(item, DownloadStatus.IN_PROGRESS);
progress = mDownloadProgressMap.get(item.getId());
......@@ -1140,7 +1129,8 @@ public class DownloadManagerService
.setFailState(FailState.CANNOT_DOWNLOAD)
.build());
removeDownloadProgress(downloadGuid);
recordDownloadResumption(UmaDownloadResumption.FAILED);
DownloadNotificationUmaHelper.recordDownloadResumptionHistogram(
UmaDownloadResumption.FAILED);
recordDownloadFinishedUMA(DownloadStatus.FAILED, downloadGuid, 0);
}
......@@ -1177,15 +1167,6 @@ public class DownloadManagerService
}
}
/**
* Helper method to record the download resumption UMA.
* @param type UMA type to be recorded.
*/
private void recordDownloadResumption(@UmaDownloadResumption int type) {
RecordHistogram.recordEnumeratedHistogram(
"MobileDownload.DownloadResumption", type, UmaDownloadResumption.NUM_ENTRIES);
}
/**
* Helper method to record the metrics when a download completes.
* @param useDownloadManager Whether the download goes through Android DownloadManager.
......
......@@ -74,6 +74,23 @@ public final class DownloadNotificationUmaHelper {
int NUM_ENTRIES = 5;
}
// Values for the histogram MobileDownloadResumptionCount.
@IntDef({UmaDownloadResumption.MANUAL_PAUSE, UmaDownloadResumption.BROWSER_KILLED,
UmaDownloadResumption.CLICKED, UmaDownloadResumption.FAILED,
UmaDownloadResumption.AUTO_STARTED, UmaDownloadResumption.BROWSER_RUNNING,
UmaDownloadResumption.BROWSER_NOT_RUNNING})
@Retention(RetentionPolicy.SOURCE)
public @interface UmaDownloadResumption {
int MANUAL_PAUSE = 0;
int BROWSER_KILLED = 1;
int CLICKED = 2;
int FAILED = 3;
int AUTO_STARTED = 4;
int BROWSER_RUNNING = 5;
int BROWSER_NOT_RUNNING = 6;
int NUM_ENTRIES = 7;
}
/**
* Records an instance where a user interacts with a notification (clicks on, pauses, etc).
* @param action Notification interaction that was taken (ie. pause, resume).
......@@ -164,4 +181,13 @@ public final class DownloadNotificationUmaHelper {
StateAtCancel.NUM_ENTRIES);
}
}
/**
* Helper method to record the download resumption UMA.
* @param type UMA type to be recorded.
*/
static void recordDownloadResumptionHistogram(@UmaDownloadResumption int type) {
RecordHistogram.recordEnumeratedHistogram(
"MobileDownload.DownloadResumption", type, UmaDownloadResumption.NUM_ENTRIES);
}
}
......@@ -33803,6 +33803,9 @@ Called by update_use_counter_css.py.-->
<int value="2" label="Resumption button clicked"/>
<int value="3" label="Resumption failed"/>
<int value="4" label="Resumption auto started"/>
<int value="5" label="Resumption started while browser process is running"/>
<int value="6"
label="Resumption started while browser process is not running"/>
</enum>
<enum name="MobileDownloadStoragePermission">
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