Move GoogleImageSearchSource() from template_url.cc to UIThreadSearchTermsData

To stop depending on chrome::VersionInfo from TemplateURL.

BUG=386365
TEST=unit_tests

Review URL: https://codereview.chromium.org/345803002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278702 0039d316-1c4b-4281-b951-d872f2087c98
parent 0105097d
......@@ -24,7 +24,6 @@
#include "chrome/browser/search/search.h"
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_version_info.h"
#include "components/google/core/browser/google_util.h"
#include "components/metrics/proto/omnibox_input_type.pb.h"
#include "components/search_engines/search_terms_data.h"
......@@ -169,23 +168,6 @@ std::string FindSearchTermsKey(const std::string& params) {
return std::string();
}
// Returns the string to use for replacements of type
// GOOGLE_IMAGE_SEARCH_SOURCE.
std::string GetGoogleImageSearchSource() {
chrome::VersionInfo version_info;
if (version_info.is_valid()) {
std::string version(version_info.Name() + " " + version_info.Version());
if (version_info.IsOfficialBuild())
version += " (Official)";
version += " " + version_info.OSType();
std::string modifier(version_info.GetVersionStringModifier());
if (!modifier.empty())
version += " " + modifier;
return version;
}
return "unknown";
}
bool IsTemplateParameterString(const std::string& param) {
return (param.length() > 2) && (*(param.begin()) == kStartParameter) &&
(*(param.rbegin()) == kEndParameter);
......@@ -593,7 +575,8 @@ bool TemplateURLRef::ParseParameter(size_t start,
replacements->push_back(
Replacement(TemplateURLRef::GOOGLE_IMAGE_ORIGINAL_WIDTH, start));
} else if (parameter == kGoogleImageSearchSource) {
url->insert(start, GetGoogleImageSearchSource());
replacements->push_back(
Replacement(TemplateURLRef::GOOGLE_IMAGE_SEARCH_SOURCE, start));
} else if (parameter == kGoogleImageThumbnailParameter) {
replacements->push_back(
Replacement(TemplateURLRef::GOOGLE_IMAGE_THUMBNAIL, start));
......@@ -1113,6 +1096,12 @@ std::string TemplateURLRef::HandleReplacements(
}
break;
case GOOGLE_IMAGE_SEARCH_SOURCE:
HandleReplacement(
std::string(), search_terms_data.GoogleImageSearchSource(), *i,
&url);
break;
default:
NOTREACHED();
break;
......
......@@ -26,6 +26,7 @@ class TestSearchTermsData : public SearchTermsData {
virtual base::string16 GetRlzParameterValue(
bool from_app_list) const OVERRIDE;
virtual std::string GetSearchClient() const OVERRIDE;
virtual std::string GoogleImageSearchSource() const OVERRIDE;
void set_google_base_url(const std::string& google_base_url) {
google_base_url_ = google_base_url;
......@@ -59,6 +60,10 @@ std::string TestSearchTermsData::GetSearchClient() const {
return search_client_;
}
std::string TestSearchTermsData::GoogleImageSearchSource() const {
return "google_image_search_source";
}
// TemplateURLTest ------------------------------------------------------------
class TemplateURLTest : public testing::Test {
......@@ -255,6 +260,10 @@ TEST_F(TemplateURLTest, URLRefTestImageURLWithPOST) {
base::IntToString(search_args.image_original_size.width()),
i->second);
break;
case TemplateURLRef::GOOGLE_IMAGE_SEARCH_SOURCE:
EXPECT_EQ("sbisrc", i->first);
EXPECT_EQ(search_terms_data.GoogleImageSearchSource(), i->second);
break;
case TemplateURLRef::GOOGLE_IMAGE_THUMBNAIL:
EXPECT_EQ("image_content", i->first);
EXPECT_EQ(search_args.image_thumbnail_content, i->second);
......
......@@ -18,6 +18,7 @@
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/pref_names.h"
#include "components/google/core/browser/google_util.h"
#include "content/public/browser/browser_thread.h"
......@@ -143,6 +144,24 @@ std::string UIThreadSearchTermsData::NTPIsThemedParam() const {
return std::string();
}
// It's acutally OK to call this method on any thread, but it's currently placed
// in UIThreadSearchTermsData since SearchTermsData cannot depend on
// VersionInfo.
std::string UIThreadSearchTermsData::GoogleImageSearchSource() const {
chrome::VersionInfo version_info;
if (version_info.is_valid()) {
std::string version(version_info.Name() + " " + version_info.Version());
if (version_info.IsOfficialBuild())
version += " (Official)";
version += " " + version_info.OSType();
std::string modifier(version_info.GetVersionStringModifier());
if (!modifier.empty())
version += " " + modifier;
return version;
}
return "unknown";
}
// static
void UIThreadSearchTermsData::SetGoogleBaseURL(const std::string& base_url) {
delete google_base_url_;
......
......@@ -29,6 +29,7 @@ class UIThreadSearchTermsData : public SearchTermsData {
virtual std::string GetSuggestClient() const OVERRIDE;
virtual std::string GetSuggestRequestIdentifier() const OVERRIDE;
virtual std::string NTPIsThemedParam() const OVERRIDE;
virtual std::string GoogleImageSearchSource() const OVERRIDE;
// Used by tests to override the value for the Google base URL. Passing the
// empty string cancels this override.
......
......@@ -61,3 +61,7 @@ std::string SearchTermsData::GetSuggestRequestIdentifier() const {
std::string SearchTermsData::NTPIsThemedParam() const {
return std::string();
}
std::string SearchTermsData::GoogleImageSearchSource() const {
return std::string();
}
......@@ -56,6 +56,10 @@ class SearchTermsData {
// non-empty for UIThreadSearchTermsData.
virtual std::string NTPIsThemedParam() const;
// Returns the value to use for replacements of type
// GOOGLE_IMAGE_SEARCH_SOURCE.
virtual std::string GoogleImageSearchSource() const;
private:
DISALLOW_COPY_AND_ASSIGN(SearchTermsData);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment