Backed out changeset ef86c7c53d21 (bug 1042561)
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Fri, 20 Mar 2015 13:32:01 +0100
changeset 251857 d00d886006d3d8fcd20ffbe8ba42467fa44cde42
parent 251856 de24b63c6966fc65208604461ba3f5477e5acfa8
child 251858 9d219be15f7dbde7ed3ebc963cefb1a51d3c0150
push id1156
push userpbrosset@mozilla.com
push dateFri, 20 Mar 2015 16:00:24 +0000
bugs1042561
milestone39.0a1
backs outef86c7c53d210dcfa697c010c34b655ca10ce232
Backed out changeset ef86c7c53d21 (bug 1042561)
toolkit/components/autocomplete/nsAutoCompleteController.cpp
toolkit/components/autocomplete/nsAutoCompleteController.h
--- a/toolkit/components/autocomplete/nsAutoCompleteController.cpp
+++ b/toolkit/components/autocomplete/nsAutoCompleteController.cpp
@@ -727,70 +727,35 @@ nsAutoCompleteController::SetSearchStrin
 
 NS_IMETHODIMP
 nsAutoCompleteController::GetSearchString(nsAString &aSearchString)
 {
   aSearchString = mSearchString;
   return NS_OK;
 }
 
-void
-nsAutoCompleteController::HandleSearchResult(nsIAutoCompleteSearch *aSearch,
-                                             nsIAutoCompleteResult *aResult)
-{
-  // Look up the index of the search which is returning.
-  for (uint32_t i = 0; i < mSearches.Length(); ++i) {
-    if (mSearches[i] == aSearch) {
-      ProcessResult(i, aResult);
-    }
-  }
-}
-
 
 ////////////////////////////////////////////////////////////////////////
 //// nsIAutoCompleteObserver
 
 NS_IMETHODIMP
 nsAutoCompleteController::OnUpdateSearchResult(nsIAutoCompleteSearch *aSearch, nsIAutoCompleteResult* aResult)
 {
-  MOZ_ASSERT(mSearches.Contains(aSearch));
-
   ClearResults();
-  HandleSearchResult(aSearch, aResult);
-  return NS_OK;
+  return OnSearchResult(aSearch, aResult);
 }
 
 NS_IMETHODIMP
 nsAutoCompleteController::OnSearchResult(nsIAutoCompleteSearch *aSearch, nsIAutoCompleteResult* aResult)
 {
-  MOZ_ASSERT(mSearchesOngoing > 0 && mSearches.Contains(aSearch));
-
-  // If this is the first search result we are processing
-  // we should clear out the previously cached results.
-  if (mFirstSearchResult) {
-    ClearResults();
-    mFirstSearchResult = false;
-  }
-
-  uint16_t result = 0;
-  if (aResult) {
-    aResult->GetSearchResult(&result);
-  }
-
-  // If our results are incremental, the search is still ongoing.
-  if (result != nsIAutoCompleteResult::RESULT_SUCCESS_ONGOING &&
-      result != nsIAutoCompleteResult::RESULT_NOMATCH_ONGOING) {
-    --mSearchesOngoing;
-  }
-
-  HandleSearchResult(aSearch, aResult);
-
-  if (mSearchesOngoing == 0) {
-    // If this is the last search to return, cleanup.
-    PostSearchCleanup();
+  // look up the index of the search which is returning
+  for (uint32_t i = 0; i < mSearches.Length(); ++i) {
+    if (mSearches[i] == aSearch) {
+      ProcessResult(i, aResult);
+    }
   }
 
   return NS_OK;
 }
 
 ////////////////////////////////////////////////////////////////////////
 //// nsITimerCallback
 
@@ -1137,17 +1102,16 @@ nsAutoCompleteController::StartSearch(ui
     nsAutoString searchParam;
     nsresult rv = input->GetSearchParam(searchParam);
     if (NS_FAILED(rv))
         return rv;
 
     rv = search->StartSearch(mSearchString, searchParam, result, static_cast<nsIAutoCompleteObserver *>(this));
     if (NS_FAILED(rv)) {
       ++mSearchesFailed;
-      MOZ_ASSERT(mSearchesOngoing > 0);
       --mSearchesOngoing;
     }
     // Because of the joy of nested event loops (which can easily happen when some
     // code uses a generator for an asynchronous AutoComplete search),
     // nsIAutoCompleteSearch::StartSearch might cause us to be detached from our input
     // field.  The next time we iterate, we'd be touching something that we shouldn't
     // be, and result in a crash.
     if (!mInput) {
@@ -1460,20 +1424,33 @@ nsAutoCompleteController::RevertTextValu
 }
 
 nsresult
 nsAutoCompleteController::ProcessResult(int32_t aSearchIndex, nsIAutoCompleteResult *aResult)
 {
   NS_ENSURE_STATE(mInput);
   nsCOMPtr<nsIAutoCompleteInput> input(mInput);
 
+  // If this is the first search result we are processing
+  // we should clear out the previously cached results
+  if (mFirstSearchResult) {
+    ClearResults();
+    mFirstSearchResult = false;
+  }
+
   uint16_t result = 0;
   if (aResult)
     aResult->GetSearchResult(&result);
 
+  // if our results are incremental, the search is still ongoing
+  if (result != nsIAutoCompleteResult::RESULT_SUCCESS_ONGOING &&
+      result != nsIAutoCompleteResult::RESULT_NOMATCH_ONGOING) {
+    --mSearchesOngoing;
+  }
+
   uint32_t oldMatchCount = 0;
   uint32_t matchCount = 0;
   if (aResult)
     aResult->GetMatchCount(&matchCount);
 
   int32_t resultIndex = mResults.IndexOf(aResult);
   if (resultIndex == -1) {
     // cache the result
@@ -1534,16 +1511,21 @@ nsAutoCompleteController::ProcessResult(
   }
 
   if (result == nsIAutoCompleteResult::RESULT_SUCCESS ||
       result == nsIAutoCompleteResult::RESULT_SUCCESS_ONGOING) {
     // Try to autocomplete the default index for this search.
     CompleteDefaultIndex(resultIndex);
   }
 
+  if (mSearchesOngoing == 0) {
+    // If this is the last search to return, cleanup.
+    PostSearchCleanup();
+  }
+
   return NS_OK;
 }
 
 nsresult
 nsAutoCompleteController::PostSearchCleanup()
 {
   NS_ENSURE_STATE(mInput);
   nsCOMPtr<nsIAutoCompleteInput> input(mInput);
--- a/toolkit/components/autocomplete/nsAutoCompleteController.h
+++ b/toolkit/components/autocomplete/nsAutoCompleteController.h
@@ -45,18 +45,16 @@ protected:
   nsresult StartSearch(uint16_t aSearchType);
 
   nsresult BeforeSearches();
   nsresult StartSearches();
   void AfterSearches();
   nsresult ClearSearchTimer();
   void MaybeCompletePlaceholder();
 
-  void HandleSearchResult(nsIAutoCompleteSearch *aSearch,
-                          nsIAutoCompleteResult *aResult);
   nsresult ProcessResult(int32_t aSearchIndex, nsIAutoCompleteResult *aResult);
   nsresult PostSearchCleanup();
 
   nsresult EnterMatch(bool aIsPopupSelection);
   nsresult RevertTextValue();
 
   nsresult CompleteDefaultIndex(int32_t aResultIndex);
   nsresult CompleteValue(nsString &aValue);