[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] | 24a555b6 | 2013-06-10 22:01:17 | [diff] [blame] | 14 | #include "base/strings/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] | bba9e63 | 2013-06-28 22:52:19 | [diff] [blame^] | 26 | // Returns a GURL that searches for |terms| using the default search engine of |
| 27 | // |profile|. |
| 28 | GURL GetDefaultSearchURLForSearchTerms(Profile* profile, const string16& terms); |
| 29 | |
[email protected] | 10aeaf1 | 2013-02-05 07:41:46 | [diff] [blame] | 30 | // Modifies |prepopulated_url| so that it contains user-modified fields from |
| 31 | // |original_turl|. Both URLs must have the same prepopulate_id. |
| 32 | void MergeIntoPrepopulatedEngineData(TemplateURLData* prepopulated_url, |
| 33 | const TemplateURL* original_turl); |
| 34 | |
[email protected] | e1ddda0 | 2010-08-26 19:43:48 | [diff] [blame] | 35 | // Processes the results of WebDataService::GetKeywords, combining it with |
| 36 | // prepopulated search providers to result in: |
| 37 | // * a set of template_urls (search providers). The caller owns the |
| 38 | // TemplateURL* returned in template_urls. |
| 39 | // * the default search provider (and if *default_search_provider is not NULL, |
| 40 | // it is contained in template_urls). |
| 41 | // * whether there is a new resource keyword version (and the value). |
| 42 | // |*new_resource_keyword_version| is set to 0 if no new value. Otherwise, |
| 43 | // it is the new value. |
| 44 | // 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] | 45 | // updated. If |removed_keyword_guids| is not NULL, any TemplateURLs removed |
| 46 | // from the keyword table in the WebDataService will have their Sync GUIDs |
| 47 | // added to it. |
[email protected] | e1ddda0 | 2010-08-26 19:43:48 | [diff] [blame] | 48 | void GetSearchProvidersUsingKeywordResult( |
| 49 | const WDTypedResult& result, |
| 50 | WebDataService* service, |
[email protected] | 16fca9b8 | 2012-04-23 18:40:26 | [diff] [blame] | 51 | Profile* profile, |
[email protected] | 01ef4a66 | 2012-05-29 15:58:25 | [diff] [blame] | 52 | TemplateURLService::TemplateURLVector* template_urls, |
[email protected] | 3613347d | 2012-04-27 20:27:37 | [diff] [blame] | 53 | TemplateURL** default_search_provider, |
[email protected] | 2eff6b1 | 2012-05-16 20:07:05 | [diff] [blame] | 54 | int* new_resource_keyword_version, |
| 55 | std::set<std::string>* removed_keyword_guids); |
[email protected] | e1ddda0 | 2010-08-26 19:43:48 | [diff] [blame] | 56 | |
[email protected] | 4a40facd | 2013-05-29 14:44:56 | [diff] [blame] | 57 | // Like GetSearchProvidersUsingKeywordResult(), but allows the caller to pass in |
| 58 | // engines in |template_urls| instead of getting them via processing a web data |
| 59 | // service request. |
| 60 | // |resource_keyword_version| should contain the version number of the current |
| 61 | // keyword data, i.e. the version number of the most recent prepopulate data |
| 62 | // that has been merged into the current keyword data. On exit, this will be |
| 63 | // set as in GetSearchProvidersUsingKeywordResult(). |
| 64 | void GetSearchProvidersUsingLoadedEngines( |
| 65 | WebDataService* service, |
| 66 | Profile* profile, |
| 67 | TemplateURLService::TemplateURLVector* template_urls, |
| 68 | TemplateURL** default_search_provider, |
| 69 | int* resource_keyword_version, |
| 70 | std::set<std::string>* removed_keyword_guids); |
| 71 | |
[email protected] | a262230 | 2012-06-27 03:36:07 | [diff] [blame] | 72 | // Due to a bug, the |input_encodings| field of TemplateURLData could have |
| 73 | // contained duplicate entries. This removes those entries and returns whether |
| 74 | // any were found. |
| 75 | bool DeDupeEncodings(std::vector<std::string>* encodings); |
| 76 | |
[email protected] | 01ef4a66 | 2012-05-29 15:58:25 | [diff] [blame] | 77 | // Removes (and deletes) TemplateURLs from |template_urls| and |service| if they |
| 78 | // have duplicate prepopulate ids. If |removed_keyword_guids| is not NULL, the |
| 79 | // Sync GUID of each item removed from the DB will be added to it. This is a |
| 80 | // helper used by GetSearchProvidersUsingKeywordResult(), but is declared here |
| 81 | // so it's accessible by unittests. |
| 82 | void RemoveDuplicatePrepopulateIDs( |
| 83 | WebDataService* service, |
| 84 | const ScopedVector<TemplateURL>& prepopulated_urls, |
| 85 | TemplateURL* default_search_provider, |
| 86 | TemplateURLService::TemplateURLVector* template_urls, |
| 87 | std::set<std::string>* removed_keyword_guids); |
| 88 | |
[email protected] | 96788b0 | 2010-06-26 21:45:34 | [diff] [blame] | 89 | #endif // CHROME_BROWSER_SEARCH_ENGINES_UTIL_H_ |