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