Bug 967119 - Hold a CPU lock while the contacts DB upgrade is running. r=bent
authorReuben Morais <reuben.morais@gmail.com>
Mon, 24 Feb 2014 09:19:20 -0500
changeset 170599 3db93067735a4ceed07a921e7c17246d5d6f934e
parent 170598 224036b8b7f59c2944b610d44c4d91020846342f
child 170600 16297d71317b2d665b1cb40e86fb5a24da13f711
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersbent
bugs967119
milestone30.0a1
Bug 967119 - Hold a CPU lock while the contacts DB upgrade is running. r=bent
dom/contacts/fallback/ContactDB.jsm
--- a/dom/contacts/fallback/ContactDB.jsm
+++ b/dom/contacts/fallback/ContactDB.jsm
@@ -789,16 +789,31 @@ ContactDB.prototype = {
       debug("Contacts DB upgrade error: " + why);
       aTransaction.abort();
     }
 
     if (aNewVersion > steps.length) {
       fail("No migration steps for the new version!");
     }
 
+    this.cpuLock = Cc["@mozilla.org/power/powermanagerservice;1"]
+                     .getService(Ci.nsIPowerManagerService)
+                     .newWakeLock("cpu");
+
+    function unlockCPU() {
+      if (outer.cpuLock) {
+        if (DEBUG) debug("unlocking cpu wakelock");
+        outer.cpuLock.unlock();
+        outer.cpuLock = null;
+      }
+    }
+
+    aTransaction.addEventListener("complete", unlockCPU);
+    aTransaction.addEventListener("abort", unlockCPU);
+
     next();
   },
 
   makeImport: function makeImport(aContact) {
     let contact = {properties: {}};
 
     contact.search = {
       name:            [],