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

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

Issue 4106014: Tweaks to improve memory consumption by TopSites. The biggest culprit (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporate review feedback Created 10 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
« no previous file with comments | « chrome/browser/history/top_sites.cc ('k') | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #pragma once 7 #pragma once
8 8
9 #include <algorithm>
9 #include <map> 10 #include <map>
11 #include <string>
10 12
11 #include "base/ref_counted.h" 13 #include "base/ref_counted.h"
12 #include "chrome/browser/history/history_types.h" 14 #include "chrome/browser/history/history_types.h"
13 15
14 class RefCountedBytes; 16 class RefCountedBytes;
15 17
16 namespace history { 18 namespace history {
17 19
18 // TopSitesCache caches the top sites and thumbnails for TopSites. 20 // TopSitesCache caches the top sites and thumbnails for TopSites.
19 class TopSitesCache { 21 class TopSitesCache {
(...skipping 29 matching lines...) Expand all
49 // Returns true if |url| is known. 51 // Returns true if |url| is known.
50 bool IsKnownURL(const GURL& url); 52 bool IsKnownURL(const GURL& url);
51 53
52 // Returns the index into |top_sites_| for |url|. 54 // Returns the index into |top_sites_| for |url|.
53 size_t GetURLIndex(const GURL& url); 55 size_t GetURLIndex(const GURL& url);
54 56
55 // Removes any thumbnails that are no longer referenced by the top sites. 57 // Removes any thumbnails that are no longer referenced by the top sites.
56 void RemoveUnreferencedThumbnails(); 58 void RemoveUnreferencedThumbnails();
57 59
58 private: 60 private:
61 // The entries in CanonicalURLs, see CanonicalURLs for details. The second
62 // argument gives the index of the URL into MostVisitedURLs redirects.
63 typedef std::pair<MostVisitedURL*, size_t> CanonicalURLEntry;
64
65 // Comparator used for CanonicalURLs.
66 class CanonicalURLComparator {
67 public:
68 bool operator()(const CanonicalURLEntry& e1,
69 const CanonicalURLEntry& e2) const {
70 return e1.first->redirects[e1.second] < e2.first->redirects[e2.second];
71 }
72 };
73
74 // This is used to map from redirect url to the MostVisitedURL the redirect is
75 // from. Ideally this would be map<GURL, size_t> (second param indexing into
76 // top_sites_), but this results in duplicating all redirect urls. As some
77 // sites have a lot of redirects, we instead use the MostVisitedURL* and the
78 // index of the redirect as the key, and the index into top_sites_ as the
79 // value. This way we aren't duplicating GURLs. CanonicalURLComparator
80 // enforces the ordering as if we were using GURLs.
81 typedef std::map<CanonicalURLEntry, size_t,
82 CanonicalURLComparator> CanonicalURLs;
83
59 // Generates the set of canonical urls from |top_sites_|. 84 // Generates the set of canonical urls from |top_sites_|.
60 void GenerateCanonicalURLs(); 85 void GenerateCanonicalURLs();
61 86
62 // Stores a set of redirects. This is used by GenerateCanonicalURLs. 87 // Stores a set of redirects. This is used by GenerateCanonicalURLs.
63 void StoreRedirectChain(const RedirectList& redirects, size_t destination); 88 void StoreRedirectChain(const RedirectList& redirects, size_t destination);
64 89
90 // Returns the iterator into canconical_urls_ for the specified url.
91 CanonicalURLs::iterator GetCanonicalURLsIterator(const GURL& url);
92
65 // The top sites. 93 // The top sites.
66 MostVisitedURLList top_sites_; 94 MostVisitedURLList top_sites_;
67 95
68 // The images. These map from canonical url to image. 96 // The images. These map from canonical url to image.
69 URLToImagesMap images_; 97 URLToImagesMap images_;
70 98
71 // Generated from the redirects to and from the most visited pages, this maps 99 // Generated from the redirects to and from the most visited pages. See
72 // the redirects to the index into top_sites_ that contains it. 100 // description above typedef for details.
73 std::map<GURL, size_t> canonical_urls_; 101 CanonicalURLs canonical_urls_;
74 102
75 DISALLOW_COPY_AND_ASSIGN(TopSitesCache); 103 DISALLOW_COPY_AND_ASSIGN(TopSitesCache);
76 }; 104 };
77 105
78 } // namespace history 106 } // namespace history
79 107
80 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_CACHE_H_ 108 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_CACHE_H_
OLDNEW
« no previous file with comments | « chrome/browser/history/top_sites.cc ('k') | chrome/browser/history/top_sites_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698