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); |
| 422 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, |
| 423 RepairPrepopulatedSearchEngines); |
418 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, UniquifyKeyword); | 424 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, UniquifyKeyword); |
419 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, | 425 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, |
420 IsLocalTemplateURLBetter); | 426 IsLocalTemplateURLBetter); |
421 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, | 427 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, |
422 ResolveSyncKeywordConflict); | 428 ResolveSyncKeywordConflict); |
423 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, PreSyncDeletes); | 429 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, PreSyncDeletes); |
424 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, MergeInSyncTemplateURL); | 430 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, MergeInSyncTemplateURL); |
425 FRIEND_TEST_ALL_PREFIXES(ToolbarModelTest, GoogleBaseURL); | 431 FRIEND_TEST_ALL_PREFIXES(ToolbarModelTest, GoogleBaseURL); |
426 | 432 |
427 friend class InstantUnitTestBase; | 433 friend class InstantUnitTestBase; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 // Boundary value. | 479 // Boundary value. |
474 DSP_CHANGE_MAX, | 480 DSP_CHANGE_MAX, |
475 }; | 481 }; |
476 | 482 |
477 // Helper functor for FindMatchingKeywords(), for finding the range of | 483 // Helper functor for FindMatchingKeywords(), for finding the range of |
478 // keywords which begin with a prefix. | 484 // keywords which begin with a prefix. |
479 class LessWithPrefix; | 485 class LessWithPrefix; |
480 | 486 |
481 void Init(const Initializer* initializers, int num_initializers); | 487 void Init(const Initializer* initializers, int num_initializers); |
482 | 488 |
| 489 // Given two engines with the same keyword, returns which should take |
| 490 // precedence. While normal engines must all have distinct keywords, |
| 491 // extension-controlled and omnibox API engines may have the same keywords as |
| 492 // each other or as normal engines. In these cases, omnibox API engines |
| 493 // override extension-controlled engines, which override normal engines; if |
| 494 // there is still a conflict after this, the most recently-added extension |
| 495 // wins. |
| 496 TemplateURL* BestEngineForKeyword(TemplateURL* engine1, TemplateURL* engine2); |
| 497 |
483 // Removes |template_url| from various internal maps | 498 // Removes |template_url| from various internal maps |
484 // (|keyword_to_turl_and_length_|, |keyword_domain_to_turl_and_length_|, | 499 // (|keyword_to_turl_and_length_|, |keyword_domain_to_turl_and_length_|, |
485 // |guid_to_turl_|, |provider_map_|). | 500 // |guid_to_turl_|, |provider_map_|). |
486 void RemoveFromMaps(TemplateURL* template_url); | 501 void RemoveFromMaps(TemplateURL* template_url); |
487 | 502 |
488 // Adds |template_url| to various internal maps | 503 // Adds |template_url| to various internal maps |
489 // (|keyword_to_turl_and_length_|, |keyword_domain_to_turl_and_length_|, | 504 // (|keyword_to_turl_and_length_|, |keyword_domain_to_turl_and_length_|, |
490 // |guid_to_turl_|, |provider_map_|) if appropriate. (It might not be | 505 // |guid_to_turl_|, |provider_map_|) if appropriate. (It might not be |
491 // appropriate if, for instance, |template_url|'s keyword conflicts with | 506 // appropriate if, for instance, |template_url|'s keyword conflicts with |
492 // the keyword of a custom search engine already existing in the maps that | 507 // 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, | 713 bool supports_replacement_only, |
699 TURLsAndMeaningfulLengths* matches); | 714 TURLsAndMeaningfulLengths* matches); |
700 | 715 |
701 // Returns the TemplateURL corresponding to |prepopulated_id|, if any. | 716 // Returns the TemplateURL corresponding to |prepopulated_id|, if any. |
702 TemplateURL* FindPrepopulatedTemplateURL(int prepopulated_id); | 717 TemplateURL* FindPrepopulatedTemplateURL(int prepopulated_id); |
703 | 718 |
704 // Returns the TemplateURL associated with |extension_id|, if any. | 719 // Returns the TemplateURL associated with |extension_id|, if any. |
705 TemplateURL* FindTemplateURLForExtension(const std::string& extension_id, | 720 TemplateURL* FindTemplateURLForExtension(const std::string& extension_id, |
706 TemplateURL::Type type); | 721 TemplateURL::Type type); |
707 | 722 |
708 // Finds the extension-supplied TemplateURL that matches |data|, if any. | 723 // Finds any NORMAL_CONTROLLED_BY_EXTENSION engine that matches |data| and |
709 TemplateURL* FindMatchingExtensionTemplateURL(const TemplateURLData& data, | 724 // wants to be default. Returns nullptr if not found. |
710 TemplateURL::Type type); | 725 TemplateURL* FindMatchingDefaultExtensionTemplateURL( |
| 726 const TemplateURLData& data); |
711 | 727 |
712 // Finds the most recently-installed NORMAL_CONTROLLED_BY_EXTENSION engine | 728 // Finds the most recently-installed NORMAL_CONTROLLED_BY_EXTENSION engine |
713 // that supports replacement and wants to be default, if any. Notifies the | 729 // that supports replacement and wants to be default, if any. Notifies the |
714 // DefaultSearchManager, which might change the effective default search | 730 // DefaultSearchManager, which might change the effective default search |
715 // engine. | 731 // engine. |
716 void UpdateExtensionDefaultSearchEngine(); | 732 void UpdateExtensionDefaultSearchEngine(); |
717 | 733 |
718 | 734 |
719 // ---------- Browser state related members --------------------------------- | 735 // ---------- Browser state related members --------------------------------- |
720 PrefService* prefs_; | 736 PrefService* prefs_; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 // Helper class to manage the default search engine. | 850 // Helper class to manage the default search engine. |
835 DefaultSearchManager default_search_manager_; | 851 DefaultSearchManager default_search_manager_; |
836 | 852 |
837 std::unique_ptr<GoogleURLTracker::Subscription> | 853 std::unique_ptr<GoogleURLTracker::Subscription> |
838 google_url_updated_subscription_; | 854 google_url_updated_subscription_; |
839 | 855 |
840 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); | 856 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); |
841 }; | 857 }; |
842 | 858 |
843 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ | 859 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ |
OLD | NEW |