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

Side by Side Diff: chrome/browser/history/top_sites_cache.h

Issue 53283004: Adding support for forced URLs to TopSites. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Corrected minor spacing problem. Created 7 years, 1 month 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 #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 27 matching lines...) Expand all
38 // ignoring "?query#ref". 38 // ignoring "?query#ref".
39 // For the latter two "URL prefix matches", we prefer the match that is closest 39 // For the latter two "URL prefix matches", we prefer the match that is closest
40 // to input URL, w.r.t. path hierarchy. 40 // to input URL, w.r.t. path hierarchy.
41 41
42 // TopSitesCache caches the top sites and thumbnails for TopSites. 42 // TopSitesCache caches the top sites and thumbnails for TopSites.
43 class TopSitesCache { 43 class TopSitesCache {
44 public: 44 public:
45 TopSitesCache(); 45 TopSitesCache();
46 ~TopSitesCache(); 46 ~TopSitesCache();
47 47
48 // The top sites. 48 // Set the top sites. In |top_sites| all forced URLs must appear before
49 // non-forced URLs. This is only checked in debug.
49 void SetTopSites(const MostVisitedURLList& top_sites); 50 void SetTopSites(const MostVisitedURLList& top_sites);
50 const MostVisitedURLList& top_sites() const { return top_sites_; } 51 const MostVisitedURLList& top_sites() const { return top_sites_; }
51 52
52 // The thumbnails. 53 // The thumbnails.
53 void SetThumbnails(const URLToImagesMap& images); 54 void SetThumbnails(const URLToImagesMap& images);
54 const URLToImagesMap& images() const { return images_; } 55 const URLToImagesMap& images() const { return images_; }
55 56
56 // Returns the thumbnail as an Image for the specified url. This adds an entry 57 // Returns the thumbnail as an Image for the specified url. This adds an entry
57 // for |url| if one has not yet been added. 58 // for |url| if one has not yet been added.
58 Images* GetImage(const GURL& url); 59 Images* GetImage(const GURL& url);
(...skipping 20 matching lines...) Expand all
79 // Similar to GetSpecializedCanonicalURL(), but searches for a URL in 80 // Similar to GetSpecializedCanonicalURL(), but searches for a URL in
80 // |canonical_urls_| that is a URL prefix of |url|, and leaset generalized. 81 // |canonical_urls_| that is a URL prefix of |url|, and leaset generalized.
81 GURL GetGeneralizedCanonicalURL(const GURL& url) const; 82 GURL GetGeneralizedCanonicalURL(const GURL& url) const;
82 83
83 // Returns true if |url| is known. 84 // Returns true if |url| is known.
84 bool IsKnownURL(const GURL& url) const; 85 bool IsKnownURL(const GURL& url) const;
85 86
86 // Returns the index into |top_sites_| for |url|. 87 // Returns the index into |top_sites_| for |url|.
87 size_t GetURLIndex(const GURL& url) const; 88 size_t GetURLIndex(const GURL& url) const;
88 89
90 // Returns the number of non-forced URLs in the cache.
91 size_t GetNbNonForcedURLs() const;
brettw 2013/11/08 22:56:07 "Nb"?
beaudoin 2013/11/11 21:58:09 Done.
92
93 // Returns the number of forced URLs in the cache.
94 size_t GetNbForcedURLs() const;
95
89 private: 96 private:
90 // The entries in CanonicalURLs, see CanonicalURLs for details. The second 97 // The entries in CanonicalURLs, see CanonicalURLs for details. The second
91 // argument gives the index of the URL into MostVisitedURLs redirects. 98 // argument gives the index of the URL into MostVisitedURLs redirects.
92 typedef std::pair<MostVisitedURL*, size_t> CanonicalURLEntry; 99 typedef std::pair<MostVisitedURL*, size_t> CanonicalURLEntry;
93 100
94 // Comparator used for CanonicalURLs. 101 // Comparator used for CanonicalURLs.
95 class CanonicalURLComparator { 102 class CanonicalURLComparator {
96 public: 103 public:
97 bool operator()(const CanonicalURLEntry& e1, 104 bool operator()(const CanonicalURLEntry& e1,
98 const CanonicalURLEntry& e2) const { 105 const CanonicalURLEntry& e2) const {
(...skipping 18 matching lines...) Expand all
117 // This is used to map from redirect url to the MostVisitedURL the redirect is 124 // This is used to map from redirect url to the MostVisitedURL the redirect is
118 // from. Ideally this would be map<GURL, size_t> (second param indexing into 125 // from. Ideally this would be map<GURL, size_t> (second param indexing into
119 // top_sites_), but this results in duplicating all redirect urls. As some 126 // top_sites_), but this results in duplicating all redirect urls. As some
120 // sites have a lot of redirects, we instead use the MostVisitedURL* and the 127 // sites have a lot of redirects, we instead use the MostVisitedURL* and the
121 // index of the redirect as the key, and the index into top_sites_ as the 128 // index of the redirect as the key, and the index into top_sites_ as the
122 // value. This way we aren't duplicating GURLs. CanonicalURLComparator 129 // value. This way we aren't duplicating GURLs. CanonicalURLComparator
123 // enforces the ordering as if we were using GURLs. 130 // enforces the ordering as if we were using GURLs.
124 typedef std::map<CanonicalURLEntry, size_t, 131 typedef std::map<CanonicalURLEntry, size_t,
125 CanonicalURLComparator> CanonicalURLs; 132 CanonicalURLComparator> CanonicalURLs;
126 133
134 // Count the number of forced URLs.
135 void CountForcedURLs();
136
127 // Generates the set of canonical urls from |top_sites_|. 137 // Generates the set of canonical urls from |top_sites_|.
128 void GenerateCanonicalURLs(); 138 void GenerateCanonicalURLs();
129 139
130 // Stores a set of redirects. This is used by GenerateCanonicalURLs. 140 // Stores a set of redirects. This is used by GenerateCanonicalURLs.
131 void StoreRedirectChain(const RedirectList& redirects, size_t destination); 141 void StoreRedirectChain(const RedirectList& redirects, size_t destination);
132 142
133 // Returns the iterator into |canonical_urls_| for the |url|. 143 // Returns the iterator into |canonical_urls_| for the |url|.
134 CanonicalURLs::const_iterator GetCanonicalURLsIterator(const GURL& url) const; 144 CanonicalURLs::const_iterator GetCanonicalURLsIterator(const GURL& url) const;
135 145
136 // Returns the GURL corresponding to an iterator in |canonical_urls_|. 146 // Returns the GURL corresponding to an iterator in |canonical_urls_|.
137 const GURL& GetURLFromIterator(CanonicalURLs::const_iterator it) const; 147 const GURL& GetURLFromIterator(CanonicalURLs::const_iterator it) const;
138 148
139 // The top sites. 149 // The number of top sites with forced URLs.
150 size_t nb_forced_urls_;
151
152 // The top sites. This list must always contain the forced URLs first followed
153 // by the non-forced URLs. This is not strictly enforced but is checked in
154 // debug.
140 MostVisitedURLList top_sites_; 155 MostVisitedURLList top_sites_;
141 156
142 // The images. These map from canonical url to image. 157 // The images. These map from canonical url to image.
143 URLToImagesMap images_; 158 URLToImagesMap images_;
144 159
145 // Generated from the redirects to and from the most visited pages. See 160 // Generated from the redirects to and from the most visited pages. See
146 // description above typedef for details. 161 // description above typedef for details.
147 CanonicalURLs canonical_urls_; 162 CanonicalURLs canonical_urls_;
148 163
149 // Helper to clear "?query#ref" from any GURL. This is set in the constructor 164 // Helper to clear "?query#ref" from any GURL. This is set in the constructor
150 // and never modified after. 165 // and never modified after.
151 GURL::Replacements clear_query_ref_; 166 GURL::Replacements clear_query_ref_;
152 167
153 // Helper to clear "/path?query#ref" from any GURL. This is set in the 168 // Helper to clear "/path?query#ref" from any GURL. This is set in the
154 // constructor and never modified after. 169 // constructor and never modified after.
155 GURL::Replacements clear_path_query_ref_; 170 GURL::Replacements clear_path_query_ref_;
156 171
157 DISALLOW_COPY_AND_ASSIGN(TopSitesCache); 172 DISALLOW_COPY_AND_ASSIGN(TopSitesCache);
158 }; 173 };
159 174
160 } // namespace history 175 } // namespace history
161 176
162 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_CACHE_H_ 177 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_CACHE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698