Chromium Code Reviews| 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 7538d1c9c8598194bd2397be002fe1e347616238..ce13800cff5ec1544fc5c927a8a66b4c3f6b5e19 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 |
| @@ -6,15 +6,18 @@ package org.chromium.chrome.browser.preferences.privacy; |
| import android.app.Activity; |
| import android.app.ProgressDialog; |
| +import android.content.Intent; |
| import android.os.Bundle; |
| import android.preference.Preference; |
| import android.preference.PreferenceFragment; |
| +import android.support.annotation.Nullable; |
| import android.widget.ListView; |
| import org.chromium.base.VisibleForTesting; |
| import org.chromium.base.metrics.RecordHistogram; |
| import org.chromium.chrome.R; |
| import org.chromium.chrome.browser.BrowsingDataType; |
| +import org.chromium.chrome.browser.ChromeFeatureList; |
| import org.chromium.chrome.browser.TimePeriod; |
| import org.chromium.chrome.browser.help.HelpAndFeedback; |
| import org.chromium.chrome.browser.preferences.ButtonPreference; |
| @@ -37,10 +40,10 @@ import java.util.EnumSet; |
| * from which to clear data. |
| */ |
| public class ClearBrowsingDataPreferences extends PreferenceFragment |
| - implements PrefServiceBridge.OnClearBrowsingDataListener, |
| + implements PrefServiceBridge.ImportantSitesCallback, |
| + PrefServiceBridge.OnClearBrowsingDataListener, |
| PrefServiceBridge.OtherFormsOfBrowsingHistoryListener, |
| - Preference.OnPreferenceClickListener, |
| - Preference.OnPreferenceChangeListener { |
| + Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener { |
| /** |
| * Represents a single item in the dialog. |
| */ |
| @@ -138,6 +141,12 @@ public class ClearBrowsingDataPreferences extends PreferenceFragment |
| "https://history.google.com/history/?utm_source=chrome_cbd"; |
| /** |
| + * Used for the onActivityResult pattern. The value is arbitrary, just to distinguish from other |
| + * activities that we might be using onActivityResult with as well. |
| + */ |
| + private static final int IMPORTANT_SITES_DIALOG_CODE = 1; |
| + |
| + /** |
| * The various data types that can be cleared via this screen. |
| */ |
| public enum DialogOption { |
| @@ -202,8 +211,19 @@ public class ClearBrowsingDataPreferences extends PreferenceFragment |
| private boolean mIsDialogAboutOtherFormsOfBrowsingHistoryEnabled; |
| private ProgressDialog mProgressDialog; |
| + private ProgressDialog mFetchingImportantProgressDialog; |
| private Item[] mItems; |
| + // This means the user asked to clear, and now we're waiting until we get our sites back to do |
| + // the clearing. |
| + private boolean mWaitingForImportantSitesBeforeClear = false; |
| + // This is the sorted list of important registerable domains. If null, then we haven't finished |
| + // fetching them yet. |
| + private String[] mSortedImportantDomains = null; |
| + // This is the dialog we show to the user that lets them 'uncheck' (or exclude) the above |
| + // important domains from being cleared. |
| + private ConfirmImportantSitesDialogFragment mConfirmImportantSitesDialog; |
| + |
| private final EnumSet<DialogOption> getSelectedOptions() { |
| EnumSet<DialogOption> selected = EnumSet.noneOf(DialogOption.class); |
| for (Item item : mItems) { |
| @@ -216,7 +236,8 @@ public 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 final void clearBrowsingData(EnumSet<DialogOption> options) { |
| + private final void clearBrowsingData( |
| + EnumSet<DialogOption> options, @Nullable String[] blacklistedDomains) { |
| showProgressDialog(); |
| int[] dataTypes = new int[options.size()]; |
| @@ -229,7 +250,12 @@ public class ClearBrowsingDataPreferences extends PreferenceFragment |
| Object spinnerSelection = |
| ((SpinnerPreference) findPreference(PREF_TIME_RANGE)).getSelectedOption(); |
| int timePeriod = ((TimePeriodSpinnerOption) spinnerSelection).getTimePeriod(); |
| - PrefServiceBridge.getInstance().clearBrowsingData(this, dataTypes, timePeriod); |
| + if (blacklistedDomains != null && blacklistedDomains.length != 0) { |
| + PrefServiceBridge.getInstance().clearBrowsingDataExcludingDomains( |
| + this, dataTypes, timePeriod, blacklistedDomains); |
| + } else { |
| + PrefServiceBridge.getInstance().clearBrowsingData(this, dataTypes, timePeriod); |
| + } |
| } |
| private void dismissProgressDialog() { |
| @@ -245,11 +271,12 @@ public class ClearBrowsingDataPreferences extends PreferenceFragment |
| */ |
| private DialogOption[] getDialogOptions() { |
| return new DialogOption[] { |
| - DialogOption.CLEAR_HISTORY, |
| - DialogOption.CLEAR_COOKIES_AND_SITE_DATA, |
| - DialogOption.CLEAR_CACHE, |
| - DialogOption.CLEAR_PASSWORDS, |
| - DialogOption.CLEAR_FORM_DATA}; |
| + DialogOption.CLEAR_HISTORY, |
| + DialogOption.CLEAR_COOKIES_AND_SITE_DATA, |
| + DialogOption.CLEAR_CACHE, |
| + DialogOption.CLEAR_PASSWORDS, |
| + DialogOption.CLEAR_FORM_DATA |
| + }; |
| } |
| /** |
| @@ -281,7 +308,7 @@ public class ClearBrowsingDataPreferences extends PreferenceFragment |
| */ |
| private boolean isOptionSelectedByDefault(DialogOption option) { |
| return PrefServiceBridge.getInstance().getBrowsingDataDeletionPreference( |
| - option.getDataType()); |
| + option.getDataType()); |
| } |
| /** |
| @@ -312,7 +339,17 @@ public class ClearBrowsingDataPreferences extends PreferenceFragment |
| @Override |
| public boolean onPreferenceClick(Preference preference) { |
| if (preference.getKey().equals(PREF_CLEAR_BUTTON)) { |
| - clearBrowsingData(getSelectedOptions()); |
| + if (!ChromeFeatureList.isEnabled(ChromeFeatureList.IMPORTANT_SITES_IN_CBD)) { |
| + clearBrowsingData(getSelectedOptions(), null); |
| + return true; |
| + } |
| + // We need to handle the case where the fetch isn't finished yet. |
| + if (mSortedImportantDomains == null) { |
| + showImportantSitesProgressDialog(); |
| + mWaitingForImportantSitesBeforeClear = true; |
| + } else { |
| + maybeShowImportantDialogThenClear(); |
| + } |
| return true; |
| } |
| return false; |
| @@ -434,6 +471,9 @@ public class ClearBrowsingDataPreferences extends PreferenceFragment |
| getPreferenceScreen().removePreference(google_summary); |
| general_summary.setSummary(R.string.clear_browsing_data_footnote_site_settings); |
| } |
| + if (ChromeFeatureList.isEnabled(ChromeFeatureList.IMPORTANT_SITES_IN_CBD)) { |
| + PrefServiceBridge.fetchImportantSites(this); |
| + } |
| } |
| @Override |
| @@ -464,11 +504,51 @@ public class ClearBrowsingDataPreferences extends PreferenceFragment |
| false); |
| } |
| + private void showImportantSitesProgressDialog() { |
| + if (getActivity() == null) return; |
| + |
| + mFetchingImportantProgressDialog = ProgressDialog.show(getActivity(), |
| + getActivity().getString(R.string.clear_browsing_data_fetch_progress_title), |
| + getActivity().getString(R.string.clear_browsing_data_fetch_progress_message), true, |
| + false); |
| + } |
| + |
| + private void dismissImportantSitesProgressDialog() { |
| + if (mFetchingImportantProgressDialog != null |
| + && mFetchingImportantProgressDialog.isShowing()) { |
| + mFetchingImportantProgressDialog.dismiss(); |
| + } |
| + mFetchingImportantProgressDialog = null; |
| + } |
| + |
| @VisibleForTesting |
| ProgressDialog getProgressDialog() { |
| return mProgressDialog; |
| } |
| + @VisibleForTesting |
| + ConfirmImportantSitesDialogFragment getImportantSitesDialogFragment() { |
| + return mConfirmImportantSitesDialog; |
| + } |
| + |
| + /** |
| + * This method shows the important sites dialog if we're enabled and if we have important |
| + * origins. If either of those is false, then it'll clear like normal. After the dialog is |
| + * shown, we correctly clear. |
| + */ |
| + private void maybeShowImportantDialogThenClear() { |
| + if (mSortedImportantDomains == null || mSortedImportantDomains.length == 0 |
| + || !ChromeFeatureList.isEnabled(ChromeFeatureList.IMPORTANT_SITES_IN_CBD)) { |
|
msramek
2016/05/17 14:02:24
If I understand correctly, important sites are onl
dmurph
2016/05/18 23:28:00
sgtm
|
| + clearBrowsingData(getSelectedOptions(), null); |
| + return; |
| + } |
| + mConfirmImportantSitesDialog = |
| + ConfirmImportantSitesDialogFragment.newInstance(mSortedImportantDomains); |
| + mConfirmImportantSitesDialog.setTargetFragment(this, IMPORTANT_SITES_DIALOG_CODE); |
| + mConfirmImportantSitesDialog.show( |
| + getFragmentManager(), ConfirmImportantSitesDialogFragment.FRAGMENT_TAG); |
| + } |
| + |
| @Override |
| public void showNoticeAboutOtherFormsOfBrowsingHistory() { |
| if (getActivity() == null) return; |
| @@ -494,4 +574,27 @@ public class ClearBrowsingDataPreferences extends PreferenceFragment |
| OtherFormsOfHistoryDialogFragment getDialogAboutOtherFormsOfBrowsingHistory() { |
| return mDialogAboutOtherFormsOfBrowsingHistory; |
| } |
| + |
| + @Override |
| + public void onImportantRegisterableDomainsReady(String[] domains) { |
| + mSortedImportantDomains = domains; |
| + if (!mWaitingForImportantSitesBeforeClear) return; |
| + mWaitingForImportantSitesBeforeClear = false; |
| + dismissImportantSitesProgressDialog(); |
| + maybeShowImportantDialogThenClear(); |
| + } |
| + |
| + /** |
| + * This is the callback for the important domain dialog. We should only clear if we get the |
| + * positive button response. |
| + */ |
| + @Override |
| + public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| + if (requestCode == IMPORTANT_SITES_DIALOG_CODE && resultCode == Activity.RESULT_OK) { |
| + // Deselected means that the user is excluding the domain from being cleared. |
| + String[] deselectedDomains = data.getStringArrayExtra( |
| + ConfirmImportantSitesDialogFragment.DESELECTED_DOMAINS_TAG); |
| + clearBrowsingData(getSelectedOptions(), deselectedDomains); |
| + } |
| + } |
| } |