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

Side by Side Diff: chrome/browser/history/top_sites_impl.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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_IMPL_H_ 5 #ifndef CHROME_BROWSER_HISTORY_TOP_SITES_IMPL_H_
6 #define CHROME_BROWSER_HISTORY_TOP_SITES_IMPL_H_ 6 #define CHROME_BROWSER_HISTORY_TOP_SITES_IMPL_H_
7 7
8 #include <list> 8 #include <list>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 // to internal state happen on the UI thread and are scheduled to update the 48 // to internal state happen on the UI thread and are scheduled to update the
49 // db using TopSitesBackend. 49 // db using TopSitesBackend.
50 class TopSitesImpl : public TopSites { 50 class TopSitesImpl : public TopSites {
51 public: 51 public:
52 explicit TopSitesImpl(Profile* profile); 52 explicit TopSitesImpl(Profile* profile);
53 53
54 // Initializes TopSitesImpl. 54 // Initializes TopSitesImpl.
55 void Init(const base::FilePath& db_name); 55 void Init(const base::FilePath& db_name);
56 56
57 virtual bool SetPageThumbnail(const GURL& url, 57 virtual bool SetPageThumbnail(const GURL& url,
58 const gfx::Image& thumbnail, 58 const gfx::Image& thumbnail,
59 const ThumbnailScore& score) OVERRIDE; 59 const ThumbnailScore& score) OVERRIDE;
60 virtual bool SetPageThumbnailToJPEGBytes( 60 virtual bool SetPageThumbnailToJPEGBytes(
61 const GURL& url, 61 const GURL& url,
62 const base::RefCountedMemory* memory, 62 const base::RefCountedMemory* memory,
63 const ThumbnailScore& score) OVERRIDE; 63 const ThumbnailScore& score) OVERRIDE;
64 virtual void GetMostVisitedURLs( 64 virtual void GetMostVisitedURLs(
65 const GetMostVisitedURLsCallback& callback) OVERRIDE; 65 const GetMostVisitedURLsCallback& callback) OVERRIDE;
66 virtual void GetAllMostVisitedURLs(
67 const GetMostVisitedURLsCallback& callback,
68 bool include_forced_urls) OVERRIDE;
66 virtual bool GetPageThumbnail( 69 virtual bool GetPageThumbnail(
67 const GURL& url, 70 const GURL& url,
68 bool prefix_match, 71 bool prefix_match,
69 scoped_refptr<base::RefCountedMemory>* bytes) OVERRIDE; 72 scoped_refptr<base::RefCountedMemory>* bytes) OVERRIDE;
70 virtual bool GetPageThumbnailScore(const GURL& url, 73 virtual bool GetPageThumbnailScore(const GURL& url,
71 ThumbnailScore* score) OVERRIDE; 74 ThumbnailScore* score) OVERRIDE;
72 virtual bool GetTemporaryPageThumbnailScore(const GURL& url, 75 virtual bool GetTemporaryPageThumbnailScore(const GURL& url,
73 ThumbnailScore* score) OVERRIDE; 76 ThumbnailScore* score) OVERRIDE;
74 virtual void SyncWithHistory() OVERRIDE; 77 virtual void SyncWithHistory() OVERRIDE;
75 virtual bool HasBlacklistedItems() const OVERRIDE; 78 virtual bool HasBlacklistedItems() const OVERRIDE;
76 virtual void AddBlacklistedURL(const GURL& url) OVERRIDE; 79 virtual void AddBlacklistedURL(const GURL& url) OVERRIDE;
77 virtual void RemoveBlacklistedURL(const GURL& url) OVERRIDE; 80 virtual void RemoveBlacklistedURL(const GURL& url) OVERRIDE;
78 virtual bool IsBlacklisted(const GURL& url) OVERRIDE; 81 virtual bool IsBlacklisted(const GURL& url) OVERRIDE;
79 virtual void ClearBlacklistedURLs() OVERRIDE; 82 virtual void ClearBlacklistedURLs() OVERRIDE;
80 virtual void Shutdown() OVERRIDE; 83 virtual void Shutdown() OVERRIDE;
81 virtual CancelableRequestProvider::Handle StartQueryForMostVisited() OVERRIDE; 84 virtual CancelableRequestProvider::Handle StartQueryForMostVisited() OVERRIDE;
82 virtual bool IsKnownURL(const GURL& url) OVERRIDE; 85 virtual bool IsKnownURL(const GURL& url) OVERRIDE;
83 virtual const std::string& GetCanonicalURLString( 86 virtual const std::string& GetCanonicalURLString(
84 const GURL& url) const OVERRIDE; 87 const GURL& url) const OVERRIDE;
85 virtual bool IsFull() OVERRIDE; 88 virtual bool IsNonForcedFull() OVERRIDE;
89 virtual bool IsForcedFull() OVERRIDE;
86 virtual MostVisitedURLList GetPrepopulatePages() OVERRIDE; 90 virtual MostVisitedURLList GetPrepopulatePages() OVERRIDE;
87 virtual bool loaded() const OVERRIDE; 91 virtual bool loaded() const OVERRIDE;
88 92
89 protected: 93 protected:
90 virtual ~TopSitesImpl(); 94 virtual ~TopSitesImpl();
91 95
92 private: 96 private:
93 friend class TopSitesImplTest; 97 friend class TopSitesImplTest;
94 FRIEND_TEST_ALL_PREFIXES(TopSitesImplTest, DiffMostVisited); 98 FRIEND_TEST_ALL_PREFIXES(TopSitesImplTest, DiffMostVisited);
99 FRIEND_TEST_ALL_PREFIXES(TopSitesImplTest, DiffMostVisitedWithForced);
100
101 typedef base::Callback<void(const MostVisitedURLList&,
102 const MostVisitedURLList&)> PendingCallback;
95 103
96 typedef std::pair<GURL, Images> TempImage; 104 typedef std::pair<GURL, Images> TempImage;
97 typedef std::list<TempImage> TempImages; 105 typedef std::list<TempImage> TempImages;
106 typedef std::vector<PendingCallback> PendingCallbacks;
98 107
99 // Generates the diff of things that happened between "old" and "new." 108 // Generates the diff of things that happened between "old" and "new."
100 // 109 //
110 // This treats forced URLs separately than non-forced URLs.
111 //
101 // The URLs that are in "new" but not "old" will be have their index into 112 // The URLs that are in "new" but not "old" will be have their index into
102 // "new" put in |added_urls|. The URLs that are in "old" but not "new" will 113 // "new" put in |added_urls|. The non-forced URLs that are in "old" but not
103 // have their index into "old" put into |deleted_urls|. 114 // "new" will have their index into "old" put into |deleted_urls|.
104 // 115 //
105 // URLs appearing in both old and new lists but having different indices will 116 // URLs appearing in both old and new lists but having different indices will
106 // have their index into "new" be put into |moved_urls|. 117 // have their index into "new" be put into |moved_urls|.
107 static void DiffMostVisited(const MostVisitedURLList& old_list, 118 static void DiffMostVisited(const MostVisitedURLList& old_list,
108 const MostVisitedURLList& new_list, 119 const MostVisitedURLList& new_list,
109 TopSitesDelta* delta); 120 TopSitesDelta* delta);
110 121
111 // Sets the thumbnail without writing to the database. Useful when 122 // Sets the thumbnail without writing to the database. Useful when
112 // reading last known top sites from the DB. 123 // reading last known top sites from the DB.
113 // Returns true if the thumbnail was set, false if the existing one is better. 124 // Returns true if the thumbnail was set, false if the existing one is better.
(...skipping 25 matching lines...) Expand all
139 void TimerFired(); 150 void TimerFired();
140 151
141 // Finds the given URL in the redirect chain for the given TopSite, and 152 // Finds the given URL in the redirect chain for the given TopSite, and
142 // returns the distance from the destination in hops that the given URL is. 153 // returns the distance from the destination in hops that the given URL is.
143 // The URL is assumed to be in the list. The destination is 0. 154 // The URL is assumed to be in the list. The destination is 0.
144 static int GetRedirectDistanceForURL(const MostVisitedURL& most_visited, 155 static int GetRedirectDistanceForURL(const MostVisitedURL& most_visited,
145 const GURL& url); 156 const GURL& url);
146 157
147 // Add prepopulated pages: 'welcome to Chrome' and themes gallery to |urls|. 158 // Add prepopulated pages: 'welcome to Chrome' and themes gallery to |urls|.
148 // Returns true if any pages were added. 159 // Returns true if any pages were added.
149 bool AddPrepopulatedPages(MostVisitedURLList* urls); 160 bool AddPrepopulatedPages(MostVisitedURLList* urls,
161 size_t nb_forced_urls);
162
163 // Add all the forced URLs from |cache_| into |new_list|, making sure not to
164 // add any URL that's already in |new_list|'s non-forced URLs. The forced URLs
165 // in |cache_| and |new_list| are assumed to appear at the front of the list
166 // and be sorted in increasing |last_forced_time|. This will still be true
167 // after the call. If the list of forced URLs overflows the older ones are
168 // dropped. Returns the number of forced URLs after the merge.
169 size_t MergeCachedForcedURLs(MostVisitedURLList* new_list);
150 170
151 // Takes |urls|, produces it's copy in |out| after removing blacklisted URLs. 171 // Takes |urls|, produces it's copy in |out| after removing blacklisted URLs.
172 // Also ensures we respect the maximum number of forced URLs and non-forced
173 // URLs.
152 void ApplyBlacklist(const MostVisitedURLList& urls, MostVisitedURLList* out); 174 void ApplyBlacklist(const MostVisitedURLList& urls, MostVisitedURLList* out);
153 175
154 // Returns an MD5 hash of the URL. Hashing is required for blacklisted URLs. 176 // Returns an MD5 hash of the URL. Hashing is required for blacklisted URLs.
155 std::string GetURLHash(const GURL& url); 177 std::string GetURLHash(const GURL& url);
156 178
157 // Returns the delay until the next update of history is needed. 179 // Returns the delay until the next update of history is needed.
158 // Uses num_urls_changed 180 // Uses num_urls_changed
159 base::TimeDelta GetUpdateDelay(); 181 base::TimeDelta GetUpdateDelay();
160 182
161 // Implementation of content::NotificationObserver. 183 // Implementation of content::NotificationObserver.
162 virtual void Observe(int type, 184 virtual void Observe(int type,
163 const content::NotificationSource& source, 185 const content::NotificationSource& source,
164 const content::NotificationDetails& details) OVERRIDE; 186 const content::NotificationDetails& details) OVERRIDE;
165 187
166 // Resets top_sites_ and updates the db (in the background). All mutations to 188 // Updates URLs in |cache_| and the db (in the background).
167 // top_sites_ *must* go through this. Should be called from the UI thread. 189 // The non-forced URLs in |new_top_sites| replace those in |cache_|.
190 // The forced URLs of |new_top_sites| are merged with those in |cache_|,
191 // if the list of forced URLs overflows, the oldest ones are dropped.
192 // All mutations to cache_ *must* go through this. Should
193 // be called from the UI thread.
168 void SetTopSites(const MostVisitedURLList& new_top_sites); 194 void SetTopSites(const MostVisitedURLList& new_top_sites);
169 195
170 // Returns the number of most visted results to request from history. This 196 // Returns the number of most visited results to request from history. This
171 // changes depending upon how many urls have been blacklisted. Should be 197 // changes depending upon how many urls have been blacklisted. Should be
172 // called from the UI thread. 198 // called from the UI thread.
173 int num_results_to_request_from_history() const; 199 int num_results_to_request_from_history() const;
174 200
175 // Invoked when transitioning to LOADED. Notifies any queued up callbacks. 201 // Invoked when transitioning to LOADED. Notifies any queued up callbacks.
176 // Should be called from the UI thread. 202 // Should be called from the UI thread.
177 void MoveStateToLoaded(); 203 void MoveStateToLoaded();
178 204
179 void ResetThreadSafeCache(); 205 void ResetThreadSafeCache();
180 206
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 size_t last_num_urls_changed_; 253 size_t last_num_urls_changed_;
228 254
229 // The pending requests for the top sites list. Can only be non-empty at 255 // The pending requests for the top sites list. Can only be non-empty at
230 // startup. After we read the top sites from the DB, we'll always have a 256 // startup. After we read the top sites from the DB, we'll always have a
231 // cached list and be able to run callbacks immediately. 257 // cached list and be able to run callbacks immediately.
232 PendingCallbacks pending_callbacks_; 258 PendingCallbacks pending_callbacks_;
233 259
234 // Stores thumbnails for unknown pages. When SetPageThumbnail is 260 // Stores thumbnails for unknown pages. When SetPageThumbnail is
235 // called, if we don't know about that URL yet and we don't have 261 // called, if we don't know about that URL yet and we don't have
236 // enough Top Sites (new profile), we store it until the next 262 // enough Top Sites (new profile), we store it until the next
237 // SetTopSites call. 263 // SetNonForcedTopSites call.
238 TempImages temp_images_; 264 TempImages temp_images_;
239 265
240 // URL List of prepopulated page. 266 // URL List of prepopulated page.
241 std::vector<GURL> prepopulated_page_urls_; 267 std::vector<GURL> prepopulated_page_urls_;
242 268
243 // Are we loaded? 269 // Are we loaded?
244 bool loaded_; 270 bool loaded_;
245 271
246 DISALLOW_COPY_AND_ASSIGN(TopSitesImpl); 272 DISALLOW_COPY_AND_ASSIGN(TopSitesImpl);
247 }; 273 };
248 274
249 } // namespace history 275 } // namespace history
250 276
251 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_IMPL_H_ 277 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698