| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 // This file contains utility functions for search engine functionality. | 9 // This file contains utility functions for search engine functionality. |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/string16.h" | 15 #include "base/string16.h" |
| 16 #include "chrome/browser/search_engines/template_url_service.h" |
| 16 | 17 |
| 17 class Profile; | 18 class Profile; |
| 18 class TemplateURL; | 19 class TemplateURL; |
| 19 class WDTypedResult; | 20 class WDTypedResult; |
| 20 class WebDataService; | 21 class WebDataService; |
| 21 | 22 |
| 22 // Returns the short name of the default search engine, or the empty string if | 23 // Returns the short name of the default search engine, or the empty string if |
| 23 // none is set. |profile| may be NULL. | 24 // none is set. |profile| may be NULL. |
| 24 string16 GetDefaultSearchEngineName(Profile* profile); | 25 string16 GetDefaultSearchEngineName(Profile* profile); |
| 25 | 26 |
| 26 // Processes the results of WebDataService::GetKeywords, combining it with | 27 // Processes the results of WebDataService::GetKeywords, combining it with |
| 27 // prepopulated search providers to result in: | 28 // prepopulated search providers to result in: |
| 28 // * a set of template_urls (search providers). The caller owns the | 29 // * a set of template_urls (search providers). The caller owns the |
| 29 // TemplateURL* returned in template_urls. | 30 // TemplateURL* returned in template_urls. |
| 30 // * the default search provider (and if *default_search_provider is not NULL, | 31 // * the default search provider (and if *default_search_provider is not NULL, |
| 31 // it is contained in template_urls). | 32 // it is contained in template_urls). |
| 32 // * whether there is a new resource keyword version (and the value). | 33 // * 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 // |*new_resource_keyword_version| is set to 0 if no new value. Otherwise, |
| 34 // it is the new value. | 35 // it is the new value. |
| 35 // Only pass in a non-NULL value for service if the WebDataService should be | 36 // Only pass in a non-NULL value for service if the WebDataService should be |
| 36 // updated. If |removed_keyword_guids| is not NULL, any TemplateURLs removed | 37 // 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 // from the keyword table in the WebDataService will have their Sync GUIDs |
| 38 // added to it. | 39 // added to it. |
| 39 void GetSearchProvidersUsingKeywordResult( | 40 void GetSearchProvidersUsingKeywordResult( |
| 40 const WDTypedResult& result, | 41 const WDTypedResult& result, |
| 41 WebDataService* service, | 42 WebDataService* service, |
| 42 Profile* profile, | 43 Profile* profile, |
| 43 std::vector<TemplateURL*>* template_urls, | 44 TemplateURLService::TemplateURLVector* template_urls, |
| 44 TemplateURL** default_search_provider, | 45 TemplateURL** default_search_provider, |
| 45 int* new_resource_keyword_version, | 46 int* new_resource_keyword_version, |
| 46 std::set<std::string>* removed_keyword_guids); | 47 std::set<std::string>* removed_keyword_guids); |
| 47 | 48 |
| 48 // Returns true if the default search provider setting has been changed or | 49 // Returns true if the default search provider setting has been changed or |
| 49 // corrupted. Returns the backup setting in |backup_default_search_provider|. | 50 // corrupted. Returns the backup setting in |backup_default_search_provider|. |
| 50 // |*backup_default_search_provider| can be NULL if the original setting is | 51 // |*backup_default_search_provider| can be NULL if the original setting is |
| 51 // lost. | 52 // lost. |
| 52 bool DidDefaultSearchProviderChange( | 53 bool DidDefaultSearchProviderChange( |
| 53 const WDTypedResult& result, | 54 const WDTypedResult& result, |
| 54 Profile* profile, | 55 Profile* profile, |
| 55 scoped_ptr<TemplateURL>* backup_default_search_provider); | 56 scoped_ptr<TemplateURL>* backup_default_search_provider); |
| 56 | 57 |
| 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 |
| 57 #endif // CHROME_BROWSER_SEARCH_ENGINES_UTIL_H_ | 70 #endif // CHROME_BROWSER_SEARCH_ENGINES_UTIL_H_ |
| OLD | NEW |