summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordcblack@chromium.org <dcblack@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-09 01:06:48 +0000
committerdcblack@chromium.org <dcblack@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-09 01:06:48 +0000
commitf6de0ec58b03e4010ba5fd352ea2f6924376d776 (patch)
tree024d23c2e5ea4c7528b7988201d1a1c48d21f4c4
parent685d692a8bb6618fd54cfb7fb3c3782582deec4a (diff)
downloadchromium_src-f6de0ec58b03e4010ba5fd352ea2f6924376d776.zip
chromium_src-f6de0ec58b03e4010ba5fd352ea2f6924376d776.tar.gz
chromium_src-f6de0ec58b03e4010ba5fd352ea2f6924376d776.tar.bz2
Fix bug where client autocomplete results weren't being read properly and add the ability for the client to retry deduping a few times to account for race conditions.
BUG= Review URL: https://chromiumcodereview.appspot.com/11096011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@160758 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/renderer/resources/extensions/searchbox/searchbox_api.js30
1 files changed, 23 insertions, 7 deletions
diff --git a/chrome/renderer/resources/extensions/searchbox/searchbox_api.js b/chrome/renderer/resources/extensions/searchbox/searchbox_api.js
index edf314d..c300abe 100644
--- a/chrome/renderer/resources/extensions/searchbox/searchbox_api.js
+++ b/chrome/renderer/resources/extensions/searchbox/searchbox_api.js
@@ -12,6 +12,7 @@ if (!chrome.searchBox) {
// =========================================================================
var MAX_CLIENT_SUGGESTIONS_TO_DEDUPE = 6;
+ var MAX_ALLOWED_DEDUPE_ATTEMPTS = 5;
var HTTP_REGEX = /^https?:\/\//;
@@ -118,25 +119,40 @@ if (!chrome.searchBox) {
}
var lastPrefixQueriedForDuplicates = '';
+ var numDedupeAttempts = 0;
function DedupeClientSuggestions(clientSuggestions) {
var userInput = GetQuery();
if (userInput == lastPrefixQueriedForDuplicates) {
- // Request blocked for privacy reasons.
- // TODO(dcblack): This check is insufficient. We should have a check
- // such that it's only callable once per onnativesuggestions, not
- // once per prefix.
- return false;
+ numDedupeAttempts += 1;
+ if (numDedupeAttempts > MAX_ALLOWED_DEDUPE_ATTEMPTS) {
+ // Request blocked for privacy reasons.
+ // TODO(dcblack): This check is insufficient. We should have a check
+ // such that it's only callable once per onnativesuggestions, not
+ // once per prefix. Also, there is a timing problem where if the user
+ // types quickly then the client will (correctly) attempt to render
+ // stale results, and end up calling dedupe multiple times when
+ // getValue shows the same prefix. A better solution would be to have
+ // the client send up rid ranges to dedupe against and have the
+ // binary keep around all the old suggestions ever given to this
+ // overlay. I suspect such an approach would clean up this code quite
+ // a bit.
+ return false;
+ }
+ } else {
+ lastPrefixQueriedForDuplicates = userInput;
+ numDedupeAttempts = 1;
}
- lastPrefixQueriedForDuplicates = userInput;
+
var autocompleteResults = GetAutocompleteResults();
var nativeUrls = {};
for (var i = 0, result; result = autocompleteResults[i]; ++i) {
var nativeUrl = CanonicalizeUrl(result.destination_url);
nativeUrls[nativeUrl] = result.rid;
}
- for (var i = 0, result; result = clientSuggestions[i] &&
+ for (var i = 0; clientSuggestions[i] &&
i < MAX_CLIENT_SUGGESTIONS_TO_DEDUPE; ++i) {
+ var result = clientSuggestions[i];
if (result.url) {
var clientUrl = CanonicalizeUrl(result.url);
if (clientUrl in nativeUrls) {