OLD | NEW |
---|---|
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 13 matching lines...) Expand all Loading... | |
24 clear_path_query_ref_.ClearQuery(); | 24 clear_path_query_ref_.ClearQuery(); |
25 clear_path_query_ref_.ClearRef(); | 25 clear_path_query_ref_.ClearRef(); |
26 clear_path_query_ref_.ClearPath(); | 26 clear_path_query_ref_.ClearPath(); |
27 } | 27 } |
28 | 28 |
29 TopSitesCache::~TopSitesCache() { | 29 TopSitesCache::~TopSitesCache() { |
30 } | 30 } |
31 | 31 |
32 void TopSitesCache::SetTopSites(const MostVisitedURLList& top_sites) { | 32 void TopSitesCache::SetTopSites(const MostVisitedURLList& top_sites) { |
33 top_sites_ = top_sites; | 33 top_sites_ = top_sites; |
34 CountForcedURLs(); | |
34 GenerateCanonicalURLs(); | 35 GenerateCanonicalURLs(); |
35 } | 36 } |
36 | 37 |
37 void TopSitesCache::SetThumbnails(const URLToImagesMap& images) { | 38 void TopSitesCache::SetThumbnails(const URLToImagesMap& images) { |
38 images_ = images; | 39 images_ = images; |
39 } | 40 } |
40 | 41 |
41 Images* TopSitesCache::GetImage(const GURL& url) { | 42 Images* TopSitesCache::GetImage(const GURL& url) { |
42 return &images_[GetCanonicalURL(url)]; | 43 return &images_[GetCanonicalURL(url)]; |
43 } | 44 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 | 142 |
142 bool TopSitesCache::IsKnownURL(const GURL& url) const { | 143 bool TopSitesCache::IsKnownURL(const GURL& url) const { |
143 return GetCanonicalURLsIterator(url) != canonical_urls_.end(); | 144 return GetCanonicalURLsIterator(url) != canonical_urls_.end(); |
144 } | 145 } |
145 | 146 |
146 size_t TopSitesCache::GetURLIndex(const GURL& url) const { | 147 size_t TopSitesCache::GetURLIndex(const GURL& url) const { |
147 DCHECK(IsKnownURL(url)); | 148 DCHECK(IsKnownURL(url)); |
148 return GetCanonicalURLsIterator(url)->second; | 149 return GetCanonicalURLsIterator(url)->second; |
149 } | 150 } |
150 | 151 |
152 size_t TopSitesCache::GetNbNonForcedURLs() const { | |
153 return top_sites_.size() - nb_forced_urls_; | |
154 } | |
155 | |
156 size_t TopSitesCache::GetNbForcedURLs() const { | |
157 return nb_forced_urls_; | |
158 } | |
159 | |
160 void TopSitesCache::CountForcedURLs() { | |
161 nb_forced_urls_ = 0; | |
brettw
2013/11/08 22:56:07
As above, I'd use "num" instead. I've never seen a
beaudoin
2013/11/11 21:58:09
Probably a French thing. Sorry. :)
Done.
| |
162 while (nb_forced_urls_ < top_sites_.size()) { | |
163 // Forced sites are all at the beginning. | |
164 if (top_sites_[nb_forced_urls_].last_forced_time.is_null()) | |
165 break; | |
166 nb_forced_urls_++; | |
167 } | |
168 // In debug, ensure the cache user is has no forced URLs pass that point. | |
brettw
2013/11/08 22:56:07
Grammar: "is has"
beaudoin
2013/11/11 21:58:09
Done.
| |
169 if (DCHECK_IS_ON()) { | |
170 for (size_t i = nb_forced_urls_; i < top_sites_.size(); ++i) { | |
171 DCHECK(top_sites_[i].last_forced_time.is_null()) | |
172 << "All the forced URLs must appear before non-forced URLs."; | |
173 } | |
174 } | |
175 } | |
176 | |
151 void TopSitesCache::GenerateCanonicalURLs() { | 177 void TopSitesCache::GenerateCanonicalURLs() { |
152 canonical_urls_.clear(); | 178 canonical_urls_.clear(); |
153 for (size_t i = 0; i < top_sites_.size(); i++) | 179 for (size_t i = 0; i < top_sites_.size(); i++) |
154 StoreRedirectChain(top_sites_[i].redirects, i); | 180 StoreRedirectChain(top_sites_[i].redirects, i); |
155 } | 181 } |
156 | 182 |
157 void TopSitesCache::StoreRedirectChain(const RedirectList& redirects, | 183 void TopSitesCache::StoreRedirectChain(const RedirectList& redirects, |
158 size_t destination) { | 184 size_t destination) { |
159 // |redirects| is empty if the user pinned a site and there are not enough top | 185 // |redirects| is empty if the user pinned a site and there are not enough top |
160 // sites before the pinned site. | 186 // sites before the pinned site. |
(...skipping 15 matching lines...) Expand all Loading... | |
176 return canonical_urls_.find(CanonicalURLQuery(url).entry()); | 202 return canonical_urls_.find(CanonicalURLQuery(url).entry()); |
177 } | 203 } |
178 | 204 |
179 const GURL& TopSitesCache::GetURLFromIterator( | 205 const GURL& TopSitesCache::GetURLFromIterator( |
180 CanonicalURLs::const_iterator it) const { | 206 CanonicalURLs::const_iterator it) const { |
181 DCHECK(it != canonical_urls_.end()); | 207 DCHECK(it != canonical_urls_.end()); |
182 return it->first.first->redirects[it->first.second]; | 208 return it->first.first->redirects[it->first.second]; |
183 } | 209 } |
184 | 210 |
185 } // namespace history | 211 } // namespace history |
OLD | NEW |