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

Side by Side 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: Replacing ASSERT_TRUE() << ... to NOTREACHED() << ... 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/history/top_sites_cache.h" 5 #include "chrome/browser/history/top_sites_cache.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/ref_counted_memory.h" 8 #include "base/memory/ref_counted_memory.h"
9 9
10 namespace history { 10 namespace history {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 std::map<GURL, Images>::const_iterator found = 48 std::map<GURL, Images>::const_iterator found =
49 images_.find(GetCanonicalURL(url)); 49 images_.find(GetCanonicalURL(url));
50 if (found != images_.end()) { 50 if (found != images_.end()) {
51 *score = found->second.thumbnail_score; 51 *score = found->second.thumbnail_score;
52 return true; 52 return true;
53 } 53 }
54 return false; 54 return false;
55 } 55 }
56 56
57 const GURL& TopSitesCache::GetCanonicalURL(const GURL& url) { 57 const GURL& TopSitesCache::GetCanonicalURL(const GURL& url) {
58 CanonicalURLs::iterator i = TopSitesCache::GetCanonicalURLsIterator(url); 58 CanonicalURLs::iterator i = GetCanonicalURLsIterator(url);
59 return i == canonical_urls_.end() ? url : i->first.first->url; 59 return i == canonical_urls_.end() ? url : i->first.first->url;
60 } 60 }
61 61
62 const GURL& TopSitesCache::GetCanonicalURLForPrefix(const GURL& url) {
63 CanonicalURLs::iterator i = GetCanonicalURLsIteratorForPrefix(url);
64 return i == canonical_urls_.end() ? url : i->first.first->url;
65 }
66
62 bool TopSitesCache::IsKnownURL(const GURL& url) { 67 bool TopSitesCache::IsKnownURL(const GURL& url) {
63 return GetCanonicalURLsIterator(url) != canonical_urls_.end(); 68 return GetCanonicalURLsIterator(url) != canonical_urls_.end();
64 } 69 }
65 70
66 size_t TopSitesCache::GetURLIndex(const GURL& url) { 71 size_t TopSitesCache::GetURLIndex(const GURL& url) {
67 DCHECK(IsKnownURL(url)); 72 DCHECK(IsKnownURL(url));
68 return GetCanonicalURLsIterator(url)->second; 73 return GetCanonicalURLsIterator(url)->second;
69 } 74 }
70 75
71 void TopSitesCache::GenerateCanonicalURLs() { 76 void TopSitesCache::GenerateCanonicalURLs() {
72 canonical_urls_.clear(); 77 canonical_urls_.clear();
73 for (size_t i = 0; i < top_sites_.size(); i++) 78 for (size_t i = 0; i < top_sites_.size(); i++)
74 StoreRedirectChain(top_sites_[i].redirects, i); 79 StoreRedirectChain(top_sites_[i].redirects, i);
75 } 80 }
76 81
77 void TopSitesCache::StoreRedirectChain(const RedirectList& redirects, 82 void TopSitesCache::StoreRedirectChain(const RedirectList& redirects,
78 size_t destination) { 83 size_t destination) {
79 // redirects is empty if the user pinned a site and there are not enough top 84 // |redirects| is empty if the user pinned a site and there are not enough top
80 // sites before the pinned site. 85 // sites before the pinned site.
81 86
82 // Map all the redirected URLs to the destination. 87 // Map all the redirected URLs to the destination.
83 for (size_t i = 0; i < redirects.size(); i++) { 88 for (size_t i = 0; i < redirects.size(); i++) {
84 // If this redirect is already known, don't replace it with a new one. 89 // If this redirect is already known, don't replace it with a new one.
85 if (!IsKnownURL(redirects[i])) { 90 if (!IsKnownURL(redirects[i])) {
86 CanonicalURLEntry entry; 91 CanonicalURLEntry entry;
87 entry.first = &(top_sites_[destination]); 92 entry.first = &(top_sites_[destination]);
88 entry.second = i; 93 entry.second = i;
89 canonical_urls_[entry] = destination; 94 canonical_urls_[entry] = destination;
90 } 95 }
91 } 96 }
92 } 97 }
93 98
94 TopSitesCache::CanonicalURLs::iterator TopSitesCache::GetCanonicalURLsIterator( 99 TopSitesCache::CanonicalURLs::iterator TopSitesCache::GetCanonicalURLsIterator(
95 const GURL& url) { 100 const GURL& url) {
96 MostVisitedURL most_visited_url; 101 MostVisitedURL most_visited_url;
97 most_visited_url.redirects.push_back(url); 102 most_visited_url.redirects.push_back(url);
98 CanonicalURLEntry entry; 103 CanonicalURLEntry entry;
99 entry.first = &most_visited_url; 104 entry.first = &most_visited_url;
100 entry.second = 0u; 105 entry.second = 0u;
101 return canonical_urls_.find(entry); 106 return canonical_urls_.find(entry);
102 } 107 }
103 108
109 TopSitesCache::CanonicalURLs::iterator
110 TopSitesCache::GetCanonicalURLsIteratorForPrefix(const GURL& prefix_url) {
111 MostVisitedURL most_visited_url;
112 most_visited_url.redirects.push_back(prefix_url);
113 CanonicalURLEntry entry;
114 entry.first = &most_visited_url;
115 entry.second = 0u;
116
117 // Perform effective binary search for URL prefix search.
118 TopSitesCache::CanonicalURLs::iterator it =
119 canonical_urls_.lower_bound(entry);
120 // Perform prefix match.
121 if (it != canonical_urls_.end()) {
122 const GURL& comp_url = it->first.first->redirects[it->first.second];
123 if (!UrlIsPrefix(prefix_url, comp_url))
124 it = canonical_urls_.end();
125 }
126 return it;
127 }
128
104 } // namespace history 129 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/top_sites_cache.h ('k') | chrome/browser/history/top_sites_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698