Index: chrome/android/java/src/org/chromium/chrome/browser/preferences/website/SingleCategoryPreferences.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/website/SingleCategoryPreferences.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/website/SingleCategoryPreferences.java |
index b686e02fc5866de1900630213c414099924b9b25..f6c714da715b907e5b07b5f0f05fbb57f61b8eb7 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/preferences/website/SingleCategoryPreferences.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/website/SingleCategoryPreferences.java |
@@ -13,10 +13,14 @@ import android.preference.PreferenceGroup; |
import android.preference.PreferenceScreen; |
import android.support.v4.view.MenuItemCompat; |
import android.support.v7.widget.SearchView; |
+import android.view.LayoutInflater; |
import android.view.Menu; |
import android.view.MenuInflater; |
import android.view.MenuItem; |
+import android.view.View; |
+import android.view.ViewGroup; |
import android.view.inputmethod.EditorInfo; |
+import android.widget.Button; |
import android.widget.ListView; |
import android.widget.TextView; |
@@ -33,6 +37,7 @@ import org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate; |
import org.chromium.chrome.browser.preferences.ManagedPreferencesUtils; |
import org.chromium.chrome.browser.preferences.PrefServiceBridge; |
import org.chromium.chrome.browser.preferences.ProtectedContentResetCredentialConfirmDialogFragment; |
+import org.chromium.chrome.browser.preferences.website.Website.StoredDataClearedCallback; |
import org.chromium.chrome.browser.profiles.Profile; |
import org.chromium.chrome.browser.widget.TintedDrawable; |
import org.chromium.ui.widget.Toast; |
@@ -52,7 +57,8 @@ import java.util.Set; |
public class SingleCategoryPreferences extends PreferenceFragment |
implements OnPreferenceChangeListener, OnPreferenceClickListener, |
AddExceptionPreference.SiteAddedCallback, |
- ProtectedContentResetCredentialConfirmDialogFragment.Listener { |
+ ProtectedContentResetCredentialConfirmDialogFragment.Listener, |
+ ClearAllStorageAction.CanClearStorage { |
// The key to use to pass which category this preference should display, |
// e.g. Location/Popups/All sites (if blank). |
public static final String EXTRA_CATEGORY = "category"; |
@@ -62,6 +68,8 @@ public class SingleCategoryPreferences extends PreferenceFragment |
private TextView mEmptyView; |
// The view for searching the list of items. |
private SearchView mSearchView; |
+ // The clear button displayed in the Storage view. |
+ private Button mClearButton; |
// The Site Settings Category we are showing. |
private SiteSettingsCategory mCategory; |
// If not blank, represents a substring to use to search for site names. |
@@ -76,6 +84,8 @@ public class SingleCategoryPreferences extends PreferenceFragment |
private boolean mIsInitialRun = true; |
// The number of sites that are on the Allowed list. |
private int mAllowedSiteCount = 0; |
+ // The websites that are currently displayed to the user. |
+ private List<WebsitePreference> mWebsites = null; |
// Keys for individual preferences. |
public static final String READ_WRITE_TOGGLE_KEY = "read_write_toggle"; |
@@ -106,11 +116,12 @@ public class SingleCategoryPreferences extends PreferenceFragment |
private class ResultsPopulator implements WebsitePermissionsFetcher.WebsitePermissionsCallback { |
@Override |
- public void onWebsitePermissionsAvailable( |
- Map<String, Set<Website>> sitesByOrigin, Map<String, Set<Website>> sitesByHost) { |
+ public void onWebsitePermissionsAvailable(Map<String, Set<Website>> sitesByOrigin, |
+ Map<String, Set<Website>> sitesByHost, List<String> importantOrigins) { |
// This method may be called after the activity has been destroyed. |
// In that case, bail out. |
if (getActivity() == null) return; |
+ mWebsites = null; |
// First we scan origins to get settings from there. |
List<WebsitePreference> websites = new ArrayList<>(); |
@@ -188,6 +199,7 @@ public class SingleCategoryPreferences extends PreferenceFragment |
} |
} |
+ mWebsites = websites; |
updateBlockedHeader(blocked); |
ChromeSwitchPreference globalToggle = (ChromeSwitchPreference) |
getPreferenceScreen().findPreference(READ_WRITE_TOGGLE_KEY); |
@@ -275,13 +287,8 @@ public class SingleCategoryPreferences extends PreferenceFragment |
} |
@Override |
- public void onActivityCreated(Bundle savedInstanceState) { |
- addPreferencesFromResource(R.xml.website_preferences); |
- ListView listView = (ListView) getView().findViewById(android.R.id.list); |
- mEmptyView = (TextView) getView().findViewById(android.R.id.empty); |
- listView.setEmptyView(mEmptyView); |
- listView.setDivider(null); |
- |
+ public View onCreateView( |
+ LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
// Read which category we should be showing. |
String category = ""; |
if (getArguments() != null) { |
@@ -291,6 +298,63 @@ public class SingleCategoryPreferences extends PreferenceFragment |
if (mCategory == null) { |
mCategory = SiteSettingsCategory.fromString(SiteSettingsCategory.CATEGORY_ALL_SITES); |
} |
+ if (!mCategory.showStorageSites()) { |
+ return super.onCreateView(inflater, container, savedInstanceState); |
+ } else { |
+ return inflater.inflate(R.layout.storage_preference_fragment, container, false); |
+ } |
+ } |
+ |
+ @Override |
+ public void clearStorage() { |
+ if (mWebsites == null) { |
+ return; |
+ } |
+ getInfoForOrigins(); |
Finnur
2016/03/03 14:15:44
I guess this can be argued either way, but just to
dmurph
2016/04/26 21:43:13
No, that's fine.
|
+ // The goal is to refresh the info for origins again after we've cleared all of them. |
+ final int[] numLeft = new int[1]; |
Finnur
2016/03/03 14:15:44
Why is this an array?
dmurph
2016/04/26 21:43:13
There's no way of having a mutable value reference
Finnur
2016/04/27 13:49:15
I guess this is a question for Ted.
|
+ numLeft[0] = mWebsites.size(); |
+ for (WebsitePreference preference : mWebsites) { |
+ preference.site().clearAllStoredData(new StoredDataClearedCallback() { |
+ @Override |
+ public void onStoredDataCleared() { |
+ if (--numLeft[0] <= 0) { |
+ getInfoForOrigins(); |
+ } |
+ } |
+ }); |
+ } |
+ } |
+ |
+ @Override |
+ public void onActivityCreated(Bundle savedInstanceState) { |
+ addPreferencesFromResource(R.xml.website_preferences); |
+ ListView listView = (ListView) getView().findViewById(android.R.id.list); |
+ mEmptyView = (TextView) getView().findViewById(android.R.id.empty); |
+ listView.setEmptyView(mEmptyView); |
+ listView.setDivider(null); |
+ |
+ mClearButton = (Button) getView().findViewById(R.id.clear_button); |
+ if (mClearButton != null) { |
+ mClearButton.setOnClickListener(new View.OnClickListener() { |
+ @Override |
+ public void onClick(View v) { |
+ if (getActivity() == null) return; |
+ |
+ getInfoForOrigins(); |
+ long totalUsage = 0; |
+ if (mWebsites != null) { |
+ for (WebsitePreference preference : mWebsites) { |
+ totalUsage += preference.site().getTotalUsage(); |
+ } |
+ } |
+ |
+ ClearAllStorageAction clearAllAction = |
+ new ClearAllStorageAction(SingleCategoryPreferences.this); |
+ clearAllAction.showClearAllDialog(getActivity(), totalUsage); |
+ } |
+ }); |
+ } |
String title = getArguments().getString(EXTRA_TITLE); |
if (title != null) getActivity().setTitle(title); |