1 // Copyright 2014 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_SEARCH_ENGINES_SEARCH_TERMS_DATA_H_
6 #define COMPONENTS_SEARCH_ENGINES_SEARCH_TERMS_DATA_H_
11 #include "base/compiler_specific.h"
13 // All data needed by TemplateURLRef::ReplaceSearchTerms which typically may
14 // only be accessed on the UI thread.
15 class SearchTermsData {
17 // Enumeration of the known search or suggest request sources. These values
18 // are not persisted or used in histograms; thus can be freely changed.
19 enum class RequestSource {
20 SEARCHBOX, // Omnibox or the NTP realbox. The default.
21 CROS_APP_LIST, // Chrome OS app list searchbox.
22 NTP_MODULE, // Suggestions for the NTP modules.
23 JOURNEYS, // Suggestions for the Journeys.
26 // Utility function that takes a snapshot of a different SearchTermsData
27 // instance. This is used to access SearchTermsData off the UI thread, or to
28 // copy the SearchTermsData for lifetime reasons.
29 static std::unique_ptr<SearchTermsData> MakeSnapshot(
30 const SearchTermsData* original_data);
34 SearchTermsData(const SearchTermsData&) = delete;
35 SearchTermsData& operator=(const SearchTermsData&) = delete;
37 virtual ~SearchTermsData();
39 // Returns the value to use for replacements of type GOOGLE_BASE_URL. This
40 // implementation simply returns the default value.
41 virtual std::string GoogleBaseURLValue() const;
43 // Returns the value to use for the GOOGLE_BASE_SEARCH_BY_IMAGE_URL. Points
44 // at Lens if the user is enrolled in the Lens experiment, and defaults to
45 // Image Search otherwise.
46 virtual std::string GoogleBaseSearchByImageURLValue() const;
48 // Returns the value for the GOOGLE_BASE_SUGGEST_URL term. This
49 // implementation simply returns the default value.
50 std::string GoogleBaseSuggestURLValue() const;
52 // Returns the locale used by the application. This implementation returns
53 // "en" and thus should be overridden where the result is actually meaningful.
54 virtual std::string GetApplicationLocale() const;
56 // Returns the value for the Chrome Omnibox rlz. This implementation returns
58 virtual std::u16string GetRlzParameterValue(bool from_app_list) const;
60 // The optional client parameter passed with Google search requests. This
61 // implementation returns the empty string.
62 virtual std::string GetSearchClient() const;
64 // The suggest client parameter ("client") passed with Google suggest
65 // requests. See GetSuggestRequestIdentifier() for more details.
66 // This implementation returns the empty string.
67 virtual std::string GetSuggestClient(RequestSource request_source) const;
69 // The suggest request identifier parameter ("gs_ri") passed with Google
70 // suggest requests. Along with suggestclient (See GetSuggestClient()),
71 // this parameter controls what suggestion results are returned.
72 // This implementation returns the empty string.
73 virtual std::string GetSuggestRequestIdentifier(
74 RequestSource request_source) const;
76 // Returns the value to use for replacements of type
77 // GOOGLE_IMAGE_SEARCH_SOURCE.
78 virtual std::string GoogleImageSearchSource() const;
80 // Returns the optional referral ID to be passed to Yandex when searching from
81 // the omnibox (returns the empty string if not supported/applicable).
82 virtual std::string GetYandexReferralID() const;
84 // Returns the optional referral ID to be passed to @MAIL.RU when searching
85 // from the omnibox (returns the empty string if not supported/applicable).
86 virtual std::string GetMailRUReferralID() const;
88 // Estimates dynamic memory usage.
89 // See base/trace_event/memory_usage_estimator.h for more info.
90 virtual size_t EstimateMemoryUsage() const;
93 #endif // COMPONENTS_SEARCH_ENGINES_SEARCH_TERMS_DATA_H_