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

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: minor cleanup 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..3e61efcf19b5826e62180e80971bec84ba0a55d0 100644
--- a/components/search_engines/template_url_service.h
+++ b/components/search_engines/template_url_service.h
@@ -76,6 +76,13 @@ class TemplateURLService : public WebDataServiceConsumer,
typedef std::vector<TemplateURL*> TemplateURLVector;
typedef std::map<std::string, syncer::SyncData> SyncDataMap;
typedef base::CallbackList<void(void)>::Subscription Subscription;
+ // Under some matching regimes, we may want to treat the keyword in a
+ // TemplateURL as being a different length than it actually is. (There
+ // may be parts of the keyword that we consider not required and don't
+ // want to penalize for the user not typing those.)
+ typedef std::pair<TemplateURL*, size_t> TemplateURLAndEffectiveKeywordLength;
+ typedef std::vector<TemplateURLAndEffectiveKeywordLength>
+ TemplateURLMatchesVector;
// Struct used for initializing the data store with fake data.
// Each initializer is mapped to a TemplateURL.
@@ -125,7 +132,18 @@ class TemplateURLService : public WebDataServiceConsumer,
// TemplateURLs that support replacement are returned.
void FindMatchingKeywords(const base::string16& prefix,
bool support_replacement_only,
- TemplateURLVector* matches);
+ TemplateURLMatchesVector* matches);
+
+ // Returns (in |matches|) all TemplateURLs for auto-generated search engines
+ // with the domain name part of the keyword starts with |prefix|, sorted
+ // shortest domain-name-first. If |support_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 FindMatchingDomainKeywords(const base::string16& prefix,
+ bool support_replacement_only,
+ TemplateURLMatchesVector* matches);
// Looks up |keyword| and returns the element it maps to. Returns NULL if
// the keyword was not found.
@@ -382,8 +400,11 @@ class TemplateURLService : public WebDataServiceConsumer,
friend class InstantUnitTestBase;
friend class TemplateURLServiceTestUtil;
- typedef std::map<base::string16, TemplateURL*> KeywordToTemplateMap;
typedef std::map<std::string, TemplateURL*> GUIDToTemplateMap;
+ typedef std::map<base::string16, TemplateURLAndEffectiveKeywordLength>
+ KeywordToTemplateMap;
+ typedef std::multimap<base::string16, TemplateURLAndEffectiveKeywordLength>
+ KeywordDomainToTemplateMap;
// 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 +445,10 @@ 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 +633,17 @@ class TemplateURLService : public WebDataServiceConsumer,
// |template_urls| on exit.
void AddTemplateURLs(TemplateURLVector* template_urls);
+ // Returns (in |matches|) all TemplateURLs stored in |keyword_to_template_map|
+ // whose keywords begin with |prefix|, sorted shortest keyword-first. If
+ // |support_replacement_only| is true, only TemplateURLs that support
+ // replacement are returned.
+ template <typename Container>
+ void FindMatchingKeywordsHelper(
+ const Container& keyword_to_template_map,
+ const base::string16& prefix,
+ bool support_replacement_only,
+ TemplateURLMatchesVector* matches);
+
// Returns the TemplateURL corresponding to |prepopulated_id|, if any.
TemplateURL* FindPrepopulatedTemplateURL(int prepopulated_id);
@@ -650,6 +686,19 @@ class TemplateURLService : public WebDataServiceConsumer,
// Mapping from keyword to the TemplateURL.
KeywordToTemplateMap keyword_to_template_map_;
+ // Mapping from keyword domain to the TemplateURL. Precisely, for
+ // auto-generated keywords such as abc.def.com, we put the keyword in this
+ // map under the name def.com. This is a multimap because multiple keywords
+ // can have the same domain. 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 auto-generated keywords in which the keyword is the
+ // domain name, no host before the domain name. (The ordinary
+ // |keyword_to_template_map_| suffices for that.) Also, non-auto-generated
+ // keywords will not have entries in this map.
+ 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