OLD | NEW |
---|---|
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 <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <list> | 10 #include <list> |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 const base::Callback<bool(const GURL&)>& url_filter, | 220 const base::Callback<bool(const GURL&)>& url_filter, |
221 base::Time created_after, | 221 base::Time created_after, |
222 base::Time created_before); | 222 base::Time created_before); |
223 | 223 |
224 // Adds a TemplateURL for an extension with an omnibox keyword. | 224 // Adds a TemplateURL for an extension with an omnibox keyword. |
225 // Only 1 keyword is allowed for a given extension. If a keyword | 225 // Only 1 keyword is allowed for a given extension. If a keyword |
226 // already exists for this extension, does nothing. | 226 // already exists for this extension, does nothing. |
227 void RegisterOmniboxKeyword(const std::string& extension_id, | 227 void RegisterOmniboxKeyword(const std::string& extension_id, |
228 const std::string& extension_name, | 228 const std::string& extension_name, |
229 const std::string& keyword, | 229 const std::string& keyword, |
230 const std::string& template_url_string); | 230 const std::string& template_url_string, |
231 const base::Time& extension_install_time); | |
231 | 232 |
232 // Returns the set of URLs describing the keywords. The elements are owned | 233 // Returns the set of URLs describing the keywords. The elements are owned |
233 // by TemplateURLService and should not be deleted. | 234 // by TemplateURLService and should not be deleted. |
234 TemplateURLVector GetTemplateURLs(); | 235 TemplateURLVector GetTemplateURLs(); |
235 | 236 |
236 // Increment the usage count of a keyword. | 237 // Increment the usage count of a keyword. |
237 // Called when a URL is loaded that was generated from a keyword. | 238 // Called when a URL is loaded that was generated from a keyword. |
238 void IncrementUsageCount(TemplateURL* url); | 239 void IncrementUsageCount(TemplateURL* url); |
239 | 240 |
240 // Resets the title, keyword and search url of the specified TemplateURL. | 241 // Resets the title, keyword and search url of the specified TemplateURL. |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
406 #endif | 407 #endif |
407 | 408 |
408 private: | 409 private: |
409 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, TestManagedDefaultSearch); | 410 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, TestManagedDefaultSearch); |
410 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, | 411 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, |
411 UpdateKeywordSearchTermsForURL); | 412 UpdateKeywordSearchTermsForURL); |
412 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, | 413 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, |
413 DontUpdateKeywordSearchForNonReplaceable); | 414 DontUpdateKeywordSearchForNonReplaceable); |
414 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, ChangeGoogleBaseValue); | 415 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, ChangeGoogleBaseValue); |
415 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, MergeDeletesUnusedProviders); | 416 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, MergeDeletesUnusedProviders); |
416 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, AddExtensionKeyword); | 417 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, AddOmniboxExtensionKeyword); |
418 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, ExtensionsWithSameKeywords); | |
419 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, | |
420 CheckEnginesWithSameKeywords); | |
417 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, LastVisitedTimeUpdate); | 421 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, LastVisitedTimeUpdate); |
418 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, UniquifyKeyword); | 422 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, UniquifyKeyword); |
419 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, | 423 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, |
420 IsLocalTemplateURLBetter); | 424 IsLocalTemplateURLBetter); |
421 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, | 425 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, |
422 ResolveSyncKeywordConflict); | 426 ResolveSyncKeywordConflict); |
423 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, PreSyncDeletes); | 427 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, PreSyncDeletes); |
424 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, MergeInSyncTemplateURL); | 428 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, MergeInSyncTemplateURL); |
425 FRIEND_TEST_ALL_PREFIXES(ToolbarModelTest, GoogleBaseURL); | 429 FRIEND_TEST_ALL_PREFIXES(ToolbarModelTest, GoogleBaseURL); |
426 | 430 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
473 // Boundary value. | 477 // Boundary value. |
474 DSP_CHANGE_MAX, | 478 DSP_CHANGE_MAX, |
475 }; | 479 }; |
476 | 480 |
477 // Helper functor for FindMatchingKeywords(), for finding the range of | 481 // Helper functor for FindMatchingKeywords(), for finding the range of |
478 // keywords which begin with a prefix. | 482 // keywords which begin with a prefix. |
479 class LessWithPrefix; | 483 class LessWithPrefix; |
480 | 484 |
481 void Init(const Initializer* initializers, int num_initializers); | 485 void Init(const Initializer* initializers, int num_initializers); |
482 | 486 |
487 // Returns best engine that should be used from two search engines with equal | |
488 // keywords. This is only can happen if at least one of engines is installed | |
489 // by extension. One of arguments is allowed to be nullptr, in this case | |
490 // another is returned. Ranking order is: | |
491 // omnibox api extension keywords > extension search engines > user engines | |
492 // When there are multiple extensions, the last-added wins. | |
Peter Kasting
2017/02/25 04:26:53
Why do we let either argument be null? It doesn't
Alexander Yashkin
2017/02/25 11:34:07
I have added nullptr support to args to support ca
| |
493 TemplateURL* BestEngineForKeyword(TemplateURL* engine1, TemplateURL* engine2); | |
494 | |
483 // Removes |template_url| from various internal maps | 495 // Removes |template_url| from various internal maps |
484 // (|keyword_to_turl_and_length_|, |keyword_domain_to_turl_and_length_|, | 496 // (|keyword_to_turl_and_length_|, |keyword_domain_to_turl_and_length_|, |
485 // |guid_to_turl_|, |provider_map_|). | 497 // |guid_to_turl_|, |provider_map_|). |
486 void RemoveFromMaps(TemplateURL* template_url); | 498 void RemoveFromMaps(TemplateURL* template_url); |
487 | 499 |
488 // Adds |template_url| to various internal maps | 500 // Adds |template_url| to various internal maps |
489 // (|keyword_to_turl_and_length_|, |keyword_domain_to_turl_and_length_|, | 501 // (|keyword_to_turl_and_length_|, |keyword_domain_to_turl_and_length_|, |
490 // |guid_to_turl_|, |provider_map_|) if appropriate. (It might not be | 502 // |guid_to_turl_|, |provider_map_|) if appropriate. (It might not be |
491 // appropriate if, for instance, |template_url|'s keyword conflicts with | 503 // appropriate if, for instance, |template_url|'s keyword conflicts with |
492 // the keyword of a custom search engine already existing in the maps that | 504 // the keyword of a custom search engine already existing in the maps that |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
698 bool supports_replacement_only, | 710 bool supports_replacement_only, |
699 TURLsAndMeaningfulLengths* matches); | 711 TURLsAndMeaningfulLengths* matches); |
700 | 712 |
701 // Returns the TemplateURL corresponding to |prepopulated_id|, if any. | 713 // Returns the TemplateURL corresponding to |prepopulated_id|, if any. |
702 TemplateURL* FindPrepopulatedTemplateURL(int prepopulated_id); | 714 TemplateURL* FindPrepopulatedTemplateURL(int prepopulated_id); |
703 | 715 |
704 // Returns the TemplateURL associated with |extension_id|, if any. | 716 // Returns the TemplateURL associated with |extension_id|, if any. |
705 TemplateURL* FindTemplateURLForExtension(const std::string& extension_id, | 717 TemplateURL* FindTemplateURLForExtension(const std::string& extension_id, |
706 TemplateURL::Type type); | 718 TemplateURL::Type type); |
707 | 719 |
708 // Finds the extension-supplied TemplateURL that matches |data|, if any. | 720 // Finds the extension-supplied TemplateURL of type |
Peter Kasting
2017/02/25 04:26:53
Nit: "Finds any NORMAL_CONTROLLED_BY_EXTENSION eng
Alexander Yashkin
2017/02/25 11:34:07
Done
| |
709 TemplateURL* FindMatchingExtensionTemplateURL(const TemplateURLData& data, | 721 // NORMAL_CONTROLLED_BY_EXTENSION that matches |data| and wants to be default. |
710 TemplateURL::Type type); | 722 // Returns nullptr if not found. |
723 TemplateURL* FindMatchingDefaultExtensionTemplateURL( | |
724 const TemplateURLData& data); | |
711 | 725 |
712 // Finds the most recently-installed NORMAL_CONTROLLED_BY_EXTENSION engine | 726 // Finds the most recently-installed NORMAL_CONTROLLED_BY_EXTENSION engine |
713 // that supports replacement and wants to be default, if any. Notifies the | 727 // that supports replacement and wants to be default, if any. Notifies the |
714 // DefaultSearchManager, which might change the effective default search | 728 // DefaultSearchManager, which might change the effective default search |
715 // engine. | 729 // engine. |
716 void UpdateExtensionDefaultSearchEngine(); | 730 void UpdateExtensionDefaultSearchEngine(); |
717 | 731 |
718 | 732 |
719 // ---------- Browser state related members --------------------------------- | 733 // ---------- Browser state related members --------------------------------- |
720 PrefService* prefs_; | 734 PrefService* prefs_; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
834 // Helper class to manage the default search engine. | 848 // Helper class to manage the default search engine. |
835 DefaultSearchManager default_search_manager_; | 849 DefaultSearchManager default_search_manager_; |
836 | 850 |
837 std::unique_ptr<GoogleURLTracker::Subscription> | 851 std::unique_ptr<GoogleURLTracker::Subscription> |
838 google_url_updated_subscription_; | 852 google_url_updated_subscription_; |
839 | 853 |
840 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); | 854 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); |
841 }; | 855 }; |
842 | 856 |
843 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ | 857 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ |
OLD | NEW |