Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Side by Side Diff: components/search_engines/template_url_prepopulate_data.h

Issue 1983773002: Cache SearchEngineType of TemplateURL (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor-extracting-terms-from-template-url
Patch Set: Fix typo Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_PREPOPULATE_DATA_H_ 5 #ifndef COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_PREPOPULATE_DATA_H_
6 #define COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_PREPOPULATE_DATA_H_ 6 #define COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_PREPOPULATE_DATA_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/memory/scoped_vector.h" 14 #include "base/memory/scoped_vector.h"
15 #include "base/strings/string16.h" 15 #include "base/strings/string16.h"
16 #include "components/search_engines/search_engine_type.h" 16 #include "components/search_engines/search_engine_type.h"
17 17
18 class GURL; 18 class GURL;
19 class PrefService; 19 class PrefService;
20 class SearchTermsData;
21 class TemplateURL;
22 struct TemplateURLData; 20 struct TemplateURLData;
23 21
24 namespace user_prefs { 22 namespace user_prefs {
25 class PrefRegistrySyncable; 23 class PrefRegistrySyncable;
26 } 24 }
27 25
28 namespace TemplateURLPrepopulateData { 26 namespace TemplateURLPrepopulateData {
29 27
30 struct PrepopulatedEngine; 28 struct PrepopulatedEngine;
31 29
32 extern const int kMaxPrepopulatedEngineID; 30 extern const int kMaxPrepopulatedEngineID;
33 31
34 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 32 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
35 33
36 // Returns the current version of the prepopulate data, so callers can know when 34 // Returns the current version of the prepopulate data, so callers can know when
37 // they need to re-merge. If the prepopulate data comes from the preferences 35 // they need to re-merge. If the prepopulate data comes from the preferences
38 // file then it returns the version specified there. 36 // file then it returns the version specified there.
39 int GetDataVersion(PrefService* prefs); 37 int GetDataVersion(PrefService* prefs);
40 38
41 // Loads the set of TemplateURLs from the prepopulate data. On return, 39 // Loads the set of TemplateURLs from the prepopulate data. On return,
42 // |default_search_provider_index| is set to the index of the default search 40 // |default_search_provider_index| is set to the index of the default search
43 // provider. 41 // provider.
44 ScopedVector<TemplateURLData> GetPrepopulatedEngines( 42 ScopedVector<TemplateURLData> GetPrepopulatedEngines(
45 PrefService* prefs, 43 PrefService* prefs,
46 size_t* default_search_provider_index); 44 size_t* default_search_provider_index);
47 45
46 // Returns all prepopulated engines for all locales. Used only by tests.
47 std::vector<const PrepopulatedEngine*> GetAllPrepopulatedEngines();
48
48 // Returns a TemplateURLData for the specified prepopulated engine. 49 // Returns a TemplateURLData for the specified prepopulated engine.
49 std::unique_ptr<TemplateURLData> MakeTemplateURLDataFromPrepopulatedEngine( 50 std::unique_ptr<TemplateURLData> MakeTemplateURLDataFromPrepopulatedEngine(
50 const PrepopulatedEngine& engine); 51 const PrepopulatedEngine& engine);
51 52
52 // Removes prepopulated engines and their version stored in user prefs. 53 // Removes prepopulated engines and their version stored in user prefs.
53 void ClearPrepopulatedEnginesInPrefs(PrefService* prefs); 54 void ClearPrepopulatedEnginesInPrefs(PrefService* prefs);
54 55
55 // Returns the default search provider specified by the prepopulate data, which 56 // Returns the default search provider specified by the prepopulate data, which
56 // may be NULL. 57 // may be NULL.
57 // If |prefs| is NULL, any search provider overrides from the preferences are 58 // If |prefs| is NULL, any search provider overrides from the preferences are
58 // not used. 59 // not used.
59 std::unique_ptr<TemplateURLData> GetPrepopulatedDefaultSearch( 60 std::unique_ptr<TemplateURLData> GetPrepopulatedDefaultSearch(
60 PrefService* prefs); 61 PrefService* prefs);
61 62
62 // Returns the type of the provided engine, or SEARCH_ENGINE_OTHER if no engines
63 // match. This checks the TLD+1 for the most part, but will report the type as
64 // SEARCH_ENGINE_GOOGLE for any hostname that causes
65 // google_util::IsGoogleHostname() to return true.
66 //
67 // NOTE: Must be called on the UI thread.
68 SearchEngineType GetEngineType(const TemplateURL& template_url,
69 const SearchTermsData& search_terms_data);
70
71 // Like the above, but takes a GURL which is expected to represent a search URL. 63 // Like the above, but takes a GURL which is expected to represent a search URL.
72 // This may be called on any thread. 64 // This may be called on any thread.
73 SearchEngineType GetEngineType(const GURL& url); 65 SearchEngineType GetEngineType(const GURL& url);
74 66
75 // Returns the identifier for the user current country. Used to update the list 67 // Returns the identifier for the user current country. Used to update the list
76 // of search engines when user switches device region settings. For use on iOS 68 // of search engines when user switches device region settings. For use on iOS
77 // only. 69 // only.
78 // TODO(ios): Once user can customize search engines ( http://crbug.com/153047 ) 70 // TODO(ios): Once user can customize search engines ( http://crbug.com/153047 )
79 // this declaration should be removed and the definition in the .cc file be 71 // this declaration should be removed and the definition in the .cc file be
80 // moved back to the anonymous namespace. 72 // moved back to the anonymous namespace.
81 int GetCurrentCountryID(); 73 int GetCurrentCountryID();
82 74
83 } // namespace TemplateURLPrepopulateData 75 } // namespace TemplateURLPrepopulateData
84 76
85 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_PREPOPULATE_DATA_H_ 77 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_PREPOPULATE_DATA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698