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

Unified Diff: components/search_engines/template_url_service.h

Issue 1411543011: Omnibox: Make Keyword Provide More Generous with Matching (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: almost all of peter's comments Created 5 years, 1 month 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: components/search_engines/template_url_service.h
diff --git a/components/search_engines/template_url_service.h b/components/search_engines/template_url_service.h
index f77879cdab5ed455f5be883a18e9390dd9fd5ee5..bec701379f28c63ae39117ca30518cf53aa1ecde 100644
--- a/components/search_engines/template_url_service.h
+++ b/components/search_engines/template_url_service.h
@@ -72,10 +72,17 @@ class TemplateURLService : public WebDataServiceConsumer,
public KeyedService,
public syncer::SyncableService {
public:
- typedef std::map<std::string, std::string> QueryTerms;
- typedef std::vector<TemplateURL*> TemplateURLVector;
- typedef std::map<std::string, syncer::SyncData> SyncDataMap;
- typedef base::CallbackList<void(void)>::Subscription Subscription;
+ using QueryTerms = std::map<std::string, std::string>;
+ using TemplateURLVector = std::vector<TemplateURL*>;
+ using SyncDataMap = std::map<std::string, syncer::SyncData>;
+ using Subscription = base::CallbackList<void(void)>::Subscription;
+
+ // We may want to treat the keyword in a TemplateURL as being a different
+ // length than it actually is. For example, for keywords that end in a
+ // registry, e.g., '.com', we want to consider the registry characters not a
Peter Kasting 2015/11/12 20:36:11 Nit: not -> as not
Mark P 2015/11/12 21:42:49 Done.
+ // meaningful part of the keyword not penalize for the user not typing those.)
Peter Kasting 2015/11/12 20:36:11 Nit: not penalize -> and not penalize
Mark P 2015/11/12 21:42:49 Done.
+ using TURLAndMeaningfulLength = std::pair<TemplateURL*, size_t>;
+ using TURLsAndMeaningfulLengths = std::vector<TURLAndMeaningfulLength>;
// Struct used for initializing the data store with fake data.
// Each initializer is mapped to a TemplateURL.
@@ -120,12 +127,23 @@ class TemplateURLService : public WebDataServiceConsumer,
const GURL& url,
TemplateURL** template_url_to_replace);
- // Returns (in |matches|) all TemplateURLs whose keywords begin with |prefix|,
- // sorted shortest keyword-first. If |support_replacement_only| is true, only
+ // Adds to |matches| all TemplateURLs whose keywords begin with |prefix|,
+ // sorted shortest-keyword-first. If |supports_replacement_only| is true, only
// TemplateURLs that support replacement are returned.
- void FindMatchingKeywords(const base::string16& prefix,
- bool support_replacement_only,
- TemplateURLVector* matches);
+ void AddMatchingKeywords(const base::string16& prefix,
+ bool supports_replacement_only,
+ TURLsAndMeaningfulLengths* matches);
+
+ // Adds to |matches| all TemplateURLs for search engines with the domain
+ // name part of the keyword starts with |prefix|, sorted
+ // shortest-domain-name-first. If |supports_replacement_only| is true, only
+ // TemplateURLs that support replacement are returned. Does not bother
+ // searching/returning keywords that would've been found with an identical
+ // call to FindMatchingKeywords(); i.e., doesn't search keywords for which
+ // the domain name is the keyword.
+ void AddMatchingDomainKeywords(const base::string16& prefix,
+ bool supports_replacement_only,
+ TURLsAndMeaningfulLengths* matches);
// Looks up |keyword| and returns the element it maps to. Returns NULL if
// the keyword was not found.
@@ -382,8 +400,22 @@ class TemplateURLService : public WebDataServiceConsumer,
friend class InstantUnitTestBase;
friend class TemplateURLServiceTestUtil;
- typedef std::map<base::string16, TemplateURL*> KeywordToTemplateMap;
- typedef std::map<std::string, TemplateURL*> GUIDToTemplateMap;
+ using GUIDToTemplateMap = std::map<std::string, TemplateURL*>;
+
+ // A mapping from keywords to the corresponding TemplateURLs and their
+ // meaningful keyword lengths. A keyword can appear only once here because
+ // there can be only one active TemplateURL associated with a given keyword.
+ using KeywordToTemplateMap =
+ std::map<base::string16, TURLAndMeaningfulLength>;
+
+ // A mapping from domain names to corresponding TemplateURLs and their
+ // meaningful keyword lengths. Specifically, for a keyword that is a
+ // hostname containing more than just a domain name, e.g., 'abc.def.com',
+ // the keyword is added to this map under the domain key 'def.com'. This
+ // means multiple keywords from the same domain share the same key, so this
+ // must be a multimap.
+ using KeywordDomainToTemplateMap =
+ std::multimap<base::string16, TURLAndMeaningfulLength>;
// Declaration of values to be used in an enumerated histogram to tally
// changes to the default search provider from various entry points. In
@@ -424,6 +456,12 @@ class TemplateURLService : public WebDataServiceConsumer,
void AddToMaps(TemplateURL* template_url);
+ // ***
+ void RemoveFromDomainMap(const TemplateURL* template_url);
+
+ // ***
+ void AddToDomainMap(TemplateURL* template_url);
+
// Sets the keywords. This is used once the keywords have been loaded.
// This does NOT notify the delegate or the database.
//
@@ -608,6 +646,17 @@ class TemplateURLService : public WebDataServiceConsumer,
// |template_urls| on exit.
void AddTemplateURLs(TemplateURLVector* template_urls);
+ // Adds to |matches| all TemplateURLs stored in |keyword_to_template_map|
+ // whose keywords begin with |prefix|, sorted shortest-keyword-first. If
+ // |supports_replacement_only| is true, only TemplateURLs that support
+ // replacement are returned.
+ template <typename Container>
+ void AddMatchingKeywordsHelper(
+ const Container& keyword_to_template_map,
+ const base::string16& prefix,
+ bool supports_replacement_only,
+ TURLsAndMeaningfulLengths* matches);
+
// Returns the TemplateURL corresponding to |prepopulated_id|, if any.
TemplateURL* FindPrepopulatedTemplateURL(int prepopulated_id);
@@ -651,6 +700,17 @@ class TemplateURLService : public WebDataServiceConsumer,
// Mapping from keyword to the TemplateURL.
KeywordToTemplateMap keyword_to_template_map_;
+ // Mapping from keyword domain to the TemplateURL.
+ // Entries are only allowed here if there is a corresponding entry in
+ // |keyword_to_template_map_|, i.e., if a template URL doesn't have an entry
+ // in |keyword_to_template_map_| because it's subsumed by another template
+ // URL with an identical keyword, the template URL will not have an entry in
+ // this map either. This map will also not bother including entries for
+ // keywords in which the keyword is the domain name, no host/sub-domain
Peter Kasting 2015/11/12 20:36:11 Nit: no host/sub-domain -> with no subdomain
Mark P 2015/11/12 21:42:49 Done.
+ // before the domain name. (The ordinary |keyword_to_template_map_|
+ // suffices for that.)
+ KeywordDomainToTemplateMap keyword_domain_to_template_map_;
+
// Mapping from Sync GUIDs to the TemplateURL.
GUIDToTemplateMap guid_to_template_map_;

Powered by Google App Engine
This is Rietveld 408576698