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_UTIL_H_ | 5 #ifndef CHROME_BROWSER_SEARCH_ENGINES_UTIL_H_ |
6 #define CHROME_BROWSER_SEARCH_ENGINES_UTIL_H_ | 6 #define CHROME_BROWSER_SEARCH_ENGINES_UTIL_H_ |
7 | 7 |
8 // This file contains utility functions for search engine functionality. | 8 // This file contains utility functions for search engine functionality. |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
15 #include "chrome/browser/search_engines/template_url_service.h" | 15 #include "chrome/browser/search_engines/template_url_service.h" |
16 | 16 |
| 17 class KeywordWebDataService; |
17 class PrefService; | 18 class PrefService; |
18 class TemplateURL; | 19 class TemplateURL; |
19 class WDTypedResult; | 20 class WDTypedResult; |
20 class WebDataService; | |
21 | 21 |
22 // Returns the short name of the default search engine, or the empty string if | 22 // Returns the short name of the default search engine, or the empty string if |
23 // none is set. | 23 // none is set. |
24 base::string16 GetDefaultSearchEngineName(TemplateURLService* service); | 24 base::string16 GetDefaultSearchEngineName(TemplateURLService* service); |
25 | 25 |
26 // Returns a GURL that searches for |terms| using the default search engine of | 26 // Returns a GURL that searches for |terms| using the default search engine of |
27 // |service|. | 27 // |service|. |
28 GURL GetDefaultSearchURLForSearchTerms(TemplateURLService* service, | 28 GURL GetDefaultSearchURLForSearchTerms(TemplateURLService* service, |
29 const base::string16& terms); | 29 const base::string16& terms); |
30 | 30 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 // produces the set of actions (see above) required to make the user's URLs | 70 // produces the set of actions (see above) required to make the user's URLs |
71 // reflect the prepopulate data. |default_search_provider| is used to avoid | 71 // reflect the prepopulate data. |default_search_provider| is used to avoid |
72 // placing the current default provider on the "to be removed" list. | 72 // placing the current default provider on the "to be removed" list. |
73 // | 73 // |
74 // NOTE: Takes ownership of, and clears, |prepopulated_urls|. | 74 // NOTE: Takes ownership of, and clears, |prepopulated_urls|. |
75 ActionsFromPrepopulateData CreateActionsFromCurrentPrepopulateData( | 75 ActionsFromPrepopulateData CreateActionsFromCurrentPrepopulateData( |
76 ScopedVector<TemplateURLData>* prepopulated_urls, | 76 ScopedVector<TemplateURLData>* prepopulated_urls, |
77 const TemplateURLService::TemplateURLVector& existing_urls, | 77 const TemplateURLService::TemplateURLVector& existing_urls, |
78 const TemplateURL* default_search_provider); | 78 const TemplateURL* default_search_provider); |
79 | 79 |
80 // Processes the results of WebDataService::GetKeywords, combining it with | 80 // Processes the results of KeywordWebDataService::GetKeywords, combining it |
81 // prepopulated search providers to result in: | 81 // with prepopulated search providers to result in: |
82 // * a set of template_urls (search providers). The caller owns the | 82 // * a set of template_urls (search providers). The caller owns the |
83 // TemplateURL* returned in template_urls. | 83 // TemplateURL* returned in template_urls. |
84 // * whether there is a new resource keyword version (and the value). | 84 // * whether there is a new resource keyword version (and the value). |
85 // |*new_resource_keyword_version| is set to 0 if no new value. Otherwise, | 85 // |*new_resource_keyword_version| is set to 0 if no new value. Otherwise, |
86 // it is the new value. | 86 // it is the new value. |
87 // Only pass in a non-NULL value for service if the WebDataService should be | 87 // Only pass in a non-NULL value for service if the KeywordWebDataService should |
88 // updated. If |removed_keyword_guids| is not NULL, any TemplateURLs removed | 88 // be updated. If |removed_keyword_guids| is not NULL, any TemplateURLs removed |
89 // from the keyword table in the WebDataService will have their Sync GUIDs | 89 // from the keyword table in the KeywordWebDataService will have their Sync |
90 // added to it. |default_search_provider| will be used to prevent removing the | 90 // GUIDs added to it. |default_search_provider| will be used to prevent removing |
91 // current user-selected DSE, regardless of changes in prepopulate data. | 91 // the current user-selected DSE, regardless of changes in prepopulate data. |
92 void GetSearchProvidersUsingKeywordResult( | 92 void GetSearchProvidersUsingKeywordResult( |
93 const WDTypedResult& result, | 93 const WDTypedResult& result, |
94 WebDataService* service, | 94 KeywordWebDataService* service, |
95 PrefService* prefs, | 95 PrefService* prefs, |
96 TemplateURLService::TemplateURLVector* template_urls, | 96 TemplateURLService::TemplateURLVector* template_urls, |
97 TemplateURL* default_search_provider, | 97 TemplateURL* default_search_provider, |
98 const SearchTermsData& search_terms_data, | 98 const SearchTermsData& search_terms_data, |
99 int* new_resource_keyword_version, | 99 int* new_resource_keyword_version, |
100 std::set<std::string>* removed_keyword_guids); | 100 std::set<std::string>* removed_keyword_guids); |
101 | 101 |
102 // Like GetSearchProvidersUsingKeywordResult(), but allows the caller to pass in | 102 // Like GetSearchProvidersUsingKeywordResult(), but allows the caller to pass in |
103 // engines in |template_urls| instead of getting them via processing a web data | 103 // engines in |template_urls| instead of getting them via processing a web data |
104 // service request. | 104 // service request. |
105 // |resource_keyword_version| should contain the version number of the current | 105 // |resource_keyword_version| should contain the version number of the current |
106 // keyword data, i.e. the version number of the most recent prepopulate data | 106 // keyword data, i.e. the version number of the most recent prepopulate data |
107 // that has been merged into the current keyword data. On exit, this will be | 107 // that has been merged into the current keyword data. On exit, this will be |
108 // set as in GetSearchProvidersUsingKeywordResult(). | 108 // set as in GetSearchProvidersUsingKeywordResult(). |
109 void GetSearchProvidersUsingLoadedEngines( | 109 void GetSearchProvidersUsingLoadedEngines( |
110 WebDataService* service, | 110 KeywordWebDataService* service, |
111 PrefService* prefs, | 111 PrefService* prefs, |
112 TemplateURLService::TemplateURLVector* template_urls, | 112 TemplateURLService::TemplateURLVector* template_urls, |
113 TemplateURL* default_search_provider, | 113 TemplateURL* default_search_provider, |
114 const SearchTermsData& search_terms_data, | 114 const SearchTermsData& search_terms_data, |
115 int* resource_keyword_version, | 115 int* resource_keyword_version, |
116 std::set<std::string>* removed_keyword_guids); | 116 std::set<std::string>* removed_keyword_guids); |
117 | 117 |
118 // Due to a bug, the |input_encodings| field of TemplateURLData could have | 118 // Due to a bug, the |input_encodings| field of TemplateURLData could have |
119 // contained duplicate entries. This removes those entries and returns whether | 119 // contained duplicate entries. This removes those entries and returns whether |
120 // any were found. | 120 // any were found. |
121 bool DeDupeEncodings(std::vector<std::string>* encodings); | 121 bool DeDupeEncodings(std::vector<std::string>* encodings); |
122 | 122 |
123 // Removes (and deletes) TemplateURLs from |template_urls| and |service| if they | 123 // Removes (and deletes) TemplateURLs from |template_urls| and |service| if they |
124 // have duplicate prepopulate ids. If |removed_keyword_guids| is not NULL, the | 124 // have duplicate prepopulate ids. If |removed_keyword_guids| is not NULL, the |
125 // Sync GUID of each item removed from the DB will be added to it. This is a | 125 // Sync GUID of each item removed from the DB will be added to it. This is a |
126 // helper used by GetSearchProvidersUsingKeywordResult(), but is declared here | 126 // helper used by GetSearchProvidersUsingKeywordResult(), but is declared here |
127 // so it's accessible by unittests. | 127 // so it's accessible by unittests. |
128 void RemoveDuplicatePrepopulateIDs( | 128 void RemoveDuplicatePrepopulateIDs( |
129 WebDataService* service, | 129 KeywordWebDataService* service, |
130 const ScopedVector<TemplateURLData>& prepopulated_urls, | 130 const ScopedVector<TemplateURLData>& prepopulated_urls, |
131 TemplateURL* default_search_provider, | 131 TemplateURL* default_search_provider, |
132 TemplateURLService::TemplateURLVector* template_urls, | 132 TemplateURLService::TemplateURLVector* template_urls, |
133 const SearchTermsData& search_terms_data, | 133 const SearchTermsData& search_terms_data, |
134 std::set<std::string>* removed_keyword_guids); | 134 std::set<std::string>* removed_keyword_guids); |
135 | 135 |
136 #endif // CHROME_BROWSER_SEARCH_ENGINES_UTIL_H_ | 136 #endif // CHROME_BROWSER_SEARCH_ENGINES_UTIL_H_ |
OLD | NEW |