Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4213)

Unified Diff: chrome/browser/history/top_sites_cache.cc

Issue 23477033: Implementing URL prefix match for history thumbnail cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Inlining; comment fixes. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/history/top_sites_cache.cc
diff --git a/chrome/browser/history/top_sites_cache.cc b/chrome/browser/history/top_sites_cache.cc
index f94013f0773be2ee3408d859a9fa827ff60cff89..6552f73ac61858267a5a713a0273b79b13442980 100644
--- a/chrome/browser/history/top_sites_cache.cc
+++ b/chrome/browser/history/top_sites_cache.cc
@@ -55,7 +55,12 @@ bool TopSitesCache::GetPageThumbnailScore(const GURL& url,
}
const GURL& TopSitesCache::GetCanonicalURL(const GURL& url) {
- CanonicalURLs::iterator i = TopSitesCache::GetCanonicalURLsIterator(url);
+ CanonicalURLs::iterator i = GetCanonicalURLsIterator(url);
+ return i == canonical_urls_.end() ? url : i->first.first->url;
+}
+
+const GURL& TopSitesCache::GetCanonicalURLForPrefix(const GURL& url) {
+ CanonicalURLs::iterator i = GetCanonicalURLsIteratorForPrefix(url);
return i == canonical_urls_.end() ? url : i->first.first->url;
}
@@ -76,7 +81,7 @@ void TopSitesCache::GenerateCanonicalURLs() {
void TopSitesCache::StoreRedirectChain(const RedirectList& redirects,
size_t destination) {
- // redirects is empty if the user pinned a site and there are not enough top
+ // |redirects| is empty if the user pinned a site and there are not enough top
// sites before the pinned site.
// Map all the redirected URLs to the destination.
@@ -101,4 +106,24 @@ TopSitesCache::CanonicalURLs::iterator TopSitesCache::GetCanonicalURLsIterator(
return canonical_urls_.find(entry);
}
+TopSitesCache::CanonicalURLs::iterator
+ TopSitesCache::GetCanonicalURLsIteratorForPrefix(const GURL& prefix_url) {
+ MostVisitedURL most_visited_url;
+ most_visited_url.redirects.push_back(prefix_url);
+ CanonicalURLEntry entry;
+ entry.first = &most_visited_url;
+ entry.second = 0u;
+
+ // Perform effective binary search for URL prefix search.
+ TopSitesCache::CanonicalURLs::iterator it =
+ canonical_urls_.lower_bound(entry);
+ // Perform prefix match.
+ if (it != canonical_urls_.end()) {
+ const GURL& comp_url = it->first.first->redirects[it->first.second];
+ if (!UrlIsPrefix(prefix_url, comp_url))
+ it = canonical_urls_.end();
+ }
+ return it;
+}
+
} // namespace history

Powered by Google App Engine
This is Rietveld 408576698