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

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: Addressed comments and added more docs. 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 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 (list->size() - i - 1)); 586 (list->size() - i - 1));
587 } 587 }
588 } 588 }
589 589
590 net::URLFetcher* SearchProvider::CreateSuggestFetcher( 590 net::URLFetcher* SearchProvider::CreateSuggestFetcher(
591 int id, 591 int id,
592 const TemplateURLRef& suggestions_url, 592 const TemplateURLRef& suggestions_url,
593 const string16& text) { 593 const string16& text) {
594 DCHECK(suggestions_url.SupportsReplacement()); 594 DCHECK(suggestions_url.SupportsReplacement());
595 net::URLFetcher* fetcher = net::URLFetcher::Create(id, 595 net::URLFetcher* fetcher = net::URLFetcher::Create(id,
596 GURL(suggestions_url.ReplaceSearchTerms(text, 596 GURL(suggestions_url.ReplaceSearchTerms(
597 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())), 597 TemplateURLRef::SearchTermsArgs(text))),
598 net::URLFetcher::GET, this); 598 net::URLFetcher::GET, this);
599 fetcher->SetRequestContext(profile_->GetRequestContext()); 599 fetcher->SetRequestContext(profile_->GetRequestContext());
600 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); 600 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES);
601 fetcher->Start(); 601 fetcher->Start();
602 return fetcher; 602 return fetcher;
603 } 603 }
604 604
605 bool SearchProvider::ParseSuggestResults(Value* root_val, bool is_keyword) { 605 bool SearchProvider::ParseSuggestResults(Value* root_val, bool is_keyword) {
606 // TODO(pkasting): Fix |have_suggest_results_|; see http://crbug.com/130631 606 // TODO(pkasting): Fix |have_suggest_results_|; see http://crbug.com/130631
607 have_suggest_results_ = false; 607 have_suggest_results_ = false;
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
1084 } 1084 }
1085 match.fill_into_edit.append(query_string); 1085 match.fill_into_edit.append(query_string);
1086 // Not all suggestions start with the original input. 1086 // Not all suggestions start with the original input.
1087 if (!input_.prevent_inline_autocomplete() && 1087 if (!input_.prevent_inline_autocomplete() &&
1088 !match.fill_into_edit.compare(search_start, input_text.length(), 1088 !match.fill_into_edit.compare(search_start, input_text.length(),
1089 input_text)) 1089 input_text))
1090 match.inline_autocomplete_offset = search_start + input_text.length(); 1090 match.inline_autocomplete_offset = search_start + input_text.length();
1091 1091
1092 const TemplateURLRef& search_url = provider_url->url_ref(); 1092 const TemplateURLRef& search_url = provider_url->url_ref();
1093 DCHECK(search_url.SupportsReplacement()); 1093 DCHECK(search_url.SupportsReplacement());
1094 match.destination_url = GURL(search_url.ReplaceSearchTerms(query_string, 1094 match.search_terms_args.reset(
1095 accepted_suggestion, input_text)); 1095 new TemplateURLRef::SearchTermsArgs(query_string));
1096 match.search_terms_args->original_query = input_text;
1097 match.search_terms_args->accepted_suggestion = accepted_suggestion;
1098 // This is the destination URL sans assisted query stats. This must be set
1099 // so the AutocompleteController can properly de-dupe; the controller will
1100 // eventually overwrite it before it reaches the user.
1101 match.destination_url =
1102 GURL(search_url.ReplaceSearchTerms(*match.search_terms_args.get()));
1096 1103
1097 // Search results don't look like URLs. 1104 // Search results don't look like URLs.
1098 match.transition = is_keyword ? 1105 match.transition = is_keyword ?
1099 content::PAGE_TRANSITION_KEYWORD : content::PAGE_TRANSITION_GENERATED; 1106 content::PAGE_TRANSITION_KEYWORD : content::PAGE_TRANSITION_GENERATED;
1100 1107
1101 // Try to add |match| to |map|. If a match for |query_string| is already in 1108 // Try to add |match| to |map|. If a match for |query_string| is already in
1102 // |map|, replace it if |match| is more relevant. 1109 // |map|, replace it if |match| is more relevant.
1103 // NOTE: Keep this ToLower() call in sync with url_database.cc. 1110 // NOTE: Keep this ToLower() call in sync with url_database.cc.
1104 const std::pair<MatchMap::iterator, bool> i = map->insert( 1111 const std::pair<MatchMap::iterator, bool> i = map->insert(
1105 std::pair<string16, AutocompleteMatch>( 1112 std::pair<string16, AutocompleteMatch>(
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1177 ACMatchClassification::NONE, &match.description_class); 1184 ACMatchClassification::NONE, &match.description_class);
1178 return match; 1185 return match;
1179 } 1186 }
1180 1187
1181 void SearchProvider::UpdateDone() { 1188 void SearchProvider::UpdateDone() {
1182 // We're done when there are no more suggest queries pending (this is set to 1 1189 // We're done when there are no more suggest queries pending (this is set to 1
1183 // when the timer is started) and we're not waiting on instant. 1190 // when the timer is started) and we're not waiting on instant.
1184 done_ = ((suggest_results_pending_ == 0) && 1191 done_ = ((suggest_results_pending_ == 0) &&
1185 (instant_finalized_ || !InstantController::IsEnabled(profile_))); 1192 (instant_finalized_ || !InstantController::IsEnabled(profile_)));
1186 } 1193 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/keyword_provider.cc ('k') | chrome/browser/autocomplete/search_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698