diff options
author | tburkard@chromium.org <tburkard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-30 23:50:59 +0000 |
---|---|---|
committer | tburkard@chromium.org <tburkard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-30 23:50:59 +0000 |
commit | 2d02bea25a2ea6d67c3d1f4a06d3bbe697938163 (patch) | |
tree | 3c9988ceefa563b197761a14b9445956a852f6b6 /chrome/browser | |
parent | 5a47f866290d8abd546f1373661f0c00c0fdd128 (diff) | |
download | chromium_src-2d02bea25a2ea6d67c3d1f4a06d3bbe697938163.zip chromium_src-2d02bea25a2ea6d67c3d1f4a06d3bbe697938163.tar.gz chromium_src-2d02bea25a2ea6d67c3d1f4a06d3bbe697938163.tar.bz2 |
Tighten conditions for when a URL is a search result, and move
it to a different class.
R=ziga, dominich
Review URL: http://codereview.chromium.org/7812011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98895 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/prerender/prerender_manager.cc | 6 | ||||
-rw-r--r-- | chrome/browser/prerender/prerender_util.cc | 10 | ||||
-rw-r--r-- | chrome/browser/prerender/prerender_util.h | 3 | ||||
-rw-r--r-- | chrome/browser/prerender/prerender_util_unittest.cc | 25 |
4 files changed, 38 insertions, 6 deletions
diff --git a/chrome/browser/prerender/prerender_manager.cc b/chrome/browser/prerender/prerender_manager.cc index 131d65d..d7030d4 100644 --- a/chrome/browser/prerender/prerender_manager.cc +++ b/chrome/browser/prerender/prerender_manager.cc @@ -9,7 +9,6 @@ #include "base/command_line.h" #include "base/logging.h" #include "base/stl_util.h" -#include "base/string_util.h" #include "base/time.h" #include "base/values.h" #include "base/utf_string_conversions.h" @@ -298,11 +297,8 @@ bool PrerenderManager::AddPrerender( const GURL& referrer) { DCHECK(CalledOnValidThread()); - if (origin == ORIGIN_LINK_REL_PRERENDER && - StartsWithASCII(referrer.host(), std::string("www.google."), true) && - !StartsWithASCII(referrer.path(), std::string("/imgres"), true)) { + if (origin == ORIGIN_LINK_REL_PRERENDER && IsGoogleSearchResultURL(referrer)) origin = ORIGIN_GWS_PRERENDER; - } histograms_->RecordPrerender(origin, url_arg); diff --git a/chrome/browser/prerender/prerender_util.cc b/chrome/browser/prerender/prerender_util.cc index 100b93e..7d1c396 100644 --- a/chrome/browser/prerender/prerender_util.cc +++ b/chrome/browser/prerender/prerender_util.cc @@ -5,6 +5,7 @@ #include "chrome/browser/prerender/prerender_util.h" #include "base/logging.h" +#include "base/string_util.h" #include "googleurl/src/url_canon.h" #include "googleurl/src/url_parse.h" #include "googleurl/src/url_util.h" @@ -61,4 +62,13 @@ uint8 GetQueryStringBasedExperiment(const GURL& url) { return kNoExperiment; } +bool IsGoogleSearchResultURL(const GURL& url) { + if (!StartsWithASCII(url.host(), std::string("www.google."), true)) + return false; + return (url.path().empty() || + StartsWithASCII(url.path(), std::string("/search"), true) || + (url.path() == "/") || + StartsWithASCII(url.path(), std::string("/webhp"), true)); +} + } // namespace prerender diff --git a/chrome/browser/prerender/prerender_util.h b/chrome/browser/prerender/prerender_util.h index 87bdc52..1948475 100644 --- a/chrome/browser/prerender/prerender_util.h +++ b/chrome/browser/prerender/prerender_util.h @@ -24,6 +24,9 @@ bool MaybeGetQueryStringBasedAliasURL(const GURL& url, GURL* alias_url); // is not an integer in the range 1 to 9. uint8 GetQueryStringBasedExperiment(const GURL& url); +// Indicates whether the URL provided could be a Google search result page. +bool IsGoogleSearchResultURL(const GURL& url); + } // namespace prerender #endif // CHROME_BROWSER_PRERENDER_PRERENDER_UTIL_H_ diff --git a/chrome/browser/prerender/prerender_util_unittest.cc b/chrome/browser/prerender/prerender_util_unittest.cc index ac8b501..79a1ffa 100644 --- a/chrome/browser/prerender/prerender_util_unittest.cc +++ b/chrome/browser/prerender/prerender_util_unittest.cc @@ -34,7 +34,6 @@ TEST_F(PrerenderUtilTest, ExtractURLInQueryStringTest) { // Ensure that extracting an experiment in the lpe= query string component // works. TEST_F(PrerenderUtilTest, ExtractExperimentInQueryStringTest) { - GURL result; EXPECT_EQ(GetQueryStringBasedExperiment( GURL("http://www.google.com/url?sa=t&source=web&cd=1&ved=0CBcQFjAA&url=http%3A%2F%2Fwww.abercrombie.com%2Fwebapp%2Fwcs%2Fstores%2Fservlet%2FStoreLocator%3FcatalogId%3D%26storeId%3D10051%26langId%3D-1&rct=j&q=allinurl%3A%26&ei=KLyUTYGSEdTWiAKUmLCdCQ&usg=AFQjCNF8nJ2MpBFfr1ijO39_f22bcKyccw&sig2=2ymyGpO0unJwU1d4kdCUjQ&lpe=4&asdf=test")), 4); EXPECT_EQ(GetQueryStringBasedExperiment( @@ -49,4 +48,28 @@ TEST_F(PrerenderUtilTest, ExtractExperimentInQueryStringTest) { GURL("http://www.google.com/test.php?lpe=10")), kNoExperiment); } +// Ensure that we detect Google search result URLs correctly. +TEST_F(PrerenderUtilTest, DetectGoogleSearchREsultURLTest) { + EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.com/#asdf"))); + EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.com/"))); + EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.com/?a=b"))); + EXPECT_TRUE(IsGoogleSearchResultURL( + GURL("http://www.google.com/search?q=hi"))); + EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.com/search"))); + EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.com/webhp"))); + EXPECT_TRUE(IsGoogleSearchResultURL( + GURL("http://www.google.com/webhp?a=b#123"))); + EXPECT_FALSE(IsGoogleSearchResultURL(GURL("http://www.google.com/imgres"))); + EXPECT_FALSE(IsGoogleSearchResultURL( + GURL("http://www.google.com/imgres?q=hi"))); + EXPECT_FALSE(IsGoogleSearchResultURL( + GURL("http://www.google.com/imgres?q=hi#123"))); + EXPECT_FALSE(IsGoogleSearchResultURL(GURL("http://google.com/search"))); + EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://WWW.GooGLE.CoM/search"))); + EXPECT_FALSE(IsGoogleSearchResultURL(GURL("http://WWW.GooGLE.CoM/SeArcH"))); + EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.co.uk/search"))); + EXPECT_FALSE(IsGoogleSearchResultURL(GURL("http://google.co.uk/search"))); + EXPECT_FALSE(IsGoogleSearchResultURL(GURL("http://www.chromium.org/search"))); +} + } // namespace prerender |