| OLD | NEW |
| 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_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 <list> | 9 #include <list> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 15 #include "base/lock.h" | 15 #include "base/lock.h" |
| 16 #include "base/ref_counted.h" |
| 17 #include "base/ref_counted_memory.h" |
| 16 #include "base/time.h" | 18 #include "base/time.h" |
| 17 #include "base/timer.h" | 19 #include "base/timer.h" |
| 18 #include "base/ref_counted.h" | |
| 19 #include "base/ref_counted_memory.h" | |
| 20 #include "chrome/browser/browser_thread.h" | 20 #include "chrome/browser/browser_thread.h" |
| 21 #include "chrome/browser/cancelable_request.h" | 21 #include "chrome/browser/cancelable_request.h" |
| 22 #include "chrome/browser/history/history_types.h" | 22 #include "chrome/browser/history/history_types.h" |
| 23 #include "chrome/browser/history/history.h" | 23 #include "chrome/browser/history/history.h" |
| 24 #include "chrome/browser/history/page_usage_data.h" | 24 #include "chrome/browser/history/page_usage_data.h" |
| 25 #include "chrome/common/notification_service.h" | 25 #include "chrome/common/notification_service.h" |
| 26 #include "chrome/common/thumbnail_score.h" | 26 #include "chrome/common/thumbnail_score.h" |
| 27 #include "googleurl/src/gurl.h" | 27 #include "googleurl/src/gurl.h" |
| 28 | 28 |
| 29 class DictionaryValue; | 29 class DictionaryValue; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 // The URLs that are in "new" but not "old" will be have their index into | 134 // The URLs that are in "new" but not "old" will be have their index into |
| 135 // "new" put in |added_urls|. The URLs that are in "old" but not "new" will | 135 // "new" put in |added_urls|. The URLs that are in "old" but not "new" will |
| 136 // have their index into "old" put into |deleted_urls|. | 136 // have their index into "old" put into |deleted_urls|. |
| 137 // | 137 // |
| 138 // URLs appearing in both old and new lists but having different indices will | 138 // URLs appearing in both old and new lists but having different indices will |
| 139 // have their index into "new" be put into |moved_urls|. | 139 // have their index into "new" be put into |moved_urls|. |
| 140 static void DiffMostVisited(const MostVisitedURLList& old_list, | 140 static void DiffMostVisited(const MostVisitedURLList& old_list, |
| 141 const MostVisitedURLList& new_list, | 141 const MostVisitedURLList& new_list, |
| 142 TopSitesDelta* delta); | 142 TopSitesDelta* delta); |
| 143 | 143 |
| 144 // Query history service for the list of available thumbnails. Returns the |
| 145 // handle for the request, or NULL if a request could not be made. |
| 146 // Public only for testing purposes. |
| 147 CancelableRequestProvider::Handle StartQueryForMostVisited(); |
| 148 |
| 144 private: | 149 private: |
| 145 friend class base::RefCountedThreadSafe<TopSites>; | 150 friend class base::RefCountedThreadSafe<TopSites>; |
| 146 friend class TopSitesTest; | 151 friend class TopSitesTest; |
| 147 | 152 |
| 148 typedef std::pair<GURL, Images> TempImage; | 153 typedef std::pair<GURL, Images> TempImage; |
| 149 typedef std::list<TempImage> TempImages; | 154 typedef std::list<TempImage> TempImages; |
| 150 | 155 |
| 151 // Enumeration of the possible states history can be in. | 156 // Enumeration of the possible states history can be in. |
| 152 enum HistoryLoadState { | 157 enum HistoryLoadState { |
| 153 // We're waiting for history to finish loading. | 158 // We're waiting for history to finish loading. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 | 201 |
| 197 // Removes the cached thumbnail for url. Does nothing if |url| if not cached | 202 // Removes the cached thumbnail for url. Does nothing if |url| if not cached |
| 198 // in |temp_images_|. | 203 // in |temp_images_|. |
| 199 void RemoveTemporaryThumbnailByURL(const GURL& url); | 204 void RemoveTemporaryThumbnailByURL(const GURL& url); |
| 200 | 205 |
| 201 // Add a thumbnail for an unknown url. See temp_thumbnails_map_. | 206 // Add a thumbnail for an unknown url. See temp_thumbnails_map_. |
| 202 void AddTemporaryThumbnail(const GURL& url, | 207 void AddTemporaryThumbnail(const GURL& url, |
| 203 const RefCountedBytes* thumbnail, | 208 const RefCountedBytes* thumbnail, |
| 204 const ThumbnailScore& score); | 209 const ThumbnailScore& score); |
| 205 | 210 |
| 206 // Query history service for the list of available thumbnails. | 211 // Called by our timer. Starts the query for the most visited sites. |
| 207 void StartQueryForMostVisited(); | 212 void TimerFired(); |
| 208 | 213 |
| 209 // Finds the given URL in the redirect chain for the given TopSite, and | 214 // Finds the given URL in the redirect chain for the given TopSite, and |
| 210 // returns the distance from the destination in hops that the given URL is. | 215 // returns the distance from the destination in hops that the given URL is. |
| 211 // The URL is assumed to be in the list. The destination is 0. | 216 // The URL is assumed to be in the list. The destination is 0. |
| 212 static int GetRedirectDistanceForURL(const MostVisitedURL& most_visited, | 217 static int GetRedirectDistanceForURL(const MostVisitedURL& most_visited, |
| 213 const GURL& url); | 218 const GURL& url); |
| 214 | 219 |
| 215 // Returns the set of prepopulate pages. | 220 // Returns the set of prepopulate pages. |
| 216 static MostVisitedURLList GetPrepopulatePages(); | 221 static MostVisitedURLList GetPrepopulatePages(); |
| 217 | 222 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 scoped_refptr<TopSitesBackend> backend_; | 289 scoped_refptr<TopSitesBackend> backend_; |
| 285 | 290 |
| 286 // The top sites data. | 291 // The top sites data. |
| 287 scoped_ptr<TopSitesCache> cache_; | 292 scoped_ptr<TopSitesCache> cache_; |
| 288 | 293 |
| 289 // Copy of the top sites data that may be accessed on any thread (assuming | 294 // Copy of the top sites data that may be accessed on any thread (assuming |
| 290 // you hold |lock_|). The data in |thread_safe_cache_| has blacklisted and | 295 // you hold |lock_|). The data in |thread_safe_cache_| has blacklisted and |
| 291 // pinned urls applied (|cache_| does not). | 296 // pinned urls applied (|cache_| does not). |
| 292 scoped_ptr<TopSitesCache> thread_safe_cache_; | 297 scoped_ptr<TopSitesCache> thread_safe_cache_; |
| 293 | 298 |
| 299 // Invokes the callback signaling the cache has been completely refreshed. |
| 300 // This is only used for testing. |
| 301 void InvokeRefreshCallback(CancelableRequestProvider::Handle handle); |
| 302 |
| 294 Profile* profile_; | 303 Profile* profile_; |
| 295 | 304 |
| 296 // Lock used to access |thread_safe_cache_|. | 305 // Lock used to access |thread_safe_cache_|. |
| 297 mutable Lock lock_; | 306 mutable Lock lock_; |
| 298 | 307 |
| 299 CancelableRequestConsumer cancelable_consumer_; | 308 CancelableRequestConsumer cancelable_consumer_; |
| 300 | 309 |
| 301 // Timer that asks history for the top sites. This is used to make sure our | 310 // Timer that asks history for the top sites. This is used to make sure our |
| 302 // data stays in sync with history. | 311 // data stays in sync with history. |
| 303 base::OneShotTimer<TopSites> timer_; | 312 base::OneShotTimer<TopSites> timer_; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 | 352 |
| 344 // Are we loaded? | 353 // Are we loaded? |
| 345 bool loaded_; | 354 bool loaded_; |
| 346 | 355 |
| 347 DISALLOW_COPY_AND_ASSIGN(TopSites); | 356 DISALLOW_COPY_AND_ASSIGN(TopSites); |
| 348 }; | 357 }; |
| 349 | 358 |
| 350 } // namespace history | 359 } // namespace history |
| 351 | 360 |
| 352 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_H_ | 361 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_H_ |
| OLD | NEW |