Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(467)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/ClearBrowsingDataPreferences.java

Issue 1465363002: [Storage] Android - ManageSpace UI, Important Origins, and CBD Dialog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: whoops, forgot files Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 85b635d8a05751d684666212e9e1864308713c2f..807e4fc87a8f7c9c063995f10328955a77568e07 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,14 +6,17 @@ 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.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;
@@ -36,10 +39,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.
*/
@@ -133,6 +136,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 {
@@ -199,6 +208,16 @@ public class ClearBrowsingDataPreferences extends PreferenceFragment
private ProgressDialog mProgressDialog;
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) {
@@ -211,7 +230,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()];
@@ -224,7 +244,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() {
@@ -240,11 +265,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
+ };
}
/**
@@ -276,7 +302,7 @@ public class ClearBrowsingDataPreferences extends PreferenceFragment
*/
private boolean isOptionSelectedByDefault(DialogOption option) {
return PrefServiceBridge.getInstance().getBrowsingDataDeletionPreference(
- option.getDataType());
+ option.getDataType());
}
/**
@@ -305,7 +331,16 @@ 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) {
+ mWaitingForImportantSitesBeforeClear = true;
Theresa 2016/05/13 06:02:30 What happens if the preference is clicked and we'r
dmurph 2016/05/13 23:46:23 No indication. Added another progress dialog.
+ } else {
+ maybeShowImportantDialogThenClear();
+ }
return true;
}
return false;
@@ -427,6 +462,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
@@ -462,6 +500,29 @@ public class ClearBrowsingDataPreferences extends PreferenceFragment
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)) {
+ 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;
@@ -487,4 +548,26 @@ public class ClearBrowsingDataPreferences extends PreferenceFragment
OtherFormsOfHistoryDialogFragment getDialogAboutOtherFormsOfBrowsingHistory() {
return mDialogAboutOtherFormsOfBrowsingHistory;
}
+
+ @Override
+ public void onImportantRegisterableDomainsReady(String[] domains) {
+ mSortedImportantDomains = domains;
+ if (!mWaitingForImportantSitesBeforeClear) return;
+ mWaitingForImportantSitesBeforeClear = false;
+ 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);
+ }
+ }
}

Powered by Google App Engine
This is Rietveld 408576698