File: template_url_prepopulate_data.h

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (112 lines) | stat: -rw-r--r-- 4,661 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_PREPOPULATE_DATA_H_
#define COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_PREPOPULATE_DATA_H_

#include <stddef.h>

#include <memory>
#include <string>
#include <vector>

#include "base/containers/span.h"
#include "build/build_config.h"

class PrefService;
struct TemplateURLData;

namespace user_prefs {
class PrefRegistrySyncable;
}

namespace TemplateURLPrepopulateData {

struct PrepopulatedEngine;

extern const int kMaxPrepopulatedEngineID;

// The maximum number of prepopulated search engines that can be returned in
// any of the EEA countries by `GetPrepopulatedEngines()`.
//
// Note: If this is increased, please also increase the declared variant count
// for the `Search.ChoiceScreenShowedEngineAt.Index{Index}` histogram.
// TODO(crbug.com/408932087): Investigate moving it to the file that actually
// populates these, `//c/regional_capabilities/r*c*_util.cc`.
inline constexpr size_t kMaxEeaPrepopulatedEngines = 8;

// The maximum number of prepopulated search engines that can be returned in
// in the rest of the world by `GetPrepopulatedEngines()`.
// TODO(crbug.com/408932087): Investigate deduping it with the constant
// `kTopSearchEnginesThreshold` in `//c/regional_capabilities/r*c*_util.cc`.
inline constexpr size_t kMaxRowPrepopulatedEngines = 5;

void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);

// Returns the current version of the prepopulate data, so callers can know when
// they need to re-merge. If the prepopulate data comes from the preferences
// file then it returns the version specified there.
int GetDataVersion(PrefService* prefs);

// Resolves the prepopulated Template URLs to use, resolving priority between
// regional data and profile-specific data.
std::vector<std::unique_ptr<TemplateURLData>> GetPrepopulatedEngines(
    PrefService& prefs,
    std::vector<const TemplateURLPrepopulateData::PrepopulatedEngine*>
        regional_prepopulated_engines);

// Returns the prepopulated search engine with the given `prepopulated_id`
// or `nullptr` if it's not known there.
// See `GetPrepopulatedEngines()` for more about how we get prepopulated
// template URLs.
std::unique_ptr<TemplateURLData> GetPrepopulatedEngine(
    PrefService& prefs,
    std::vector<const TemplateURLPrepopulateData::PrepopulatedEngine*>
        regional_prepopulated_engines,
    int prepopulated_id);

// Returns the prepopulated search engine with the given `prepopulated_id`
// from the full list of known prepopulated search engines, or `nullptr` if
// it's not known there.
// The region-specific list is used to ensure we prioritise returning a search
// engine relevant for the given country, for cases where the `prepopulated_id`
// could be associated with multiple country-specific variants.
std::unique_ptr<TemplateURLData> GetPrepopulatedEngineFromFullList(
    PrefService& prefs,
    std::vector<const TemplateURLPrepopulateData::PrepopulatedEngine*>
        regional_prepopulated_engines,
    int prepopulated_id);

#if BUILDFLAG(IS_ANDROID)
// Returns the prepopulated URLs associated with `country_code`.
// `country_code` is a two-character uppercase ISO 3166-1 country code.
// `prefs` is the main profile's preferences.
std::vector<std::unique_ptr<TemplateURLData>> GetLocalPrepopulatedEngines(
    const std::string& country_code,
    PrefService& prefs);
#endif

// Removes prepopulated engines and their version stored in user prefs.
void ClearPrepopulatedEnginesInPrefs(PrefService* prefs);

// Returns the fallback default search provider, currently hardcoded to be
// Google, or whichever one is the first of the list if Google is not in the
// list of prepopulated search engines.
// Search provider overrides are read from `prefs`.
// The region-specific list is used to ensure we prioritise returning a search
// engine relevant for the given country, for cases where the `prepopulated_id`
// could be associated with multiple country-specific variants.
// May return `nullptr` if for some reason there are no prepopulated search
// engines available.
std::unique_ptr<TemplateURLData> GetPrepopulatedFallbackSearch(
    PrefService& prefs,
    std::vector<const TemplateURLPrepopulateData::PrepopulatedEngine*>
        regional_prepopulated_engines);

// Returns all prepopulated engines for all locales.
const base::span<const PrepopulatedEngine* const> GetAllPrepopulatedEngines();

}  // namespace TemplateURLPrepopulateData

#endif  // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_PREPOPULATE_DATA_H_