Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: chrome/browser/autocomplete/search_provider.cc

Issue 10537154: A working implementation of AQS (Assisted Query Stats). (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Added Autocomplete unit tests. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/autocomplete/search_provider.h" 5 #include "chrome/browser/autocomplete/search_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 (*list)[i].set_relevance(CalculateRelevanceForNavigation(is_keyword) + 584 (*list)[i].set_relevance(CalculateRelevanceForNavigation(is_keyword) +
585 (list->size() - i - 1)); 585 (list->size() - i - 1));
586 } 586 }
587 } 587 }
588 588
589 net::URLFetcher* SearchProvider::CreateSuggestFetcher( 589 net::URLFetcher* SearchProvider::CreateSuggestFetcher(
590 int id, 590 int id,
591 const TemplateURLRef& suggestions_url, 591 const TemplateURLRef& suggestions_url,
592 const string16& text) { 592 const string16& text) {
593 DCHECK(suggestions_url.SupportsReplacement()); 593 DCHECK(suggestions_url.SupportsReplacement());
594 net::URLFetcher* fetcher = content::URLFetcher::Create(id, 594 net::URLFetcher* fetcher = content::URLFetcher::Create(
595 GURL(suggestions_url.ReplaceSearchTerms(text, 595 id, GURL(suggestions_url.ReplaceSearchTerms(
596 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())), 596 TemplateURLRef::SearchTermsArgs(text))),
597 net::URLFetcher::GET, this); 597 net::URLFetcher::GET, this);
598 fetcher->SetRequestContext(profile_->GetRequestContext()); 598 fetcher->SetRequestContext(profile_->GetRequestContext());
599 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); 599 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES);
600 fetcher->Start(); 600 fetcher->Start();
601 return fetcher; 601 return fetcher;
602 } 602 }
603 603
604 bool SearchProvider::ParseSuggestResults(Value* root_val, bool is_keyword) { 604 bool SearchProvider::ParseSuggestResults(Value* root_val, bool is_keyword) {
605 // TODO(pkasting): Fix |have_suggest_results_|; see http://crbug.com/130631 605 // TODO(pkasting): Fix |have_suggest_results_|; see http://crbug.com/130631
606 have_suggest_results_ = false; 606 have_suggest_results_ = false;
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 } 1071 }
1072 match.fill_into_edit.append(query_string); 1072 match.fill_into_edit.append(query_string);
1073 // Not all suggestions start with the original input. 1073 // Not all suggestions start with the original input.
1074 if (!input_.prevent_inline_autocomplete() && 1074 if (!input_.prevent_inline_autocomplete() &&
1075 !match.fill_into_edit.compare(search_start, input_text.length(), 1075 !match.fill_into_edit.compare(search_start, input_text.length(),
1076 input_text)) 1076 input_text))
1077 match.inline_autocomplete_offset = search_start + input_text.length(); 1077 match.inline_autocomplete_offset = search_start + input_text.length();
1078 1078
1079 const TemplateURLRef& search_url = provider_url->url_ref(); 1079 const TemplateURLRef& search_url = provider_url->url_ref();
1080 DCHECK(search_url.SupportsReplacement()); 1080 DCHECK(search_url.SupportsReplacement());
1081 match.destination_url = GURL(search_url.ReplaceSearchTerms(query_string, 1081 match.search_terms_args.reset(
1082 accepted_suggestion, input_text)); 1082 new TemplateURLRef::SearchTermsArgs(query_string));
1083 match.search_terms_args->original_query = input_text;
1084 match.search_terms_args->accepted_suggestion = accepted_suggestion;
1085 // This is the destination URL sans assisted query stats. This must be set
1086 // so the AutocompleteController can properly de-dupe; the controller will
1087 // eventually overwrite it before it reaches the user.
1088 match.destination_url =
1089 GURL(search_url.ReplaceSearchTerms(*match.search_terms_args.get()));
1083 1090
1084 // Search results don't look like URLs. 1091 // Search results don't look like URLs.
1085 match.transition = is_keyword ? 1092 match.transition = is_keyword ?
1086 content::PAGE_TRANSITION_KEYWORD : content::PAGE_TRANSITION_GENERATED; 1093 content::PAGE_TRANSITION_KEYWORD : content::PAGE_TRANSITION_GENERATED;
1087 1094
1088 // Try to add |match| to |map|. If a match for |query_string| is already in 1095 // Try to add |match| to |map|. If a match for |query_string| is already in
1089 // |map|, replace it if |match| is more relevant. 1096 // |map|, replace it if |match| is more relevant.
1090 // NOTE: Keep this ToLower() call in sync with url_database.cc. 1097 // NOTE: Keep this ToLower() call in sync with url_database.cc.
1091 const std::pair<MatchMap::iterator, bool> i = map->insert( 1098 const std::pair<MatchMap::iterator, bool> i = map->insert(
1092 std::pair<string16, AutocompleteMatch>( 1099 std::pair<string16, AutocompleteMatch>(
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 ACMatchClassification::NONE, &match.description_class); 1171 ACMatchClassification::NONE, &match.description_class);
1165 return match; 1172 return match;
1166 } 1173 }
1167 1174
1168 void SearchProvider::UpdateDone() { 1175 void SearchProvider::UpdateDone() {
1169 // We're done when there are no more suggest queries pending (this is set to 1 1176 // We're done when there are no more suggest queries pending (this is set to 1
1170 // when the timer is started) and we're not waiting on instant. 1177 // when the timer is started) and we're not waiting on instant.
1171 done_ = ((suggest_results_pending_ == 0) && 1178 done_ = ((suggest_results_pending_ == 0) &&
1172 (instant_finalized_ || !InstantController::IsEnabled(profile_))); 1179 (instant_finalized_ || !InstantController::IsEnabled(profile_)));
1173 } 1180 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698