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 467d523406e670c246419ac141c8f28641b122cc..d29b851bd781a595184e23d509f1a1312ade6618 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 |
@@ -4,6 +4,8 @@ |
package org.chromium.chrome.browser.preferences.website; |
+import android.app.ActivityManager; |
+import android.content.Context; |
import android.os.Bundle; |
import android.preference.Preference; |
import android.preference.Preference.OnPreferenceChangeListener; |
@@ -13,10 +15,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; |
@@ -32,9 +38,11 @@ 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.widget.TintedDrawable; |
import org.chromium.ui.widget.Toast; |
+import java.io.File; |
import java.util.ArrayList; |
import java.util.Collections; |
import java.util.HashSet; |
@@ -50,7 +58,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"; |
@@ -60,6 +69,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. |
@@ -74,6 +85,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"; |
@@ -109,6 +122,7 @@ public class SingleCategoryPreferences extends PreferenceFragment |
// 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<>(); |
@@ -186,6 +200,7 @@ public class SingleCategoryPreferences extends PreferenceFragment |
} |
} |
+ mWebsites = websites; |
updateBlockedHeader(blocked); |
ChromeSwitchPreference globalToggle = (ChromeSwitchPreference) |
getPreferenceScreen().findPreference(READ_WRITE_TOGGLE_KEY); |
@@ -273,13 +288,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) { |
@@ -289,6 +299,102 @@ 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); |
+ } |
+ } |
+ |
+ public static boolean deleteDir(File dir) { |
Finnur
2015/11/26 15:54:41
nit: Document these functions.
Also (Newton), is
dmurph
2015/11/30 22:16:53
Done. Yes, please let me know where I should put t
|
+ if (dir != null && dir.isDirectory()) { |
+ String[] children = dir.list(); |
+ for (int i = 0; i < children.length; i++) { |
+ boolean success = deleteDir(new File(dir, children[i])); |
+ if (!success) { |
+ return false; |
+ } |
+ } |
+ } |
+ return dir.delete(); |
+ } |
+ |
+ @Override |
+ public void clearAllAppData() { |
+ int currentapiVersion = android.os.Build.VERSION.SDK_INT; |
+ |
+ boolean success = false; |
+ if (currentapiVersion >= android.os.Build.VERSION_CODES.KITKAT) { |
+ ActivityManager result = |
+ (ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE); |
+ success = result == null ? false : result.clearApplicationUserData(); |
+ } |
+ if (currentapiVersion < android.os.Build.VERSION_CODES.KITKAT || !success) { |
+ File cache = getActivity().getCacheDir(); |
+ File appDir = new File(cache.getParent()); |
+ if (appDir.exists()) { |
+ String[] children = appDir.list(); |
+ for (String s : children) { |
+ if (!s.equals("lib")) { |
Finnur
2015/11/26 15:54:41
I don't know what the file structure looks like on
dmurph
2015/11/30 22:16:53
I emailed Dianne Hackborn (hackbod@google) to see
|
+ deleteDir(new File(appDir, s)); |
Finnur
2015/11/26 15:54:41
I notice we ignore errors here. That can leave Chr
dmurph
2015/11/30 22:16:53
Yes, that sounds good. I'll chat w/ Rebecca and cl
|
+ } |
+ } |
+ } |
+ getActivity().finishAffinity(); |
+ System.exit(0); |
+ } |
+ } |
+ |
+ @Override |
+ public void clearAllWebsiteStorage() { |
+ if (mWebsites == null) { |
+ return; |
+ } |
+ getInfoForOrigins(); |
+ // The goal is to refresh the info for origins again after we've cleared all of them. |
+ final int[] numLeft = new int[1]; |
+ 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.showClearDialog(getActivity(), totalUsage); |
+ } |
+ }); |
+ } |
String title = getArguments().getString(EXTRA_TITLE); |
if (title != null) getActivity().setTitle(title); |