OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ |
6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ | 6 #define CHROME_BROWSER_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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 // a TemplateURL for an existing TemplateURL that shares the same host. | 149 // a TemplateURL for an existing TemplateURL that shares the same host. |
150 bool CanReplaceKeyword(const base::string16& keyword, | 150 bool CanReplaceKeyword(const base::string16& keyword, |
151 const GURL& url, | 151 const GURL& url, |
152 TemplateURL** template_url_to_replace); | 152 TemplateURL** template_url_to_replace); |
153 | 153 |
154 // Returns (in |matches|) all TemplateURLs whose keywords begin with |prefix|, | 154 // Returns (in |matches|) all TemplateURLs whose keywords begin with |prefix|, |
155 // sorted shortest keyword-first. If |support_replacement_only| is true, only | 155 // sorted shortest keyword-first. If |support_replacement_only| is true, only |
156 // TemplateURLs that support replacement are returned. | 156 // TemplateURLs that support replacement are returned. |
157 void FindMatchingKeywords(const base::string16& prefix, | 157 void FindMatchingKeywords(const base::string16& prefix, |
158 bool support_replacement_only, | 158 bool support_replacement_only, |
159 TemplateURLVector* matches) const; | 159 TemplateURLVector* matches); |
160 | 160 |
161 // Looks up |keyword| and returns the element it maps to. Returns NULL if | 161 // Looks up |keyword| and returns the element it maps to. Returns NULL if |
162 // the keyword was not found. | 162 // the keyword was not found. |
163 // The caller should not try to delete the returned pointer; the data store | 163 // The caller should not try to delete the returned pointer; the data store |
164 // retains ownership of it. | 164 // retains ownership of it. |
165 TemplateURL* GetTemplateURLForKeyword(const base::string16& keyword); | 165 TemplateURL* GetTemplateURLForKeyword(const base::string16& keyword); |
166 | 166 |
167 // Returns that TemplateURL with the specified GUID, or NULL if not found. | 167 // Returns that TemplateURL with the specified GUID, or NULL if not found. |
168 // The caller should not try to delete the returned pointer; the data store | 168 // The caller should not try to delete the returned pointer; the data store |
169 // retains ownership of it. | 169 // retains ownership of it. |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 // Returns the default search specified in the prepopulated data, if it | 269 // Returns the default search specified in the prepopulated data, if it |
270 // exists. If not, returns first URL in |template_urls_|, or NULL if that's | 270 // exists. If not, returns first URL in |template_urls_|, or NULL if that's |
271 // empty. The returned object is owned by TemplateURLService and can be | 271 // empty. The returned object is owned by TemplateURLService and can be |
272 // destroyed at any time so should be used right after the call. | 272 // destroyed at any time so should be used right after the call. |
273 TemplateURL* FindNewDefaultSearchProvider(); | 273 TemplateURL* FindNewDefaultSearchProvider(); |
274 | 274 |
275 // Performs the same actions that happen when the prepopulate data version is | 275 // Performs the same actions that happen when the prepopulate data version is |
276 // revved: all existing prepopulated entries are checked against the current | 276 // revved: all existing prepopulated entries are checked against the current |
277 // prepopulate data, any now-extraneous safe_for_autoreplace() entries are | 277 // prepopulate data, any now-extraneous safe_for_autoreplace() entries are |
278 // removed, any existing engines are reset to the provided data (except for | 278 // removed, any existing engines are reset to the provided data (except for |
279 // user-edited names or keywords), and any new prepopulated anegines are | 279 // user-edited names or keywords), and any new prepopulated engines are |
280 // added. | 280 // added. |
281 // | 281 // |
282 // After this, the default search engine is reset to the default entry in the | 282 // After this, the default search engine is reset to the default entry in the |
283 // prepopulate data. | 283 // prepopulate data. |
284 void RepairPrepopulatedSearchEngines(); | 284 void RepairPrepopulatedSearchEngines(); |
285 | 285 |
286 // Observers used to listen for changes to the model. | 286 // Observers used to listen for changes to the model. |
287 // TemplateURLService does NOT delete the observers when deleted. | 287 // TemplateURLService does NOT delete the observers when deleted. |
288 void AddObserver(TemplateURLServiceObserver* observer); | 288 void AddObserver(TemplateURLServiceObserver* observer); |
289 void RemoveObserver(TemplateURLServiceObserver* observer); | 289 void RemoveObserver(TemplateURLServiceObserver* observer); |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 void AddTemplateURLsAndSetupDefaultEngine( | 666 void AddTemplateURLsAndSetupDefaultEngine( |
667 TemplateURLVector* template_urls, | 667 TemplateURLVector* template_urls, |
668 TemplateURL* default_search_provider); | 668 TemplateURL* default_search_provider); |
669 | 669 |
670 // If there is no current default search provider, sets the default to the | 670 // If there is no current default search provider, sets the default to the |
671 // result of calling FindNewDefaultSearchProvider(). | 671 // result of calling FindNewDefaultSearchProvider(). |
672 void EnsureDefaultSearchProviderExists(); | 672 void EnsureDefaultSearchProviderExists(); |
673 | 673 |
674 // Returns a new TemplateURL for the given extension. | 674 // Returns a new TemplateURL for the given extension. |
675 TemplateURL* CreateTemplateURLForExtension( | 675 TemplateURL* CreateTemplateURLForExtension( |
676 const ExtensionKeyword& extension_keyword) const; | 676 const ExtensionKeyword& extension_keyword); |
677 | 677 |
678 // Returns the TemplateURL associated with |extension_id|, if any. | 678 // Returns the TemplateURL associated with |extension_id|, if any. |
679 TemplateURL* FindTemplateURLForExtension(const std::string& extension_id, | 679 TemplateURL* FindTemplateURLForExtension(const std::string& extension_id, |
680 TemplateURL::Type type) const; | 680 TemplateURL::Type type); |
681 | 681 |
682 // Finds the most recently-installed NORMAL_CONTROLLED_BY_EXTENSION engine | 682 // Finds the most recently-installed NORMAL_CONTROLLED_BY_EXTENSION engine |
683 // that supports replacement and wants to be default, if any. | 683 // that supports replacement and wants to be default, if any. |
684 TemplateURL* FindExtensionDefaultSearchEngine() const; | 684 TemplateURL* FindExtensionDefaultSearchEngine() const; |
685 | 685 |
686 // Sets the default search provider to: | 686 // Sets the default search provider to: |
687 // (1) BestDefaultExtensionControlledTURL(), if any; or, | 687 // (1) BestDefaultExtensionControlledTURL(), if any; or, |
688 // (2) LoadDefaultSearchProviderFromPrefs(), if we have a TURL with that ID; | 688 // (2) LoadDefaultSearchProviderFromPrefs(), if we have a TURL with that ID; |
689 // or, | 689 // or, |
690 // (3) FindNewDefaultSearchProvider(). | 690 // (3) FindNewDefaultSearchProvider(). |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 WebDataService::Handle load_handle_; | 725 WebDataService::Handle load_handle_; |
726 | 726 |
727 // Service used to store entries. | 727 // Service used to store entries. |
728 scoped_refptr<WebDataService> service_; | 728 scoped_refptr<WebDataService> service_; |
729 | 729 |
730 // All visits that occurred before we finished loading. Once loaded | 730 // All visits that occurred before we finished loading. Once loaded |
731 // UpdateKeywordSearchTermsForURL is invoked for each element of the vector. | 731 // UpdateKeywordSearchTermsForURL is invoked for each element of the vector. |
732 std::vector<history::URLVisitedDetails> visits_to_add_; | 732 std::vector<history::URLVisitedDetails> visits_to_add_; |
733 | 733 |
734 // Once loaded, the default search provider. This is a pointer to a | 734 // Once loaded, the default search provider. This is a pointer to a |
735 // TemplateURL owned by template_urls_. | 735 // TemplateURL owned by |template_urls_|. |
736 TemplateURL* default_search_provider_; | 736 TemplateURL* default_search_provider_; |
737 | 737 |
738 // The initial search provider extracted from preferences. This is only valid | 738 // The initial search provider extracted from preferences. This is only valid |
739 // if we haven't been loaded or loading failed. | 739 // if we haven't been loaded or loading failed. |
740 scoped_ptr<TemplateURL> initial_default_search_provider_; | 740 scoped_ptr<TemplateURL> initial_default_search_provider_; |
741 | 741 |
742 // Whether the default search is managed via policy. | 742 // Whether the default search is managed via policy. |
743 bool is_default_search_managed_; | 743 bool is_default_search_managed_; |
744 | 744 |
745 // ID assigned to next TemplateURL added to this model. This is an ever | 745 // ID assigned to next TemplateURL added to this model. This is an ever |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 std::set<std::string> pre_sync_deletes_; | 779 std::set<std::string> pre_sync_deletes_; |
780 | 780 |
781 // This is used to log the origin of changes to the default search provider. | 781 // This is used to log the origin of changes to the default search provider. |
782 // We set this value to increasingly specific values when we know what is the | 782 // We set this value to increasingly specific values when we know what is the |
783 // cause/origin of a default search change. | 783 // cause/origin of a default search change. |
784 DefaultSearchChangeOrigin dsp_change_origin_; | 784 DefaultSearchChangeOrigin dsp_change_origin_; |
785 | 785 |
786 // Stores a list of callbacks to be run after TemplateURLService has loaded. | 786 // Stores a list of callbacks to be run after TemplateURLService has loaded. |
787 base::CallbackList<void(void)> on_loaded_callbacks_; | 787 base::CallbackList<void(void)> on_loaded_callbacks_; |
788 | 788 |
789 // Helper class to manage the default search engine. This will be NULL when | 789 // Helper class to manage the default search engine. |
790 // using the testing-specific constructor. | 790 DefaultSearchManager default_search_manager_; |
791 scoped_ptr<DefaultSearchManager> default_search_manager_; | |
792 | 791 |
793 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); | 792 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); |
794 }; | 793 }; |
795 | 794 |
796 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ | 795 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ |
OLD | NEW |