Bug 513710 - Places toolkit JS should use XPCOMUtils.defineLazy[Service]Getter
authorShawn Wilsher <sdwilsh@shawnwilsher.com>
Wed, 02 Sep 2009 13:55:16 -0700
changeset 26284 dcb2a386b619f6aac910acb380d97dc160b57f7d
parent 26283 016941cc64aa5374ceeec63a993232f326b79db9
child 26285 4cf34ccb293edb5dfce3bca576d5a627a8ed204c
push id1834
push userclokep@gmail.com
push dateMon, 23 Jan 2017 21:48:40 +0000
treeherdercomm-beta@293cffe83e59 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs513710
Bug 513710 - Places toolkit JS should use XPCOMUtils.defineLazy[Service]Getter r=sayrer for XPCOMUtils change r=mak for places changes
suite/common/places/src/nsPlacesAutoComplete.js
--- a/suite/common/places/src/nsPlacesAutoComplete.js
+++ b/suite/common/places/src/nsPlacesAutoComplete.js
@@ -232,101 +232,84 @@ function nsPlacesAutoComplete()
                    sql_base_fragment("moz_places") +
                    "AND +h.id NOT IN (SELECT id FROM moz_places_temp) " +
                    "ORDER BY h.frecency DESC " +
                    "LIMIT :maxResults";
 
   //////////////////////////////////////////////////////////////////////////////
   //// Smart Getters
 
