blob: 158841aa27f1fa8c825b78148151084cbdbcaadd [file] [log] [blame]
[email protected]16fca9b82012-04-23 18:40:261// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]96788b02010-06-26 21:45:342// 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]96788b02010-06-26 21:45:347
8// This file contains utility functions for search engine functionality.
[email protected]2eff6b12012-05-16 20:07:059#include <set>
10#include <string>
[email protected]e1ddda02010-08-26 19:43:4811#include <vector>
[email protected]96788b02010-06-26 21:45:3412
[email protected]2ede21312011-12-22 13:31:2613#include "base/memory/scoped_ptr.h"
[email protected]96788b02010-06-26 21:45:3414#include "base/string16.h"
[email protected]01ef4a662012-05-29 15:58:2515#include "chrome/browser/search_engines/template_url_service.h"
[email protected]96788b02010-06-26 21:45:3416
17class Profile;
[email protected]e1ddda02010-08-26 19:43:4818class TemplateURL;
19class WDTypedResult;
20class WebDataService;
[email protected]96788b02010-06-26 21:45:3421
22// Returns the short name of the default search engine, or the empty string if
23// none is set. |profile| may be NULL.
24string16 GetDefaultSearchEngineName(Profile* profile);
25
[email protected]10aeaf12013-02-05 07:41:4626// Modifies |prepopulated_url| so that it contains user-modified fields from
27// |original_turl|. Both URLs must have the same prepopulate_id.
28void MergeIntoPrepopulatedEngineData(TemplateURLData* prepopulated_url,
29 const TemplateURL* original_turl);
30
[email protected]e1ddda02010-08-26 19:43:4831// Processes the results of WebDataService::GetKeywords, combining it with
32// prepopulated search providers to result in:
33// * a set of template_urls (search providers). The caller owns the
34// TemplateURL* returned in template_urls.
35// * the default search provider (and if *default_search_provider is not NULL,
36// it is contained in template_urls).
37// * whether there is a new resource keyword version (and the value).
38// |*new_resource_keyword_version| is set to 0 if no new value. Otherwise,
39// it is the new value.
40// Only pass in a non-NULL value for service if the WebDataService should be
[email protected]2eff6b12012-05-16 20:07:0541// updated. If |removed_keyword_guids| is not NULL, any TemplateURLs removed
42// from the keyword table in the WebDataService will have their Sync GUIDs
43// added to it.
[email protected]e1ddda02010-08-26 19:43:4844void GetSearchProvidersUsingKeywordResult(
45 const WDTypedResult& result,
46 WebDataService* service,
[email protected]16fca9b82012-04-23 18:40:2647 Profile* profile,
[email protected]01ef4a662012-05-29 15:58:2548 TemplateURLService::TemplateURLVector* template_urls,
[email protected]3613347d2012-04-27 20:27:3749 TemplateURL** default_search_provider,
[email protected]2eff6b12012-05-16 20:07:0550 int* new_resource_keyword_version,
51 std::set<std::string>* removed_keyword_guids);
[email protected]e1ddda02010-08-26 19:43:4852
[email protected]4a40facd2013-05-29 14:44:5653// Like GetSearchProvidersUsingKeywordResult(), but allows the caller to pass in
54// engines in |template_urls| instead of getting them via processing a web data
55// service request.
56// |resource_keyword_version| should contain the version number of the current
57// keyword data, i.e. the version number of the most recent prepopulate data
58// that has been merged into the current keyword data. On exit, this will be
59// set as in GetSearchProvidersUsingKeywordResult().
60void GetSearchProvidersUsingLoadedEngines(
61 WebDataService* service,
62 Profile* profile,
63 TemplateURLService::TemplateURLVector* template_urls,
64 TemplateURL** default_search_provider,
65 int* resource_keyword_version,
66 std::set<std::string>* removed_keyword_guids);
67
[email protected]a2622302012-06-27 03:36:0768// Due to a bug, the |input_encodings| field of TemplateURLData could have
69// contained duplicate entries. This removes those entries and returns whether
70// any were found.
71bool DeDupeEncodings(std::vector<std::string>* encodings);
72
[email protected]01ef4a662012-05-29 15:58:2573// Removes (and deletes) TemplateURLs from |template_urls| and |service| if they
74// have duplicate prepopulate ids. If |removed_keyword_guids| is not NULL, the
75// Sync GUID of each item removed from the DB will be added to it. This is a
76// helper used by GetSearchProvidersUsingKeywordResult(), but is declared here
77// so it's accessible by unittests.
78void RemoveDuplicatePrepopulateIDs(
79 WebDataService* service,
80 const ScopedVector<TemplateURL>& prepopulated_urls,
81 TemplateURL* default_search_provider,
82 TemplateURLService::TemplateURLVector* template_urls,
83 std::set<std::string>* removed_keyword_guids);
84
[email protected]96788b02010-06-26 21:45:3485#endif // CHROME_BROWSER_SEARCH_ENGINES_UTIL_H_