Bug 556480 - AutoCompleteUtils error [r=vingtetun]
authorMark Finkle <mfinkle@mozilla.com>
Thu, 22 Apr 2010 11:18:38 -0400
changeset 66165 24c516a1cec4c903a2179aa6a93ff51a016168f3
parent 66164 70f68eea069d3e837dbc83b71c42c3eda1215912
child 66166 b62a7a3ada57162ec7ae1f9a5eddf168c538c3c0
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvingtetun
bugs556480
Bug 556480 - AutoCompleteUtils error [r=vingtetun]
mobile/components/AutoCompleteCache.js
--- a/mobile/components/AutoCompleteCache.js
+++ b/mobile/components/AutoCompleteCache.js
@@ -74,16 +74,17 @@ function getDir(aKey) {
 }
 
 // -----------------------------------------------------------------------
 // AutoCompleteUtils support the cache and prefetching system used by
 // the AutoCompleteCache service
 // -----------------------------------------------------------------------
 
 var AutoCompleteUtils = {
+  cacheFile: null,
   cache: null,
   query: "",
   busy: false,
   timer: null,
   DELAY: 10000,
 
   // Use the base places search to get results
   fetch: function fetch(query, onResult) {
@@ -141,16 +142,19 @@ var AutoCompleteUtils = {
         // Do the actual fetch if we aren't busy
         if (!AutoCompleteUtils.busy)
           AutoCompleteUtils.fetch(AutoCompleteUtils.query);
       }
     }, this.DELAY, Ci.nsITimer.TYPE_ONE_SHOT);
   },
 
   init: function init() {
+    if (this.cacheFile)
+      return;
+
     this.cacheFile = getDir("ProfD");
     this.cacheFile.append("autocomplete.json");
 
     if (this.cacheFile.exists()) {
       // Load the existing cache
       this.loadCache();
     } else {
       // Make the empty query cache
@@ -184,17 +188,17 @@ var AutoCompleteUtils = {
       let data = converter.convertToInputStream(JSON.stringify(cache));
 
       // Write to the cache file asynchronously
       NetUtil.asyncCopy(data, ostream, function(rv) {
         if (!Components.isSuccessCode(rv))
           Cu.reportError("AutoCompleteUtils: failure during asyncCopy: " + rv);
       });
     } catch (ex) {
-      Cu.reportError("AutoCompleteUtils: Could not write to cache file: " + ex);
+      Cu.reportError("AutoCompleteUtils: Could not write to cache file: " + this.cacheFile + " | " + ex);
     }
   },
 
   loadCache: function loadCache() {
     try {
       // Load the cached results from the file
       let stream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream);
       let json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
@@ -273,16 +277,17 @@ AutoCompleteCache.prototype = {
     }
   }
 };
 
 // -----------------------------------------------------------------------
 // BookmarkObserver updates the cache when a bookmark is added
 // -----------------------------------------------------------------------
 function BookmarkObserver() {
+  AutoCompleteUtils.init();
   this._batch = false;
 }
 
 BookmarkObserver.prototype = {
   onBeginUpdateBatch: function() {
     this._batch = true;
   },
   onEndUpdateBatch: function() {