-  this.__defineGetter__("_db", function() {
-    delete this._db;
-    return this._db = Cc["@mozilla.org/browser/nav-history-service;1"].
-                      getService(Ci.nsPIPlacesDatabase).
-                      DBConnection;
-  });
-
-  this.__defineGetter__("_bh", function() {
-    delete this._bh;
-    return this._bh = Cc["@mozilla.org/browser/global-history;2"].
-                      getService(Ci.nsIBrowserHistory);
-  });
-
-  this.__defineGetter__("_textURIService", function() {
-    delete this._textURIService;
-    return this._textURIService = Cc["@mozilla.org/intl/texttosuburi;1"].
-                                  getService(Ci.nsITextToSubURI);
+  XPCOMUtils.defineLazyGetter(this, "_db", function() {
+    return Cc["@mozilla.org/browser/nav-history-service;1"].
+           getService(Ci.nsPIPlacesDatabase).
+           DBConnection;
   });
 
-  this.__defineGetter__("_bs", function() {
-    delete this._bs;
-    return this._bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
-                      getService(Ci.nsINavBookmarksService);
-  });
+  XPCOMUtils.defineLazyServiceGetter(this, "_bh",
+                                     "@mozilla.org/browser/global-history;2",
+                                     "nsIBrowserHistory");
+
+  XPCOMUtils.defineLazyServiceGetter(this, "_textURIService",
+                                     "@mozilla.org/intl/texttosuburi;1",
+                                     "nsITextToSubURI");
+
+  XPCOMUtils.defineLazyServiceGetter(this, "_bs",
+                                     "@mozilla.org/browser/nav-bookmarks-service;1",
+                                     "nsINavBookmarksService");
 
-  this.__defineGetter__("_ioService", function() {
-    delete this._ioService;
-    return this._ioService = Cc["@mozilla.org/network/io-service;1"].
-                             getService(Ci.nsIIOService);
-  });
+  XPCOMUtils.defineLazyServiceGetter(this, "_ioService",
+                                     "@mozilla.org/network/io-service;1",
+                                     "nsIIOService");
 
-  this.__defineGetter__("_faviconService", function() {
-    delete this._faviconService;
-    return this._faviconService = Cc["@mozilla.org/browser/favicon-service;1"].
-                                  getService(Ci.nsIFaviconService);
-  });
+  XPCOMUtils.defineLazyServiceGetter(this, "_faviconService",
+                                     "@mozilla.org/browser/favicon-service;1",
+                                     "nsIFaviconService");
 
-  this.__defineGetter__("_defaultQuery", function() {
-    delete this._defaultQuery;
+  XPCOMUtils.defineLazyGetter(this, "_defaultQuery", function() {
     let replacementText = "";
-    return this._defaultQuery = this._db.createStatement(
+    return this._db.createStatement(
       SQL_BASE.replace("{ADDITIONAL_CONDITIONS}", replacementText, "g")
     );
   });
 
-  this.__defineGetter__("_historyQuery", function() {
-    delete this._historyQuery;
+  XPCOMUtils.defineLazyGetter(this, "_historyQuery", function() {
     let replacementText = "AND h.visit_count > 0";
-    return this._historyQuery = this._db.createStatement(
+    return this._db.createStatement(
       SQL_BASE.replace("{ADDITIONAL_CONDITIONS}", replacementText, "g")
     );
   });
 
-  this.__defineGetter__("_bookmarkQuery", function() {
-    delete this._bookmarkQuery;
+  XPCOMUtils.defineLazyGetter(this, "_bookmarkQuery", function() {
     let replacementText = "AND bookmark IS NOT NULL";
-    return this._bookmarkQuery = this._db.createStatement(
+    return this._db.createStatement(
       SQL_BASE.replace("{ADDITIONAL_CONDITIONS}", replacementText, "g")
     );
   });
 
-  this.__defineGetter__("_tagsQuery", function() {
-    delete this._tagsQuery;
+  XPCOMUtils.defineLazyGetter(this, "_tagsQuery", function() {
     let replacementText = "AND tags IS NOT NULL";
-    return this._tagsQuery = this._db.createStatement(
+    return this._db.createStatement(
       SQL_BASE.replace("{ADDITIONAL_CONDITIONS}", replacementText, "g")
     );
   });
 
-  this.__defineGetter__("_typedQuery", function() {
-    delete this._typedQuery;
+  XPCOMUtils.defineLazyGetter(this, "_typedQuery", function() {
     let replacementText = "AND h.typed = 1";
-    return this._typedQuery = this._db.createStatement(
+    return this._db.createStatement(
       SQL_BASE.replace("{ADDITIONAL_CONDITIONS}", replacementText, "g")
     );
   });
 
-  this.__defineGetter__("_adaptiveQuery", function() {
-    delete this._adaptiveQuery;
+  XPCOMUtils.defineLazyGetter(this, "_adaptiveQuery", function() {
     // In this query, we are taking kBookTagSQLFragment only for h.id because it
     // uses data from the moz_bookmarks table and we sync tables on bookmark
     // insert.  So, most likely, h.id will always be populated when we have any
     // bookmark.  We still need to join on moz_places_temp for other data (eg.
     // title).
-    return this._adaptiveQuery = this._db.createStatement(
+    return this._db.createStatement(
       "/* do not warn (bug 487789) */ " +
       "SELECT IFNULL(h_t.url, h.url), IFNULL(h_t.title, h.title), f.url, " +
               kBookTagSQLFragment + ", IFNULL(h_t.visit_count, h.visit_count), " +
               "IFNULL(h_t.typed, h.typed), IFNULL(h_t.id, h.id), " +
               ":query_type, rank " +
       "FROM ( " +
         "SELECT ROUND(MAX(((i.input = :search_string) + " +
                           "(SUBSTR(i.input, 1, LENGTH(:search_string)) = :search_string)) * " +
@@ -338,19 +321,18 @@ function nsPlacesAutoComplete()
       "LEFT JOIN moz_places h ON h.id = i.place_id " +
       "LEFT JOIN moz_places_temp h_t ON h_t.id = i.place_id " +
       "LEFT JOIN moz_favicons f ON f.id = IFNULL(h_t.favicon_id, h.favicon_id) "+
       "WHERE IFNULL(h_t.url, h.url) NOTNULL " +
       "ORDER BY rank DESC, IFNULL(h_t.frecency, h.frecency) DESC"
     );
   });
 
-  this.__defineGetter__("_keywordQuery", function() {
-    delete this._keywordQuery;
-    return this._keywordQuery = this._db.createStatement(
+  XPCOMUtils.defineLazyGetter(this, "_keywordQuery", function() {
+    return this._db.createStatement(
       "/* do not warn (bug 487787) */ " +
       "SELECT IFNULL( " +
           "(SELECT REPLACE(url, '%s', :query_string) FROM moz_places_temp WHERE id = b.fk), " +
           "(SELECT REPLACE(url, '%s', :query_string) FROM moz_places WHERE id = b.fk) " +
         ") AS search_url, IFNULL(h_t.title, h.title), " +
         "COALESCE(f.url, " + best_favicon_for_revhost("moz_places_temp") + "," +
                   best_favicon_for_revhost("moz_places") + "), b.parent, " +
         "b.title, NULL, IFNULL(h_t.visit_count, h.visit_count), " +