Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ios / chrome / browser / search_engines / ui_thread_search_terms_data.cc
blobe09d36f08c6ba84b5e85fb034ebfe8761c460eba
1 // Copyright 2015 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 "ios/chrome/browser/search_engines/ui_thread_search_terms_data.h"
7 #include "base/logging.h"
8 #include "base/strings/string16.h"
9 #include "components/google/core/browser/google_url_tracker.h"
10 #include "components/google/core/browser/google_util.h"
11 #include "components/omnibox/browser/omnibox_field_trial.h"
12 #include "components/search/search.h"
13 #include "components/version_info/version_info.h"
14 #include "ios/chrome/browser/application_context.h"
15 #include "ios/chrome/browser/google/google_brand.h"
16 #include "ios/chrome/browser/google/google_url_tracker_factory.h"
17 #include "ios/chrome/common/channel_info.h"
18 #include "ios/web/public/web_thread.h"
19 #include "url/gurl.h"
21 #if defined(ENABLE_RLZ)
22 #include "components/rlz/rlz_tracker.h"
23 #endif
25 namespace ios {
27 UIThreadSearchTermsData::UIThreadSearchTermsData(
28 ios::ChromeBrowserState* browser_state)
29 : browser_state_(browser_state) {
30 DCHECK(!web::WebThread::IsThreadInitialized(web::WebThread::UI) ||
31 web::WebThread::CurrentlyOn(web::WebThread::UI));
34 UIThreadSearchTermsData::~UIThreadSearchTermsData() {}
36 std::string UIThreadSearchTermsData::GoogleBaseURLValue() const {
37 DCHECK(thread_checker_.CalledOnValidThread());
38 GURL google_base_url = google_util::CommandLineGoogleBaseURL();
39 if (google_base_url.is_valid())
40 return google_base_url.spec();
42 if (!browser_state_)
43 return SearchTermsData::GoogleBaseURLValue();
45 GoogleURLTracker* google_url_tracker =
46 ios::GoogleURLTrackerFactory::GetForBrowserState(browser_state_);
47 return google_url_tracker ? google_url_tracker->google_url().spec()
48 : GoogleURLTracker::kDefaultGoogleHomepage;
51 std::string UIThreadSearchTermsData::GetApplicationLocale() const {
52 DCHECK(thread_checker_.CalledOnValidThread());
53 return GetApplicationContext()->GetApplicationLocale();
56 base::string16 UIThreadSearchTermsData::GetRlzParameterValue(
57 bool from_app_list) const {
58 DCHECK(!from_app_list);
59 DCHECK(thread_checker_.CalledOnValidThread());
60 base::string16 rlz_string;
61 #if defined(ENABLE_RLZ)
62 // For organic brandcode do not use rlz at all.
63 std::string brand;
64 if (ios::google_brand::GetBrand(&brand) &&
65 !ios::google_brand::IsOrganic(brand)) {
66 // This call will may return false until the value has been cached. This
67 // normally would mean that a few omnibox searches might not send the RLZ
68 // data but this is not really a problem (as the value will eventually be
69 // set and cached).
70 rlz::RLZTracker::GetAccessPointRlz(rlz::RLZTracker::ChromeOmnibox(),
71 &rlz_string);
73 #endif
74 return rlz_string;
77 std::string UIThreadSearchTermsData::GetSearchClient() const {
78 DCHECK(thread_checker_.CalledOnValidThread());
79 return std::string();
82 std::string UIThreadSearchTermsData::GetSuggestClient() const {
83 DCHECK(thread_checker_.CalledOnValidThread());
84 return search::IsInstantExtendedAPIEnabled() ? "chrome-omni" : "chrome";
87 std::string UIThreadSearchTermsData::GetSuggestRequestIdentifier() const {
88 DCHECK(thread_checker_.CalledOnValidThread());
89 return "chrome-ext-ansg";
92 bool UIThreadSearchTermsData::IsShowingSearchTermsOnSearchResultsPages() const {
93 DCHECK(thread_checker_.CalledOnValidThread());
94 return search::IsInstantExtendedAPIEnabled() &&
95 search::IsQueryExtractionEnabled();
98 std::string UIThreadSearchTermsData::InstantExtendedEnabledParam(
99 bool for_search) const {
100 DCHECK(thread_checker_.CalledOnValidThread());
101 return search::InstantExtendedEnabledParam(for_search);
104 std::string UIThreadSearchTermsData::ForceInstantResultsParam(
105 bool for_prerender) const {
106 DCHECK(thread_checker_.CalledOnValidThread());
107 return search::ForceInstantResultsParam(for_prerender);
110 int UIThreadSearchTermsData::OmniboxStartMargin() const {
111 DCHECK(thread_checker_.CalledOnValidThread());
112 // iOS has not InstantService.
113 return search::kDisableStartMargin;
116 std::string UIThreadSearchTermsData::NTPIsThemedParam() const {
117 DCHECK(thread_checker_.CalledOnValidThread());
118 // iOS does not supports themed NTP.
119 return std::string();
122 std::string UIThreadSearchTermsData::GoogleImageSearchSource() const {
123 DCHECK(thread_checker_.CalledOnValidThread());
124 std::string version(version_info::GetProductName() + " " +
125 version_info::GetVersionNumber());
126 if (version_info::IsOfficialBuild())
127 version += " (Official)";
128 version += " " + version_info::GetOSType();
129 std::string modifier(GetChannelString());
130 if (!modifier.empty())
131 version += " " + modifier;
132 return version;
135 } // namespace ios