Chromium Code Reviews| 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.) |
|
Peter Kasting
2015/11/09 23:11:15
Nit: How about: "For keywords that end in a TLD, e
Mark P
2015/11/11 07:41:01
I find this confusing. I don't know what your exp
|
| + typedef std::pair<TemplateURL*, size_t> TemplateURLAndEffectiveKeywordLength; |
|
Peter Kasting
2015/11/09 23:11:16
Nit: This is excessively verbose; call this TURLAn
Mark P
2015/11/11 07:41:01
Done, except used Meaningful, not Effective, per y
|
| + typedef std::vector<TemplateURLAndEffectiveKeywordLength> |
| + TemplateURLMatchesVector; |
|
Peter Kasting
2015/11/09 23:11:15
Nit: Don't put "Vector" in the typedef name, and "
Mark P
2015/11/11 07:41:01
Makes sense to me. Done (except using meaningful,
|
| // 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 |
|
Peter Kasting
2015/11/09 23:11:15
Nit: with -> where
Be careful using "domain name"
Mark P
2015/11/11 07:41:01
Done.
|
| + // shortest domain-name-first. If |support_replacement_only| is true, only |
|
Peter Kasting
2015/11/09 23:11:15
Nit: Also hyphen after "shortest". Also we should
Mark P
2015/11/11 07:41:01
Done.
Also we should probably rename
|
| + // 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> |
|
Peter Kasting
2015/11/09 23:11:15
Nit: The Chromium C++11 guide says to prefer type
Mark P
2015/11/11 07:41:01
Revised this whole .h file accordingly.
|
| + KeywordToTemplateMap; |
| + typedef std::multimap<base::string16, TemplateURLAndEffectiveKeywordLength> |
| + KeywordDomainToTemplateMap; |
|
Peter Kasting
2015/11/09 23:11:15
Nit: Add comments to describe each of these maps,
Mark P
2015/11/11 07:41:01
Done.
Peter Kasting
2015/11/12 20:36:10
Seems OK to me.
Peter Kasting
2015/11/12 22:32:11
You didn't make these changes.
Mark P
2015/11/12 23:18:41
Now done. Also changed the names of the internal
|
| // 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); |
|
Peter Kasting
2015/11/09 23:11:15
Nit: Please add comments for all these functions w
Mark P
2015/11/12 20:13:03
Done. (Added comments to all these Add/Remove fun
|
| + |
| // 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 |
|
Peter Kasting
2015/11/09 23:11:16
Nit: Also hyphen after "shortest"
Mark P
2015/11/11 07:41:01
Done.
|
| + // |support_replacement_only| is true, only TemplateURLs that support |
|
Peter Kasting
2015/11/09 23:11:16
Nit: support_ -> supports_
Mark P
2015/11/11 07:41:01
Done.
|
| + // 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 |
|
Peter Kasting
2015/11/09 23:11:15
Nit: Blank line above
Mark P
2015/11/11 07:41:01
Done.
|
| + // 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. |
|
Peter Kasting
2015/11/09 23:11:16
How about this comment:
Mapping from TLD+1s to co
Mark P
2015/11/11 07:41:01
Done. Used the first paragraph of the comment by
|
| + KeywordDomainToTemplateMap keyword_domain_to_template_map_; |
| // Mapping from Sync GUIDs to the TemplateURL. |
| GUIDToTemplateMap guid_to_template_map_; |