--- a/suite/common/places/src/nsPlacesAutoComplete.js
+++ b/suite/common/places/src/nsPlacesAutoComplete.js
@@ -138,20 +138,24 @@ function best_favicon_for_revhost(aTable
//// AutoCompleteStatementCallbackWrapper class
/**
* Wraps a callback and ensures that handleCompletion is not dispatched if the
* query is no longer tracked.
*
* @param aCallback
* A reference to a nsPlacesAutoComplete.
+ * @param aDBConnection
+ * The database connection to execute the queries on.
*/
-function AutoCompleteStatementCallbackWrapper(aCallback)
+function AutoCompleteStatementCallbackWrapper(aCallback,
+ aDBConnection)
{
this._callback = aCallback;
+ this._db = aDBConnection;
}
AutoCompleteStatementCallbackWrapper.prototype = {
//////////////////////////////////////////////////////////////////////////////
//// mozIStorageStatementCallback
handleResult: function ACSCW_handleResult(aResultSet)
{
@@ -174,23 +178,25 @@ AutoCompleteStatementCallbackWrapper.pro
//////////////////////////////////////////////////////////////////////////////
//// AutoCompleteStatementCallbackWrapper
/**
* Executes the specified query asynchronously. This object will notify
* this._callback if we should notify (logic explained in handleCompletion).
*
- * @param aQuery
- * The query to execute asynchronously.
- * @return a mozIStoragePendingStatement that can be used to cancel the query.
+ * @param aQueries
+ * The queries to execute asynchronously.
+ * @return a mozIStoragePendingStatement that can be used to cancel the
+ * queries.
*/
- executeAsync: function ACSCW_executeAsync(aQuery)
+ executeAsync: function ACSCW_executeAsync(aQueries)
{
- return this._handle = aQuery.executeAsync(this);
+ return this._handle = this._db.executeAsync(aQueries, aQueries.length,
+ this);
},
//////////////////////////////////////////////////////////////////////////////
//// nsISupports
QueryInterface: XPCOMUtils.generateQI([
Ci.mozIStorageStatementCallback,
])
@@ -433,17 +439,17 @@ nsPlacesAutoComplete.prototype = {
// Set up our persistent state for the duration of the search.
this._searchTokens = tokens;
this._usedPlaceIds = {};
},
stopSearch: function PAC_stopSearch()
{
// We need to cancel our searches so we do not get any [more] results.
- this._stopActiveQueries();
+ this._stopActiveQuery();
this._finishSearch(false);
},
//////////////////////////////////////////////////////////////////////////////
//// nsIAutoCompleteSimpleResultListener
onValueRemoved: function PAC_onValueRemoved(aResult, aURISpec, aRemoveFromDB)
@@ -458,18 +464,18 @@ nsPlacesAutoComplete.prototype = {
handleResult: function PAC_handleResult(aResultSet)
{
let row, haveMatches = false;
while (row = aResultSet.getNextRow()) {
let match = this._processRow(row);
haveMatches = haveMatches || match;
if (this._result.matchCount == this._maxRichResults) {
- // We have enough results, so stop running our queries.
- this._stopActiveQueries();
+ // We have enough results, so stop running our search.
+ this._stopActiveQuery();
// And finish our search.
this._finishSearch(true);
return;
}
}
@@ -484,25 +490,16 @@ nsPlacesAutoComplete.prototype = {
},
handleCompletion: function PAC_handleCompletion(aReason)
{
// If we have already finished our search, we should bail out early.
if (this.isSearchComplete())
return;
- // Remove the first query in our array of pending queries since it is the
- // one we are getting notified about.
- this._pendingQueries.shift();
-
- // If we still have pending queries, we bail out because we aren't done
- // getting results.
- if (this._pendingQueries.length)
- return;
-
// If we do not have enough results, and our match type is
// MATCH_BOUNDARY_ANYWHERE, search again with MATCH_ANYWHERE to get more
// results.
if (this._matchBehavior == MATCH_BOUNDARY_ANYWHERE &&
this._result.matchCount < this._maxRichResults && !this._secondPass) {
this._secondPass = true;
let query = this._getBoundSearchQuery(MATCH_ANYWHERE, this._searchTokens);
this._executeQueries([query]);
@@ -605,45 +602,44 @@ nsPlacesAutoComplete.prototype = {
// Clear our state
delete this._originalSearchString;
delete this._currentSearchString;
delete this._searchTokens;
delete this._listener;
delete this._result;
delete this._usedPlaceIds;
+ delete this._pendingQuery;
this._secondPass = false;
},
/**
* Executes the given queries asynchronously.
*
* @param aQueries
* The queries to execute.
*/
_executeQueries: function PAC_executeQueries(aQueries)
{
// Because we might get a handleCompletion for canceled queries, we want to
// filter out queries we no longer care about (described in the
// handleCompletion implementation of AutoCompleteStatementCallbackWrapper).
- let PAC = this;
- this._pendingQueries = aQueries.map(function(aQuery) {
- // Create our wrapper object and execute the query.
- let callbackWrapper = new AutoCompleteStatementCallbackWrapper(PAC);
- return callbackWrapper.executeAsync(aQuery);
- });
+
+ // Create our wrapper object and execute the queries.
+ let wrapper = new AutoCompleteStatementCallbackWrapper(this, this._db);
+ this._pendingQuery = wrapper.executeAsync(aQueries);
},
/**
- * Stops executing all active queries.
+ * Stops executing our active query.
*/
- _stopActiveQueries: function PAC_stopActiveQueries()
+ _stopActiveQuery: function PAC_stopActiveQuery()
{
- this._pendingQueries.forEach(function(aQuery) aQuery.cancel());
- delete this._pendingQueries;
+ this._pendingQuery.cancel();
+ delete this._pendingQuery;
},
/**
* Notifies the listener about results.
*
* @param aSearchOngoing
* Indicates if the search is ongoing or not.
*/
@@ -1007,33 +1003,33 @@ nsPlacesAutoComplete.prototype = {
/**
* Determines if we are done searching or not.
*
* @return true if we have completed searching, false otherwise.
*/
isSearchComplete: function PAC_isSearchComplete()
{
- // If _pendingQueries is null, we should no longer do any work since we have
+ // If _pendingQuery is null, we should no longer do any work since we have
// already called _finishSearch. This means we completed our search.
- return this._pendingQueries == null;
+ return this._pendingQuery == null;
},
/**
* Determines if the given handle of a pending statement is a pending search
* or not.
*
* @param aHandle
* A mozIStoragePendingStatement to check and see if we are waiting for
* results from it still.
* @return true if it is a pending query, false otherwise.
*/
isPendingSearch: function PAC_isPendingSearch(aHandle)
{
- return this._pendingQueries.indexOf(aHandle) != -1;
+ return this._pendingQuery == aHandle;
},
//////////////////////////////////////////////////////////////////////////////
//// nsISupports
classDescription: "AutoComplete result generator for Places.",
classID: Components.ID("d0272978-beab-4adc-a3d4-04b76acfa4e7"),
contractID: "@mozilla.org/autocomplete/search;1?name=history",