Commit 18d5b9dd authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Android] Fix data types filtering in ClearBrowsingDataPreferences

This CL fixes a crash in ClearBrowsingDataPreferences that was
introduced in https://crrev.com/c/1215202 by erroneously replacing
getDialogOptions with getSelectedOptions. This CL also changes the
return type of getDialogOptions to list to keep using removeAll.

Bug: 887830
Change-Id: I22491ebd4a6b027dfaa61403e618df81f26a48a2
Reviewed-on: https://chromium-review.googlesource.com/1238218
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Reviewed-by: default avatarFinnur Thorarinsson <finnur@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593156}
parent a5181e70
......@@ -367,10 +367,9 @@ public abstract class ClearBrowsingDataPreferences extends PreferenceFragment
}
/**
* Returns the Array of {@link DialogOption}. Options are displayed in the same
* order as they appear in the array.
* Returns the list of supported {@link DialogOption}.
*/
abstract protected int[] getDialogOptions();
abstract protected List<Integer> getDialogOptions();
/**
* Returns whether this preference page is a basic or advanced tab in order to use separate
......@@ -530,13 +529,14 @@ public abstract class ClearBrowsingDataPreferences extends PreferenceFragment
mDialogOpened = SystemClock.elapsedRealtime();
getActivity().setTitle(R.string.clear_browsing_data_title);
PreferenceUtils.addPreferencesFromResource(this, getPreferenceXmlId());
int[] options = getDialogOptions();
mItems = new Item[options.length];
for (int i = 0; i < options.length; i++) {
List<Integer> options = getDialogOptions();
mItems = new Item[options.size()];
for (int i = 0; i < options.size(); i++) {
@DialogOption int option = options.get(i);
boolean enabled = true;
// It is possible to disable the deletion of browsing history.
if (options[i] == DialogOption.CLEAR_HISTORY
if (option == DialogOption.CLEAR_HISTORY
&& !PrefServiceBridge.getInstance().getBoolean(
Pref.ALLOW_DELETING_BROWSER_HISTORY)) {
enabled = false;
......@@ -547,16 +547,15 @@ public abstract class ClearBrowsingDataPreferences extends PreferenceFragment
false);
}
mItems[i] = new Item(getActivity(), this, options[i],
(ClearBrowsingDataCheckBoxPreference) findPreference(
getPreferenceKey(options[i])),
isOptionSelectedByDefault(options[i]), enabled);
mItems[i] = new Item(getActivity(), this, option,
(ClearBrowsingDataCheckBoxPreference) findPreference(getPreferenceKey(option)),
isOptionSelectedByDefault(option), enabled);
}
// 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();
unboundOptions.removeAll(getSelectedOptions());
unboundOptions.removeAll(options);
for (@DialogOption Integer option : unboundOptions) {
getPreferenceScreen().removePreference(findPreference(getPreferenceKey(option)));
}
......
......@@ -8,6 +8,9 @@ import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.metrics.RecordUserAction;
import org.chromium.chrome.browser.browsing_data.ClearBrowsingDataTab;
import java.util.Arrays;
import java.util.List;
/**
* A more advanced version of {@link ClearBrowsingDataPreferences} with more dialog options and less
* explanatory text.
......@@ -19,11 +22,11 @@ public class ClearBrowsingDataPreferencesAdvanced extends ClearBrowsingDataPrefe
}
@Override
protected int[] getDialogOptions() {
return new int[] {DialogOption.CLEAR_HISTORY, DialogOption.CLEAR_COOKIES_AND_SITE_DATA,
protected List<Integer> getDialogOptions() {
return Arrays.asList(DialogOption.CLEAR_HISTORY, DialogOption.CLEAR_COOKIES_AND_SITE_DATA,
DialogOption.CLEAR_CACHE, DialogOption.CLEAR_PASSWORDS,
DialogOption.CLEAR_FORM_DATA, DialogOption.CLEAR_SITE_SETTINGS,
DialogOption.CLEAR_MEDIA_LICENSES};
DialogOption.CLEAR_MEDIA_LICENSES);
}
@Override
......
......@@ -21,6 +21,9 @@ import org.chromium.components.signin.ChromeSigninController;
import org.chromium.components.sync.AndroidSyncSettings;
import org.chromium.components.sync.ModelType;
import java.util.Arrays;
import java.util.List;
/**
* A simpler version of {@link ClearBrowsingDataPreferences} with fewer dialog options and more
* explanatory text.
......@@ -67,9 +70,9 @@ public class ClearBrowsingDataPreferencesBasic extends ClearBrowsingDataPreferen
}
@Override
protected int[] getDialogOptions() {
return new int[] {DialogOption.CLEAR_HISTORY, DialogOption.CLEAR_COOKIES_AND_SITE_DATA,
DialogOption.CLEAR_CACHE};
protected List<Integer> getDialogOptions() {
return Arrays.asList(DialogOption.CLEAR_HISTORY, DialogOption.CLEAR_COOKIES_AND_SITE_DATA,
DialogOption.CLEAR_CACHE);
}
@Override
......
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