diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-13 00:19:00 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-13 00:19:00 +0000 |
commit | 4c1fb7ec9e85150afcbc7f3e0c2cbe788e31e9de (patch) | |
tree | 114c7194a922ef8c6dfdea7ebbc38f41abf8588a | |
parent | d7cbf44926f66dde008ef8a6b8141ec8a774692c (diff) | |
download | chromium_src-4c1fb7ec9e85150afcbc7f3e0c2cbe788e31e9de.zip chromium_src-4c1fb7ec9e85150afcbc7f3e0c2cbe788e31e9de.tar.gz chromium_src-4c1fb7ec9e85150afcbc7f3e0c2cbe788e31e9de.tar.bz2 |
Omnibox metrics logging patch splitout, part 5: Add additional AutocompleteMatch types, and pass a type to the AutocompleteMatch constructor. The added detail in the new types is not used for anything functional; its sole purpose is for metric logging. Someday we could probably update other bits of the code to make use of this, though (e.g. the paste-and-search vs. paste-and-go determinant code).
These are separable changes, but doing either one without the other would have required an annoying number of fragile temporary changes.
Review URL: http://codereview.chromium.org/10855
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5329 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/autocomplete/autocomplete.cc | 23 | ||||
-rw-r--r-- | chrome/browser/autocomplete/autocomplete.h | 38 | ||||
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit.cc | 4 | ||||
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_popup.cc | 4 | ||||
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_unittest.cc | 7 | ||||
-rw-r--r-- | chrome/browser/autocomplete/history_contents_provider.cc | 3 | ||||
-rw-r--r-- | chrome/browser/autocomplete/history_url_provider.cc | 5 | ||||
-rw-r--r-- | chrome/browser/autocomplete/keyword_provider.cc | 4 | ||||
-rw-r--r-- | chrome/browser/autocomplete/search_provider.cc | 16 | ||||
-rw-r--r-- | chrome/browser/autocomplete/search_provider.h | 1 |
10 files changed, 58 insertions, 47 deletions
diff --git a/chrome/browser/autocomplete/autocomplete.cc b/chrome/browser/autocomplete/autocomplete.cc index e2c89c1..5d2fb87 100644 --- a/chrome/browser/autocomplete/autocomplete.cc +++ b/chrome/browser/autocomplete/autocomplete.cc @@ -253,14 +253,15 @@ void AutocompleteInput::Clear() { AutocompleteMatch::AutocompleteMatch(AutocompleteProvider* provider, int relevance, - bool deletable) + bool deletable, + Type type) : provider(provider), relevance(relevance), deletable(deletable), inline_autocomplete_offset(std::wstring::npos), transition(PageTransition::TYPED), is_history_what_you_typed_match(false), - type(URL), + type(type), template_url(NULL), starred(false) { } @@ -268,10 +269,17 @@ AutocompleteMatch::AutocompleteMatch(AutocompleteProvider* provider, // static std::string AutocompleteMatch::TypeToString(Type type) { switch (type) { - case URL: return "url"; - case KEYWORD: return "keyword"; - case SEARCH: return "search"; - case HISTORY_SEARCH: return "history"; + case URL_WHAT_YOU_TYPED: return "url-what-you-typed"; + case HISTORY_URL: return "history-url"; + case HISTORY_TITLE: return "history-title"; + case HISTORY_BODY: return "history-body"; + case HISTORY_KEYWORD: return "history-keyword"; + case NAVSUGGEST: return "navsuggest"; + case SEARCH_WHAT_YOU_TYPED: return "search-what-you-typed"; + case SEARCH_HISTORY: return "search-history"; + case SEARCH_SUGGEST: return "search-suggest"; + case SEARCH_OTHER_ENGINE: return "search-other-engine"; + case OPEN_HISTORY_PAGE: return "open-history-page"; default: NOTREACHED(); @@ -762,8 +770,7 @@ void AutocompleteController::AddHistoryContentsShortcut() { } // else, fall through and add item. } - AutocompleteMatch match(NULL, 0, false); - match.type = AutocompleteMatch::HISTORY_SEARCH; + AutocompleteMatch match(NULL, 0, false, AutocompleteMatch::OPEN_HISTORY_PAGE); match.fill_into_edit = input_.text(); // Mark up the text such that the user input text is bold. diff --git a/chrome/browser/autocomplete/autocomplete.h b/chrome/browser/autocomplete/autocomplete.h index 1c94cf9..71da6ef 100644 --- a/chrome/browser/autocomplete/autocomplete.h +++ b/chrome/browser/autocomplete/autocomplete.h @@ -276,33 +276,27 @@ struct AutocompleteMatch { typedef std::vector<ACMatchClassification> ACMatchClassifications; // The type of this match. - // URL: a url, typically one the user previously entered but it may have - // also been suggested. This is the default. - // KEYWORD: a keyword. - // SEARCH: short cut for typing type into the Google homepage. This should - // only be used if the full URL is not shown. enum Type { - // Something that looks like a URL ("http://foo.com", "internal-server/"). - // This is the default. - URL, - - // A manually created or auto-generated keyword, with or without a query - // component. Auto-generated keywords may look similar to urls. See - // keyword_autocomplete.cc. - KEYWORD, - - // A search term or phrase for the user's default search provider - // ("games", "foo"). These visually look similar to keywords. See - // google_autocomplete.cc. - SEARCH, - - // Shortcut that takes the user to destinations->history. - HISTORY_SEARCH + URL_WHAT_YOU_TYPED, // The input as a URL. + HISTORY_URL, // A past page whose URL contains the input. + HISTORY_TITLE, // A past page whose title contains the input. + HISTORY_BODY, // A past page whose body contains the input. + HISTORY_KEYWORD, // A past page whose keyword contains the input. + NAVSUGGEST, // A suggested URL. + SEARCH_WHAT_YOU_TYPED, // The input as a search query (with the default + // engine). + SEARCH_HISTORY, // A past search (with the default engine) + // containing the input. + SEARCH_SUGGEST, // A suggested search (with the default engine). + SEARCH_OTHER_ENGINE, // A search with a non-default engine. + OPEN_HISTORY_PAGE, // A synthetic result that opens the history page to + // search for the input. }; AutocompleteMatch(AutocompleteProvider* provider, int relevance, - bool deletable); + bool deletable, + Type type); // Converts |type| to a string representation. Used in logging. static std::string TypeToString(Type type); diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc index f9cd006..680c851 100644 --- a/chrome/browser/autocomplete/autocomplete_edit.cc +++ b/chrome/browser/autocomplete/autocomplete_edit.cc @@ -439,7 +439,9 @@ void AutocompleteEditModel::OnPopupDataChanged( // selected keyword, or (subtle!) if we would be showing a selected keyword // but for keyword_ui_state_ == NO_KEYWORD. const bool show_search_hint = keyword.empty() && - (type == AutocompleteMatch::SEARCH); + ((type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED) || + (type == AutocompleteMatch::SEARCH_HISTORY) || + (type == AutocompleteMatch::SEARCH_SUGGEST)); // Update keyword/hint-related local state. bool keyword_state_changed = (keyword_ != keyword) || diff --git a/chrome/browser/autocomplete/autocomplete_popup.cc b/chrome/browser/autocomplete/autocomplete_popup.cc index 5a457c9..e355813 100644 --- a/chrome/browser/autocomplete/autocomplete_popup.cc +++ b/chrome/browser/autocomplete/autocomplete_popup.cc @@ -527,7 +527,7 @@ void AutocompletePopupView::DrawEntry(HDC dc, const AutocompleteMatch& match = model_->result().match_at(line); if ((description_width < (line_info_.ave_char_width * 20)) || all_descriptions_empty || - (match.type == AutocompleteMatch::HISTORY_SEARCH)) { + (match.type == AutocompleteMatch::OPEN_HISTORY_PAGE)) { star_x = description_max_x - star_col_width + kStarPadding; DrawMatchFragments(dc, match.contents, match.contents_class, content_min_x, y, star_x - kStarPadding, status); @@ -951,7 +951,7 @@ void AutocompletePopupModel::Observe(NotificationType type, std::wstring inline_autocomplete_text; std::wstring keyword; bool is_keyword_hint = false; - AutocompleteMatch::Type type = AutocompleteMatch::SEARCH; + AutocompleteMatch::Type type = AutocompleteMatch::SEARCH_WHAT_YOU_TYPED; const AutocompleteResult::const_iterator match(result.default_match()); if (match != result.end()) { if ((match->inline_autocomplete_offset != std::wstring::npos) && diff --git a/chrome/browser/autocomplete/autocomplete_unittest.cc b/chrome/browser/autocomplete/autocomplete_unittest.cc index 386207c..a945a5b 100644 --- a/chrome/browser/autocomplete/autocomplete_unittest.cc +++ b/chrome/browser/autocomplete/autocomplete_unittest.cc @@ -69,7 +69,8 @@ void TestProvider::Run() { void TestProvider::AddResults(int start_at, int num) { for (int i = start_at; i < num; i++) { - AutocompleteMatch match(this, relevance_ - i, false); + AutocompleteMatch match(this, relevance_ - i, false, + AutocompleteMatch::URL_WHAT_YOU_TYPED); wchar_t str[16]; swprintf_s(str, L"%d", i); @@ -257,8 +258,8 @@ TEST(AutocompleteMatch, MoreRelevant) { { -5, -10, false }, }; - AutocompleteMatch m1(NULL, 0, false); - AutocompleteMatch m2(NULL, 0, false); + AutocompleteMatch m1(NULL, 0, false, AutocompleteMatch::URL_WHAT_YOU_TYPED); + AutocompleteMatch m2(NULL, 0, false, AutocompleteMatch::URL_WHAT_YOU_TYPED); for (int i = 0; i < arraysize(cases); ++i) { m1.relevance = cases[i].r1; diff --git a/chrome/browser/autocomplete/history_contents_provider.cc b/chrome/browser/autocomplete/history_contents_provider.cc index 1d3ed28..9eef77c 100644 --- a/chrome/browser/autocomplete/history_contents_provider.cc +++ b/chrome/browser/autocomplete/history_contents_provider.cc @@ -192,7 +192,8 @@ AutocompleteMatch HistoryContentsProvider::ResultToMatch( int score) { // TODO(sky): if matched title highlight matching words in title. // Also show star in popup. - AutocompleteMatch match(this, score, false); + AutocompleteMatch match(this, score, false, MatchInTitle(result) ? + AutocompleteMatch::HISTORY_TITLE : AutocompleteMatch::HISTORY_BODY); match.fill_into_edit = StringForURLDisplay(result.url(), true); match.destination_url = UTF8ToWide(result.url().spec()); match.contents = match.fill_into_edit; diff --git a/chrome/browser/autocomplete/history_url_provider.cc b/chrome/browser/autocomplete/history_url_provider.cc index 01293db..175fca4 100644 --- a/chrome/browser/autocomplete/history_url_provider.cc +++ b/chrome/browser/autocomplete/history_url_provider.cc @@ -219,7 +219,8 @@ void HistoryURLProvider::QueryComplete( void HistoryURLProvider::SuggestExactInput(const AutocompleteInput& input, bool trim_http) { AutocompleteMatch match(this, - CalculateRelevance(input.type(), WHAT_YOU_TYPED, 0), false); + CalculateRelevance(input.type(), WHAT_YOU_TYPED, 0), false, + AutocompleteMatch::URL_WHAT_YOU_TYPED); // Try to canonicalize the URL. If this fails, don't create a What You Typed // suggestion, since it can't be navigated to. We also need this so other @@ -796,7 +797,7 @@ AutocompleteMatch HistoryURLProvider::HistoryMatchToACMatch( const history::URLRow& info = history_match.url_info; AutocompleteMatch match(this, CalculateRelevance(params->input.type(), match_type, match_number), - !!info.visit_count()); + !!info.visit_count(), AutocompleteMatch::HISTORY_URL); match.destination_url = UTF8ToWide(info.url().possibly_invalid_spec()); match.fill_into_edit = gfx::ElideUrl(info.url(), ChromeFont(), 0, match_type == WHAT_YOU_TYPED ? std::wstring() : params->languages); diff --git a/chrome/browser/autocomplete/keyword_provider.cc b/chrome/browser/autocomplete/keyword_provider.cc index 7c9f55b..79c7a08 100644 --- a/chrome/browser/autocomplete/keyword_provider.cc +++ b/chrome/browser/autocomplete/keyword_provider.cc @@ -248,8 +248,8 @@ AutocompleteMatch KeywordProvider::CreateAutocompleteMatch( // preference, score them highly regardless of whether // the input provides query text. input.prefer_keyword() || !supports_replacement), - false); - result.type = AutocompleteMatch::KEYWORD; + false, supports_replacement ? AutocompleteMatch::SEARCH_OTHER_ENGINE : + AutocompleteMatch::HISTORY_KEYWORD); result.fill_into_edit.assign(keyword); if (!remaining_input.empty() || !keyword_complete || supports_replacement) result.fill_into_edit.push_back(L' '); diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc index 2a2ec53..47ccdd8 100644 --- a/chrome/browser/autocomplete/search_provider.cc +++ b/chrome/browser/autocomplete/search_provider.cc @@ -61,7 +61,8 @@ void SearchProvider::Start(const AutocompleteInput& input, if (input.text().empty()) { // User typed "?" alone. Give them a placeholder result indicating what // this syntax does. - AutocompleteMatch match(this, 0, false); + AutocompleteMatch match(this, 0, false, + AutocompleteMatch::SEARCH_WHAT_YOU_TYPED); static const std::wstring kNoQueryInput( l10n_util::GetString(IDS_AUTOCOMPLETE_NO_QUERY)); match.contents.assign(l10n_util::GetStringF( @@ -69,7 +70,6 @@ void SearchProvider::Start(const AutocompleteInput& input, kNoQueryInput)); match.contents_class.push_back( ACMatchClassification(0, ACMatchClassification::DIM)); - match.type = AutocompleteMatch::SEARCH; matches_.push_back(match); Stop(); return; @@ -342,16 +342,19 @@ void SearchProvider::ConvertResultsToAutocompleteMatches() { TemplateURLRef::NO_SUGGESTION_CHOSEN; const Time no_time; AddMatchToMap(input_.text(), CalculateRelevanceForWhatYouTyped(), + AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, did_not_accept_suggestion, &map); for (HistoryResults::const_iterator i(history_results_.begin()); i != history_results_.end(); ++i) { AddMatchToMap(i->term, CalculateRelevanceForHistory(i->time), - did_not_accept_suggestion, &map); + AutocompleteMatch::SEARCH_HISTORY, did_not_accept_suggestion, + &map); } for (size_t i = 0; i < suggest_results_.size(); ++i) { AddMatchToMap(suggest_results_[i], CalculateRelevanceForSuggestion(i), + AutocompleteMatch::SEARCH_SUGGEST, static_cast<int>(i), &map); } @@ -485,10 +488,10 @@ int SearchProvider::CalculateRelevanceForNavigation( void SearchProvider::AddMatchToMap(const std::wstring& query_string, int relevance, + AutocompleteMatch::Type type, int accepted_suggestion, MatchMap* map) { - AutocompleteMatch match(this, relevance, false); - match.type = AutocompleteMatch::SEARCH; + AutocompleteMatch match(this, relevance, false, type); std::vector<size_t> content_param_offsets; match.contents.assign(l10n_util::GetStringF(IDS_AUTOCOMPLETE_SEARCH_CONTENTS, default_provider_.short_name(), @@ -559,7 +562,8 @@ void SearchProvider::AddMatchToMap(const std::wstring& query_string, AutocompleteMatch SearchProvider::NavigationToMatch( const NavigationResult& navigation, int relevance) { - AutocompleteMatch match(this, relevance, false); + AutocompleteMatch match(this, relevance, false, + AutocompleteMatch::NAVSUGGEST); match.destination_url = navigation.url; match.contents = StringForURLDisplay(GURL(navigation.url), true); // TODO(kochi): Consider moving HistoryURLProvider::TrimHttpPrefix() to some diff --git a/chrome/browser/autocomplete/search_provider.h b/chrome/browser/autocomplete/search_provider.h index e6030dc..07eb8c8 100644 --- a/chrome/browser/autocomplete/search_provider.h +++ b/chrome/browser/autocomplete/search_provider.h @@ -128,6 +128,7 @@ class SearchProvider : public AutocompleteProvider, // exists, whichever one has lower relevance is eliminated. void AddMatchToMap(const std::wstring& query_string, int relevance, + AutocompleteMatch::Type type, int accepted_suggestion, MatchMap* map); // Returns an AutocompleteMatch for a navigational suggestion. |