summaryrefslogtreecommitdiffstats
path: root/src/com/android/browser/BrowserSettings.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/browser/BrowserSettings.java')
-rw-r--r--src/com/android/browser/BrowserSettings.java41
1 files changed, 10 insertions, 31 deletions
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;
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 @@ class BrowserSettings extends Observable {
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 @@ class BrowserSettings extends Observable {
// 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 @@ class BrowserSettings extends Observable {
return jsFlags;
}
+ public WebStorageSizeManager getWebStorageSizeManager() {
+ return webStorageSizeManager;
+ }
+
public void setHomePage(Context context, String url) {
Editor ed = PreferenceManager.
getDefaultSharedPreferences(context).edit();
@@ -532,6 +538,8 @@ class BrowserSettings extends Observable {
true);
// reset homeUrl
setHomePage(ctx, getFactoryResetHomeUrl(ctx));
+ // reset appcache max size
+ appCacheMaxSize = webStorageSizeManager.getAppCacheMaxSize();
}
private String getFactoryResetHomeUrl(Context context) {
@@ -543,35 +551,6 @@ class BrowserSettings extends Observable {
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() {
}