Chromium Code Reviews| Index: chrome/browser/autocomplete/autocomplete.cc |
| diff --git a/chrome/browser/autocomplete/autocomplete.cc b/chrome/browser/autocomplete/autocomplete.cc |
| index 4f87500830bd40e23c106072b9e2452f9e475de3..6ce6336e3b890e43c6d18ffc4ae31e2b27222ea8 100644 |
| --- a/chrome/browser/autocomplete/autocomplete.cc |
| +++ b/chrome/browser/autocomplete/autocomplete.cc |
| @@ -14,6 +14,7 @@ |
| #include "base/metrics/histogram.h" |
| #include "base/string_number_conversions.h" |
| #include "base/string_util.h" |
| +#include "base/stringprintf.h" |
| #include "base/utf_string_conversions.h" |
| #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h" |
| #include "chrome/browser/autocomplete/autocomplete_match.h" |
| @@ -53,6 +54,45 @@ |
| using base::TimeDelta; |
| +namespace { |
| + |
| +// 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.
|
| +int AutocompleteMatchToAssistedQueryType(const AutocompleteMatch::Type& type) { |
| + switch (type) { |
| + 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.
|
| + return 0; |
| + case AutocompleteMatch::NAVSUGGEST: |
| + return 5; |
| + case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED: |
| + return 57; |
| + case AutocompleteMatch::URL_WHAT_YOU_TYPED: |
| + return 58; |
| + case AutocompleteMatch::SEARCH_HISTORY: |
| + return 59; |
| + case AutocompleteMatch::HISTORY_URL: |
| + return 60; |
| + case AutocompleteMatch::HISTORY_TITLE: |
| + return 61; |
| + case AutocompleteMatch::HISTORY_BODY: |
| + return 62; |
| + case AutocompleteMatch::HISTORY_KEYWORD: |
| + return 63; |
| + default: |
| + return 64; |
| + } |
| +} |
| + |
| +// Appends query stats of the given type and number to the existing AQS string. |
| +void AppendQueryStats(int type, int count, std::string* aqs) { |
| + if (!aqs->empty()) |
| + aqs->append("j"); |
| + base::StringAppendF(aqs, "%d", type); |
| + if (count > 1) |
| + base::StringAppendF(aqs, "l%d", count); |
| +} |
| + |
| +} // namespace |
| + |
| // AutocompleteInput ---------------------------------------------------------- |
| AutocompleteInput::AutocompleteInput() |
| @@ -1044,6 +1084,7 @@ void AutocompleteController::UpdateResult(bool is_synchronous_pass) { |
| UpdateKeywordDescriptions(&result_); |
| UpdateAssociatedKeywords(&result_); |
| + UpdateAssistedQueryStats(&result_); |
| bool notify_default_match = is_synchronous_pass; |
| if (!is_synchronous_pass) { |
| @@ -1100,6 +1141,45 @@ void AutocompleteController::UpdateAssociatedKeywords( |
| } |
| } |
| +void AutocompleteController::UpdateAssistedQueryStats( |
| + AutocompleteResult* result) { |
| + if (result->empty()) |
| + return; |
| + |
| + // Build the impressions string (the AQS part after "."). |
| + std::string aqs; |
| + int count = 0; |
| + int last_type = -1; |
| + for (ACMatches::iterator match(result->begin()); match != result->end(); |
| + ++match) { |
| + int type = AutocompleteMatchToAssistedQueryType(match->type); |
| + if (last_type != -1 && type != last_type) { |
| + AppendQueryStats(last_type, count, &aqs); |
| + count = 1; |
| + } else { |
| + count++; |
| + } |
| + last_type = type; |
| + } |
| + AppendQueryStats(last_type, count, &aqs); |
| + |
| + // 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
|
| + int index = 0; |
| + for (ACMatches::iterator match(result->begin()); match != result->end(); |
| + ++match, ++index) { |
| + if (match->provider != search_provider_) |
| + continue; |
| + const TemplateURL* template_url = match->GetTemplateURL(profile_); |
| + if (!template_url || !template_url->url_ref().SupportsAssistedQueryStats()) |
| + continue; |
| + std::string url(match->destination_url.spec()); |
| + if (url.find("&aqs=") != std::string::npos) |
| + continue; |
| + url.append(base::StringPrintf("&aqs=%d", index)).append(".").append(aqs); |
| + match->destination_url = GURL(url); |
| + } |
| +} |
| + |
| void AutocompleteController::UpdateKeywordDescriptions( |
| AutocompleteResult* result) { |
| string16 last_keyword; |