summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhuangs@chromium.org <huangs@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-24 05:43:19 +0000
committerhuangs@chromium.org <huangs@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-24 05:43:19 +0000
commit66d71de913cfabd9d94a9a43f637a8ad57106034 (patch)
tree237a4fad7081872f089fc003d3809b0ebfdb9cce
parent7de7ee0b02d0d083a4b72fc0902b7567e7b02304 (diff)
downloadchromium_src-66d71de913cfabd9d94a9a43f637a8ad57106034.zip
chromium_src-66d71de913cfabd9d94a9a43f637a8ad57106034.tar.gz
chromium_src-66d71de913cfabd9d94a9a43f637a8ad57106034.tar.bz2
Make chrome://thumb2 check both HTTP and HTTPS
To improve thumbnail matches for chrome://thumb2, we now check both HTTP and HTTPS for input URLs. Details: - Priority is given to the original protocol; so HTTP => check [HTTP, HTTPS], and HTTPS => check [HTTPS, HTTP]. - No change in behavior for other protocols. - Added ToggleHTTPAndHTTPS() in url_utils.cc, and unit test. - Some minor changes in other files. BUG= Review URL: https://codereview.chromium.org/35773002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@230651 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/history/top_sites_cache.h4
-rw-r--r--chrome/browser/history/top_sites_impl.cc38
-rw-r--r--chrome/browser/history/top_sites_impl_unittest.cc4
-rw-r--r--chrome/browser/history/url_utils.cc15
-rw-r--r--chrome/browser/history/url_utils.h4
-rw-r--r--chrome/browser/history/url_utils_unittest.cc9
6 files changed, 56 insertions, 18 deletions
diff --git a/chrome/browser/history/top_sites_cache.h b/chrome/browser/history/top_sites_cache.h
index ad0826f..0ce7308 100644
--- a/chrome/browser/history/top_sites_cache.h
+++ b/chrome/browser/history/top_sites_cache.h
@@ -146,12 +146,12 @@ class TopSitesCache {
// description above typedef for details.
CanonicalURLs canonical_urls_;
- // Helper to clear "?query#ref" from any GURL. This is set in the contrustor
+ // Helper to clear "?query#ref" from any GURL. This is set in the constructor
// and never modified after.
GURL::Replacements clear_query_ref_;
// Helper to clear "/path?query#ref" from any GURL. This is set in the
- // contrustor and never modified after.
+ // constructor and never modified after.
GURL::Replacements clear_path_query_ref_;
DISALLOW_COPY_AND_ASSIGN(TopSitesCache);
diff --git a/chrome/browser/history/top_sites_impl.cc b/chrome/browser/history/top_sites_impl.cc
index 7df73c4..509efb5 100644
--- a/chrome/browser/history/top_sites_impl.cc
+++ b/chrome/browser/history/top_sites_impl.cc
@@ -26,6 +26,7 @@
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/history/page_usage_data.h"
#include "chrome/browser/history/top_sites_cache.h"
+#include "chrome/browser/history/url_utils.h"
#include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/ntp/most_visited_handler.h"
@@ -235,21 +236,30 @@ bool TopSitesImpl::GetPageThumbnail(
}
if (prefix_match) {
- base::AutoLock lock(lock_);
-
- GURL canonical_url;
- // Test whether |url| is prefix of any stored URL.
- canonical_url = thread_safe_cache_->GetSpecializedCanonicalURL(url);
- if (!canonical_url.is_empty() &&
- thread_safe_cache_->GetPageThumbnail(canonical_url, bytes)) {
- return true;
- }
+ // If http or https, search with |url| first, then try the other one.
+ std::vector<GURL> url_list;
+ url_list.push_back(url);
+ if (url.SchemeIsHTTPOrHTTPS())
+ url_list.push_back(ToggleHTTPAndHTTPS(url));
+
+ for (std::vector<GURL>::iterator it = url_list.begin();
+ it != url_list.end(); ++it) {
+ base::AutoLock lock(lock_);
+
+ GURL canonical_url;
+ // Test whether |url| is prefix of any stored URL.
+ canonical_url = thread_safe_cache_->GetSpecializedCanonicalURL(*it);
+ if (!canonical_url.is_empty() &&
+ thread_safe_cache_->GetPageThumbnail(canonical_url, bytes)) {
+ return true;
+ }
- // Test whether any stored URL is a prefix of |url|.
- canonical_url = thread_safe_cache_->GetGeneralizedCanonicalURL(url);
- if (!canonical_url.is_empty() &&
- thread_safe_cache_->GetPageThumbnail(canonical_url, bytes)) {
- return true;
+ // Test whether any stored URL is a prefix of |url|.
+ canonical_url = thread_safe_cache_->GetGeneralizedCanonicalURL(*it);
+ if (!canonical_url.is_empty() &&
+ thread_safe_cache_->GetPageThumbnail(canonical_url, bytes)) {
+ return true;
+ }
}
}
diff --git a/chrome/browser/history/top_sites_impl_unittest.cc b/chrome/browser/history/top_sites_impl_unittest.cc
index a32a01f..0062968 100644
--- a/chrome/browser/history/top_sites_impl_unittest.cc
+++ b/chrome/browser/history/top_sites_impl_unittest.cc
@@ -512,7 +512,7 @@ TEST_F(TopSitesImplTest, GetPageThumbnail) {
EXPECT_TRUE(top_sites()->GetPageThumbnail(url1.url, false, &result));
EXPECT_TRUE(top_sites()->SetPageThumbnail(GURL("http://gmail.com"),
- thumbnail, score));
+ thumbnail, score));
EXPECT_TRUE(top_sites()->GetPageThumbnail(GURL("http://gmail.com"),
false,
&result));
@@ -522,7 +522,7 @@ TEST_F(TopSitesImplTest, GetPageThumbnail) {
&result));
EXPECT_TRUE(top_sites()->SetPageThumbnail(GURL("http://mail.google.com"),
- thumbnail, score));
+ thumbnail, score));
EXPECT_TRUE(top_sites()->GetPageThumbnail(url2.url, false, &result));
EXPECT_TRUE(ThumbnailEqualsBytes(thumbnail, result.get()));
diff --git a/chrome/browser/history/url_utils.cc b/chrome/browser/history/url_utils.cc
index 7c96b8a..292fcd6 100644
--- a/chrome/browser/history/url_utils.cc
+++ b/chrome/browser/history/url_utils.cc
@@ -68,4 +68,19 @@ bool IsPathPrefix(const std::string& p1, const std::string& p2) {
return *(first_diff.second) == '/';
}
+GURL ToggleHTTPAndHTTPS(const GURL& url) {
+ std::string new_scheme;
+ if (url.SchemeIs("http"))
+ new_scheme = "https";
+ else if (url.SchemeIs("https"))
+ new_scheme = "http";
+ else
+ return GURL::EmptyGURL();
+ url_parse::Component comp;
+ comp.len = new_scheme.length();
+ GURL::Replacements replacement;
+ replacement.SetScheme(new_scheme.c_str(), comp);
+ return url.ReplaceComponents(replacement);
+}
+
} // namespace history
diff --git a/chrome/browser/history/url_utils.h b/chrome/browser/history/url_utils.h
index 586d084..c5b74fe 100644
--- a/chrome/browser/history/url_utils.h
+++ b/chrome/browser/history/url_utils.h
@@ -37,6 +37,10 @@ bool HaveSameSchemeHostAndPort(const GURL&url1, const GURL& url2);
// prefix of "testing", even though "test" is a (string) prefix of "testing".
bool IsPathPrefix(const std::string& p1, const std::string& p2);
+// Converts |url| from HTTP to HTTPS, and vice versa, then returns the result.
+// If |url| is neither HTTP nor HTTPS, returns an empty URL.
+GURL ToggleHTTPAndHTTPS(const GURL& url);
+
} // namespace history
#endif // CHROME_BROWSER_HISTORY_URL_UTILS_H_
diff --git a/chrome/browser/history/url_utils_unittest.cc b/chrome/browser/history/url_utils_unittest.cc
index 02b1ff9..b1ffb6a 100644
--- a/chrome/browser/history/url_utils_unittest.cc
+++ b/chrome/browser/history/url_utils_unittest.cc
@@ -116,6 +116,15 @@ TEST(HistoryUrlUtilsTest, IsPathPrefix) {
}
}
+TEST(HistoryUrlUtilsTest, ToggleHTTPAndHTTPS) {
+ EXPECT_EQ(GURL("http://www.google.com/test?q#r"),
+ ToggleHTTPAndHTTPS(GURL("https://www.google.com/test?q#r")));
+ EXPECT_EQ(GURL("https://www.google.com:137/"),
+ ToggleHTTPAndHTTPS(GURL("http://www.google.com:137/")));
+ EXPECT_EQ(GURL::EmptyGURL(),
+ ToggleHTTPAndHTTPS(GURL("ftp://www.google.com/")));
+}
+
} // namespace
} // namespace history