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