| Index: chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/ClearBrowsingDataPreferences.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/ClearBrowsingDataPreferences.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/ClearBrowsingDataPreferences.java
|
| index 0faf79963d76e57df8844eae9a48543f4f7395b7..32de9065399a9f174033d7ce25e04d6f4a9912da 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/ClearBrowsingDataPreferences.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/ClearBrowsingDataPreferences.java
|
| @@ -4,6 +4,7 @@
|
|
|
| package org.chromium.chrome.browser.preferences.privacy;
|
|
|
| +import android.app.Activity;
|
| import android.app.ProgressDialog;
|
| import android.os.Bundle;
|
| import android.preference.CheckBoxPreference;
|
| @@ -15,6 +16,7 @@ import org.chromium.chrome.R;
|
| import org.chromium.chrome.browser.BrowsingDataType;
|
| import org.chromium.chrome.browser.preferences.ButtonPreference;
|
| import org.chromium.chrome.browser.preferences.PrefServiceBridge;
|
| +import org.chromium.chrome.browser.preferences.SpinnerPreference;
|
| import org.chromium.chrome.browser.preferences.privacy.BrowsingDataCounterBridge.BrowsingDataCounterCallback;
|
| import org.chromium.sync.signin.ChromeSigninController;
|
|
|
| @@ -27,7 +29,8 @@ import java.util.EnumSet;
|
| */
|
| public class ClearBrowsingDataPreferences extends PreferenceFragment
|
| implements PrefServiceBridge.OnClearBrowsingDataListener,
|
| - Preference.OnPreferenceClickListener {
|
| + Preference.OnPreferenceClickListener,
|
| + Preference.OnPreferenceChangeListener{
|
| /**
|
| * Represents a single item in the dialog.
|
| */
|
| @@ -91,6 +94,7 @@ public class ClearBrowsingDataPreferences extends PreferenceFragment
|
| private static final String PREF_BOOKMARKS = "clear_bookmarks_checkbox";
|
|
|
| private static final String PREF_SUMMARY = "summary";
|
| + private static final String PREF_TIME_RANGE = "time_period_spinner";
|
|
|
| /** The "Clear" button preference. Referenced in tests. */
|
| public static final String PREF_CLEAR_BUTTON = "clear_button";
|
| @@ -130,6 +134,52 @@ public class ClearBrowsingDataPreferences extends PreferenceFragment
|
| }
|
| }
|
|
|
| + /**
|
| + * Enum for the deletion time periods.
|
| + */
|
| + public enum TimePeriodSpinnerOption {
|
| + LAST_HOUR(org.chromium.chrome.browser.TimePeriod.LAST_HOUR,
|
| + R.string.clear_browsing_data_period_hour),
|
| + LAST_DAY(org.chromium.chrome.browser.TimePeriod.LAST_DAY,
|
| + R.string.clear_browsing_data_period_day),
|
| + LAST_WEEK(org.chromium.chrome.browser.TimePeriod.LAST_WEEK,
|
| + R.string.clear_browsing_data_period_week),
|
| + FOUR_WEEKS(org.chromium.chrome.browser.TimePeriod.FOUR_WEEKS,
|
| + R.string.clear_browsing_data_period_four_weeks),
|
| + EVERYTHING(org.chromium.chrome.browser.TimePeriod.EVERYTHING,
|
| + R.string.clear_browsing_data_period_everything);
|
| +
|
| + int mTimePeriod;
|
| + int mStringResource;
|
| + String mStringRepresentation;
|
| +
|
| + private TimePeriodSpinnerOption(int timePeriod, int stringResource) {
|
| + mTimePeriod = timePeriod;
|
| + mStringResource = stringResource;
|
| + }
|
| +
|
| + /**
|
| + * @return The time period represented as an int from the shared enum
|
| + * {@link org.chromium.chrome.browser.TimePeriod}
|
| + */
|
| + public int getTimePeriod() {
|
| + return mTimePeriod;
|
| + }
|
| +
|
| + /**
|
| + * Sets the parent activity that will be used to get a string from the stringResource.
|
| + * @param Activity activity The activity to use.
|
| + */
|
| + public void setActivity(Activity activity) {
|
| + mStringRepresentation = activity.getString(mStringResource);
|
| + }
|
| +
|
| + @Override
|
| + public String toString() {
|
| + return mStringRepresentation;
|
| + }
|
| + }
|
| +
|
| private ProgressDialog mProgressDialog;
|
| private boolean mCanDeleteBrowsingHistory;
|
| private Item[] mItems;
|
| @@ -178,6 +228,25 @@ public class ClearBrowsingDataPreferences extends PreferenceFragment
|
| }
|
|
|
| /**
|
| + * Returns the Array of time periods. Options are displayed in the same order as they appear
|
| + * in the array.
|
| + */
|
| + protected TimePeriodSpinnerOption[] getTimePeriodSpinnerOptions() {
|
| + TimePeriodSpinnerOption[] options = new TimePeriodSpinnerOption[] {
|
| + TimePeriodSpinnerOption.LAST_HOUR,
|
| + TimePeriodSpinnerOption.LAST_DAY,
|
| + TimePeriodSpinnerOption.LAST_WEEK,
|
| + TimePeriodSpinnerOption.FOUR_WEEKS,
|
| + TimePeriodSpinnerOption.EVERYTHING};
|
| +
|
| + for (TimePeriodSpinnerOption option : options) {
|
| + option.setActivity(getActivity());
|
| + }
|
| +
|
| + return options;
|
| + }
|
| +
|
| + /**
|
| * Decides whether a given dialog option should be selected when the dialog is initialized.
|
| * @param option The option in question.
|
| * @return boolean Whether the given option should be preselected.
|
| @@ -205,6 +274,16 @@ public class ClearBrowsingDataPreferences extends PreferenceFragment
|
| return false;
|
| }
|
|
|
| + @Override
|
| + public boolean onPreferenceChange(Preference preference, Object value) {
|
| + if (preference.getKey().equals(PREF_TIME_RANGE)) {
|
| + PrefServiceBridge.getInstance().setBrowsingDataDeletionTimePeriod(
|
| + ((TimePeriodSpinnerOption) value).getTimePeriod());
|
| + return true;
|
| + }
|
| + return false;
|
| + }
|
| +
|
| /**
|
| * Disable the "Clear" button if none of the options are selected. Otherwise, enable it.
|
| */
|
| @@ -249,6 +328,13 @@ public class ClearBrowsingDataPreferences extends PreferenceFragment
|
| getPreferenceScreen().removePreference(findPreference(option.getPreferenceKey()));
|
| }
|
|
|
| + // The time range selection spinner.
|
| + SpinnerPreference spinner = (SpinnerPreference) findPreference(PREF_TIME_RANGE);
|
| + spinner.setOnPreferenceChangeListener(this);
|
| + spinner.setOptions(
|
| + getTimePeriodSpinnerOptions(),
|
| + PrefServiceBridge.getInstance().getBrowsingDataDeletionTimePeriod());
|
| +
|
| // The "Clear" button.
|
| ButtonPreference clearButton = (ButtonPreference) findPreference(PREF_CLEAR_BUTTON);
|
| clearButton.setOnPreferenceClickListener(this);
|
|
|