Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" | 5 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/google/google_brand.h" | 12 #include "chrome/browser/google/google_brand.h" |
| 13 #include "chrome/browser/google/google_url_tracker_factory.h" | 13 #include "chrome/browser/google/google_url_tracker_factory.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/search/instant_service.h" | 15 #include "chrome/browser/search/instant_service.h" |
| 16 #include "chrome/browser/search/instant_service_factory.h" | 16 #include "chrome/browser/search/instant_service_factory.h" |
| 17 #include "chrome/browser/search/search.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/channel_info.h" | 18 #include "chrome/common/channel_info.h" |
| 21 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 23 #include "components/google/core/browser/google_url_tracker.h" | 21 #include "components/google/core/browser/google_url_tracker.h" |
| 24 #include "components/google/core/browser/google_util.h" | 22 #include "components/google/core/browser/google_util.h" |
| 25 #include "components/omnibox/browser/omnibox_field_trial.h" | 23 #include "components/omnibox/browser/omnibox_field_trial.h" |
| 26 #include "components/search/search.h" | 24 #include "components/search/search.h" |
| 27 #include "components/version_info/version_info.h" | 25 #include "components/version_info/version_info.h" |
| 28 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 29 #include "ui/base/device_form_factor.h" | 27 #include "ui/base/device_form_factor.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 std::string UIThreadSearchTermsData::GetSuggestRequestIdentifier() const { | 117 std::string UIThreadSearchTermsData::GetSuggestRequestIdentifier() const { |
| 120 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || | 118 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || |
| 121 BrowserThread::CurrentlyOn(BrowserThread::UI)); | 119 BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 122 #if defined(OS_ANDROID) | 120 #if defined(OS_ANDROID) |
| 123 if (ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_PHONE) | 121 if (ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_PHONE) |
| 124 return "chrome-mobile-ext-ansg"; | 122 return "chrome-mobile-ext-ansg"; |
| 125 #endif | 123 #endif |
| 126 return "chrome-ext-ansg"; | 124 return "chrome-ext-ansg"; |
| 127 } | 125 } |
| 128 | 126 |
| 129 bool UIThreadSearchTermsData::IsShowingSearchTermsOnSearchResultsPages() const { | |
|
samarth
2015/12/28 20:12:21
Unless this is directly related to the query param
Peter Kasting
2016/01/04 21:47:11
It's directly related; the only caller of it is th
| |
| 130 return search::IsInstantExtendedAPIEnabled() && | |
| 131 search::IsQueryExtractionEnabled(); | |
| 132 } | |
| 133 | |
| 134 std::string UIThreadSearchTermsData::InstantExtendedEnabledParam( | 127 std::string UIThreadSearchTermsData::InstantExtendedEnabledParam( |
| 135 bool for_search) const { | 128 bool for_search) const { |
| 136 return search::InstantExtendedEnabledParam(for_search); | 129 return search::InstantExtendedEnabledParam(for_search); |
| 137 } | 130 } |
| 138 | 131 |
| 139 std::string UIThreadSearchTermsData::ForceInstantResultsParam( | 132 std::string UIThreadSearchTermsData::ForceInstantResultsParam( |
| 140 bool for_prerender) const { | 133 bool for_prerender) const { |
| 141 return search::ForceInstantResultsParam(for_prerender); | 134 return search::ForceInstantResultsParam(for_prerender); |
| 142 } | 135 } |
| 143 | 136 |
| 144 int UIThreadSearchTermsData::OmniboxStartMargin() const { | |
| 145 InstantService* instant_service = | |
| 146 InstantServiceFactory::GetForProfile(profile_); | |
| 147 // Android and iOS have no InstantService. | |
| 148 return instant_service ? instant_service->omnibox_start_margin() | |
| 149 : search::kDisableStartMargin; | |
| 150 } | |
| 151 | |
| 152 std::string UIThreadSearchTermsData::NTPIsThemedParam() const { | |
| 153 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || | |
| 154 BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 155 #if defined(ENABLE_THEMES) | |
| 156 if (!search::IsInstantExtendedAPIEnabled()) | |
| 157 return std::string(); | |
| 158 | |
| 159 // TODO(dhollowa): Determine fraction of custom themes that don't affect the | |
| 160 // NTP background and/or color. | |
| 161 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile_); | |
| 162 // NTP is considered themed if the theme is not default and not native (GTK+). | |
| 163 if (theme_service && !theme_service->UsingDefaultTheme() && | |
| 164 !theme_service->UsingSystemTheme()) | |
| 165 return "es_th=1&"; | |
| 166 #endif // defined(ENABLE_THEMES) | |
| 167 | |
| 168 return std::string(); | |
| 169 } | |
| 170 | |
| 171 // It's acutally OK to call this method on any thread, but it's currently placed | 137 // It's acutally OK to call this method on any thread, but it's currently placed |
| 172 // in UIThreadSearchTermsData since SearchTermsData cannot depend on src/chrome | 138 // in UIThreadSearchTermsData since SearchTermsData cannot depend on src/chrome |
| 173 // as it is shared with iOS. | 139 // as it is shared with iOS. |
| 174 std::string UIThreadSearchTermsData::GoogleImageSearchSource() const { | 140 std::string UIThreadSearchTermsData::GoogleImageSearchSource() const { |
| 175 std::string version(version_info::GetProductName() + " " + | 141 std::string version(version_info::GetProductName() + " " + |
| 176 version_info::GetVersionNumber()); | 142 version_info::GetVersionNumber()); |
| 177 if (version_info::IsOfficialBuild()) | 143 if (version_info::IsOfficialBuild()) |
| 178 version += " (Official)"; | 144 version += " (Official)"; |
| 179 version += " " + version_info::GetOSType(); | 145 version += " " + version_info::GetOSType(); |
| 180 std::string modifier(chrome::GetChannelString()); | 146 std::string modifier(chrome::GetChannelString()); |
| 181 if (!modifier.empty()) | 147 if (!modifier.empty()) |
| 182 version += " " + modifier; | 148 version += " " + modifier; |
| 183 return version; | 149 return version; |
| 184 } | 150 } |
| 185 | 151 |
| 186 std::string UIThreadSearchTermsData::GetAcceptLanguages() const { | 152 std::string UIThreadSearchTermsData::GetAcceptLanguages() const { |
| 187 return profile_ ? profile_->GetPrefs()->GetString(prefs::kAcceptLanguages) | 153 return profile_ ? profile_->GetPrefs()->GetString(prefs::kAcceptLanguages) |
| 188 : std::string(); | 154 : std::string(); |
| 189 } | 155 } |
| 190 | 156 |
| 191 // static | 157 // static |
| 192 void UIThreadSearchTermsData::SetGoogleBaseURL(const std::string& base_url) { | 158 void UIThreadSearchTermsData::SetGoogleBaseURL(const std::string& base_url) { |
| 193 delete google_base_url_; | 159 delete google_base_url_; |
| 194 google_base_url_ = base_url.empty() ? NULL : new std::string(base_url); | 160 google_base_url_ = base_url.empty() ? NULL : new std::string(base_url); |
| 195 } | 161 } |
| OLD | NEW |