Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / search_engines / ui_thread_search_terms_data.cc
blobf02d31fc9de71cf2f62a36f2998787657729b430
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
3 // found in the LICENSE file.
5 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "base/metrics/field_trial.h"
10 #include "base/prefs/pref_service.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/google/google_brand.h"
13 #include "chrome/browser/google/google_url_tracker_factory.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/search/instant_service.h"
16 #include "chrome/browser/search/instant_service_factory.h"
17 #include "chrome/browser/search/search.h"
18 #include "chrome/browser/themes/theme_service.h"
19 #include "chrome/browser/themes/theme_service_factory.h"
20 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/chrome_version_info.h"
22 #include "components/google/core/browser/google_url_tracker.h"
23 #include "components/google/core/browser/google_util.h"
24 #include "components/omnibox/omnibox_field_trial.h"
25 #include "components/search/search.h"
26 #include "content/public/browser/browser_thread.h"
27 #include "ui/base/device_form_factor.h"
28 #include "url/gurl.h"
30 #if defined(ENABLE_RLZ)
31 #include "chrome/browser/rlz/rlz.h"
32 #endif
34 using content::BrowserThread;
36 // static
37 std::string* UIThreadSearchTermsData::google_base_url_ = NULL;
39 UIThreadSearchTermsData::UIThreadSearchTermsData(Profile* profile)
40 : profile_(profile) {
41 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) ||
42 BrowserThread::CurrentlyOn(BrowserThread::UI));
45 std::string UIThreadSearchTermsData::GoogleBaseURLValue() const {
46 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) ||
47 BrowserThread::CurrentlyOn(BrowserThread::UI));
48 if (google_base_url_)
49 return *google_base_url_;
50 GURL base_url(google_util::CommandLineGoogleBaseURL());
51 if (base_url.is_valid())
52 return base_url.spec();
54 if (!profile_)
55 return SearchTermsData::GoogleBaseURLValue();
57 const GoogleURLTracker* tracker =
58 GoogleURLTrackerFactory::GetForProfile(profile_);
59 return tracker ?
60 tracker->google_url().spec() : GoogleURLTracker::kDefaultGoogleHomepage;
63 std::string UIThreadSearchTermsData::GetApplicationLocale() const {
64 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) ||
65 BrowserThread::CurrentlyOn(BrowserThread::UI));
66 return g_browser_process->GetApplicationLocale();
69 // Android implementations are in ui_thread_search_terms_data_android.cc.
70 #if !defined(OS_ANDROID)
71 base::string16 UIThreadSearchTermsData::GetRlzParameterValue(
72 bool from_app_list) const {
73 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) ||
74 BrowserThread::CurrentlyOn(BrowserThread::UI));
75 base::string16 rlz_string;
76 #if defined(ENABLE_RLZ)
77 // For organic brandcodes do not use rlz at all. Empty brandcode usually
78 // means a chromium install. This is ok.
79 std::string brand;
80 if (google_brand::GetBrand(&brand) && !brand.empty() &&
81 !google_brand::IsOrganic(brand)) {
82 // This call will return false the first time(s) it is called until the
83 // value has been cached. This normally would mean that at most one omnibox
84 // search might not send the RLZ data but this is not really a problem.
85 rlz_lib::AccessPoint access_point = RLZTracker::ChromeOmnibox();
86 #if !defined(OS_IOS)
87 if (from_app_list)
88 access_point = RLZTracker::ChromeAppList();
89 #endif
90 RLZTracker::GetAccessPointRlz(access_point, &rlz_string);
92 #endif
93 return rlz_string;
96 // We can enable this on non-Android if other platforms ever want a non-empty
97 // search client string. There is already a unit test in place for Android
98 // called TemplateURLTest::SearchClient.
99 std::string UIThreadSearchTermsData::GetSearchClient() const {
100 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) ||
101 BrowserThread::CurrentlyOn(BrowserThread::UI));
102 return std::string();
104 #endif
106 std::string UIThreadSearchTermsData::GetSuggestClient() const {
107 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) ||
108 BrowserThread::CurrentlyOn(BrowserThread::UI));
109 #if defined(OS_ANDROID)
110 return ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_PHONE ?
111 "chrome" : "chrome-omni";
112 #else
113 return chrome::IsInstantExtendedAPIEnabled() ? "chrome-omni" : "chrome";
114 #endif
117 std::string UIThreadSearchTermsData::GetSuggestRequestIdentifier() const {
118 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) ||
119 BrowserThread::CurrentlyOn(BrowserThread::UI));
120 #if defined(OS_ANDROID)
121 if (ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_PHONE) {
122 return OmniboxFieldTrial::EnableAnswersInSuggest() ?
123 "chrome-mobile-ext-ansg" : "chrome-mobile-ext";
125 #endif
126 return OmniboxFieldTrial::EnableAnswersInSuggest() ?
127 "chrome-ext-ansg" : "chrome-ext";
130 bool UIThreadSearchTermsData::EnableAnswersInSuggest() const {
131 return OmniboxFieldTrial::EnableAnswersInSuggest();
134 bool UIThreadSearchTermsData::IsShowingSearchTermsOnSearchResultsPages() const {
135 return chrome::IsInstantExtendedAPIEnabled() &&
136 chrome::IsQueryExtractionEnabled();
139 std::string UIThreadSearchTermsData::InstantExtendedEnabledParam(
140 bool for_search) const {
141 return chrome::InstantExtendedEnabledParam(for_search);
144 std::string UIThreadSearchTermsData::ForceInstantResultsParam(
145 bool for_prerender) const {
146 return chrome::ForceInstantResultsParam(for_prerender);
149 int UIThreadSearchTermsData::OmniboxStartMargin() const {
150 InstantService* instant_service =
151 InstantServiceFactory::GetForProfile(profile_);
152 // Android and iOS have no InstantService.
153 return instant_service ?
154 instant_service->omnibox_start_margin() : chrome::kDisableStartMargin;
157 std::string UIThreadSearchTermsData::NTPIsThemedParam() const {
158 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) ||
159 BrowserThread::CurrentlyOn(BrowserThread::UI));
160 #if defined(ENABLE_THEMES)
161 if (!chrome::IsInstantExtendedAPIEnabled())
162 return std::string();
164 // TODO(dhollowa): Determine fraction of custom themes that don't affect the
165 // NTP background and/or color.
166 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile_);
167 // NTP is considered themed if the theme is not default and not native (GTK+).
168 if (theme_service && !theme_service->UsingDefaultTheme() &&
169 !theme_service->UsingSystemTheme())
170 return "es_th=1&";
171 #endif // defined(ENABLE_THEMES)
173 return std::string();
176 // It's acutally OK to call this method on any thread, but it's currently placed
177 // in UIThreadSearchTermsData since SearchTermsData cannot depend on
178 // VersionInfo.
179 std::string UIThreadSearchTermsData::GoogleImageSearchSource() const {
180 chrome::VersionInfo version_info;
181 std::string version(version_info.Name() + " " + version_info.Version());
182 if (version_info.IsOfficialBuild())
183 version += " (Official)";
184 version += " " + version_info.OSType();
185 std::string modifier(version_info.GetVersionStringModifier());
186 if (!modifier.empty())
187 version += " " + modifier;
188 return version;
191 // static
192 void UIThreadSearchTermsData::SetGoogleBaseURL(const std::string& base_url) {
193 delete google_base_url_;
194 google_base_url_ = base_url.empty() ? NULL : new std::string(base_url);