[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] [torbutton/master 19/31] Explicitly write prefs to disk for crash detection.



Author: Mike Perry <mikeperry-git@xxxxxxxxxx>
Date: Tue, 28 Dec 2010 18:53:02 -0600
Subject: Explicitly write prefs to disk for crash detection.
Commit: 27af24fe205a2b515feaac18bf3ac1268ee102c5

---
 src/chrome/content/preferences.js |    5 +++++
 src/chrome/content/torbutton.js   |   23 ++++++++++++++++++++++-
 src/components/crash-observer.js  |   16 +++++++++++-----
 3 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/src/chrome/content/preferences.js b/src/chrome/content/preferences.js
index cfcfe2d..379a04b 100644
--- a/src/chrome/content/preferences.js
+++ b/src/chrome/content/preferences.js
@@ -717,4 +717,9 @@ function torbutton_prefs_reset_defaults() {
 
     torbutton_log(4, "Preferences reset to defaults");
     torbutton_prefs_init(window.document);
+
+    // In all cases, force prefs to be synced to disk
+    var prefService = Components.classes["@mozilla.org/preferences-service;1"]
+        .getService(Components.interfaces.nsIPrefService);
+    prefService.savePrefFile(null);
 }
diff --git a/src/chrome/content/torbutton.js b/src/chrome/content/torbutton.js
index 558737e..022d62d 100644
--- a/src/chrome/content/torbutton.js
+++ b/src/chrome/content/torbutton.js
@@ -1519,8 +1519,13 @@ function torbutton_update_status(mode, force_update) {
     }
 
     // No need to clear cookies if just updating prefs
-    if(!changed && force_update)
+    if(!changed && force_update) {
+        // Force prefs to be synced to disk
+        var prefService = Components.classes["@mozilla.org/preferences-service;1"]
+            .getService(Components.interfaces.nsIPrefService);
+        prefService.savePrefFile(null);
         return;
+    }
 
     torbutton_set_timezone(mode, false);
 
@@ -1590,6 +1595,12 @@ function torbutton_update_status(mode, force_update) {
     }
 
     m_tb_prefs.setBoolPref("extensions.torbutton.settings_applied", mode);
+
+    // Force prefs to be synced to disk
+    var prefService = Components.classes["@mozilla.org/preferences-service;1"]
+        .getService(Components.interfaces.nsIPrefService);
+    prefService.savePrefFile(null);
+
     torbutton_log(3, "Settings applied for mode: "+mode);
 }
 
@@ -2564,6 +2575,11 @@ function torbutton_crash_recover()
         }
 
         m_tb_prefs.setBoolPref("extensions.torbutton.crashed", false);
+
+        // Force prefs to be synced to disk
+        var prefService = Components.classes["@mozilla.org/preferences-service;1"]
+                                           .getService(Components.interfaces.nsIPrefService);
+        prefService.savePrefFile(null);
     }
 
     torbutton_log(3, "End crash recover check");
@@ -3303,6 +3319,11 @@ function torbutton_set_initial_state() {
         } // 2 means leave it as it was
 
         m_tb_prefs.setBoolPref("extensions.torbutton.noncrashed", false);
+
+        // Force prefs to be synced to disk
+        var prefService = Components.classes["@mozilla.org/preferences-service;1"]
+                                           .getService(Components.interfaces.nsIPrefService);
+        prefService.savePrefFile(null);
     }
 }
 
diff --git a/src/components/crash-observer.js b/src/components/crash-observer.js
index 39db181..5f9c291 100644
--- a/src/components/crash-observer.js
+++ b/src/components/crash-observer.js
@@ -5,11 +5,12 @@
  * pref event) that the browser in fact crashed.
  *
  * XXX: Cases to test (each during Tor and Non-Tor)
- *    0. Crash (watch cookies!)
- *    1. Fresh install
- *    2. Uninstall
- *    3. Upgrade
- *    4. Profile restore without crash
+ *    0. Crash
+ *       * XXX: Sometimes just saves window list..
+ *    2. Upgrade
+ *    1. Uninstall
+ *    3. Profile restore without crash
+ *    4. Fresh install
  *
  *************************************************************************/
 
@@ -116,6 +117,11 @@ CrashObserver.prototype = {
         this.logger.log(3, "Torbutton normal exit.");
         //this.unregister();
       }
+
+      // In all cases, force prefs to be synced to disk
+      var prefService = Components.classes["@mozilla.org/preferences-service;1"]
+          .getService(Components.interfaces.nsIPrefService);
+      prefService.savePrefFile(null);
     },
   QueryInterface: function(iid) {
     if (iid.equals(Components.interfaces.nsISupports)) {
-- 
1.7.1