[email protected] | 16fca9b8 | 2012-04-23 18:40:26 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 96788b0 | 2010-06-26 21:45:34 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_SEARCH_ENGINES_UTIL_H_ |
| 6 | #define CHROME_BROWSER_SEARCH_ENGINES_UTIL_H_ |
[email protected] | 96788b0 | 2010-06-26 21:45:34 | [diff] [blame] | 7 | |
| 8 | // This file contains utility functions for search engine functionality. |
[email protected] | 2eff6b1 | 2012-05-16 20:07:05 | [diff] [blame] | 9 | #include <set> |
| 10 | #include <string> |
[email protected] | e1ddda0 | 2010-08-26 19:43:48 | [diff] [blame] | 11 | #include <vector> |
[email protected] | 96788b0 | 2010-06-26 21:45:34 | [diff] [blame] | 12 | |
[email protected] | 2ede2131 | 2011-12-22 13:31:26 | [diff] [blame] | 13 | #include "base/memory/scoped_ptr.h" |
[email protected] | 96788b0 | 2010-06-26 21:45:34 | [diff] [blame] | 14 | #include "base/string16.h" |
[email protected] | 01ef4a66 | 2012-05-29 15:58:25 | [diff] [blame] | 15 | #include "chrome/browser/search_engines/template_url_service.h" |
[email protected] | 96788b0 | 2010-06-26 21:45:34 | [diff] [blame] | 16 | |
| 17 | class Profile; |
[email protected] | e1ddda0 | 2010-08-26 19:43:48 | [diff] [blame] | 18 | class TemplateURL; |
| 19 | class WDTypedResult; |
| 20 | class WebDataService; |
[email protected] | 96788b0 | 2010-06-26 21:45:34 | [diff] [blame] | 21 | |
| 22 | // Returns the short name of the default search engine, or the empty string if |
| 23 | // none is set. |profile| may be NULL. |
| 24 | string16 GetDefaultSearchEngineName(Profile* profile); |
| 25 | |
[email protected] | e1ddda0 | 2010-08-26 19:43:48 | [diff] [blame] | 26 | // Processes the results of WebDataService::GetKeywords, combining it with |
| 27 | // prepopulated search providers to result in: |
| 28 | // * a set of template_urls (search providers). The caller owns the |
| 29 | // TemplateURL* returned in template_urls. |
| 30 | // * the default search provider (and if *default_search_provider is not NULL, |
| 31 | // it is contained in template_urls). |
| 32 | // * whether there is a new resource keyword version (and the value). |
| 33 | // |*new_resource_keyword_version| is set to 0 if no new value. Otherwise, |
| 34 | // it is the new value. |
| 35 | // Only pass in a non-NULL value for service if the WebDataService should be |
[email protected] | 2eff6b1 | 2012-05-16 20:07:05 | [diff] [blame] | 36 | // updated. If |removed_keyword_guids| is not NULL, any TemplateURLs removed |
| 37 | // from the keyword table in the WebDataService will have their Sync GUIDs |
| 38 | // added to it. |
[email protected] | e1ddda0 | 2010-08-26 19:43:48 | [diff] [blame] | 39 | void GetSearchProvidersUsingKeywordResult( |
| 40 | const WDTypedResult& result, |
| 41 | WebDataService* service, |
[email protected] | 16fca9b8 | 2012-04-23 18:40:26 | [diff] [blame] | 42 | Profile* profile, |
[email protected] | 01ef4a66 | 2012-05-29 15:58:25 | [diff] [blame] | 43 | TemplateURLService::TemplateURLVector* template_urls, |
[email protected] | 3613347d | 2012-04-27 20:27:37 | [diff] [blame] | 44 | TemplateURL** default_search_provider, |
[email protected] | 2eff6b1 | 2012-05-16 20:07:05 | [diff] [blame] | 45 | int* new_resource_keyword_version, |
| 46 | std::set<std::string>* removed_keyword_guids); |
[email protected] | e1ddda0 | 2010-08-26 19:43:48 | [diff] [blame] | 47 | |
[email protected] | a262230 | 2012-06-27 03:36:07 | [diff] [blame] | 48 | // Due to a bug, the |input_encodings| field of TemplateURLData could have |
| 49 | // contained duplicate entries. This removes those entries and returns whether |
| 50 | // any were found. |
| 51 | bool DeDupeEncodings(std::vector<std::string>* encodings); |
| 52 | |
[email protected] | 01ef4a66 | 2012-05-29 15:58:25 | [diff] [blame] | 53 | // Removes (and deletes) TemplateURLs from |template_urls| and |service| if they |
| 54 | // have duplicate prepopulate ids. If |removed_keyword_guids| is not NULL, the |
| 55 | // Sync GUID of each item removed from the DB will be added to it. This is a |
| 56 | // helper used by GetSearchProvidersUsingKeywordResult(), but is declared here |
| 57 | // so it's accessible by unittests. |
| 58 | void RemoveDuplicatePrepopulateIDs( |
| 59 | WebDataService* service, |
| 60 | const ScopedVector<TemplateURL>& prepopulated_urls, |
| 61 | TemplateURL* default_search_provider, |
| 62 | TemplateURLService::TemplateURLVector* template_urls, |
| 63 | std::set<std::string>* removed_keyword_guids); |
| 64 | |
[email protected] | 96788b0 | 2010-06-26 21:45:34 | [diff] [blame] | 65 | #endif // CHROME_BROWSER_SEARCH_ENGINES_UTIL_H_ |