Bug 731968 - AddLivemark callback should wait for all the writes.
authorMarco Bonardo <mbonardo@mozilla.com>
Fri, 02 Mar 2012 18:05:33 +0100
changeset 88354 a3b1c010b101260cb007702d656f3b45b26828e1
parent 88353 2d9f9bef5aa0a121b59181d3160aea11c1738efb
child 88355 e4006a8627b6b3981663689577629d8c748bb75a
push id157
push userMs2ger@gmail.com
push dateWed, 07 Mar 2012 19:27:10 +0000
bugs731968
milestone13.0a1
Bug 731968 - AddLivemark callback should wait for all the writes. r=dietrich
toolkit/components/places/nsLivemarkService.js
--- a/toolkit/components/places/nsLivemarkService.js
+++ b/toolkit/components/places/nsLivemarkService.js
@@ -119,19 +119,19 @@ LivemarkService.prototype = {
       },
       handleCompletion: function LS_handleCompletion() {
         livemarkSvc._pendingStmt = null;
       }
     });
     stmt.finalize();
   },
 
-  _onCacheReady: function LS__onCacheReady(aCallback)
+  _onCacheReady: function LS__onCacheReady(aCallback, aWaitForAsyncWrites)
   {
-    if (this._pendingStmt) {
+    if (this._pendingStmt || aWaitForAsyncWrites) {
       // The cache is still being populated, so enqueue the job to the Storage
       // async thread.  Ideally this should just dispatch a runnable to it,
       // that would call back on the main thread, but bug 608142 made that
       // impossible.  Thus just enqueue the cheapest query possible.
       let db = PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase)
                                   .DBConnection;
       let stmt = db.createAsyncStatement("PRAGMA encoding");
       stmt.executeAsync({
@@ -416,17 +416,17 @@ LivemarkService.prototype = {
       livemark = null;
     }
     finally {
       if (aLivemarkCallback) {
         this._onCacheReady(function LS_addLivemark_ETAT() {
           try {
             aLivemarkCallback.onCompletion(result, livemark);
           } catch(ex2) {}
-        });
+        }, true);
       }
     }
   },
 
   removeLivemark: function LS_removeLivemark(aLivemarkInfo, aLivemarkCallback)
   {
     if (!aLivemarkInfo) {
       throw Cr.NS_ERROR_INVALID_ARG;