Refactor the WebStorage size management:
- Abandon the Quota UI: it does not make sense to ask the users to decide individual database quota increases. It is unlikely anyone will be able to make a meaningul decision.
- Introduce a global limit for all WebStorage content. This is shared between Database and AppCache.
- Make the quota increase decision automatic
- Treat out-of-space situations by creaying a system notification (TODO).
diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java
index d2371cd..3074d2b 100644
--- a/src/com/android/browser/BrowserSettings.java
+++ b/src/com/android/browser/BrowserSettings.java
@@ -25,7 +25,6 @@
 import android.content.SharedPreferences.Editor;
 import android.preference.PreferenceActivity;
 import android.preference.PreferenceScreen;
-import android.os.StatFs;
 import android.webkit.CookieManager;
 import android.webkit.WebView;
 import android.webkit.WebViewDatabase;
@@ -79,6 +78,7 @@
     private boolean appCacheEnabled = true;
     private String appCachePath;  // default value set in loadFromDb().
     private long appCacheMaxSize = Long.MAX_VALUE;
+    private WebStorageSizeManager webStorageSizeManager;
     private boolean domStorageEnabled = true;
     private String jsFlags = "";
 
@@ -238,7 +238,9 @@
         // Set the default value for the Application Caches path.
         appCachePath = ctx.getDir("appcache", 0).getPath();
         // Determine the maximum size of the application cache.
-        appCacheMaxSize = getAppCacheMaxSize();
+        webStorageSizeManager = WebStorageSizeManager.getInstance(appCachePath,
+                ctx);
+        appCacheMaxSize = webStorageSizeManager.getAppCacheMaxSize();
         // Set the default value for the Database path.
         databasePath = ctx.getDir("databases", 0).getPath();
 
@@ -363,6 +365,10 @@
         return jsFlags;
     }
 
+    public WebStorageSizeManager getWebStorageSizeManager() {
+        return webStorageSizeManager;
+    }
+
     public void setHomePage(Context context, String url) {
         Editor ed = PreferenceManager.
                 getDefaultSharedPreferences(context).edit();
@@ -532,6 +538,8 @@
                 true);
         // reset homeUrl
         setHomePage(ctx, getFactoryResetHomeUrl(ctx));
+        // reset appcache max size
+        appCacheMaxSize = webStorageSizeManager.getAppCacheMaxSize();
     }
 
     private String getFactoryResetHomeUrl(Context context) {
@@ -543,35 +551,6 @@
         return url;
     }
 
-    private long getAppCacheMaxSize() {
-        StatFs dataPartition = new StatFs(appCachePath);
-        long freeSpace = dataPartition.getAvailableBlocks()
-            * dataPartition.getBlockSize();
-        long fileSystemSize = dataPartition.getBlockCount()
-            * dataPartition.getBlockSize();
-        return calculateAppCacheMaxSize(fileSystemSize, freeSpace);
-    }
-
-    /*package*/ static long calculateAppCacheMaxSize(long fileSystemSizeBytes,
-            long freeSpaceBytes) {
-        if (fileSystemSizeBytes <= 0
-                || freeSpaceBytes <= 0
-                || freeSpaceBytes > fileSystemSizeBytes) {
-            return 0;
-        }
-
-        long fileSystemSizeRatio =
-            4 << ((int) Math.floor(Math.log10(fileSystemSizeBytes / (1024 * 1024))));
-        long maxSizeBytes = (long) Math.min(Math.floor(fileSystemSizeBytes / fileSystemSizeRatio),
-                Math.floor(freeSpaceBytes / 4));
-        // Round maxSizeBytes up to a multiple of 512KB (except when freeSpaceBytes < 1MB).
-        long maxSizeStepBytes = 512 * 1024;
-        if (freeSpaceBytes < maxSizeStepBytes * 2) {
-            return 0;
-        }
-        return (maxSizeStepBytes * ((maxSizeBytes / maxSizeStepBytes) + 1));
-    }
-
     // Private constructor that does nothing.
     private BrowserSettings() {
     }