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 #ifndef CHROME_BROWSER_HISTORY_TOP_SITES_CACHE_H_ | 5 #ifndef CHROME_BROWSER_HISTORY_TOP_SITES_CACHE_H_ |
6 #define CHROME_BROWSER_HISTORY_TOP_SITES_CACHE_H_ | 6 #define CHROME_BROWSER_HISTORY_TOP_SITES_CACHE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 // ignoring "?query#ref". | 35 // ignoring "?query#ref". |
36 // For the latter two "URL prefix matches", we prefer the match that is closest | 36 // For the latter two "URL prefix matches", we prefer the match that is closest |
37 // to input URL, w.r.t. path hierarchy. | 37 // to input URL, w.r.t. path hierarchy. |
38 | 38 |
39 // TopSitesCache caches the top sites and thumbnails for TopSites. | 39 // TopSitesCache caches the top sites and thumbnails for TopSites. |
40 class TopSitesCache { | 40 class TopSitesCache { |
41 public: | 41 public: |
42 TopSitesCache(); | 42 TopSitesCache(); |
43 ~TopSitesCache(); | 43 ~TopSitesCache(); |
44 | 44 |
45 // The top sites. | 45 // Set the top sites. In |top_sites| all forced URLs must appear before |
| 46 // non-forced URLs. This is only checked in debug. |
46 void SetTopSites(const MostVisitedURLList& top_sites); | 47 void SetTopSites(const MostVisitedURLList& top_sites); |
47 const MostVisitedURLList& top_sites() const { return top_sites_; } | 48 const MostVisitedURLList& top_sites() const { return top_sites_; } |
48 | 49 |
49 // The thumbnails. | 50 // The thumbnails. |
50 void SetThumbnails(const URLToImagesMap& images); | 51 void SetThumbnails(const URLToImagesMap& images); |
51 const URLToImagesMap& images() const { return images_; } | 52 const URLToImagesMap& images() const { return images_; } |
52 | 53 |
53 // Returns the thumbnail as an Image for the specified url. This adds an entry | 54 // Returns the thumbnail as an Image for the specified url. This adds an entry |
54 // for |url| if one has not yet been added. | 55 // for |url| if one has not yet been added. |
55 Images* GetImage(const GURL& url); | 56 Images* GetImage(const GURL& url); |
(...skipping 16 matching lines...) Expand all Loading... |
72 // ignoring "?query#ref". Returns the resulting canonical URL if match is | 73 // ignoring "?query#ref". Returns the resulting canonical URL if match is |
73 // found, otherwise returns an empty GURL. | 74 // found, otherwise returns an empty GURL. |
74 GURL GetGeneralizedCanonicalURL(const GURL& url) const; | 75 GURL GetGeneralizedCanonicalURL(const GURL& url) const; |
75 | 76 |
76 // Returns true if |url| is known. | 77 // Returns true if |url| is known. |
77 bool IsKnownURL(const GURL& url) const; | 78 bool IsKnownURL(const GURL& url) const; |
78 | 79 |
79 // Returns the index into |top_sites_| for |url|. | 80 // Returns the index into |top_sites_| for |url|. |
80 size_t GetURLIndex(const GURL& url) const; | 81 size_t GetURLIndex(const GURL& url) const; |
81 | 82 |
| 83 // Returns the number of non-forced URLs in the cache. |
| 84 size_t GetNumNonForcedURLs() const; |
| 85 |
| 86 // Returns the number of forced URLs in the cache. |
| 87 size_t GetNumForcedURLs() const; |
| 88 |
82 private: | 89 private: |
83 // The entries in CanonicalURLs, see CanonicalURLs for details. The second | 90 // The entries in CanonicalURLs, see CanonicalURLs for details. The second |
84 // argument gives the index of the URL into MostVisitedURLs redirects. | 91 // argument gives the index of the URL into MostVisitedURLs redirects. |
85 typedef std::pair<MostVisitedURL*, size_t> CanonicalURLEntry; | 92 typedef std::pair<MostVisitedURL*, size_t> CanonicalURLEntry; |
86 | 93 |
87 // Comparator used for CanonicalURLs. | 94 // Comparator used for CanonicalURLs. |
88 class CanonicalURLComparator { | 95 class CanonicalURLComparator { |
89 public: | 96 public: |
90 bool operator()(const CanonicalURLEntry& e1, | 97 bool operator()(const CanonicalURLEntry& e1, |
91 const CanonicalURLEntry& e2) const { | 98 const CanonicalURLEntry& e2) const { |
(...skipping 18 matching lines...) Expand all Loading... |
110 // This is used to map from redirect url to the MostVisitedURL the redirect is | 117 // This is used to map from redirect url to the MostVisitedURL the redirect is |
111 // from. Ideally this would be map<GURL, size_t> (second param indexing into | 118 // from. Ideally this would be map<GURL, size_t> (second param indexing into |
112 // top_sites_), but this results in duplicating all redirect urls. As some | 119 // top_sites_), but this results in duplicating all redirect urls. As some |
113 // sites have a lot of redirects, we instead use the MostVisitedURL* and the | 120 // sites have a lot of redirects, we instead use the MostVisitedURL* and the |
114 // index of the redirect as the key, and the index into top_sites_ as the | 121 // index of the redirect as the key, and the index into top_sites_ as the |
115 // value. This way we aren't duplicating GURLs. CanonicalURLComparator | 122 // value. This way we aren't duplicating GURLs. CanonicalURLComparator |
116 // enforces the ordering as if we were using GURLs. | 123 // enforces the ordering as if we were using GURLs. |
117 typedef std::map<CanonicalURLEntry, size_t, | 124 typedef std::map<CanonicalURLEntry, size_t, |
118 CanonicalURLComparator> CanonicalURLs; | 125 CanonicalURLComparator> CanonicalURLs; |
119 | 126 |
| 127 // Count the number of forced URLs. |
| 128 void CountForcedURLs(); |
| 129 |
120 // Generates the set of canonical urls from |top_sites_|. | 130 // Generates the set of canonical urls from |top_sites_|. |
121 void GenerateCanonicalURLs(); | 131 void GenerateCanonicalURLs(); |
122 | 132 |
123 // Stores a set of redirects. This is used by GenerateCanonicalURLs. | 133 // Stores a set of redirects. This is used by GenerateCanonicalURLs. |
124 void StoreRedirectChain(const RedirectList& redirects, size_t destination); | 134 void StoreRedirectChain(const RedirectList& redirects, size_t destination); |
125 | 135 |
126 // Returns the iterator into |canonical_urls_| for the |url|. | 136 // Returns the iterator into |canonical_urls_| for the |url|. |
127 CanonicalURLs::const_iterator GetCanonicalURLsIterator(const GURL& url) const; | 137 CanonicalURLs::const_iterator GetCanonicalURLsIterator(const GURL& url) const; |
128 | 138 |
129 // Returns the GURL corresponding to an iterator in |canonical_urls_|. | 139 // Returns the GURL corresponding to an iterator in |canonical_urls_|. |
130 const GURL& GetURLFromIterator(CanonicalURLs::const_iterator it) const; | 140 const GURL& GetURLFromIterator(CanonicalURLs::const_iterator it) const; |
131 | 141 |
132 // The top sites. | 142 // The number of top sites with forced URLs. |
| 143 size_t num_forced_urls_; |
| 144 |
| 145 // The top sites. This list must always contain the forced URLs first followed |
| 146 // by the non-forced URLs. This is not strictly enforced but is checked in |
| 147 // debug. |
133 MostVisitedURLList top_sites_; | 148 MostVisitedURLList top_sites_; |
134 | 149 |
135 // The images. These map from canonical url to image. | 150 // The images. These map from canonical url to image. |
136 URLToImagesMap images_; | 151 URLToImagesMap images_; |
137 | 152 |
138 // Generated from the redirects to and from the most visited pages. See | 153 // Generated from the redirects to and from the most visited pages. See |
139 // description above typedef for details. | 154 // description above typedef for details. |
140 CanonicalURLs canonical_urls_; | 155 CanonicalURLs canonical_urls_; |
141 | 156 |
142 // Helper to clear "?query#ref" from any GURL. This is set in the constructor | 157 // Helper to clear "?query#ref" from any GURL. This is set in the constructor |
143 // and never modified after. | 158 // and never modified after. |
144 GURL::Replacements clear_query_ref_; | 159 GURL::Replacements clear_query_ref_; |
145 | 160 |
146 // Helper to clear "/path?query#ref" from any GURL. This is set in the | 161 // Helper to clear "/path?query#ref" from any GURL. This is set in the |
147 // constructor and never modified after. | 162 // constructor and never modified after. |
148 GURL::Replacements clear_path_query_ref_; | 163 GURL::Replacements clear_path_query_ref_; |
149 | 164 |
150 DISALLOW_COPY_AND_ASSIGN(TopSitesCache); | 165 DISALLOW_COPY_AND_ASSIGN(TopSitesCache); |
151 }; | 166 }; |
152 | 167 |
153 } // namespace history | 168 } // namespace history |
154 | 169 |
155 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_CACHE_H_ | 170 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_CACHE_H_ |
OLD | NEW |