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

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

Issue 3477001: Add pyauto hook for getting and manipulating the data underneath the NTP.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 2 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 | « chrome/browser/dom_ui/new_tab_ui.cc ('k') | chrome/browser/history/top_sites.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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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_H_ 5 #ifndef CHROME_BROWSER_HISTORY_TOP_SITES_H_
6 #define CHROME_BROWSER_HISTORY_TOP_SITES_H_ 6 #define CHROME_BROWSER_HISTORY_TOP_SITES_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 30 matching lines...) Expand all
41 // Stores the data for the top "most visited" sites. This includes a cache of 41 // Stores the data for the top "most visited" sites. This includes a cache of
42 // the most visited data from history, as well as the corresponding thumbnails 42 // the most visited data from history, as well as the corresponding thumbnails
43 // of those sites. 43 // of those sites.
44 // 44 //
45 // This class IS threadsafe. It is designed to be used from the UI thread of 45 // This class IS threadsafe. It is designed to be used from the UI thread of
46 // the browser (where history requests must be kicked off and received from) 46 // the browser (where history requests must be kicked off and received from)
47 // and from the I/O thread (where new tab page requests come in). Handling the 47 // and from the I/O thread (where new tab page requests come in). Handling the
48 // new tab page requests on the I/O thread without proxying to the UI thread is 48 // new tab page requests on the I/O thread without proxying to the UI thread is
49 // a nontrivial performance win, especially when the browser is starting and 49 // a nontrivial performance win, especially when the browser is starting and
50 // the UI thread is busy. 50 // the UI thread is busy.
51 class TopSites : 51 class TopSites
52 public base::RefCountedThreadSafe<TopSites, 52 : public base::RefCountedThreadSafe<TopSites,
53 ChromeThread::DeleteOnUIThread>, 53 ChromeThread::DeleteOnUIThread>,
54 public NotificationObserver, 54 public NotificationObserver,
55 public CancelableRequestProvider { 55 public CancelableRequestProvider {
56 public: 56 public:
57 explicit TopSites(Profile* profile); 57 explicit TopSites(Profile* profile);
58 58
59 // Returns whether top sites is enabled. 59 // Returns whether top sites is enabled.
60 static bool IsEnabled(); 60 static bool IsEnabled();
61 61
62 class MockHistoryService { 62 class MockHistoryService {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 130
131 // Return a URL pinned at |index| via |out|. Returns true if there 131 // Return a URL pinned at |index| via |out|. Returns true if there
132 // is a URL pinned at |index|. 132 // is a URL pinned at |index|.
133 bool GetPinnedURLAtIndex(size_t index, GURL* out); 133 bool GetPinnedURLAtIndex(size_t index, GURL* out);
134 134
135 // TopSites must be deleted on a UI thread. This happens 135 // TopSites must be deleted on a UI thread. This happens
136 // automatically in a real browser, but in unit_tests we don't have 136 // automatically in a real browser, but in unit_tests we don't have
137 // a real UI thread. Use this function to delete a TopSites object. 137 // a real UI thread. Use this function to delete a TopSites object.
138 static void DeleteTopSites(scoped_refptr<TopSites>& ptr); 138 static void DeleteTopSites(scoped_refptr<TopSites>& ptr);
139 139
140 // For use only in testing. Refreshes the top sites list and invokes the
141 // callback on the UI thread when done. Should be called on the UI thread.
142 void RefreshAndCallback(CancelableRequestConsumer* consumer,
143 Callback0::Type* callback);
144
140 // Sets the profile pointer to NULL. This is for the case where 145 // Sets the profile pointer to NULL. This is for the case where
141 // TopSites outlives the profile, since TopSites is refcounted. 146 // TopSites outlives the profile, since TopSites is refcounted.
142 void ClearProfile(); 147 void ClearProfile();
143 148
144 private: 149 private:
145 friend struct ChromeThread::DeleteOnThread<ChromeThread::UI>; 150 friend struct ChromeThread::DeleteOnThread<ChromeThread::UI>;
146 friend class DeleteTask<TopSites>; 151 friend class DeleteTask<TopSites>;
147 friend class TopSitesTest; 152 friend class TopSitesTest;
148 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, GetMostVisited); 153 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, GetMostVisited);
149 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, RealDatabase); 154 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, RealDatabase);
150 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, MockDatabase); 155 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, MockDatabase);
151 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, DeleteNotifications); 156 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, DeleteNotifications);
152 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, PinnedURLsDeleted); 157 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, PinnedURLsDeleted);
153 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, GetUpdateDelay); 158 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, GetUpdateDelay);
154 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, Migration); 159 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, Migration);
155 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, QueueingRequestsForTopSites); 160 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, QueueingRequestsForTopSites);
156 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, CancelingRequestsForTopSites); 161 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, CancelingRequestsForTopSites);
157 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, AddTemporaryThumbnail); 162 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, AddTemporaryThumbnail);
158 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, Blacklisting); 163 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, Blacklisting);
159 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, PinnedURLs); 164 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, PinnedURLs);
160 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, BlacklistingAndPinnedURLs); 165 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, BlacklistingAndPinnedURLs);
161 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, AddPrepopulatedPages); 166 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, AddPrepopulatedPages);
162 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, GetPageThumbnail); 167 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, GetPageThumbnail);
168 FRIEND_TEST_ALL_PREFIXES(TopSitesTest, RefreshCallback);
163 169
164 ~TopSites(); 170 ~TopSites();
165 171
166 // Sets the thumbnail without writing to the database. Useful when 172 // Sets the thumbnail without writing to the database. Useful when
167 // reading last known top sites from the DB. 173 // reading last known top sites from the DB.
168 // Returns true if the thumbnail was set, false if the existing one is better. 174 // Returns true if the thumbnail was set, false if the existing one is better.
169 bool SetPageThumbnailNoDB(const GURL& url, 175 bool SetPageThumbnailNoDB(const GURL& url,
170 const RefCountedBytes* thumbnail_data, 176 const RefCountedBytes* thumbnail_data,
171 const ThumbnailScore& score); 177 const ThumbnailScore& score);
172 178
173 // A version of SetPageThumbnail that takes RefCountedBytes as 179 // A version of SetPageThumbnail that takes RefCountedBytes as
174 // returned by HistoryService. 180 // returned by HistoryService.
175 bool SetPageThumbnailEncoded(const GURL& url, 181 bool SetPageThumbnailEncoded(const GURL& url,
176 const RefCountedBytes* thumbnail, 182 const RefCountedBytes* thumbnail,
177 const ThumbnailScore& score); 183 const ThumbnailScore& score);
178 184
179 // Query history service for the list of available thumbnails. 185 // Query history service for the list of available thumbnails. Returns the
180 void StartQueryForMostVisited(); 186 // handle for the request, or NULL if a request could not be made.
187 CancelableRequestProvider::Handle StartQueryForMostVisited();
188
189 // Called by our timer. Starts the query for the most visited sites.
190 void TimerFired();
181 191
182 // Query history service for the thumbnail for a given url. |index| 192 // Query history service for the thumbnail for a given url. |index|
183 // is the index into top_sites_. 193 // is the index into top_sites_.
184 void StartQueryForThumbnail(size_t index); 194 void StartQueryForThumbnail(size_t index);
185 195
186 // Called when history service returns a list of top URLs. 196 // Called when history service returns a list of top URLs.
187 void OnTopSitesAvailable(CancelableRequestProvider::Handle handle, 197 void OnTopSitesAvailable(CancelableRequestProvider::Handle handle,
188 MostVisitedURLList data); 198 MostVisitedURLList data);
189 199
190 // Returns a list of urls to each pending callback. 200 // Returns a list of urls to each pending callback.
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 // blacklisted URLs and reordering pinned URLs. 298 // blacklisted URLs and reordering pinned URLs.
289 void ApplyBlacklistAndPinnedURLs(const MostVisitedURLList& urls, 299 void ApplyBlacklistAndPinnedURLs(const MostVisitedURLList& urls,
290 MostVisitedURLList* out); 300 MostVisitedURLList* out);
291 301
292 // Converts a url into a canonical string representation. 302 // Converts a url into a canonical string representation.
293 std::string GetURLString(const GURL& url); 303 std::string GetURLString(const GURL& url);
294 304
295 // Returns an MD5 hash of the URL. Hashing is required for blacklisted URLs. 305 // Returns an MD5 hash of the URL. Hashing is required for blacklisted URLs.
296 std::string GetURLHash(const GURL& url); 306 std::string GetURLHash(const GURL& url);
297 307
308 // Invokes the callback signaling the cache has been completely refreshed.
309 // This is only used for testing.
310 void InvokeRefreshCallback();
311 void InvokeRefreshCallbackOnUIThread();
312
298 Profile* profile_; 313 Profile* profile_;
299 // A mockup to use for testing. If NULL, use the real HistoryService 314 // A mockup to use for testing. If NULL, use the real HistoryService
300 // from the profile_. See SetMockHistoryService. 315 // from the profile_. See SetMockHistoryService.
301 MockHistoryService* mock_history_service_; 316 MockHistoryService* mock_history_service_;
302 CancelableRequestConsumerTSimple<size_t> cancelable_consumer_; 317 CancelableRequestConsumerTSimple<size_t> cancelable_consumer_;
303 mutable Lock lock_; 318 mutable Lock lock_;
304 319
305 // The cached version of the top sites. The 0th item in this vector is the 320 // The cached version of the top sites. The 0th item in this vector is the
306 // #1 site. 321 // #1 site.
307 MostVisitedURLList top_sites_; 322 MostVisitedURLList top_sites_;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 // key is the URL, value is a dummy value. This is owned by the 370 // key is the URL, value is a dummy value. This is owned by the
356 // PrefService. 371 // PrefService.
357 DictionaryValue* blacklist_; 372 DictionaryValue* blacklist_;
358 373
359 // This is a dictionary for the pinned URLs for the the most visited 374 // This is a dictionary for the pinned URLs for the the most visited
360 // part of the new tab page. Key is the URL, value is 375 // part of the new tab page. Key is the URL, value is
361 // index where it is pinned at (may be the same as key). This is 376 // index where it is pinned at (may be the same as key). This is
362 // owned by the PrefService. 377 // owned by the PrefService.
363 DictionaryValue* pinned_urls_; 378 DictionaryValue* pinned_urls_;
364 379
380 // For testing use only. The callback to invoke after a refresh has occurred.
381 // Should be accessed on the UI thread.
382 scoped_refptr<CancelableRequest<Callback0::Type> > refresh_callback_;
383
384 // For testing use only. The history request handle that is being waited upon.
385 // Should be accessed on the UI thread.
386 CancelableRequestProvider::Handle handle_to_wait_for_;
387
365 DISALLOW_COPY_AND_ASSIGN(TopSites); 388 DISALLOW_COPY_AND_ASSIGN(TopSites);
366 }; 389 };
367 390
368 } // namespace history 391 } // namespace history
369 392
370 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_H_ 393 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_H_
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/new_tab_ui.cc ('k') | chrome/browser/history/top_sites.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698