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

Unified Diff: chrome/browser/autocomplete/shortcuts_backend.cc

Issue 165163002: Handle Search suggest subtypes for Shortcuts DB (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased on refactoring Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autocomplete/shortcuts_backend.cc
diff --git a/chrome/browser/autocomplete/shortcuts_backend.cc b/chrome/browser/autocomplete/shortcuts_backend.cc
index b7d5d780a16a96bdf486113031e85ca63389d819..c099a7faf8f71efee114165d2dd196020048e0ae 100644
--- a/chrome/browser/autocomplete/shortcuts_backend.cc
+++ b/chrome/browser/autocomplete/shortcuts_backend.cc
@@ -21,6 +21,7 @@
#include "chrome/browser/history/shortcuts_database.h"
#include "chrome/browser/omnibox/omnibox_log.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/autocomplete_match_type.h"
#include "chrome/common/chrome_constants.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_details.h"
@@ -31,6 +32,32 @@ using content::BrowserThread;
namespace {
+const GURL GetDestinationURLForShortcut(
Peter Kasting 2014/03/21 18:36:26 Discussed briefly in person: Let's use CreateSearc
Anuj 2014/03/24 07:16:16 The simple implementation doesn't seem too bad.
+ const AutocompleteMatch& match,
+ Profile* profile) {
+ if (AutocompleteMatch::IsSearchSuggestType(match.type) && profile) {
+ scoped_ptr<TemplateURLRef::SearchTermsArgs> search_terms_args(
+ new TemplateURLRef::SearchTermsArgs(match.fill_into_edit));
+ const TemplateURL* template_url = match.GetTemplateURL(profile, false);
+ if (template_url) {
+ return GURL(template_url->url_ref().ReplaceSearchTerms(
+ *search_terms_args.get()));
+ }
+ }
+ return match.destination_url;
+}
+
+const base::string16 GetContentsForShortcut(const AutocompleteMatch& match) {
+ return AutocompleteMatch::IsSearchSuggestType(match.type) ?
+ match.fill_into_edit : match.contents;
+}
+
+const base::string16 GetDescriptionForShortcut(const AutocompleteMatch& match) {
+ return (match.type == AutocompleteMatchType::SEARCH_SUGGEST_ENTITY ||
+ match.type == AutocompleteMatchType::SEARCH_SUGGEST_PROFILE) ?
+ base::string16() : match.description;
+}
+
// Takes Match classification vector and removes all matched positions,
// compacting repetitions if necessary.
std::string StripMatchMarkers(const ACMatchClassifications& matches) {
@@ -43,6 +70,13 @@ std::string StripMatchMarkers(const ACMatchClassifications& matches) {
return AutocompleteMatch::ClassificationsToString(unmatched);
}
+std::string GetClassificationsForShortcut(
+ AutocompleteMatchType::Type type,
+ const ACMatchClassifications& classifications) {
+ return AutocompleteMatch::IsSearchSuggestType(type) ?
+ "" : StripMatchMarkers(classifications);
+}
+
// Normally shortcuts have the same match type as the original match they were
// created from, but for certain match types, we should modify the shortcut's
// type slightly to reflect that the origin of the shortcut is historical.
@@ -52,16 +86,12 @@ AutocompleteMatch::Type GetTypeForShortcut(AutocompleteMatch::Type type) {
case AutocompleteMatchType::NAVSUGGEST:
return AutocompleteMatchType::HISTORY_URL;
- case AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED:
- case AutocompleteMatchType::SEARCH_SUGGEST:
- case AutocompleteMatchType::SEARCH_SUGGEST_ENTITY:
- case AutocompleteMatchType::SEARCH_SUGGEST_INFINITE:
- case AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED:
- case AutocompleteMatchType::SEARCH_SUGGEST_PROFILE:
- return AutocompleteMatchType::SEARCH_HISTORY;
+ case AutocompleteMatchType::SEARCH_OTHER_ENGINE:
+ return type;
default:
- return type;
+ return AutocompleteMatch::IsSearchType(type) ?
+ AutocompleteMatchType::SEARCH_HISTORY : type;
}
}
@@ -71,7 +101,8 @@ AutocompleteMatch::Type GetTypeForShortcut(AutocompleteMatch::Type type) {
// ShortcutsBackend -----------------------------------------------------------
ShortcutsBackend::ShortcutsBackend(Profile* profile, bool suppress_db)
- : current_state_(NOT_INITIALIZED),
+ : profile_(profile),
+ current_state_(NOT_INITIALIZED),
no_db_access_(suppress_db) {
if (!suppress_db) {
db_ = new history::ShortcutsDatabase(
@@ -124,13 +155,13 @@ void ShortcutsBackend::AddOrUpdateShortcut(const base::string16& text,
StartsWith(it->first, text_lowercase, true); ++it) {
if (match.destination_url == it->second.match_core.destination_url) {
UpdateShortcut(history::ShortcutsDatabase::Shortcut(
- it->second.id, text, MatchToMatchCore(match), now,
+ it->second.id, text, MatchToMatchCore(match, profile_), now,
it->second.number_of_hits + 1));
return;
}
}
AddShortcut(history::ShortcutsDatabase::Shortcut(
- base::GenerateGUID(), text, MatchToMatchCore(match), now, 1));
+ base::GenerateGUID(), text, MatchToMatchCore(match, profile_), now, 1));
}
ShortcutsBackend::~ShortcutsBackend() {
@@ -138,12 +169,18 @@ ShortcutsBackend::~ShortcutsBackend() {
// static
history::ShortcutsDatabase::Shortcut::MatchCore
- ShortcutsBackend::MatchToMatchCore(const AutocompleteMatch& match) {
+ ShortcutsBackend::MatchToMatchCore(const AutocompleteMatch& match,
+ Profile* profile) {
return history::ShortcutsDatabase::Shortcut::MatchCore(
- match.fill_into_edit, match.destination_url, match.contents,
- StripMatchMarkers(match.contents_class), match.description,
- StripMatchMarkers(match.description_class), match.transition,
- GetTypeForShortcut(match.type), match.keyword);
+ match.fill_into_edit,
+ GetDestinationURLForShortcut(match, profile),
+ GetContentsForShortcut(match),
+ GetClassificationsForShortcut(match.type, match.contents_class),
+ GetDescriptionForShortcut(match),
+ GetClassificationsForShortcut(match.type, match.description_class),
+ match.transition,
+ GetTypeForShortcut(match.type),
+ match.keyword);
}
void ShortcutsBackend::ShutdownOnUIThread() {

Powered by Google App Engine
This is Rietveld 408576698