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

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

Issue 10537154: A working implementation of AQS (Assisted Query Stats). (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Add missing change to google engine. 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/autocomplete.h" 5 #include "chrome/browser/autocomplete/autocomplete.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <set> 9 #include <set>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/i18n/number_formatting.h" 13 #include "base/i18n/number_formatting.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/string_number_conversions.h" 15 #include "base/string_number_conversions.h"
16 #include "base/string_util.h" 16 #include "base/string_util.h"
17 #include "base/stringprintf.h"
17 #include "base/utf_string_conversions.h" 18 #include "base/utf_string_conversions.h"
18 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h" 19 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h"
19 #include "chrome/browser/autocomplete/autocomplete_match.h" 20 #include "chrome/browser/autocomplete/autocomplete_match.h"
20 #include "chrome/browser/autocomplete/builtin_provider.h" 21 #include "chrome/browser/autocomplete/builtin_provider.h"
21 #include "chrome/browser/autocomplete/extension_app_provider.h" 22 #include "chrome/browser/autocomplete/extension_app_provider.h"
22 #include "chrome/browser/autocomplete/history_contents_provider.h" 23 #include "chrome/browser/autocomplete/history_contents_provider.h"
23 #include "chrome/browser/autocomplete/history_quick_provider.h" 24 #include "chrome/browser/autocomplete/history_quick_provider.h"
24 #include "chrome/browser/autocomplete/history_url_provider.h" 25 #include "chrome/browser/autocomplete/history_url_provider.h"
25 #include "chrome/browser/autocomplete/keyword_provider.h" 26 #include "chrome/browser/autocomplete/keyword_provider.h"
26 #include "chrome/browser/autocomplete/search_provider.h" 27 #include "chrome/browser/autocomplete/search_provider.h"
(...skipping 19 matching lines...) Expand all
46 #include "googleurl/src/url_util.h" 47 #include "googleurl/src/url_util.h"
47 #include "grit/generated_resources.h" 48 #include "grit/generated_resources.h"
48 #include "grit/theme_resources.h" 49 #include "grit/theme_resources.h"
49 #include "net/base/net_util.h" 50 #include "net/base/net_util.h"
50 #include "net/base/registry_controlled_domain.h" 51 #include "net/base/registry_controlled_domain.h"
51 #include "net/url_request/url_request.h" 52 #include "net/url_request/url_request.h"
52 #include "ui/base/l10n/l10n_util.h" 53 #include "ui/base/l10n/l10n_util.h"
53 54
54 using base::TimeDelta; 55 using base::TimeDelta;
55 56
57 namespace {
58
59 // Converts the given type to an integer based on the AQS specification.
Peter Kasting 2012/06/14 01:04:23 We either need a copy of or link to the spec, or a
Bart N 2012/06/15 18:07:34 Done.
60 int AutocompleteMatchToAssistedQueryType(const AutocompleteMatch::Type& type) {
61 switch (type) {
62 case AutocompleteMatch::SEARCH_SUGGEST:
Peter Kasting 2012/06/14 01:04:23 Nit: I suggest putting the return statements on th
Bart N 2012/06/15 18:07:34 Done.
63 return 0;
64 case AutocompleteMatch::NAVSUGGEST:
65 return 5;
66 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED:
67 return 57;
68 case AutocompleteMatch::URL_WHAT_YOU_TYPED:
69 return 58;
70 case AutocompleteMatch::SEARCH_HISTORY:
71 return 59;
72 case AutocompleteMatch::HISTORY_URL:
73 return 60;
74 case AutocompleteMatch::HISTORY_TITLE:
75 return 61;
76 case AutocompleteMatch::HISTORY_BODY:
77 return 62;
78 case AutocompleteMatch::HISTORY_KEYWORD:
79 return 63;
80 default:
81 return 64;
82 }
83 }
84
85 // Appends query stats of the given type and number to the existing AQS string.
86 void AppendQueryStats(int type, int count, std::string* aqs) {
87 if (!aqs->empty())
88 aqs->append("j");
89 base::StringAppendF(aqs, "%d", type);
90 if (count > 1)
91 base::StringAppendF(aqs, "l%d", count);
92 }
93
94 } // namespace
95
56 // AutocompleteInput ---------------------------------------------------------- 96 // AutocompleteInput ----------------------------------------------------------
57 97
58 AutocompleteInput::AutocompleteInput() 98 AutocompleteInput::AutocompleteInput()
59 : type_(INVALID), 99 : type_(INVALID),
60 prevent_inline_autocomplete_(false), 100 prevent_inline_autocomplete_(false),
61 prefer_keyword_(false), 101 prefer_keyword_(false),
62 allow_exact_keyword_match_(true), 102 allow_exact_keyword_match_(true),
63 matches_requested_(ALL_MATCHES) { 103 matches_requested_(ALL_MATCHES) {
64 } 104 }
65 105
(...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 #endif 1077 #endif
1038 1078
1039 if (!done_) { 1079 if (!done_) {
1040 // This conditional needs to match the conditional in Start that invokes 1080 // This conditional needs to match the conditional in Start that invokes
1041 // StartExpireTimer. 1081 // StartExpireTimer.
1042 result_.CopyOldMatches(input_, last_result); 1082 result_.CopyOldMatches(input_, last_result);
1043 } 1083 }
1044 1084
1045 UpdateKeywordDescriptions(&result_); 1085 UpdateKeywordDescriptions(&result_);
1046 UpdateAssociatedKeywords(&result_); 1086 UpdateAssociatedKeywords(&result_);
1087 UpdateAssistedQueryStats(&result_);
1047 1088
1048 bool notify_default_match = is_synchronous_pass; 1089 bool notify_default_match = is_synchronous_pass;
1049 if (!is_synchronous_pass) { 1090 if (!is_synchronous_pass) {
1050 const bool last_default_was_valid = 1091 const bool last_default_was_valid =
1051 last_result.default_match() != last_result.end(); 1092 last_result.default_match() != last_result.end();
1052 const bool default_is_valid = result_.default_match() != result_.end(); 1093 const bool default_is_valid = result_.default_match() != result_.end();
1053 // We've gotten async results. Send notification that the default match 1094 // We've gotten async results. Send notification that the default match
1054 // updated if fill_into_edit differs or associated_keyword differ. (The 1095 // updated if fill_into_edit differs or associated_keyword differ. (The
1055 // latter can change if we've just started Chrome and the keyword database 1096 // latter can change if we've just started Chrome and the keyword database
1056 // finishes loading while processing this request.) We don't check the URL 1097 // finishes loading while processing this request.) We don't check the URL
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 match->associated_keyword.reset(new AutocompleteMatch( 1134 match->associated_keyword.reset(new AutocompleteMatch(
1094 keyword_provider_->CreateAutocompleteMatch(match->fill_into_edit, 1135 keyword_provider_->CreateAutocompleteMatch(match->fill_into_edit,
1095 keyword, input_))); 1136 keyword, input_)));
1096 } else { 1137 } else {
1097 match->associated_keyword.reset(); 1138 match->associated_keyword.reset();
1098 } 1139 }
1099 } 1140 }
1100 } 1141 }
1101 } 1142 }
1102 1143
1144 void AutocompleteController::UpdateAssistedQueryStats(
1145 AutocompleteResult* result) {
1146 if (result->empty())
1147 return;
1148
1149 // Build the impressions string (the AQS part after ".").
1150 std::string aqs;
1151 int count = 0;
1152 int last_type = -1;
1153 for (ACMatches::iterator match(result->begin()); match != result->end();
1154 ++match) {
1155 int type = AutocompleteMatchToAssistedQueryType(match->type);
1156 if (last_type != -1 && type != last_type) {
1157 AppendQueryStats(last_type, count, &aqs);
1158 count = 1;
1159 } else {
1160 count++;
1161 }
1162 last_type = type;
1163 }
1164 AppendQueryStats(last_type, count, &aqs);
1165
1166 // Go over all matches and set AQS if the match supports it.
Peter Kasting 2012/06/14 01:04:23 Don't do things this way. Instead let TemplateURL
Bart N 2012/06/14 01:22:13 I really wanted to do it that way, but I ran into
Peter Kasting 2012/06/14 03:18:17 Right; I was attempting to address that, but assum
Bart N 2012/06/15 18:07:34 Done, as we discussed. On 2012/06/14 03:18:17, Pet
1167 int index = 0;
1168 for (ACMatches::iterator match(result->begin()); match != result->end();
1169 ++match, ++index) {
1170 if (match->provider != search_provider_)
1171 continue;
1172 const TemplateURL* template_url = match->GetTemplateURL(profile_);
1173 if (!template_url || !template_url->url_ref().SupportsAssistedQueryStats())
1174 continue;
1175 std::string url(match->destination_url.spec());
1176 if (url.find("&aqs=") != std::string::npos)
1177 continue;
1178 url.append(base::StringPrintf("&aqs=%d", index)).append(".").append(aqs);
1179 match->destination_url = GURL(url);
1180 }
1181 }
1182
1103 void AutocompleteController::UpdateKeywordDescriptions( 1183 void AutocompleteController::UpdateKeywordDescriptions(
1104 AutocompleteResult* result) { 1184 AutocompleteResult* result) {
1105 string16 last_keyword; 1185 string16 last_keyword;
1106 for (AutocompleteResult::iterator i = result->begin(); i != result->end(); 1186 for (AutocompleteResult::iterator i = result->begin(); i != result->end();
1107 ++i) { 1187 ++i) {
1108 if (((i->provider == keyword_provider_) && !i->keyword.empty()) || 1188 if (((i->provider == keyword_provider_) && !i->keyword.empty()) ||
1109 ((i->provider == search_provider_) && 1189 ((i->provider == search_provider_) &&
1110 (i->type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED || 1190 (i->type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED ||
1111 i->type == AutocompleteMatch::SEARCH_HISTORY || 1191 i->type == AutocompleteMatch::SEARCH_HISTORY ||
1112 i->type == AutocompleteMatch::SEARCH_SUGGEST))) { 1192 i->type == AutocompleteMatch::SEARCH_SUGGEST))) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 current_page_classification(current_page_classification), 1259 current_page_classification(current_page_classification),
1180 elapsed_time_since_user_first_modified_omnibox( 1260 elapsed_time_since_user_first_modified_omnibox(
1181 elapsed_time_since_user_first_modified_omnibox), 1261 elapsed_time_since_user_first_modified_omnibox),
1182 inline_autocompleted_length(inline_autocompleted_length), 1262 inline_autocompleted_length(inline_autocompleted_length),
1183 result(result), 1263 result(result),
1184 providers_info() { 1264 providers_info() {
1185 } 1265 }
1186 1266
1187 AutocompleteLog::~AutocompleteLog() { 1267 AutocompleteLog::~AutocompleteLog() {
1188 } 1268 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698