search: Log when bookmark bar is pinned.
We want to understand how showing search terms in the omnibox interacts
with the presence of the bookmark bar. For users in a field trial that's
showing search terms, this change adds a CGI arg &bmbp=1 to search URLs
if the bookmark bar is pinned and &bmbp=0 otherwise.
This isn't privacy-sensitive, because in theory we could get this
information by looking at outerHeight - innerHeight from search page
Javascript. Logging it explicitly this way is just more reliable than
doing that.
BUG=291244
TEST=unit tests,manual
Review URL: https://codereview.chromium.org/25324003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@226506 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/search_engines/prepopulated_engines.json b/chrome/browser/search_engines/prepopulated_engines.json
index 9c90271..d8d741e 100644
--- a/chrome/browser/search_engines/prepopulated_engines.json
+++ b/chrome/browser/search_engines/prepopulated_engines.json
@@ -26,7 +26,7 @@
// Increment this if you change the data in ways that mean users with
// existing data should get a new version.
- "kCurrentDataVersion": 65
+ "kCurrentDataVersion": 66
},
// The following engines are included in country lists and are added to the
@@ -486,7 +486,7 @@
"name": "Google",
"keyword": "google.com",
"favicon_url": "http://www.google.com/favicon.ico",
- "search_url": "{google:baseURL}search?q={searchTerms}&{google:RLZ}{google:originalQueryForSuggestion}{google:assistedQueryStats}{google:searchFieldtrialParameter}{google:searchClient}{google:sourceId}{google:instantExtendedEnabledParameter}{google:omniboxStartMarginParameter}ie={inputEncoding}",
+ "search_url": "{google:baseURL}search?q={searchTerms}&{google:RLZ}{google:originalQueryForSuggestion}{google:assistedQueryStats}{google:searchFieldtrialParameter}{google:bookmarkBarPinned}{google:searchClient}{google:sourceId}{google:instantExtendedEnabledParameter}{google:omniboxStartMarginParameter}ie={inputEncoding}",
"suggest_url": "{google:baseSuggestURL}search?{google:searchFieldtrialParameter}client={google:suggestClient}&q={searchTerms}&{google:cursorPosition}{google:zeroPrefixUrl}{google:pageClassification}sugkey={google:suggestAPIKeyParameter}",
"instant_url": "{google:baseURL}webhp?sourceid=chrome-instant&{google:RLZ}{google:instantEnabledParameter}{google:instantExtendedEnabledParameter}{google:ntpIsThemedParameter}{google:omniboxStartMarginParameter}ie={inputEncoding}",
"image_url": "{google:baseURL}searchbyimage/upload",
diff --git a/chrome/browser/search_engines/template_url.cc b/chrome/browser/search_engines/template_url.cc
index 7d964e40..19019fb 100644
--- a/chrome/browser/search_engines/template_url.cc
+++ b/chrome/browser/search_engines/template_url.cc
@@ -20,6 +20,7 @@
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/google/google_util.h"
+#include "chrome/browser/search/search.h"
#include "chrome/browser/search_engines/search_terms_data.h"
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/common/chrome_switches.h"
@@ -60,6 +61,7 @@
// Like google:baseURL, but for the Search Suggest capability.
const char kGoogleBaseSuggestURLParameter[] = "google:baseSuggestURL";
const char kGoogleBaseSuggestURLParameterFull[] = "{google:baseSuggestURL}";
+const char kGoogleBookmarkBarPinnedParameter[] = "google:bookmarkBarPinned";
const char kGoogleCursorPositionParameter[] = "google:cursorPosition";
const char kGoogleInstantEnabledParameter[] = "google:instantEnabledParameter";
const char kGoogleInstantExtendedEnabledParameter[] =
@@ -182,6 +184,11 @@
(*(param.rbegin()) == kEndParameter);
}
+bool ShowingSearchTermsOnSRP() {
+ return chrome::IsInstantExtendedAPIEnabled() &&
+ !chrome::ShouldSuppressInstantExtendedOnSRP();
+}
+
} // namespace
@@ -193,6 +200,7 @@
cursor_position(string16::npos),
omnibox_start_margin(-1),
page_classification(AutocompleteInput::INVALID_SPEC),
+ bookmark_bar_pinned(false),
append_extra_query_params(false) {
}
@@ -210,7 +218,8 @@
valid_(false),
supports_replacements_(false),
search_term_key_location_(url_parse::Parsed::QUERY),
- prepopulated_(false) {
+ prepopulated_(false),
+ showing_search_terms_(ShowingSearchTermsOnSRP()) {
DCHECK(owner_);
DCHECK_NE(INDEXED, type_);
}
@@ -223,7 +232,8 @@
valid_(false),
supports_replacements_(false),
search_term_key_location_(url_parse::Parsed::QUERY),
- prepopulated_(false) {
+ prepopulated_(false),
+ showing_search_terms_(ShowingSearchTermsOnSRP()) {
DCHECK(owner_);
DCHECK_LT(index_in_owner_, owner_->URLCount());
}
@@ -536,6 +546,8 @@
replacements->push_back(Replacement(GOOGLE_BASE_URL, start));
} else if (parameter == kGoogleBaseSuggestURLParameter) {
replacements->push_back(Replacement(GOOGLE_BASE_SUGGEST_URL, start));
+ } else if (parameter == kGoogleBookmarkBarPinnedParameter) {
+ replacements->push_back(Replacement(GOOGLE_BOOKMARK_BAR_PINNED, start));
} else if (parameter == kGoogleCursorPositionParameter) {
replacements->push_back(Replacement(GOOGLE_CURSOR_POSITION, start));
} else if (parameter == kGoogleImageOriginalHeight) {
@@ -828,6 +840,17 @@
&url);
break;
+ case GOOGLE_BOOKMARK_BAR_PINNED:
+ if (showing_search_terms_) {
+ // Log whether the bookmark bar is pinned when the user is seeing
+ // InstantExtended on the SRP.
+ DCHECK(!i->is_post_param);
+ HandleReplacement(
+ "bmbp", search_terms_args.bookmark_bar_pinned ? "1" : "0", *i,
+ &url);
+ }
+ break;
+
case GOOGLE_CURSOR_POSITION:
DCHECK(!i->is_post_param);
if (search_terms_args.cursor_position != string16::npos)
diff --git a/chrome/browser/search_engines/template_url.h b/chrome/browser/search_engines/template_url.h
index 1798e1a6..ec5d1423 100644
--- a/chrome/browser/search_engines/template_url.h
+++ b/chrome/browser/search_engines/template_url.h
@@ -101,6 +101,9 @@
// Which omnibox the user used to type the prefix.
AutocompleteInput::PageClassification page_classification;
+ // True for searches issued with the bookmark bar pref set to shown.
+ bool bookmark_bar_pinned;
+
// If set, ReplaceSearchTerms() will automatically append any extra query
// params specified via the --extra-search-query-params command-line
// argument. Generally, this should be set when dealing with the search or
@@ -231,6 +234,7 @@
FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLTwoParameters);
FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNestedParameter);
FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, URLRefTestImageURLWithPOST);
+ FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ReflectsBookmarkBarPinned);
// Enumeration of the known types.
enum ReplacementType {
@@ -238,6 +242,7 @@
GOOGLE_ASSISTED_QUERY_STATS,
GOOGLE_BASE_URL,
GOOGLE_BASE_SUGGEST_URL,
+ GOOGLE_BOOKMARK_BAR_PINNED,
GOOGLE_CURSOR_POSITION,
GOOGLE_IMAGE_ORIGINAL_HEIGHT,
GOOGLE_IMAGE_ORIGINAL_WIDTH,
@@ -384,6 +389,10 @@
// Whether the contained URL is a pre-populated URL.
bool prepopulated_;
+ // Whether search terms are shown in the omnibox on search results pages.
+ // This is kept as a member so it can be overridden by tests.
+ bool showing_search_terms_;
+
DISALLOW_COPY_AND_ASSIGN(TemplateURLRef);
};
@@ -680,6 +689,7 @@
private:
friend class TemplateURLService;
+ FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ReflectsBookmarkBarPinned);
void CopyFrom(const TemplateURL& other);
diff --git a/chrome/browser/search_engines/template_url_unittest.cc b/chrome/browser/search_engines/template_url_unittest.cc
index 5882e5dc..99f5b906 100644
--- a/chrome/browser/search_engines/template_url_unittest.cc
+++ b/chrome/browser/search_engines/template_url_unittest.cc
@@ -1233,3 +1233,29 @@
search_provider.IsSearchURL(GURL(url_data[i].url)));
}
}
+
+TEST_F(TemplateURLTest, ReflectsBookmarkBarPinned) {
+ TemplateURLData data;
+ data.input_encodings.push_back("UTF-8");
+ data.SetURL("{google:baseURL}?{google:bookmarkBarPinned}q={searchTerms}");
+ TemplateURL url(NULL, data);
+ EXPECT_TRUE(url.url_ref().IsValid());
+ ASSERT_TRUE(url.url_ref().SupportsReplacement());
+ TemplateURLRef::SearchTermsArgs search_terms_args(ASCIIToUTF16("foo"));
+
+ // Do not add the param when InstantExtended is suppressed on SRPs.
+ url.url_ref_.showing_search_terms_ = false;
+ std::string result = url.url_ref().ReplaceSearchTerms(search_terms_args);
+ EXPECT_EQ("http://www.google.com/?q=foo", result);
+
+ // Add the param when InstantExtended is not suppressed on SRPs.
+ url.url_ref_.showing_search_terms_ = true;
+ search_terms_args.bookmark_bar_pinned = false;
+ result = url.url_ref().ReplaceSearchTerms(search_terms_args);
+ EXPECT_EQ("http://www.google.com/?bmbp=0&q=foo", result);
+
+ url.url_ref_.showing_search_terms_ = true;
+ search_terms_args.bookmark_bar_pinned = true;
+ result = url.url_ref().ReplaceSearchTerms(search_terms_args);
+ EXPECT_EQ("http://www.google.com/?bmbp=1&q=foo", result);
+}