| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 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/search_terms_data.h" | 5 #include "components/search_engines/search_terms_data.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | |
| 8 #include "base/logging.h" | 7 #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_profile_helper.h" | |
| 14 #include "chrome/browser/google/google_util.h" | |
| 15 #include "chrome/browser/profiles/profile.h" | |
| 16 #include "chrome/browser/search/search.h" | |
| 17 #include "chrome/browser/sync/glue/device_info.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/pref_names.h" | |
| 22 #include "components/google/core/browser/google_url_tracker.h" | 8 #include "components/google/core/browser/google_url_tracker.h" |
| 23 #include "content/public/browser/browser_thread.h" | |
| 24 #include "sync/protocol/sync.pb.h" | |
| 25 #include "url/gurl.h" | 9 #include "url/gurl.h" |
| 26 | 10 |
| 27 #if defined(ENABLE_RLZ) | |
| 28 #include "chrome/browser/rlz/rlz.h" | |
| 29 #endif | |
| 30 | |
| 31 using content::BrowserThread; | |
| 32 | |
| 33 SearchTermsData::SearchTermsData() { | 11 SearchTermsData::SearchTermsData() { |
| 34 } | 12 } |
| 35 | 13 |
| 36 SearchTermsData::~SearchTermsData() { | 14 SearchTermsData::~SearchTermsData() { |
| 37 } | 15 } |
| 38 | 16 |
| 39 std::string SearchTermsData::GoogleBaseURLValue() const { | 17 std::string SearchTermsData::GoogleBaseURLValue() const { |
| 40 return GoogleURLTracker::kDefaultGoogleHomepage; | 18 return GoogleURLTracker::kDefaultGoogleHomepage; |
| 41 } | 19 } |
| 42 | 20 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 return std::string(); | 54 return std::string(); |
| 77 } | 55 } |
| 78 | 56 |
| 79 std::string SearchTermsData::GetSuggestRequestIdentifier() const { | 57 std::string SearchTermsData::GetSuggestRequestIdentifier() const { |
| 80 return std::string(); | 58 return std::string(); |
| 81 } | 59 } |
| 82 | 60 |
| 83 std::string SearchTermsData::NTPIsThemedParam() const { | 61 std::string SearchTermsData::NTPIsThemedParam() const { |
| 84 return std::string(); | 62 return std::string(); |
| 85 } | 63 } |
| 86 | |
| 87 // static | |
| 88 std::string* UIThreadSearchTermsData::google_base_url_ = NULL; | |
| 89 | |
| 90 UIThreadSearchTermsData::UIThreadSearchTermsData(Profile* profile) | |
| 91 : profile_(profile) { | |
| 92 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || | |
| 93 BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 94 } | |
| 95 | |
| 96 std::string UIThreadSearchTermsData::GoogleBaseURLValue() const { | |
| 97 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || | |
| 98 BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 99 if (google_base_url_) | |
| 100 return *google_base_url_; | |
| 101 GURL base_url(google_util::CommandLineGoogleBaseURL()); | |
| 102 if (base_url.is_valid()) | |
| 103 return base_url.spec(); | |
| 104 return profile_ ? | |
| 105 google_profile_helper::GetGoogleHomePageURL(profile_).spec() : | |
| 106 SearchTermsData::GoogleBaseURLValue(); | |
| 107 } | |
| 108 | |
| 109 std::string UIThreadSearchTermsData::GetApplicationLocale() const { | |
| 110 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || | |
| 111 BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 112 return g_browser_process->GetApplicationLocale(); | |
| 113 } | |
| 114 | |
| 115 // Android implementations are located in search_terms_data_android.cc. | |
| 116 #if !defined(OS_ANDROID) | |
| 117 base::string16 UIThreadSearchTermsData::GetRlzParameterValue( | |
| 118 bool from_app_list) const { | |
| 119 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || | |
| 120 BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 121 base::string16 rlz_string; | |
| 122 #if defined(ENABLE_RLZ) | |
| 123 // For organic brandcodes do not use rlz at all. Empty brandcode usually | |
| 124 // means a chromium install. This is ok. | |
| 125 std::string brand; | |
| 126 if (google_brand::GetBrand(&brand) && !brand.empty() && | |
| 127 !google_brand::IsOrganic(brand)) { | |
| 128 // This call will return false the first time(s) it is called until the | |
| 129 // value has been cached. This normally would mean that at most one omnibox | |
| 130 // search might not send the RLZ data but this is not really a problem. | |
| 131 rlz_lib::AccessPoint access_point = RLZTracker::ChromeOmnibox(); | |
| 132 #if !defined(OS_IOS) | |
| 133 if (from_app_list) | |
| 134 access_point = RLZTracker::ChromeAppList(); | |
| 135 #endif | |
| 136 RLZTracker::GetAccessPointRlz(access_point, &rlz_string); | |
| 137 } | |
| 138 #endif | |
| 139 return rlz_string; | |
| 140 } | |
| 141 | |
| 142 // We can enable this on non-Android if other platforms ever want a non-empty | |
| 143 // search client string. There is already a unit test in place for Android | |
| 144 // called TemplateURLTest::SearchClient. | |
| 145 std::string UIThreadSearchTermsData::GetSearchClient() const { | |
| 146 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || | |
| 147 BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 148 return std::string(); | |
| 149 } | |
| 150 #endif | |
| 151 | |
| 152 std::string UIThreadSearchTermsData::GetSuggestClient() const { | |
| 153 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || | |
| 154 BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 155 #if defined(OS_ANDROID) | |
| 156 sync_pb::SyncEnums::DeviceType device_type = | |
| 157 browser_sync::DeviceInfo::GetLocalDeviceType(); | |
| 158 return device_type == sync_pb::SyncEnums_DeviceType_TYPE_PHONE ? | |
| 159 "chrome" : "chrome-omni"; | |
| 160 #else | |
| 161 return chrome::IsInstantExtendedAPIEnabled() ? "chrome-omni" : "chrome"; | |
| 162 #endif | |
| 163 } | |
| 164 | |
| 165 std::string UIThreadSearchTermsData::GetSuggestRequestIdentifier() const { | |
| 166 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || | |
| 167 BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 168 #if defined(OS_ANDROID) | |
| 169 sync_pb::SyncEnums::DeviceType device_type = | |
| 170 browser_sync::DeviceInfo::GetLocalDeviceType(); | |
| 171 if (device_type == sync_pb::SyncEnums_DeviceType_TYPE_PHONE) { | |
| 172 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 173 switches::kEnableAnswersInSuggest)) { | |
| 174 return "chrome-mobile-ext-ansg"; | |
| 175 } else { | |
| 176 return "chrome-mobile-ext"; | |
| 177 } | |
| 178 } | |
| 179 return "chrome-ext"; | |
| 180 #else | |
| 181 return "chrome-ext"; | |
| 182 #endif | |
| 183 } | |
| 184 | |
| 185 std::string UIThreadSearchTermsData::NTPIsThemedParam() const { | |
| 186 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || | |
| 187 BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 188 #if defined(ENABLE_THEMES) | |
| 189 if (!chrome::IsInstantExtendedAPIEnabled()) | |
| 190 return std::string(); | |
| 191 | |
| 192 // TODO(dhollowa): Determine fraction of custom themes that don't affect the | |
| 193 // NTP background and/or color. | |
| 194 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile_); | |
| 195 // NTP is considered themed if the theme is not default and not native (GTK+). | |
| 196 if (theme_service && !theme_service->UsingDefaultTheme() && | |
| 197 !theme_service->UsingSystemTheme()) | |
| 198 return "es_th=1&"; | |
| 199 #endif // defined(ENABLE_THEMES) | |
| 200 | |
| 201 return std::string(); | |
| 202 } | |
| 203 | |
| 204 // static | |
| 205 void UIThreadSearchTermsData::SetGoogleBaseURL(const std::string& base_url) { | |
| 206 delete google_base_url_; | |
| 207 google_base_url_ = base_url.empty() ? NULL : new std::string(base_url); | |
| 208 } | |
| OLD | NEW |