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

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

Issue 23477033: Implementing URL prefix match for history thumbnail cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
« no previous file with comments | « no previous file | chrome/browser/history/top_sites_cache.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <string>
9 #include <utility> 10 #include <utility>
10 11
11 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
12 #include "chrome/browser/history/history_types.h" 13 #include "chrome/browser/history/history_types.h"
13 14
14 namespace history { 15 namespace history {
15 16
17 // The entries in CanonicalURLs, see CanonicalURLs for details. The second
18 // argument gives the index of the URL into MostVisitedURLs redirects.
19 typedef std::pair<MostVisitedURL*, size_t> CanonicalURLEntry;
20
21 // Defines the "path-prefix" compare of two URLs
22 // Comparator used for CanonicalURLs.
23 class CanonicalURLComparator {
24 public:
25 bool operator()(const CanonicalURLEntry& e1,
26 const CanonicalURLEntry& e2) const;
27 static bool CompareString(const std::string& s1,
28 const std::string& s2);
29 };
30
16 // TopSitesCache caches the top sites and thumbnails for TopSites. 31 // TopSitesCache caches the top sites and thumbnails for TopSites.
17 class TopSitesCache { 32 class TopSitesCache {
18 public: 33 public:
19 TopSitesCache(); 34 TopSitesCache();
20 ~TopSitesCache(); 35 ~TopSitesCache();
21 36
22 // The top sites. 37 // The top sites.
23 void SetTopSites(const MostVisitedURLList& top_sites); 38 void SetTopSites(const MostVisitedURLList& top_sites);
24 const MostVisitedURLList& top_sites() const { return top_sites_; } 39 const MostVisitedURLList& top_sites() const { return top_sites_; }
25 40
26 // The thumbnails. 41 // The thumbnails.
27 void SetThumbnails(const URLToImagesMap& images); 42 void SetThumbnails(const URLToImagesMap& images);
28 const URLToImagesMap& images() const { return images_; } 43 const URLToImagesMap& images() const { return images_; }
29 44
30 // Returns the thumbnail as an Image for the specified url. This adds an entry 45 // Returns the thumbnail as an Image for the specified url. This adds an entry
31 // for |url| if one has not yet been added. 46 // for |url| if one has not yet been added.
32 Images* GetImage(const GURL& url); 47 Images* GetImage(const GURL& url);
33 48
34 // Fetches the thumbnail for the specified url. Returns true if there is a 49 // Fetches the thumbnail for the specified url. Returns true if there is a
35 // thumbnail for the specified url. It is possible for a URL to be in TopSites 50 // thumbnail for the specified url. It is possible for a URL to be in TopSites
36 // but not have an thumbnail. 51 // but not have an thumbnail.
37 bool GetPageThumbnail(const GURL& url, 52 bool GetPageThumbnail(const GURL& url,
38 scoped_refptr<base::RefCountedMemory>* bytes); 53 scoped_refptr<base::RefCountedMemory>* bytes);
39 54
55 // Similar to GetPageThumbnail(), but rather than requiring URL exact match,
beaudoin 2013/09/03 23:22:39 URL exact match --> an exact match
huangs 2013/09/04 02:02:05 Done.
56 // only requires the specified URL to be the prefix of a URL in TopSites.
57 // If multiple matches exist, considers the lexicographically earliest one.
beaudoin 2013/09/03 23:22:39 considers [...] --> returns the thumbnail for the
huangs 2013/09/04 02:02:05 Done.
58 bool GetPageThumbnailForPrefix(const GURL& prefix_url,
59 scoped_refptr<base::RefCountedMemory>* bytes);
60
40 // Fetches the thumbnail score for the specified url. Returns true if 61 // Fetches the thumbnail score for the specified url. Returns true if
41 // there is a thumbnail score for the specified url. 62 // there is a thumbnail score for the specified url.
42 bool GetPageThumbnailScore(const GURL& url, ThumbnailScore* score); 63 bool GetPageThumbnailScore(const GURL& url, ThumbnailScore* score);
43 64
44 // Returns the canonical URL for |url|. 65 // Returns the canonical URL for |url|.
45 const GURL& GetCanonicalURL(const GURL& url); 66 const GURL& GetCanonicalURL(const GURL& url);
46 67
68 // Returns the canonical URL for |url_prefix|, which specifies a prefix for
69 // stored URLs in |canonical_urls_|.
beaudoin 2013/09/03 23:22:39 I think the comment about favoring the first URL i
huangs 2013/09/04 02:02:05 Also performs canonicalization. Updated comments.
70 const GURL& GetCanonicalURLForPrefix(const GURL& url_prefix);
71
47 // Returns true if |url| is known. 72 // Returns true if |url| is known.
48 bool IsKnownURL(const GURL& url); 73 bool IsKnownURL(const GURL& url);
49 74
50 // Returns the index into |top_sites_| for |url|. 75 // Returns the index into |top_sites_| for |url|.
51 size_t GetURLIndex(const GURL& url); 76 size_t GetURLIndex(const GURL& url);
52 77
78 // Returns whether or not |url1| is a prefix of |url2|. Criteria:
79 // - Scheme, host, port: exact match required.
80 // - Path: considered as a list of path components (e.g., ["a", "bb"] in
81 // "/a/bb"), and |url1|'s list must be a prefix of |url2|'s list.
82 // - Query: ignored.
83 // Note that "http://www.google.com/test" is NOT a prefix of
84 // "http://www.google.com/testing", even though "test" is prefix of "testing".
beaudoin 2013/09/03 23:22:39 Nit: a prefix
huangs 2013/09/04 02:02:05 Done.
85 // Also, "http://www.google.com" will not match "http://www.google.com:80".
86 static bool UrlIsPrefix(const GURL& url1, const GURL& url2);
87
53 private: 88 private:
54 // The entries in CanonicalURLs, see CanonicalURLs for details. The second
55 // argument gives the index of the URL into MostVisitedURLs redirects.
56 typedef std::pair<MostVisitedURL*, size_t> CanonicalURLEntry;
57
58 // Comparator used for CanonicalURLs.
59 class CanonicalURLComparator {
60 public:
61 bool operator()(const CanonicalURLEntry& e1,
62 const CanonicalURLEntry& e2) const {
63 return e1.first->redirects[e1.second] < e2.first->redirects[e2.second];
64 }
65 };
66
67 // This is used to map from redirect url to the MostVisitedURL the redirect is 89 // This is used to map from redirect url to the MostVisitedURL the redirect is
68 // from. Ideally this would be map<GURL, size_t> (second param indexing into 90 // from. Ideally this would be map<GURL, size_t> (second param indexing into
69 // top_sites_), but this results in duplicating all redirect urls. As some 91 // top_sites_), but this results in duplicating all redirect urls. As some
70 // sites have a lot of redirects, we instead use the MostVisitedURL* and the 92 // sites have a lot of redirects, we instead use the MostVisitedURL* and the
71 // index of the redirect as the key, and the index into top_sites_ as the 93 // index of the redirect as the key, and the index into top_sites_ as the
72 // value. This way we aren't duplicating GURLs. CanonicalURLComparator 94 // value. This way we aren't duplicating GURLs. CanonicalURLComparator
73 // enforces the ordering as if we were using GURLs. 95 // enforces the ordering as if we were using GURLs.
74 typedef std::map<CanonicalURLEntry, size_t, 96 typedef std::map<CanonicalURLEntry, size_t,
75 CanonicalURLComparator> CanonicalURLs; 97 CanonicalURLComparator> CanonicalURLs;
76 98
77 // Generates the set of canonical urls from |top_sites_|. 99 // Generates the set of canonical urls from |top_sites_|.
78 void GenerateCanonicalURLs(); 100 void GenerateCanonicalURLs();
79 101
80 // Stores a set of redirects. This is used by GenerateCanonicalURLs. 102 // Stores a set of redirects. This is used by GenerateCanonicalURLs.
81 void StoreRedirectChain(const RedirectList& redirects, size_t destination); 103 void StoreRedirectChain(const RedirectList& redirects, size_t destination);
82 104
83 // Returns the iterator into canconical_urls_ for the specified url. 105 // Returns the iterator into canonical_urls_ for the |url|. If |match_prefix|
84 CanonicalURLs::iterator GetCanonicalURLsIterator(const GURL& url); 106 // is true, then returns the first iterator into canonical_urls_ that has
107 // |urL| as a path-prefix.
beaudoin 2013/09/03 23:22:39 Nit: |url|
huangs 2013/09/04 02:02:05 Done.
108 CanonicalURLs::iterator GetCanonicalURLsIterator(const GURL& url,
109 bool match_prefix);
85 110
86 // The top sites. 111 // The top sites.
87 MostVisitedURLList top_sites_; 112 MostVisitedURLList top_sites_;
88 113
89 // The images. These map from canonical url to image. 114 // The images. These map from canonical url to image.
90 URLToImagesMap images_; 115 URLToImagesMap images_;
91 116
92 // Generated from the redirects to and from the most visited pages. See 117 // Generated from the redirects to and from the most visited pages. See
93 // description above typedef for details. 118 // description above typedef for details.
94 CanonicalURLs canonical_urls_; 119 CanonicalURLs canonical_urls_;
95 120
96 DISALLOW_COPY_AND_ASSIGN(TopSitesCache); 121 DISALLOW_COPY_AND_ASSIGN(TopSitesCache);
97 }; 122 };
98 123
99 } // namespace history 124 } // namespace history
100 125
101 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_CACHE_H_ 126 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_CACHE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/history/top_sites_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698