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

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: Removed SupportsAssistedQueryStats. 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 {
Peter Kasting 2012/06/16 03:14:17 Nit: Because these functions are only used inside
Bart N 2012/06/16 23:38:10 Done.
58
59 // Converts the given type to an integer based on the AQS specification.
60 // For more details, See http://go/binary-clients-logging.
Peter Kasting 2012/06/16 03:14:17 Nit: See->see; go->goto.google.com; I suggest a sp
Bart N 2012/06/16 23:38:10 Yes, we can have a sanitized version later on. Don
61 int AutocompleteMatchToAssistedQueryType(const AutocompleteMatch::Type& type) {
62 switch (type) {
63 case AutocompleteMatch::SEARCH_SUGGEST: return 0;
64 case AutocompleteMatch::NAVSUGGEST: return 5;
65 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED: return 57;
66 case AutocompleteMatch::URL_WHAT_YOU_TYPED: return 58;
67 case AutocompleteMatch::SEARCH_HISTORY: return 59;
68 case AutocompleteMatch::HISTORY_URL: return 60;
69 case AutocompleteMatch::HISTORY_TITLE: return 61;
70 case AutocompleteMatch::HISTORY_BODY: return 62;
71 case AutocompleteMatch::HISTORY_KEYWORD: return 63;
72 default: return 64;
73 }
74 }
75
76 // Appends available autocompletion of the given type and number to the existing
77 // available autocompletions string, encoding according to the spec.
78 void AppendAvailableAutocompletion(int type, int count,
Peter Kasting 2012/06/16 03:14:17 Nit: One arg per line (2 places)
Bart N 2012/06/16 23:38:10 Done.
79 std::string* autocompletions) {
80 if (!autocompletions->empty())
81 autocompletions->append("j");
82 base::StringAppendF(autocompletions, "%d", type);
83 if (count > 1)
84 base::StringAppendF(autocompletions, "l%d", count);
85 }
86
87 // Constructs the final form of AQS param.
88 string16 ConstructAssistedQueryStatsString(
89 const std::string& client, int query_index,
90 const std::string& available_autocompletions) {
91 std::string aqs(client);
92 aqs.append(".").append(base::StringPrintf("%d", query_index)).append(".")
Peter Kasting 2012/06/16 03:14:17 Nit: Why not just something like return base::S
Bart N 2012/06/16 23:38:10 Done.
93 .append(available_autocompletions);
94 return ASCIIToUTF16(aqs);
95 }
96
97 } // namespace
98
56 // AutocompleteInput ---------------------------------------------------------- 99 // AutocompleteInput ----------------------------------------------------------
57 100
58 AutocompleteInput::AutocompleteInput() 101 AutocompleteInput::AutocompleteInput()
59 : type_(INVALID), 102 : type_(INVALID),
60 prevent_inline_autocomplete_(false), 103 prevent_inline_autocomplete_(false),
61 prefer_keyword_(false), 104 prefer_keyword_(false),
62 allow_exact_keyword_match_(true), 105 allow_exact_keyword_match_(true),
63 matches_requested_(ALL_MATCHES) { 106 matches_requested_(ALL_MATCHES) {
64 } 107 }
65 108
(...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 #endif 1080 #endif
1038 1081
1039 if (!done_) { 1082 if (!done_) {
1040 // This conditional needs to match the conditional in Start that invokes 1083 // This conditional needs to match the conditional in Start that invokes
1041 // StartExpireTimer. 1084 // StartExpireTimer.
1042 result_.CopyOldMatches(input_, last_result); 1085 result_.CopyOldMatches(input_, last_result);
1043 } 1086 }
1044 1087
1045 UpdateKeywordDescriptions(&result_); 1088 UpdateKeywordDescriptions(&result_);
1046 UpdateAssociatedKeywords(&result_); 1089 UpdateAssociatedKeywords(&result_);
1090 UpdateAssistedQueryStats(&result_);
1047 1091
1048 bool notify_default_match = is_synchronous_pass; 1092 bool notify_default_match = is_synchronous_pass;
1049 if (!is_synchronous_pass) { 1093 if (!is_synchronous_pass) {
1050 const bool last_default_was_valid = 1094 const bool last_default_was_valid =
1051 last_result.default_match() != last_result.end(); 1095 last_result.default_match() != last_result.end();
1052 const bool default_is_valid = result_.default_match() != result_.end(); 1096 const bool default_is_valid = result_.default_match() != result_.end();
1053 // We've gotten async results. Send notification that the default match 1097 // We've gotten async results. Send notification that the default match
1054 // updated if fill_into_edit differs or associated_keyword differ. (The 1098 // 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 1099 // 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 1100 // 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( 1137 match->associated_keyword.reset(new AutocompleteMatch(
1094 keyword_provider_->CreateAutocompleteMatch(match->fill_into_edit, 1138 keyword_provider_->CreateAutocompleteMatch(match->fill_into_edit,
1095 keyword, input_))); 1139 keyword, input_)));
1096 } else { 1140 } else {
1097 match->associated_keyword.reset(); 1141 match->associated_keyword.reset();
1098 } 1142 }
1099 } 1143 }
1100 } 1144 }
1101 } 1145 }
1102 1146
1147 void AutocompleteController::UpdateAssistedQueryStats(
1148 AutocompleteResult* result) {
1149 if (result->empty())
1150 return;
1151
1152 // Build the impressions string (the AQS part after ".").
1153 std::string autocompletions;
1154 int count = 0;
1155 int last_type = -1;
1156 for (ACMatches::iterator match(result->begin()); match != result->end();
1157 ++match) {
1158 int type = AutocompleteMatchToAssistedQueryType(match->type);
1159 if (last_type != -1 && type != last_type) {
1160 AppendAvailableAutocompletion(last_type, count, &autocompletions);
1161 count = 1;
1162 } else {
1163 count++;
1164 }
1165 last_type = type;
1166 }
1167 // It's OK to call it, because there is always at least one match.
Peter Kasting 2012/06/16 03:14:17 Nit: I'd remove this comment (it seems clear enoug
Bart N 2012/06/16 23:38:10 It wasn't clear to another reviewer, so I added it
1168 AppendAvailableAutocompletion(last_type, count, &autocompletions);
1169
1170 // Go over all matches and set AQS if the match supports it.
1171 int index = 0;
1172 for (ACMatches::iterator match(result->begin()); match != result->end();
Peter Kasting 2012/06/16 03:14:17 Nit: Since you need to use an index anyway, just o
Bart N 2012/06/16 23:38:10 Done. Except size_t which is a pain to get proper
1173 ++match, ++index) {
1174 if (match->provider != search_provider_)
Peter Kasting 2012/06/16 03:14:17 Nit: Omit this check; there's no theoretical reaso
Bart N 2012/06/16 23:38:10 Done.
1175 continue;
1176 const TemplateURL* template_url = match->GetTemplateURL(profile_);
1177 if (!template_url || !match->search_terms_args.get())
1178 continue;
1179 SearchTermsArgs& search_terms_args = *match->search_terms_args.get();
Peter Kasting 2012/06/16 03:14:17 Nit: We generally avoid non-const refs; I suggest
Bart N 2012/06/16 23:38:10 Done.
1180 search_terms_args.assisted_query_stats =
1181 ConstructAssistedQueryStatsString("chrome", index, autocompletions);
1182 match->destination_url = GURL(template_url->url_ref().ReplaceSearchTerms(
1183 search_terms_args));
1184 }
1185 }
1186
1103 void AutocompleteController::UpdateKeywordDescriptions( 1187 void AutocompleteController::UpdateKeywordDescriptions(
1104 AutocompleteResult* result) { 1188 AutocompleteResult* result) {
1105 string16 last_keyword; 1189 string16 last_keyword;
1106 for (AutocompleteResult::iterator i = result->begin(); i != result->end(); 1190 for (AutocompleteResult::iterator i = result->begin(); i != result->end();
1107 ++i) { 1191 ++i) {
1108 if (((i->provider == keyword_provider_) && !i->keyword.empty()) || 1192 if (((i->provider == keyword_provider_) && !i->keyword.empty()) ||
1109 ((i->provider == search_provider_) && 1193 ((i->provider == search_provider_) &&
1110 (i->type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED || 1194 (i->type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED ||
1111 i->type == AutocompleteMatch::SEARCH_HISTORY || 1195 i->type == AutocompleteMatch::SEARCH_HISTORY ||
1112 i->type == AutocompleteMatch::SEARCH_SUGGEST))) { 1196 i->type == AutocompleteMatch::SEARCH_SUGGEST))) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 current_page_classification(current_page_classification), 1263 current_page_classification(current_page_classification),
1180 elapsed_time_since_user_first_modified_omnibox( 1264 elapsed_time_since_user_first_modified_omnibox(
1181 elapsed_time_since_user_first_modified_omnibox), 1265 elapsed_time_since_user_first_modified_omnibox),
1182 inline_autocompleted_length(inline_autocompleted_length), 1266 inline_autocompleted_length(inline_autocompleted_length),
1183 result(result), 1267 result(result),
1184 providers_info() { 1268 providers_info() {
1185 } 1269 }
1186 1270
1187 AutocompleteLog::~AutocompleteLog() { 1271 AutocompleteLog::~AutocompleteLog() {
1188 } 1272 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698