Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / search_engines / search_terms_data.h
blobafa09d890c6590099e172254b908f2c005e6bcca
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_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/strings/string16.h"
14 class Profile;
16 // All data needed by TemplateURLRef::ReplaceSearchTerms which typically may
17 // only be accessed on the UI thread.
18 class SearchTermsData {
19 public:
20 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
36 // the empty string.
37 virtual base::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 suggest client parameter ("client") passed with Google suggest
44 // requests. See GetSuggestRequestIdentifier() for more details.
45 // This implementation returns the empty string.
46 virtual std::string GetSuggestClient() const;
48 // The suggest request identifier parameter ("gs_ri") passed with Google
49 // suggest requests. Along with suggestclient (See GetSuggestClient()),
50 // this parameter controls what suggestion results are returned.
51 // This implementation returns the empty string.
52 virtual std::string GetSuggestRequestIdentifier() const;
54 // Returns a string that will cause the search results page to update
55 // incrementally. Currently, Instant Extended passes a different param to
56 // search results pages that also has this effect, so by default this function
57 // returns the empty string when Instant Extended is enabled. However, when
58 // doing instant search result prerendering, we still need to pass this param,
59 // as Instant Extended does not cause incremental updates by default for the
60 // prerender page. Callers should set |for_prerender| in this case to force
61 // the returned string to be non-empty.
62 virtual std::string ForceInstantResultsParam(bool for_prerender) const;
64 // Returns a string indicating whether InstantExtended is enabled, suitable
65 // for adding as a query string param to the homepage or search requests.
66 // Returns an empty string otherwise. Determining this requires accessing the
67 // Profile, so this can only ever be non-empty for UIThreadSearchTermsData.
68 virtual std::string InstantExtendedEnabledParam() const;
70 // Returns a string indicating whether a non-default theme is active,
71 // suitable for adding as a query string param to the homepage. This only
72 // applies if Instant Extended is enabled. Returns an empty string otherwise.
73 // Determining this requires accessing the Profile, so this can only ever be
74 // non-empty for UIThreadSearchTermsData.
75 virtual std::string NTPIsThemedParam() const;
77 private:
78 DISALLOW_COPY_AND_ASSIGN(SearchTermsData);
81 // Implementation of SearchTermsData that is only usable on the UI thread.
82 class UIThreadSearchTermsData : public SearchTermsData {
83 public:
84 // If |profile_| is NULL, the Google base URL accessors will return default
85 // values, and ForceInstantResultsParam(), InstantExtendedEnabledParam(), and
86 // NTPIsThemedParam(), will return the empty string.
87 explicit UIThreadSearchTermsData(Profile* profile);
89 virtual std::string GoogleBaseURLValue() const OVERRIDE;
90 virtual std::string GetApplicationLocale() const OVERRIDE;
91 virtual base::string16 GetRlzParameterValue() const OVERRIDE;
92 virtual std::string GetSearchClient() const OVERRIDE;
93 virtual std::string GetSuggestClient() const OVERRIDE;
94 virtual std::string GetSuggestRequestIdentifier() const OVERRIDE;
95 virtual std::string ForceInstantResultsParam(
96 bool for_prerender) const OVERRIDE;
97 virtual std::string InstantExtendedEnabledParam() const OVERRIDE;
98 virtual std::string NTPIsThemedParam() const OVERRIDE;
100 // Used by tests to override the value for the Google base URL. Passing the
101 // empty string cancels this override.
102 static void SetGoogleBaseURL(const std::string& base_url);
104 private:
105 static std::string* google_base_url_;
106 Profile* profile_;
108 DISALLOW_COPY_AND_ASSIGN(UIThreadSearchTermsData);
111 #endif // CHROME_BROWSER_SEARCH_ENGINES_SEARCH_TERMS_DATA_H_