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 5914d9910c1966729724223aaad4cd52d0dea75a..4448c89e939bba9484294042cd3078c5cd878e10 100644 |
--- a/chrome/browser/history/top_sites_cache.cc |
+++ b/chrome/browser/history/top_sites_cache.cc |
@@ -31,6 +31,7 @@ TopSitesCache::~TopSitesCache() { |
void TopSitesCache::SetTopSites(const MostVisitedURLList& top_sites) { |
top_sites_ = top_sites; |
+ CountForcedURLs(); |
GenerateCanonicalURLs(); |
} |
@@ -119,6 +120,31 @@ size_t TopSitesCache::GetURLIndex(const GURL& url) const { |
return GetCanonicalURLsIterator(url)->second; |
} |
+size_t TopSitesCache::GetNumNonForcedURLs() const { |
+ return top_sites_.size() - num_forced_urls_; |
+} |
+ |
+size_t TopSitesCache::GetNumForcedURLs() const { |
+ return num_forced_urls_; |
+} |
+ |
+void TopSitesCache::CountForcedURLs() { |
+ num_forced_urls_ = 0; |
+ while (num_forced_urls_ < top_sites_.size()) { |
+ // Forced sites are all at the beginning. |
+ if (top_sites_[num_forced_urls_].last_forced_time.is_null()) |
+ break; |
+ num_forced_urls_++; |
+ } |
+ // In debug, ensure the cache user has no forced URLs pass that point. |
+ if (DCHECK_IS_ON()) { |
+ for (size_t i = num_forced_urls_; i < top_sites_.size(); ++i) { |
+ DCHECK(top_sites_[i].last_forced_time.is_null()) |
+ << "All the forced URLs must appear before non-forced URLs."; |
+ } |
+ } |
+} |
+ |
void TopSitesCache::GenerateCanonicalURLs() { |
canonical_urls_.clear(); |
for (size_t i = 0; i < top_sites_.size(); i++) |