Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1037 #endif | 1038 #endif |
| 1038 | 1039 |
| 1039 if (!done_) { | 1040 if (!done_) { |
| 1040 // This conditional needs to match the conditional in Start that invokes | 1041 // This conditional needs to match the conditional in Start that invokes |
| 1041 // StartExpireTimer. | 1042 // StartExpireTimer. |
| 1042 result_.CopyOldMatches(input_, last_result); | 1043 result_.CopyOldMatches(input_, last_result); |
| 1043 } | 1044 } |
| 1044 | 1045 |
| 1045 UpdateKeywordDescriptions(&result_); | 1046 UpdateKeywordDescriptions(&result_); |
| 1046 UpdateAssociatedKeywords(&result_); | 1047 UpdateAssociatedKeywords(&result_); |
| 1048 UpdateAssistedQueryStats(&result_); | |
| 1047 | 1049 |
| 1048 bool notify_default_match = is_synchronous_pass; | 1050 bool notify_default_match = is_synchronous_pass; |
| 1049 if (!is_synchronous_pass) { | 1051 if (!is_synchronous_pass) { |
| 1050 const bool last_default_was_valid = | 1052 const bool last_default_was_valid = |
| 1051 last_result.default_match() != last_result.end(); | 1053 last_result.default_match() != last_result.end(); |
| 1052 const bool default_is_valid = result_.default_match() != result_.end(); | 1054 const bool default_is_valid = result_.default_match() != result_.end(); |
| 1053 // We've gotten async results. Send notification that the default match | 1055 // We've gotten async results. Send notification that the default match |
| 1054 // updated if fill_into_edit differs or associated_keyword differ. (The | 1056 // 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 | 1057 // 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 | 1058 // finishes loading while processing this request.) We don't check the URL |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1093 match->associated_keyword.reset(new AutocompleteMatch( | 1095 match->associated_keyword.reset(new AutocompleteMatch( |
| 1094 keyword_provider_->CreateAutocompleteMatch(match->fill_into_edit, | 1096 keyword_provider_->CreateAutocompleteMatch(match->fill_into_edit, |
| 1095 keyword, input_))); | 1097 keyword, input_))); |
| 1096 } else { | 1098 } else { |
| 1097 match->associated_keyword.reset(); | 1099 match->associated_keyword.reset(); |
| 1098 } | 1100 } |
| 1099 } | 1101 } |
| 1100 } | 1102 } |
| 1101 } | 1103 } |
| 1102 | 1104 |
| 1105 namespace { | |
|
msw
2012/06/13 22:39:33
anon namespaces and contents belong at the top of
Bart N
2012/06/13 23:17:13
Done.
| |
| 1106 | |
| 1107 // Converts the given type to an integer based on the AQS specification. | |
|
msw
2012/06/13 22:39:33
Are these magic numbers really necessary? Why not
Bart N
2012/06/13 23:17:13
These values must map to existing enum on the serv
msw
2012/06/13 23:42:08
I wouldn't bother, but maybe add a vague statement
| |
| 1108 int AutocompletMatchToAssistedQueryType(const AutocompleteMatch::Type& type) { | |
|
msw
2012/06/13 22:39:33
Spelling: Autocomplet*e*MatchToAssistedQueryType
Bart N
2012/06/13 23:17:13
Done.
| |
| 1109 switch (type) { | |
| 1110 case AutocompleteMatch::SEARCH_SUGGEST: | |
| 1111 return 0; | |
| 1112 case AutocompleteMatch::NAVSUGGEST: | |
| 1113 return 5; | |
| 1114 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED: | |
| 1115 return 57; | |
| 1116 case AutocompleteMatch::URL_WHAT_YOU_TYPED: | |
| 1117 return 58; | |
| 1118 case AutocompleteMatch::SEARCH_HISTORY: | |
| 1119 return 59; | |
| 1120 case AutocompleteMatch::HISTORY_URL: | |
| 1121 return 60; | |
| 1122 case AutocompleteMatch::HISTORY_TITLE: | |
| 1123 return 61; | |
| 1124 case AutocompleteMatch::HISTORY_BODY: | |
| 1125 return 62; | |
| 1126 case AutocompleteMatch::HISTORY_KEYWORD: | |
| 1127 return 63; | |
| 1128 default: | |
| 1129 return 64; | |
| 1130 } | |
| 1131 } | |
| 1132 | |
| 1133 // Appends query stats of the given type and number to the existing AQS string. | |
| 1134 void AppendQueryStats(int type, int count, std::string* aqs) { | |
| 1135 if (!aqs->empty()) | |
| 1136 aqs->append("j"); | |
| 1137 base::StringAppendF(aqs, "%d", type); | |
| 1138 if (count > 1) | |
| 1139 base::StringAppendF(aqs, "l%d", count); | |
| 1140 } | |
| 1141 | |
| 1142 } // namespace | |
| 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; | |
|
msw
2012/06/13 22:39:33
Use string16 if possible.
Bart N
2012/06/13 23:17:13
Hmmm.. a few methods broke when I switched to stri
msw
2012/06/13 23:42:08
Use + and += operators, IIRC. See base/string16.h
| |
| 1151 int count = 0; | |
| 1152 int last_type = -1; | |
| 1153 for (ACMatches::iterator match(result->begin()); match != result->end(); | |
|
msw
2012/06/13 22:39:33
Is there a reason for combining consecutive matche
Bart N
2012/06/13 23:17:13
Yes, it's required by the spec. For instance, inst
msw
2012/06/13 23:42:08
Fair enough.
| |
| 1154 ++match) { | |
| 1155 int type = AutocompletMatchToAssistedQueryType(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); | |
|
msw
2012/06/13 22:39:33
Should this be done even if there were no matches?
Bart N
2012/06/13 23:17:13
There is always at least one. See the check at the
msw
2012/06/13 23:42:08
Doh! Thanks for the heads up on the empty check.
| |
| 1165 | |
| 1166 // Go over all matches and set AQS if the match supports it. | |
| 1167 int index = 0; | |
| 1168 for (AutocompleteResult::iterator i = result->begin(); i != result->end(); | |
|
msw
2012/06/13 22:39:33
nit: consistency is nice, consider matching your l
Bart N
2012/06/13 23:17:13
Ah yes, done.
| |
| 1169 ++i, ++index) { | |
| 1170 if (i->provider != search_provider_) | |
|
msw
2012/06/13 22:39:33
It'd be nice if we could put this logic in SearchP
Bart N
2012/06/13 23:17:13
Currently, I rely on the fact that we check for Su
msw
2012/06/13 23:42:08
So, I'm not terribly familiar with AQS or what you
| |
| 1171 continue; | |
| 1172 const TemplateURL* template_url = i->GetTemplateURL(profile_); | |
| 1173 if (!template_url || !template_url->url_ref().SupportsAssistedQueryStats()) | |
| 1174 continue; | |
| 1175 std::string url(i->destination_url.spec()); | |
| 1176 if (url.find("&aqs=") != std::string::npos) | |
| 1177 continue; | |
| 1178 url.append(base::StringPrintf("&aqs=%d", index)).append(".").append(aqs); | |
|
msw
2012/06/13 22:39:33
Whoa, we're sending the ordered list of match type
Bart N
2012/06/13 23:17:13
Yes. It was approved today, I can forward an email
msw
2012/06/13 23:42:08
You should link this CL to a chromium bug (set BUG
| |
| 1179 i->destination_url = GURL(url); | |
| 1180 | |
| 1181 VLOG(1) << "[" << i->provider->name() << "] URL = " << i->destination_url; | |
|
msw
2012/06/13 22:39:33
Will this LOG help end users? if not, please remov
Bart N
2012/06/13 23:17:13
Removed.
| |
| 1182 } | |
| 1183 } | |
| 1184 | |
| 1103 void AutocompleteController::UpdateKeywordDescriptions( | 1185 void AutocompleteController::UpdateKeywordDescriptions( |
| 1104 AutocompleteResult* result) { | 1186 AutocompleteResult* result) { |
| 1105 string16 last_keyword; | 1187 string16 last_keyword; |
| 1106 for (AutocompleteResult::iterator i = result->begin(); i != result->end(); | 1188 for (AutocompleteResult::iterator i = result->begin(); i != result->end(); |
| 1107 ++i) { | 1189 ++i) { |
| 1108 if (((i->provider == keyword_provider_) && !i->keyword.empty()) || | 1190 if (((i->provider == keyword_provider_) && !i->keyword.empty()) || |
| 1109 ((i->provider == search_provider_) && | 1191 ((i->provider == search_provider_) && |
| 1110 (i->type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED || | 1192 (i->type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED || |
| 1111 i->type == AutocompleteMatch::SEARCH_HISTORY || | 1193 i->type == AutocompleteMatch::SEARCH_HISTORY || |
| 1112 i->type == AutocompleteMatch::SEARCH_SUGGEST))) { | 1194 i->type == AutocompleteMatch::SEARCH_SUGGEST))) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1179 current_page_classification(current_page_classification), | 1261 current_page_classification(current_page_classification), |
| 1180 elapsed_time_since_user_first_modified_omnibox( | 1262 elapsed_time_since_user_first_modified_omnibox( |
| 1181 elapsed_time_since_user_first_modified_omnibox), | 1263 elapsed_time_since_user_first_modified_omnibox), |
| 1182 inline_autocompleted_length(inline_autocompleted_length), | 1264 inline_autocompleted_length(inline_autocompleted_length), |
| 1183 result(result), | 1265 result(result), |
| 1184 providers_info() { | 1266 providers_info() { |
| 1185 } | 1267 } |
| 1186 | 1268 |
| 1187 AutocompleteLog::~AutocompleteLog() { | 1269 AutocompleteLog::~AutocompleteLog() { |
| 1188 } | 1270 } |
| OLD | NEW |