[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] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 96788b0 | 2010-06-26 21:45:34 | [diff] [blame] | 8 | |
| 9 | // This file contains utility functions for search engine functionality. |
[email protected] | 2eff6b1 | 2012-05-16 20:07:05 | [diff] [blame] | 10 | #include <set> |
| 11 | #include <string> |
[email protected] | e1ddda0 | 2010-08-26 19:43:48 | [diff] [blame] | 12 | #include <vector> |
[email protected] | 96788b0 | 2010-06-26 21:45:34 | [diff] [blame] | 13 | |
[email protected] | 2ede2131 | 2011-12-22 13:31:26 | [diff] [blame] | 14 | #include "base/memory/scoped_ptr.h" |
[email protected] | 96788b0 | 2010-06-26 21:45:34 | [diff] [blame] | 15 | #include "base/string16.h" |
[email protected] | 01ef4a66 | 2012-05-29 15:58:25 | [diff] [blame^] | 16 | #include "chrome/browser/search_engines/template_url_service.h" |
[email protected] | 96788b0 | 2010-06-26 21:45:34 | [diff] [blame] | 17 | |
| 18 | class Profile; |
[email protected] | e1ddda0 | 2010-08-26 19:43:48 | [diff] [blame] | 19 | class TemplateURL; |
| 20 | class WDTypedResult; |
| 21 | class WebDataService; |
[email protected] | 96788b0 | 2010-06-26 21:45:34 | [diff] [blame] | 22 | |
| 23 | // Returns the short name of the default search engine, or the empty string if |
| 24 | // none is set. |profile| may be NULL. |
| 25 | string16 GetDefaultSearchEngineName(Profile* profile); |
| 26 | |
[email protected] | e1ddda0 | 2010-08-26 19:43:48 | [diff] [blame] | 27 | // Processes the results of WebDataService::GetKeywords, combining it with |
| 28 | // prepopulated search providers to result in: |
| 29 | // * a set of template_urls (search providers). The caller owns the |
| 30 | // TemplateURL* returned in template_urls. |
| 31 | // * the default search provider (and if *default_search_provider is not NULL, |
| 32 | // it is contained in template_urls). |
| 33 | // * whether there is a new resource keyword version (and the value). |
| 34 | // |*new_resource_keyword_version| is set to 0 if no new value. Otherwise, |
| 35 | // it is the new value. |
| 36 | // 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] | 37 | // updated. If |removed_keyword_guids| is not NULL, any TemplateURLs removed |
| 38 | // from the keyword table in the WebDataService will have their Sync GUIDs |
| 39 | // added to it. |
[email protected] | e1ddda0 | 2010-08-26 19:43:48 | [diff] [blame] | 40 | void GetSearchProvidersUsingKeywordResult( |
| 41 | const WDTypedResult& result, |
| 42 | WebDataService* service, |
[email protected] | 16fca9b8 | 2012-04-23 18:40:26 | [diff] [blame] | 43 | Profile* profile, |
[email protected] | 01ef4a66 | 2012-05-29 15:58:25 | [diff] [blame^] | 44 | TemplateURLService::TemplateURLVector* template_urls, |
[email protected] | 3613347d | 2012-04-27 20:27:37 | [diff] [blame] | 45 | TemplateURL** default_search_provider, |
[email protected] | 2eff6b1 | 2012-05-16 20:07:05 | [diff] [blame] | 46 | int* new_resource_keyword_version, |
| 47 | std::set<std::string>* removed_keyword_guids); |
[email protected] | e1ddda0 | 2010-08-26 19:43:48 | [diff] [blame] | 48 | |
[email protected] | 75a4eca | 2011-10-26 20:40:09 | [diff] [blame] | 49 | // Returns true if the default search provider setting has been changed or |
| 50 | // corrupted. Returns the backup setting in |backup_default_search_provider|. |
| 51 | // |*backup_default_search_provider| can be NULL if the original setting is |
| 52 | // lost. |
| 53 | bool DidDefaultSearchProviderChange( |
| 54 | const WDTypedResult& result, |
[email protected] | 16fca9b8 | 2012-04-23 18:40:26 | [diff] [blame] | 55 | Profile* profile, |
[email protected] | 2ede2131 | 2011-12-22 13:31:26 | [diff] [blame] | 56 | scoped_ptr<TemplateURL>* backup_default_search_provider); |
[email protected] | 75a4eca | 2011-10-26 20:40:09 | [diff] [blame] | 57 | |
[email protected] | 01ef4a66 | 2012-05-29 15:58:25 | [diff] [blame^] | 58 | // Removes (and deletes) TemplateURLs from |template_urls| and |service| if they |
| 59 | // have duplicate prepopulate ids. If |removed_keyword_guids| is not NULL, the |
| 60 | // Sync GUID of each item removed from the DB will be added to it. This is a |
| 61 | // helper used by GetSearchProvidersUsingKeywordResult(), but is declared here |
| 62 | // so it's accessible by unittests. |
| 63 | void RemoveDuplicatePrepopulateIDs( |
| 64 | WebDataService* service, |
| 65 | const ScopedVector<TemplateURL>& prepopulated_urls, |
| 66 | TemplateURL* default_search_provider, |
| 67 | TemplateURLService::TemplateURLVector* template_urls, |
| 68 | std::set<std::string>* removed_keyword_guids); |
| 69 | |
[email protected] | 96788b0 | 2010-06-26 21:45:34 | [diff] [blame] | 70 | #endif // CHROME_BROWSER_SEARCH_ENGINES_UTIL_H_ |