| 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_UTIL_H_ | 5 #ifndef COMPONENTS_SEARCH_ENGINES_UTIL_H_ |
| 6 #define COMPONENTS_SEARCH_ENGINES_UTIL_H_ | 6 #define COMPONENTS_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 <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 // Given the user's current URLs and the current set of prepopulated URLs, | 73 // Given the user's current URLs and the current set of prepopulated URLs, |
| 74 // produces the set of actions (see above) required to make the user's URLs | 74 // produces the set of actions (see above) required to make the user's URLs |
| 75 // reflect the prepopulate data. |default_search_provider| is used to avoid | 75 // reflect the prepopulate data. |default_search_provider| is used to avoid |
| 76 // placing the current default provider on the "to be removed" list. | 76 // placing the current default provider on the "to be removed" list. |
| 77 // | 77 // |
| 78 // NOTE: Takes ownership of, and clears, |prepopulated_urls|. | 78 // NOTE: Takes ownership of, and clears, |prepopulated_urls|. |
| 79 ActionsFromPrepopulateData CreateActionsFromCurrentPrepopulateData( | 79 ActionsFromPrepopulateData CreateActionsFromCurrentPrepopulateData( |
| 80 ScopedVector<TemplateURLData>* prepopulated_urls, | 80 ScopedVector<TemplateURLData>* prepopulated_urls, |
| 81 const TemplateURLService::TemplateURLVector& existing_urls, | 81 const TemplateURLService::OwnedTemplateURLVector& existing_urls, |
| 82 const TemplateURL* default_search_provider); | 82 const TemplateURL* default_search_provider); |
| 83 | 83 |
| 84 // Processes the results of KeywordWebDataService::GetKeywords, combining it | 84 // Processes the results of KeywordWebDataService::GetKeywords, combining it |
| 85 // with prepopulated search providers to result in: | 85 // with prepopulated search providers to result in: |
| 86 // * a set of template_urls (search providers). The caller owns the | 86 // * a set of template_urls (search providers). The caller owns the |
| 87 // TemplateURL* returned in template_urls. | 87 // TemplateURL* returned in template_urls. |
| 88 // * whether there is a new resource keyword version (and the value). | 88 // * whether there is a new resource keyword version (and the value). |
| 89 // |*new_resource_keyword_version| is set to 0 if no new value. Otherwise, | 89 // |*new_resource_keyword_version| is set to 0 if no new value. Otherwise, |
| 90 // it is the new value. | 90 // it is the new value. |
| 91 // Only pass in a non-NULL value for service if the KeywordWebDataService should | 91 // Only pass in a non-NULL value for service if the KeywordWebDataService should |
| 92 // be updated. If |removed_keyword_guids| is not NULL, any TemplateURLs removed | 92 // be updated. If |removed_keyword_guids| is not NULL, any TemplateURLs removed |
| 93 // from the keyword table in the KeywordWebDataService will have their Sync | 93 // from the keyword table in the KeywordWebDataService will have their Sync |
| 94 // GUIDs added to it. |default_search_provider| will be used to prevent removing | 94 // GUIDs added to it. |default_search_provider| will be used to prevent removing |
| 95 // the current user-selected DSE, regardless of changes in prepopulate data. | 95 // the current user-selected DSE, regardless of changes in prepopulate data. |
| 96 void GetSearchProvidersUsingKeywordResult( | 96 void GetSearchProvidersUsingKeywordResult( |
| 97 const WDTypedResult& result, | 97 const WDTypedResult& result, |
| 98 KeywordWebDataService* service, | 98 KeywordWebDataService* service, |
| 99 PrefService* prefs, | 99 PrefService* prefs, |
| 100 TemplateURLService::TemplateURLVector* template_urls, | 100 TemplateURLService::OwnedTemplateURLVector* template_urls, |
| 101 TemplateURL* default_search_provider, | 101 TemplateURL* default_search_provider, |
| 102 const SearchTermsData& search_terms_data, | 102 const SearchTermsData& search_terms_data, |
| 103 int* new_resource_keyword_version, | 103 int* new_resource_keyword_version, |
| 104 std::set<std::string>* removed_keyword_guids); | 104 std::set<std::string>* removed_keyword_guids); |
| 105 | 105 |
| 106 // Like GetSearchProvidersUsingKeywordResult(), but allows the caller to pass in | 106 // Like GetSearchProvidersUsingKeywordResult(), but allows the caller to pass in |
| 107 // engines in |template_urls| instead of getting them via processing a web data | 107 // engines in |template_urls| instead of getting them via processing a web data |
| 108 // service request. | 108 // service request. |
| 109 // |resource_keyword_version| should contain the version number of the current | 109 // |resource_keyword_version| should contain the version number of the current |
| 110 // keyword data, i.e. the version number of the most recent prepopulate data | 110 // keyword data, i.e. the version number of the most recent prepopulate data |
| 111 // that has been merged into the current keyword data. On exit, this will be | 111 // that has been merged into the current keyword data. On exit, this will be |
| 112 // set as in GetSearchProvidersUsingKeywordResult(). | 112 // set as in GetSearchProvidersUsingKeywordResult(). |
| 113 void GetSearchProvidersUsingLoadedEngines( | 113 void GetSearchProvidersUsingLoadedEngines( |
| 114 KeywordWebDataService* service, | 114 KeywordWebDataService* service, |
| 115 PrefService* prefs, | 115 PrefService* prefs, |
| 116 TemplateURLService::TemplateURLVector* template_urls, | 116 TemplateURLService::OwnedTemplateURLVector* template_urls, |
| 117 TemplateURL* default_search_provider, | 117 TemplateURL* default_search_provider, |
| 118 const SearchTermsData& search_terms_data, | 118 const SearchTermsData& search_terms_data, |
| 119 int* resource_keyword_version, | 119 int* resource_keyword_version, |
| 120 std::set<std::string>* removed_keyword_guids); | 120 std::set<std::string>* removed_keyword_guids); |
| 121 | 121 |
| 122 // Due to a bug, the |input_encodings| field of TemplateURLData could have | 122 // Due to a bug, the |input_encodings| field of TemplateURLData could have |
| 123 // contained duplicate entries. This removes those entries and returns whether | 123 // contained duplicate entries. This removes those entries and returns whether |
| 124 // any were found. | 124 // any were found. |
| 125 bool DeDupeEncodings(std::vector<std::string>* encodings); | 125 bool DeDupeEncodings(std::vector<std::string>* encodings); |
| 126 | 126 |
| 127 // Removes (and deletes) TemplateURLs from |template_urls| and |service| if they | 127 // Removes (and deletes) TemplateURLs from |template_urls| and |service| if they |
| 128 // have duplicate prepopulate ids. If |removed_keyword_guids| is not NULL, the | 128 // have duplicate prepopulate ids. If |removed_keyword_guids| is not NULL, the |
| 129 // Sync GUID of each item removed from the DB will be added to it. This is a | 129 // Sync GUID of each item removed from the DB will be added to it. This is a |
| 130 // helper used by GetSearchProvidersUsingKeywordResult(), but is declared here | 130 // helper used by GetSearchProvidersUsingKeywordResult(), but is declared here |
| 131 // so it's accessible by unittests. | 131 // so it's accessible by unittests. |
| 132 void RemoveDuplicatePrepopulateIDs( | 132 void RemoveDuplicatePrepopulateIDs( |
| 133 KeywordWebDataService* service, | 133 KeywordWebDataService* service, |
| 134 const ScopedVector<TemplateURLData>& prepopulated_urls, | 134 const ScopedVector<TemplateURLData>& prepopulated_urls, |
| 135 TemplateURL* default_search_provider, | 135 TemplateURL* default_search_provider, |
| 136 TemplateURLService::TemplateURLVector* template_urls, | 136 TemplateURLService::OwnedTemplateURLVector* template_urls, |
| 137 const SearchTermsData& search_terms_data, | 137 const SearchTermsData& search_terms_data, |
| 138 std::set<std::string>* removed_keyword_guids); | 138 std::set<std::string>* removed_keyword_guids); |
| 139 | 139 |
| 140 TemplateURLService::OwnedTemplateURLVector::iterator FindTemplateURL( |
| 141 TemplateURLService::OwnedTemplateURLVector* urls, |
| 142 TemplateURL* url); |
| 143 |
| 140 #endif // COMPONENTS_SEARCH_ENGINES_UTIL_H_ | 144 #endif // COMPONENTS_SEARCH_ENGINES_UTIL_H_ |
| OLD | NEW |