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 ...@@ -367,10 +367,9 @@ public abstract class ClearBrowsingDataPreferences extends PreferenceFragment
} }
/** /**
* Returns the Array of {@link DialogOption}. Options are displayed in the same * Returns the list of supported {@link DialogOption}.
* order as they appear in the array.
*/ */
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 * 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 ...@@ -530,13 +529,14 @@ public abstract class ClearBrowsingDataPreferences extends PreferenceFragment
mDialogOpened = SystemClock.elapsedRealtime(); mDialogOpened = SystemClock.elapsedRealtime();
getActivity().setTitle(R.string.clear_browsing_data_title); getActivity().setTitle(R.string.clear_browsing_data_title);
PreferenceUtils.addPreferencesFromResource(this, getPreferenceXmlId()); PreferenceUtils.addPreferencesFromResource(this, getPreferenceXmlId());
int[] options = getDialogOptions(); List<Integer> options = getDialogOptions();
mItems = new Item[options.length]; mItems = new Item[options.size()];
for (int i = 0; i < options.length; i++) { for (int i = 0; i < options.size(); i++) {
@DialogOption int option = options.get(i);
boolean enabled = true; boolean enabled = true;
// It is possible to disable the deletion of browsing history. // It is possible to disable the deletion of browsing history.
if (options[i] == DialogOption.CLEAR_HISTORY if (option == DialogOption.CLEAR_HISTORY
&& !PrefServiceBridge.getInstance().getBoolean( && !PrefServiceBridge.getInstance().getBoolean(
Pref.ALLOW_DELETING_BROWSER_HISTORY)) { Pref.ALLOW_DELETING_BROWSER_HISTORY)) {
enabled = false; enabled = false;
...@@ -547,16 +547,15 @@ public abstract class ClearBrowsingDataPreferences extends PreferenceFragment ...@@ -547,16 +547,15 @@ public abstract class ClearBrowsingDataPreferences extends PreferenceFragment
false); false);
} }
mItems[i] = new Item(getActivity(), this, options[i], mItems[i] = new Item(getActivity(), this, option,
(ClearBrowsingDataCheckBoxPreference) findPreference( (ClearBrowsingDataCheckBoxPreference) findPreference(getPreferenceKey(option)),
getPreferenceKey(options[i])), isOptionSelectedByDefault(option), enabled);
isOptionSelectedByDefault(options[i]), enabled);
} }
// 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(); ArraySet<Integer> unboundOptions = getAllOptions();
unboundOptions.removeAll(getSelectedOptions()); unboundOptions.removeAll(options);
for (@DialogOption Integer option : unboundOptions) { for (@DialogOption Integer option : unboundOptions) {
getPreferenceScreen().removePreference(findPreference(getPreferenceKey(option))); getPreferenceScreen().removePreference(findPreference(getPreferenceKey(option)));
} }
......
...@@ -8,6 +8,9 @@ import org.chromium.base.metrics.RecordHistogram; ...@@ -8,6 +8,9 @@ import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.metrics.RecordUserAction; import org.chromium.base.metrics.RecordUserAction;
import org.chromium.chrome.browser.browsing_data.ClearBrowsingDataTab; 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 * A more advanced version of {@link ClearBrowsingDataPreferences} with more dialog options and less
* explanatory text. * explanatory text.
...@@ -19,11 +22,11 @@ public class ClearBrowsingDataPreferencesAdvanced extends ClearBrowsingDataPrefe ...@@ -19,11 +22,11 @@ public class ClearBrowsingDataPreferencesAdvanced extends ClearBrowsingDataPrefe
} }
@Override @Override
protected int[] getDialogOptions() { protected List<Integer> getDialogOptions() {
return new int[] {DialogOption.CLEAR_HISTORY, DialogOption.CLEAR_COOKIES_AND_SITE_DATA, return Arrays.asList(DialogOption.CLEAR_HISTORY, DialogOption.CLEAR_COOKIES_AND_SITE_DATA,
DialogOption.CLEAR_CACHE, DialogOption.CLEAR_PASSWORDS, DialogOption.CLEAR_CACHE, DialogOption.CLEAR_PASSWORDS,
DialogOption.CLEAR_FORM_DATA, DialogOption.CLEAR_SITE_SETTINGS, DialogOption.CLEAR_FORM_DATA, DialogOption.CLEAR_SITE_SETTINGS,
DialogOption.CLEAR_MEDIA_LICENSES}; DialogOption.CLEAR_MEDIA_LICENSES);
} }
@Override @Override
......
...@@ -21,6 +21,9 @@ import org.chromium.components.signin.ChromeSigninController; ...@@ -21,6 +21,9 @@ import org.chromium.components.signin.ChromeSigninController;
import org.chromium.components.sync.AndroidSyncSettings; import org.chromium.components.sync.AndroidSyncSettings;
import org.chromium.components.sync.ModelType; 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 * A simpler version of {@link ClearBrowsingDataPreferences} with fewer dialog options and more
* explanatory text. * explanatory text.
...@@ -67,9 +70,9 @@ public class ClearBrowsingDataPreferencesBasic extends ClearBrowsingDataPreferen ...@@ -67,9 +70,9 @@ public class ClearBrowsingDataPreferencesBasic extends ClearBrowsingDataPreferen
} }
@Override @Override
protected int[] getDialogOptions() { protected List<Integer> getDialogOptions() {
return new int[] {DialogOption.CLEAR_HISTORY, DialogOption.CLEAR_COOKIES_AND_SITE_DATA, return Arrays.asList(DialogOption.CLEAR_HISTORY, DialogOption.CLEAR_COOKIES_AND_SITE_DATA,
DialogOption.CLEAR_CACHE}; DialogOption.CLEAR_CACHE);
} }
@Override @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