Commit aeec7095 authored by Christian Dullweber's avatar Christian Dullweber Committed by Commit Bot

Log UserDeletedCookieOrCacheFromDialog from Android

We currently log the UserDeletedCookieOrCacheFromDialog histogram from
Desktop. On Android we only know about total cookie/cache deletion
and not those started from CBD.
This CL adds logging of the UserDeletedCookieOrCacheFromDialog histogram
to the CBD dialog on Android.

Change-Id: I51c1ff6d3c5dc6f531f5bfccc59f522718b1abef
Reviewed-on: https://chromium-review.googlesource.com/c/1276605
Commit-Queue: Christian Dullweber <dullweber@chromium.org>
Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#599185}
parent 0f7980b3
......@@ -22,12 +22,14 @@ import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ListView;
import org.chromium.base.CollectionUtil;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.browsing_data.BrowsingDataType;
import org.chromium.chrome.browser.browsing_data.ClearBrowsingDataTab;
import org.chromium.chrome.browser.browsing_data.CookieOrCacheDeletionChoice;
import org.chromium.chrome.browser.browsing_data.TimePeriod;
import org.chromium.chrome.browser.historyreport.AppIndexingReporter;
import org.chromium.chrome.browser.multiwindow.MultiWindowUtils;
......@@ -42,6 +44,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
......@@ -280,8 +283,8 @@ public abstract class ClearBrowsingDataPreferences extends PreferenceFragment
/**
* @return All available {@link DialogOption} entries.
*/
protected final static ArraySet<Integer> getAllOptions() {
ArraySet<Integer> all = new ArraySet<>();
protected final static Set<Integer> getAllOptions() {
Set<Integer> all = new ArraySet<>();
for (@DialogOption int i = DialogOption.CLEAR_HISTORY; i < DialogOption.NUM_ENTRIES; i++) {
all.add(i);
}
......@@ -293,11 +296,10 @@ public abstract class ClearBrowsingDataPreferences extends PreferenceFragment
* @param options The set of selected {@link DialogOption} entries.
* @return int[] List of {@link BrowsingDataType} that should be deleted.
*/
protected int[] getDataTypesFromOptions(ArraySet<Integer> options) {
int[] dataTypes = new int[options.size()];
int i = 0;
protected Set<Integer> getDataTypesFromOptions(Set<Integer> options) {
Set<Integer> dataTypes = new ArraySet<>();
for (@DialogOption Integer option : options) {
dataTypes[i++] = getDataType(option);
dataTypes.add(getDataType(option));
}
return dataTypes;
}
......@@ -305,8 +307,8 @@ public abstract class ClearBrowsingDataPreferences extends PreferenceFragment
/**
* @return The currently selected {@link DialogOption} entries.
*/
protected final ArraySet<Integer> getSelectedOptions() {
ArraySet<Integer> selected = new ArraySet<>();
protected final Set<Integer> getSelectedOptions() {
Set<Integer> selected = new ArraySet<>();
for (Item item : mItems) {
if (item.isSelected()) selected.add(item.getOption());
}
......@@ -334,26 +336,41 @@ public abstract class ClearBrowsingDataPreferences extends PreferenceFragment
* Requests the browsing data corresponding to the given dialog options to be deleted.
* @param options The dialog options whose corresponding data should be deleted.
*/
private void clearBrowsingData(ArraySet<Integer> options, @Nullable String[] blacklistedDomains,
private void clearBrowsingData(Set<Integer> options, @Nullable String[] blacklistedDomains,
@Nullable int[] blacklistedDomainReasons, @Nullable String[] ignoredDomains,
@Nullable int[] ignoredDomainReasons) {
onClearBrowsingData();
showProgressDialog();
Set<Integer> dataTypes = getDataTypesFromOptions(options);
RecordHistogram.recordMediumTimesHistogram("History.ClearBrowsingData.TimeSpentInDialog",
SystemClock.elapsedRealtime() - mDialogOpened, TimeUnit.MILLISECONDS);
int[] dataTypes = getDataTypesFromOptions(options);
final @CookieOrCacheDeletionChoice int choice;
if (dataTypes.contains(BrowsingDataType.COOKIES)) {
choice = dataTypes.contains(BrowsingDataType.CACHE)
? CookieOrCacheDeletionChoice.BOTH_COOKIES_AND_CACHE
: CookieOrCacheDeletionChoice.ONLY_COOKIES;
} else {
choice = dataTypes.contains(BrowsingDataType.CACHE)
? CookieOrCacheDeletionChoice.ONLY_CACHE
: CookieOrCacheDeletionChoice.NEITHER_COOKIES_NOR_CACHE;
}
RecordHistogram.recordEnumeratedHistogram(
"History.ClearBrowsingData.UserDeletedCookieOrCacheFromDialog", choice,
CookieOrCacheDeletionChoice.MAX_CHOICE_VALUE);
Object spinnerSelection =
((SpinnerPreference) findPreference(PREF_TIME_RANGE)).getSelectedOption();
int timePeriod = ((TimePeriodSpinnerOption) spinnerSelection).getTimePeriod();
// TODO(bsazonov): Change integerListToIntArray to handle Collection<Integer>.
int[] dataTypesArray = CollectionUtil.integerListToIntArray(new ArrayList<>(dataTypes));
if (blacklistedDomains != null && blacklistedDomains.length != 0) {
BrowsingDataBridge.getInstance().clearBrowsingDataExcludingDomains(this, dataTypes,
BrowsingDataBridge.getInstance().clearBrowsingDataExcludingDomains(this, dataTypesArray,
timePeriod, blacklistedDomains, blacklistedDomainReasons, ignoredDomains,
ignoredDomainReasons);
} else {
BrowsingDataBridge.getInstance().clearBrowsingData(this, dataTypes, timePeriod);
BrowsingDataBridge.getInstance().clearBrowsingData(this, dataTypesArray, timePeriod);
}
// Clear all reported entities.
......@@ -454,7 +471,7 @@ public abstract class ClearBrowsingDataPreferences extends PreferenceFragment
* </ol>
*/
private boolean shouldShowImportantSitesDialog() {
ArraySet<Integer> selectedOptions = getSelectedOptions();
Set<Integer> selectedOptions = getSelectedOptions();
if (!selectedOptions.contains(DialogOption.CLEAR_CACHE)
&& !selectedOptions.contains(DialogOption.CLEAR_COOKIES_AND_SITE_DATA)) {
return false;
......@@ -555,7 +572,7 @@ public abstract class ClearBrowsingDataPreferences extends PreferenceFragment
// Not all checkboxes defined in the layout are necessarily handled by this class
// or a particular subclass. Hide those that are not.
ArraySet<Integer> unboundOptions = getAllOptions();
Set<Integer> unboundOptions = getAllOptions();
unboundOptions.removeAll(options);
for (@DialogOption Integer option : unboundOptions) {
getPreferenceScreen().removePreference(findPreference(getPreferenceKey(option)));
......
......@@ -5,7 +5,6 @@
package org.chromium.chrome.browser.preferences.privacy;
import android.os.Bundle;
import android.support.v4.util.ArraySet;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.metrics.RecordUserAction;
......@@ -23,6 +22,7 @@ import org.chromium.components.sync.ModelType;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
/**
* A simpler version of {@link ClearBrowsingDataPreferences} with fewer dialog options and more
......@@ -76,20 +76,13 @@ public class ClearBrowsingDataPreferencesBasic extends ClearBrowsingDataPreferen
}
@Override
protected int[] getDataTypesFromOptions(ArraySet<Integer> options) {
int[] dataTypes;
int i = 0;
protected Set<Integer> getDataTypesFromOptions(Set<Integer> options) {
Set<Integer> dataTypes = super.getDataTypesFromOptions(options);
if (options.contains(DialogOption.CLEAR_COOKIES_AND_SITE_DATA)) {
// COOKIES checkbox includes MEDIA_LICENSES, which need to be
// specified separately. This is only done for the basic tab.
// On the advanced tab Media Licenses has its own checkbox.
dataTypes = new int[options.size() + 1];
dataTypes[i++] = BrowsingDataType.MEDIA_LICENSES;
} else {
dataTypes = new int[options.size()];
}
for (Integer option : options) {
dataTypes[i++] = getDataType(option);
dataTypes.add(BrowsingDataType.MEDIA_LICENSES);
}
return dataTypes;
}
......
......@@ -66,6 +66,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Integration tests for ClearBrowsingDataPreferences.
......@@ -624,7 +625,7 @@ public class ClearBrowsingDataPreferencesTest {
}
}
private void setDataTypesToClear(final ArraySet<Integer> typesToClear) {
private void setDataTypesToClear(final Set<Integer> typesToClear) {
ThreadUtils.runOnUiThreadBlocking(() -> {
for (@DialogOption Integer option : ClearBrowsingDataPreferences.getAllOptions()) {
boolean enabled = typesToClear.contains(option);
......
......@@ -330,6 +330,7 @@ java_cpp_enum("content_public_android_java_enums_srcjar") {
"//content/browser/android/select_popup.cc",
"//content/public/browser/android/child_process_importance.h",
"//content/public/browser/android/motion_event_action.h",
"//content/public/browser/browsing_data_remover.h",
"//content/public/browser/invalidate_type.h",
"//content/public/browser/navigation_controller.h",
"//content/public/common/browser_controls_state.h",
......
......@@ -121,6 +121,9 @@ class BrowsingDataRemover {
// A helper enum to report the deletion of cookies and/or cache. Do not
// reorder the entries, as this enum is passed to UMA.
// A Java counterpart will be generated for this enum so that it can be
// logged on Android.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.browsing_data
enum CookieOrCacheDeletionChoice {
NEITHER_COOKIES_NOR_CACHE,
ONLY_COOKIES,
......
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