Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / search_engines / search_terms_data.cc
blobabb201a7a52bdfa9b5a0da86fe724d5aa1f82400
1 // Copyright 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 #include "chrome/browser/search_engines/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_url_tracker.h"
13 #include "chrome/browser/google/google_util.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/search/search.h"
16 #include "chrome/browser/sync/glue/device_info.h"
17 #include "chrome/browser/themes/theme_service.h"
18 #include "chrome/browser/themes/theme_service_factory.h"
19 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/pref_names.h"
21 #include "content/public/browser/browser_thread.h"
22 #include "sync/protocol/sync.pb.h"
23 #include "url/gurl.h"
25 #if defined(ENABLE_RLZ)
26 #include "chrome/browser/rlz/rlz.h"
27 #endif
29 using content::BrowserThread;
31 SearchTermsData::SearchTermsData() {
34 SearchTermsData::~SearchTermsData() {
37 std::string SearchTermsData::GoogleBaseURLValue() const {
38 return GoogleURLTracker::kDefaultGoogleHomepage;
41 std::string SearchTermsData::GoogleBaseSuggestURLValue() const {
42 // Start with the Google base URL.
43 const GURL base_url(GoogleBaseURLValue());
44 DCHECK(base_url.is_valid());
46 GURL::Replacements repl;
48 // Replace any existing path with "/complete/".
49 // SetPathStr() requires its argument to stay in scope as long as |repl| is,
50 // so "/complete/" can't be passed to SetPathStr() directly, it needs to be in
51 // a variable.
52 const std::string suggest_path("/complete/");
53 repl.SetPathStr(suggest_path);
55 // Clear the query and ref.
56 repl.ClearQuery();
57 repl.ClearRef();
58 return base_url.ReplaceComponents(repl).spec();
61 std::string SearchTermsData::GetApplicationLocale() const {
62 return "en";
65 base::string16 SearchTermsData::GetRlzParameterValue(bool from_app_list) const {
66 return base::string16();
69 std::string SearchTermsData::GetSearchClient() const {
70 return std::string();
73 std::string SearchTermsData::GetSuggestClient() const {
74 return std::string();
77 std::string SearchTermsData::GetSuggestRequestIdentifier() const {
78 return std::string();
81 std::string SearchTermsData::NTPIsThemedParam() const {
82 return std::string();
85 // static
86 std::string* UIThreadSearchTermsData::google_base_url_ = NULL;
88 UIThreadSearchTermsData::UIThreadSearchTermsData(Profile* profile)
89 : profile_(profile) {
90 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) ||
91 BrowserThread::CurrentlyOn(BrowserThread::UI));
94 std::string UIThreadSearchTermsData::GoogleBaseURLValue() const {
95 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) ||
96 BrowserThread::CurrentlyOn(BrowserThread::UI));
97 if (google_base_url_)
98 return *google_base_url_;
99 GURL base_url(google_util::CommandLineGoogleBaseURL());
100 if (base_url.is_valid())
101 return base_url.spec();
102 return profile_ ? GoogleURLTracker::GoogleURL(profile_).spec() :
103 SearchTermsData::GoogleBaseURLValue();
106 std::string UIThreadSearchTermsData::GetApplicationLocale() const {
107 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) ||
108 BrowserThread::CurrentlyOn(BrowserThread::UI));
109 return g_browser_process->GetApplicationLocale();
112 // Android implementations are located in search_terms_data_android.cc.
113 #if !defined(OS_ANDROID)
114 base::string16 UIThreadSearchTermsData::GetRlzParameterValue(
115 bool from_app_list) const {
116 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) ||
117 BrowserThread::CurrentlyOn(BrowserThread::UI));
118 base::string16 rlz_string;
119 #if defined(ENABLE_RLZ)
120 // For organic brandcodes do not use rlz at all. Empty brandcode usually
121 // means a chromium install. This is ok.
122 std::string brand;
123 if (google_util::GetBrand(&brand) && !brand.empty() &&
124 !google_util::IsOrganic(brand)) {
125 // This call will return false the first time(s) it is called until the
126 // value has been cached. This normally would mean that at most one omnibox
127 // search might not send the RLZ data but this is not really a problem.
128 rlz_lib::AccessPoint access_point = RLZTracker::CHROME_OMNIBOX;
129 #if !defined(OS_IOS)
130 if (from_app_list)
131 access_point = RLZTracker::CHROME_APP_LIST;
132 #endif
133 RLZTracker::GetAccessPointRlz(access_point, &rlz_string);
135 #endif
136 return rlz_string;
139 // We can enable this on non-Android if other platforms ever want a non-empty
140 // search client string. There is already a unit test in place for Android
141 // called TemplateURLTest::SearchClient.
142 std::string UIThreadSearchTermsData::GetSearchClient() const {
143 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) ||
144 BrowserThread::CurrentlyOn(BrowserThread::UI));
145 return std::string();
147 #endif
149 std::string UIThreadSearchTermsData::GetSuggestClient() const {
150 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) ||
151 BrowserThread::CurrentlyOn(BrowserThread::UI));
152 #if defined(OS_ANDROID)
153 sync_pb::SyncEnums::DeviceType device_type =
154 browser_sync::DeviceInfo::GetLocalDeviceType();
155 return device_type == sync_pb::SyncEnums_DeviceType_TYPE_PHONE ?
156 "chrome" : "chrome-omni";
157 #else
158 return chrome::IsInstantExtendedAPIEnabled() ? "chrome-omni" : "chrome";
159 #endif
162 std::string UIThreadSearchTermsData::GetSuggestRequestIdentifier() const {
163 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) ||
164 BrowserThread::CurrentlyOn(BrowserThread::UI));
165 #if defined(OS_ANDROID)
166 sync_pb::SyncEnums::DeviceType device_type =
167 browser_sync::DeviceInfo::GetLocalDeviceType();
168 if (device_type == sync_pb::SyncEnums_DeviceType_TYPE_PHONE) {
169 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
170 switches::kEnableAnswersInSuggest)) {
171 return "chrome-mobile-ext-ansg";
172 } else {
173 return "chrome-mobile-ext";
176 return "chrome-ext";
177 #else
178 return "chrome-ext";
179 #endif
182 std::string UIThreadSearchTermsData::NTPIsThemedParam() const {
183 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) ||
184 BrowserThread::CurrentlyOn(BrowserThread::UI));
185 #if defined(ENABLE_THEMES)
186 if (!chrome::IsInstantExtendedAPIEnabled())
187 return std::string();
189 // TODO(dhollowa): Determine fraction of custom themes that don't affect the
190 // NTP background and/or color.
191 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile_);
192 // NTP is considered themed if the theme is not default and not native (GTK+).
193 if (theme_service && !theme_service->UsingDefaultTheme() &&
194 !theme_service->UsingNativeTheme())
195 return "es_th=1&";
196 #endif // defined(ENABLE_THEMES)
198 return std::string();
201 // static
202 void UIThreadSearchTermsData::SetGoogleBaseURL(const std::string& base_url) {
203 delete google_base_url_;
204 google_base_url_ = base_url.empty() ? NULL : new std::string(base_url);