Bug 451599 - "Add preferences UI for disk cache size and clearing the cache" [r=mkmelin+mozilla]
authorBryan W Clark <clarkbw@gnome.org>
Sat, 04 Oct 2008 09:30:17 +0100
changeset 498 b4fe0e98a33ce17a8fcc2682f5da2019fc78b513
parent 497 d60d975cf03b456ae575eba2f922a259ee257573
child 499 410f5ead898e00864b04d3561a7f7a6e17a70b68
push id439
push userbugzilla@standard8.plus.com
push dateSat, 04 Oct 2008 08:30:56 +0000
treeherdercomm-central@b4fe0e98a33c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs451599
Bug 451599 - "Add preferences UI for disk cache size and clearing the cache" [r=mkmelin+mozilla]
mail/components/preferences/advanced.js
mail/components/preferences/advanced.xul
mail/locales/en-US/chrome/messenger/preferences/advanced.dtd
--- a/mail/components/preferences/advanced.js
+++ b/mail/components/preferences/advanced.js
@@ -73,16 +73,58 @@ var gAdvancedPane = {
 
   showConfigEdit: function()
   {
     document.documentElement.openWindow("Preferences:ConfigManager",
                                         "chrome://global/content/config.xul",
                                         "", null);
   },
 
+  // NETWORK TAB
+
+  /*
+   * Preferences:
+   *
+   * browser.cache.disk.capacity
+   * - the size of the browser cache in KB
+   */
+
+  /**
+   * Converts the cache size from units of KB to units of MB and returns that
+   * value.
+   */
+  readCacheSize: function ()
+  {
+    var preference = document.getElementById("browser.cache.disk.capacity");
+    return preference.value / 1024;
+  },
+
+  /**
+   * Converts the cache size as specified in UI (in MB) to KB and returns that
+   * value.
+   */
+  writeCacheSize: function ()
+  {
+    var cacheSize = document.getElementById("cacheSize");
+    var intValue = parseInt(cacheSize.value, 10);
+    return isNaN(intValue) ? 0 : intValue * 1024;
+  },
+
+  /**
+   * Clears the cache.
+   */
+  clearCache: function ()
+  {
+    var cacheService = Components.classes["@mozilla.org/network/cache-service;1"]
+                                 .getService(Components.interfaces.nsICacheService);
+    try {
+      cacheService.evictEntries(Components.interfaces.nsICache.STORE_ANYWHERE);
+    } catch(ex) {}
+  },
+
   updateButtons: function (aButtonID, aPreferenceID)
   {
     var button = document.getElementById(aButtonID);
     var preference = document.getElementById(aPreferenceID);
     // This is actually before the value changes, so the value is not as you expect. 
     button.disabled = preference.value == true;
     return undefined;
   },
--- a/mail/components/preferences/advanced.xul
+++ b/mail/components/preferences/advanced.xul
@@ -59,31 +59,36 @@
                   name="mailnews.mark_message_read.auto" type="bool"/>
       <preference id="mailnews.mark_message_read.delay"
                   name="mailnews.mark_message_read.delay" type="bool"
                   onchange="gAdvancedPane.updateMarkAsReadTextbox(this.value);"/>
       <preference id="mailnews.mark_message_read.delay.interval"
                   name="mailnews.mark_message_read.delay.interval" type="int"/>
       <preference id="mail.showFolderPaneColumns" name="mail.showFolderPaneColumns" type="bool"/>
       <preference id="mailnews.reuse_message_window" name="mailnews.reuse_message_window" type="bool"/>
+      <!-- Network tab -->
       <preference id="mail.prompt_purge_threshhold"          name="mail.prompt_purge_threshhold"    type="bool"/>
       <preference id="mail.purge_threshhold"                 name="mail.purge_threshhold"    type="int"/>
+      <preference id="browser.cache.disk.capacity"
+                  name="browser.cache.disk.capacity" type="int"/>
+      <!-- Update tab -->
       <preference id="app.update.enabled" name="app.update.enabled" type="bool"
                   onchange="gAdvancedPane.updateAppUpdateItems();
                             gAdvancedPane.updateAutoItems();
                             gAdvancedPane.updateModeItems();"/>
       <preference id="app.update.auto" name="app.update.auto" type="bool"
                   onchange="gAdvancedPane.updateAutoItems(); gAdvancedPane.updateModeItems();"/>
       <preference id="app.update.mode" name="app.update.mode" type="int"
                   onchange="gAdvancedPane.updateModeItems();"/>
       <preference id="extensions.update.enabled" name="extensions.update.enabled" type="bool"
                   onchange="gAdvancedPane.updateAddonUpdateUI();"/>
       <preference id="app.update.disable_button.showUpdateHistory"
                   name="app.update.disable_button.showUpdateHistory"
                   type="bool"/>
+      <!-- Certificates tab -->
       <preference id="security.disable_button.openCertManager"
                   name="security.disable_button.openCertManager"
                   type="bool"/>
       <preference id="security.OCSP.disable_button.managecrl"
                   name="security.OCSP.disable_button.managecrl"
                   type="bool"/>
       <preference id="security.disable_button.openDeviceManager"
                   name="security.disable_button.openDeviceManager"
@@ -195,16 +200,29 @@
                       accesskey="&showOffline.accesskey;"
                       oncommand="gAdvancedPane.showOffline();"/>
             </hbox>
           </groupbox>
 
           <groupbox>
             <caption label="&Diskspace;"/>
             <hbox align="center">
+              <label id="useCacheBefore" control="cacheSize"
+                     accesskey="&useCacheBefore.accesskey;" value="&useCacheBefore.label;"/>
+              <textbox id="cacheSize" type="number" size="2"
+                       preference="browser.cache.disk.capacity"
+                       onsyncfrompreference="return gAdvancedPane.readCacheSize();"
+                       onsynctopreference="return gAdvancedPane.writeCacheSize();"
+                       aria-labelledby="useCacheBefore cacheSize useCacheAfter"/>
+              <label id="useCacheAfter" flex="1">&useCacheAfter.label;</label>
+              <button id="clearCacheButton" icon="clear"
+                      label="&clearCacheNow.label;" accesskey="&clearCacheNow.accesskey;"
+                      oncommand="gAdvancedPane.clearCache();"/>
+            </hbox>
+            <hbox align="center">
                 <checkbox id="offlineCompactFolder" label="&offlineCompact.label;" accesskey="&offlineCompact.accesskey;"
                           preference="mail.prompt_purge_threshhold"/>
                 <textbox id="offlineCompactFolderMin" size="5" value="100" preference="mail.purge_threshhold" aria-labelledby="offlineCompactFolder offlineCompactFolderMin compactFolderKB"/>
                 <label id="compactFolderKB" value="&kb.label;"/>
             </hbox>
           </groupbox>
         </tabpanel>
 
--- a/mail/locales/en-US/chrome/messenger/preferences/advanced.dtd
+++ b/mail/locales/en-US/chrome/messenger/preferences/advanced.dtd
@@ -63,16 +63,28 @@
 <!ENTITY showOffline.label             "Offline…">
 <!ENTITY showOffline.accesskey         "O">
 
 <!ENTITY Diskspace "Disk Space">
 <!ENTITY offlineCompact.label "Compact folders when it will save over">
 <!ENTITY offlineCompact.accesskey "v">
 <!ENTITY kb.label "KB">
 
+<!-- LOCALIZATION NOTE:
+  The entities useCacheBefore.label and useCacheAfter.label appear on a single
+  line in preferences as follows:
+
+  &useCacheBefore.label  [ textbox for cache size in MB ]   &useCacheAfter.label;
+-->
+<!ENTITY useCacheBefore.label            "Use up to">
+<!ENTITY useCacheBefore.accesskey        "U">
+<!ENTITY useCacheAfter.label             "MB of space for the cache">
+<!ENTITY clearCacheNow.label             "Clear Now">
+<!ENTITY clearCacheNow.accesskey         "C">
+
 <!-- Certificates -->
 <!ENTITY certificatesInfo2.label        "Manage certificates, revocation lists, certificate validation and security devices.">
 <!ENTITY viewCertificates.label         "View Certificates">
 <!ENTITY viewCertificates.accesskey     "a">
 <!ENTITY viewCRLs.label                 "Revocation Lists">
 <!ENTITY viewCRLs.accesskey             "e">
 <!ENTITY validation.label               "Validation">
 <!ENTITY validation.accesskey           "d">