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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SEARCH_ENGINES_SEARCH_TERMS_DATA_H_
6 #define CHROME_BROWSER_SEARCH_ENGINES_SEARCH_TERMS_DATA_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/strings/string16.h"
16 // All data needed by TemplateURLRef::ReplaceSearchTerms which typically may
17 // only be accessed on the UI thread.
18 class SearchTermsData {
21 virtual ~SearchTermsData();
23 // Returns the value to use for replacements of type GOOGLE_BASE_URL. This
24 // implementation simply returns the default value.
25 virtual std::string GoogleBaseURLValue() const;
27 // Returns the value for the GOOGLE_BASE_SUGGEST_URL term. This
28 // implementation simply returns the default value.
29 std::string GoogleBaseSuggestURLValue() const;
31 // Returns the locale used by the application. This implementation returns
32 // "en" and thus should be overridden where the result is actually meaningful.
33 virtual std::string GetApplicationLocale() const;
35 // Returns the value for the Chrome Omnibox rlz. This implementation returns
37 virtual string16 GetRlzParameterValue() const;
39 // The optional client parameter passed with Google search requests. This
40 // implementation returns the empty string.
41 virtual std::string GetSearchClient() const;
43 // The client parameter passed with Google suggest requests. This
44 // implementation returns the empty string.
45 virtual std::string GetSuggestClient() const;
47 // Returns a string that will cause the search results page to update
48 // incrementally. Currently, Instant Extended passes a different param to
49 // search results pages that also has this effect, so by default this function
50 // returns the empty string when Instant Extended is enabled. However, when
51 // doing instant search result prerendering, we still need to pass this param,
52 // as Instant Extended does not cause incremental updates by default for the
53 // prerender page. Callers should set |for_prerender| in this case to force
54 // the returned string to be non-empty.
55 virtual std::string ForceInstantResultsParam(bool for_prerender) const;
57 // Returns a string indicating whether InstantExtended is enabled, suitable
58 // for adding as a query string param to the homepage or search requests.
59 // Returns an empty string otherwise. Determining this requires accessing the
60 // Profile, so this can only ever be non-empty for UIThreadSearchTermsData.
61 virtual std::string InstantExtendedEnabledParam() const;
63 // Returns a string indicating whether a non-default theme is active,
64 // suitable for adding as a query string param to the homepage. This only
65 // applies if Instant Extended is enabled. Returns an empty string otherwise.
66 // Determining this requires accessing the Profile, so this can only ever be
67 // non-empty for UIThreadSearchTermsData.
68 virtual std::string NTPIsThemedParam() const;
71 DISALLOW_COPY_AND_ASSIGN(SearchTermsData);
74 // Implementation of SearchTermsData that is only usable on the UI thread.
75 class UIThreadSearchTermsData : public SearchTermsData {
77 // If |profile_| is NULL, the Google base URL accessors will return default
78 // values, and ForceInstantResultsParam(), InstantExtendedEnabledParam(), and
79 // NTPIsThemedParam(), will return the empty string.
80 explicit UIThreadSearchTermsData(Profile* profile);
82 virtual std::string GoogleBaseURLValue() const OVERRIDE;
83 virtual std::string GetApplicationLocale() const OVERRIDE;
84 virtual string16 GetRlzParameterValue() const OVERRIDE;
85 virtual std::string GetSearchClient() const OVERRIDE;
86 virtual std::string GetSuggestClient() const OVERRIDE;
87 virtual std::string ForceInstantResultsParam(
88 bool for_prerender) const OVERRIDE;
89 virtual std::string InstantExtendedEnabledParam() const OVERRIDE;
90 virtual std::string NTPIsThemedParam() const OVERRIDE;
92 // Used by tests to override the value for the Google base URL. Passing the
93 // empty string cancels this override.
94 static void SetGoogleBaseURL(const std::string& base_url);
97 static std::string* google_base_url_;
100 DISALLOW_COPY_AND_ASSIGN(UIThreadSearchTermsData);
103 #endif // CHROME_BROWSER_SEARCH_ENGINES_SEARCH_TERMS_DATA_H_