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

Side by Side 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: == -> >= 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ 5 #ifndef COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_
6 #define COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ 6 #define COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_
7 7
8 #include <list> 8 #include <list>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 // otherwise TemplateURLService handles deletion. 69 // otherwise TemplateURLService handles deletion.
70 70
71 class TemplateURLService : public WebDataServiceConsumer, 71 class TemplateURLService : public WebDataServiceConsumer,
72 public KeyedService, 72 public KeyedService,
73 public syncer::SyncableService { 73 public syncer::SyncableService {
74 public: 74 public:
75 typedef std::map<std::string, std::string> QueryTerms; 75 typedef std::map<std::string, std::string> QueryTerms;
76 typedef std::vector<TemplateURL*> TemplateURLVector; 76 typedef std::vector<TemplateURL*> TemplateURLVector;
77 typedef std::map<std::string, syncer::SyncData> SyncDataMap; 77 typedef std::map<std::string, syncer::SyncData> SyncDataMap;
78 typedef base::CallbackList<void(void)>::Subscription Subscription; 78 typedef base::CallbackList<void(void)>::Subscription Subscription;
79 // Under some matching regimes, we may want to treat the keyword in a
80 // TemplateURL as being a different length than it actually is. (There
81 // may be parts of the keyword that we consider not required and don't
82 // 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
83 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
84 typedef std::vector<TemplateURLAndEffectiveKeywordLength>
85 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,
79 86
80 // Struct used for initializing the data store with fake data. 87 // Struct used for initializing the data store with fake data.
81 // Each initializer is mapped to a TemplateURL. 88 // Each initializer is mapped to a TemplateURL.
82 struct Initializer { 89 struct Initializer {
83 const char* const keyword; 90 const char* const keyword;
84 const char* const url; 91 const char* const url;
85 const char* const content; 92 const char* const content;
86 }; 93 };
87 94
88 struct URLVisitedDetails { 95 struct URLVisitedDetails {
(...skipping 29 matching lines...) Expand all
118 // a keyword for hosts already associated with a manually-edited keyword. 125 // a keyword for hosts already associated with a manually-edited keyword.
119 bool CanAddAutogeneratedKeyword(const base::string16& keyword, 126 bool CanAddAutogeneratedKeyword(const base::string16& keyword,
120 const GURL& url, 127 const GURL& url,
121 TemplateURL** template_url_to_replace); 128 TemplateURL** template_url_to_replace);
122 129
123 // Returns (in |matches|) all TemplateURLs whose keywords begin with |prefix|, 130 // Returns (in |matches|) all TemplateURLs whose keywords begin with |prefix|,
124 // sorted shortest keyword-first. If |support_replacement_only| is true, only 131 // sorted shortest keyword-first. If |support_replacement_only| is true, only
125 // TemplateURLs that support replacement are returned. 132 // TemplateURLs that support replacement are returned.
126 void FindMatchingKeywords(const base::string16& prefix, 133 void FindMatchingKeywords(const base::string16& prefix,
127 bool support_replacement_only, 134 bool support_replacement_only,
128 TemplateURLVector* matches); 135 TemplateURLMatchesVector* matches);
136
137 // Returns (in |matches|) all TemplateURLs for auto-generated search engines
138 // 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.
139 // 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
140 // TemplateURLs that support replacement are returned. Does not bother
141 // searching/returning keywords that would've been found with an identical
142 // call to FindMatchingKeywords(); i.e., doesn't search keywords for which
143 // the domain name is the keyword.
144 void FindMatchingDomainKeywords(const base::string16& prefix,
145 bool support_replacement_only,
146 TemplateURLMatchesVector* matches);
129 147
130 // Looks up |keyword| and returns the element it maps to. Returns NULL if 148 // Looks up |keyword| and returns the element it maps to. Returns NULL if
131 // the keyword was not found. 149 // the keyword was not found.
132 // The caller should not try to delete the returned pointer; the data store 150 // The caller should not try to delete the returned pointer; the data store
133 // retains ownership of it. 151 // retains ownership of it.
134 TemplateURL* GetTemplateURLForKeyword(const base::string16& keyword); 152 TemplateURL* GetTemplateURLForKeyword(const base::string16& keyword);
135 153
136 // Returns that TemplateURL with the specified GUID, or NULL if not found. 154 // Returns that TemplateURL with the specified GUID, or NULL if not found.
137 // The caller should not try to delete the returned pointer; the data store 155 // The caller should not try to delete the returned pointer; the data store
138 // retains ownership of it. 156 // retains ownership of it.
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, 393 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest,
376 IsLocalTemplateURLBetter); 394 IsLocalTemplateURLBetter);
377 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, 395 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest,
378 ResolveSyncKeywordConflict); 396 ResolveSyncKeywordConflict);
379 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, PreSyncDeletes); 397 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, PreSyncDeletes);
380 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, MergeInSyncTemplateURL); 398 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, MergeInSyncTemplateURL);
381 399
382 friend class InstantUnitTestBase; 400 friend class InstantUnitTestBase;
383 friend class TemplateURLServiceTestUtil; 401 friend class TemplateURLServiceTestUtil;
384 402
385 typedef std::map<base::string16, TemplateURL*> KeywordToTemplateMap;
386 typedef std::map<std::string, TemplateURL*> GUIDToTemplateMap; 403 typedef std::map<std::string, TemplateURL*> GUIDToTemplateMap;
404 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.
405 KeywordToTemplateMap;
406 typedef std::multimap<base::string16, TemplateURLAndEffectiveKeywordLength>
407 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
387 408
388 // Declaration of values to be used in an enumerated histogram to tally 409 // Declaration of values to be used in an enumerated histogram to tally
389 // changes to the default search provider from various entry points. In 410 // changes to the default search provider from various entry points. In
390 // particular, we use this to see what proportion of changes are from Sync 411 // particular, we use this to see what proportion of changes are from Sync
391 // entry points, to help spot erroneous Sync activity. 412 // entry points, to help spot erroneous Sync activity.
392 enum DefaultSearchChangeOrigin { 413 enum DefaultSearchChangeOrigin {
393 // Various known Sync entry points. 414 // Various known Sync entry points.
394 DSP_CHANGE_SYNC_PREF, 415 DSP_CHANGE_SYNC_PREF,
395 DSP_CHANGE_SYNC_ADD, 416 DSP_CHANGE_SYNC_ADD,
396 DSP_CHANGE_SYNC_DELETE, 417 DSP_CHANGE_SYNC_DELETE,
(...skipping 20 matching lines...) Expand all
417 // Helper functor for FindMatchingKeywords(), for finding the range of 438 // Helper functor for FindMatchingKeywords(), for finding the range of
418 // keywords which begin with a prefix. 439 // keywords which begin with a prefix.
419 class LessWithPrefix; 440 class LessWithPrefix;
420 441
421 void Init(const Initializer* initializers, int num_initializers); 442 void Init(const Initializer* initializers, int num_initializers);
422 443
423 void RemoveFromMaps(TemplateURL* template_url); 444 void RemoveFromMaps(TemplateURL* template_url);
424 445
425 void AddToMaps(TemplateURL* template_url); 446 void AddToMaps(TemplateURL* template_url);
426 447
448 void RemoveFromDomainMap(const TemplateURL* template_url);
449
450 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
451
427 // Sets the keywords. This is used once the keywords have been loaded. 452 // Sets the keywords. This is used once the keywords have been loaded.
428 // This does NOT notify the delegate or the database. 453 // This does NOT notify the delegate or the database.
429 // 454 //
430 // This transfers ownership of the elements in |urls| to |this|, and may 455 // This transfers ownership of the elements in |urls| to |this|, and may
431 // delete some elements, so it's not safe for callers to access any elements 456 // delete some elements, so it's not safe for callers to access any elements
432 // after calling; to reinforce this, this function clears |urls| on exit. 457 // after calling; to reinforce this, this function clears |urls| on exit.
433 void SetTemplateURLs(TemplateURLVector* urls); 458 void SetTemplateURLs(TemplateURLVector* urls);
434 459
435 // Transitions to the loaded state. 460 // Transitions to the loaded state.
436 void ChangeToLoadedState(); 461 void ChangeToLoadedState();
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 void OnSyncedDefaultSearchProviderGUIDChanged(); 626 void OnSyncedDefaultSearchProviderGUIDChanged();
602 627
603 // Adds |template_urls| to |template_urls_|. 628 // Adds |template_urls| to |template_urls_|.
604 // 629 //
605 // This transfers ownership of the elements in |template_urls| to |this|, and 630 // This transfers ownership of the elements in |template_urls| to |this|, and
606 // may delete some elements, so it's not safe for callers to access any 631 // may delete some elements, so it's not safe for callers to access any
607 // elements after calling; to reinforce this, this function clears 632 // elements after calling; to reinforce this, this function clears
608 // |template_urls| on exit. 633 // |template_urls| on exit.
609 void AddTemplateURLs(TemplateURLVector* template_urls); 634 void AddTemplateURLs(TemplateURLVector* template_urls);
610 635
636 // Returns (in |matches|) all TemplateURLs stored in |keyword_to_template_map|
637 // 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.
638 // |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.
639 // replacement are returned.
640 template <typename Container>
641 void FindMatchingKeywordsHelper(
642 const Container& keyword_to_template_map,
643 const base::string16& prefix,
644 bool support_replacement_only,
645 TemplateURLMatchesVector* matches);
646
611 // Returns the TemplateURL corresponding to |prepopulated_id|, if any. 647 // Returns the TemplateURL corresponding to |prepopulated_id|, if any.
612 TemplateURL* FindPrepopulatedTemplateURL(int prepopulated_id); 648 TemplateURL* FindPrepopulatedTemplateURL(int prepopulated_id);
613 649
614 // Returns the TemplateURL associated with |extension_id|, if any. 650 // Returns the TemplateURL associated with |extension_id|, if any.
615 TemplateURL* FindTemplateURLForExtension(const std::string& extension_id, 651 TemplateURL* FindTemplateURLForExtension(const std::string& extension_id,
616 TemplateURL::Type type); 652 TemplateURL::Type type);
617 653
618 // Finds the extension-supplied TemplateURL that matches |data|, if any. 654 // Finds the extension-supplied TemplateURL that matches |data|, if any.
619 TemplateURL* FindMatchingExtensionTemplateURL(const TemplateURLData& data, 655 TemplateURL* FindMatchingExtensionTemplateURL(const TemplateURLData& data,
620 TemplateURL::Type type); 656 TemplateURL::Type type);
(...skipping 22 matching lines...) Expand all
643 rappor::RapporService* rappor_service_; 679 rappor::RapporService* rappor_service_;
644 680
645 // This closure is run when the default search provider is set to Google. 681 // This closure is run when the default search provider is set to Google.
646 base::Closure dsp_change_callback_; 682 base::Closure dsp_change_callback_;
647 683
648 684
649 PrefChangeRegistrar pref_change_registrar_; 685 PrefChangeRegistrar pref_change_registrar_;
650 686
651 // Mapping from keyword to the TemplateURL. 687 // Mapping from keyword to the TemplateURL.
652 KeywordToTemplateMap keyword_to_template_map_; 688 KeywordToTemplateMap keyword_to_template_map_;
689 // 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.
690 // auto-generated keywords such as abc.def.com, we put the keyword in this
691 // map under the name def.com. This is a multimap because multiple keywords
692 // can have the same domain. Entries are only allowed here if there is a
693 // corresponding entry in |keyword_to_template_map_|, i.e., if a template URL
694 // doesn't have an entry in |keyword_to_template_map_| because it's subsumed
695 // by another template URL with an identical keyword, the template URL will
696 // not have an entry in this map either. This map will also not bother
697 // including entries for auto-generated keywords in which the keyword is the
698 // domain name, no host before the domain name. (The ordinary
699 // |keyword_to_template_map_| suffices for that.) Also, non-auto-generated
700 // 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
701 KeywordDomainToTemplateMap keyword_domain_to_template_map_;
653 702
654 // Mapping from Sync GUIDs to the TemplateURL. 703 // Mapping from Sync GUIDs to the TemplateURL.
655 GUIDToTemplateMap guid_to_template_map_; 704 GUIDToTemplateMap guid_to_template_map_;
656 705
657 TemplateURLVector template_urls_; 706 TemplateURLVector template_urls_;
658 707
659 base::ObserverList<TemplateURLServiceObserver> model_observers_; 708 base::ObserverList<TemplateURLServiceObserver> model_observers_;
660 709
661 // Maps from host to set of TemplateURLs whose search url host is host. 710 // Maps from host to set of TemplateURLs whose search url host is host.
662 // NOTE: This is always non-NULL; we use a scoped_ptr<> to avoid circular 711 // NOTE: This is always non-NULL; we use a scoped_ptr<> to avoid circular
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 778
730 // Helper class to manage the default search engine. 779 // Helper class to manage the default search engine.
731 DefaultSearchManager default_search_manager_; 780 DefaultSearchManager default_search_manager_;
732 781
733 scoped_ptr<GoogleURLTracker::Subscription> google_url_updated_subscription_; 782 scoped_ptr<GoogleURLTracker::Subscription> google_url_updated_subscription_;
734 783
735 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); 784 DISALLOW_COPY_AND_ASSIGN(TemplateURLService);
736 }; 785 };
737 786
738 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ 787 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698