| OLD | NEW |
| 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_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 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
| 13 #include "base/task/cancelable_task_tracker.h" | 12 #include "base/task/cancelable_task_tracker.h" |
| 14 #include "components/history/core/browser/history_types.h" | 13 #include "components/history/core/browser/history_types.h" |
| 15 #include "components/history/core/browser/top_sites_observer.h" | 14 #include "components/history/core/browser/top_sites_observer.h" |
| 16 #include "components/history/core/common/thumbnail_score.h" | 15 #include "components/history/core/common/thumbnail_score.h" |
| 16 #include "components/keyed_service/core/refcounted_keyed_service.h" |
| 17 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
| 18 #include "third_party/skia/include/core/SkColor.h" | 18 #include "third_party/skia/include/core/SkColor.h" |
| 19 #include "ui/gfx/image/image.h" | 19 #include "ui/gfx/image/image.h" |
| 20 | 20 |
| 21 class GURL; | 21 class GURL; |
| 22 class Profile; | 22 class Profile; |
| 23 | 23 |
| 24 namespace base { | 24 namespace base { |
| 25 class FilePath; | 25 class FilePath; |
| 26 class RefCountedBytes; | 26 class RefCountedBytes; |
| 27 class RefCountedMemory; | 27 class RefCountedMemory; |
| 28 } | 28 } |
| 29 | 29 |
| 30 namespace history { | 30 namespace history { |
| 31 | 31 |
| 32 class TopSitesCache; | 32 class TopSitesCache; |
| 33 | 33 |
| 34 // Interface for TopSites, which stores the data for the top "most visited" | 34 // Interface for TopSites, which stores the data for the top "most visited" |
| 35 // sites. This includes a cache of the most visited data from history, as well | 35 // sites. This includes a cache of the most visited data from history, as well |
| 36 // as the corresponding thumbnails of those sites. | 36 // as the corresponding thumbnails of those sites. |
| 37 // | 37 // |
| 38 // Some methods should only be called from the UI thread (see method | 38 // Some methods should only be called from the UI thread (see method |
| 39 // descriptions below). All others are assumed to be threadsafe. | 39 // descriptions below). All others are assumed to be threadsafe. |
| 40 class TopSites | 40 class TopSites : public RefcountedKeyedService, |
| 41 : public base::RefCountedThreadSafe<TopSites>, | 41 public content::NotificationObserver { |
| 42 public content::NotificationObserver { | |
| 43 public: | 42 public: |
| 44 TopSites(); | 43 TopSites(); |
| 45 | 44 |
| 46 // Initializes TopSites. | |
| 47 static TopSites* Create(Profile* profile, const base::FilePath& db_name); | |
| 48 | |
| 49 // Sets the given thumbnail for the given URL. Returns true if the thumbnail | 45 // Sets the given thumbnail for the given URL. Returns true if the thumbnail |
| 50 // was updated. False means either the URL wasn't known to us, or we felt | 46 // was updated. False means either the URL wasn't known to us, or we felt |
| 51 // that our current thumbnail was superior to the given one. Should be called | 47 // that our current thumbnail was superior to the given one. Should be called |
| 52 // from the UI thread. | 48 // from the UI thread. |
| 53 virtual bool SetPageThumbnail(const GURL& url, | 49 virtual bool SetPageThumbnail(const GURL& url, |
| 54 const gfx::Image& thumbnail, | 50 const gfx::Image& thumbnail, |
| 55 const ThumbnailScore& score) = 0; | 51 const ThumbnailScore& score) = 0; |
| 56 | 52 |
| 57 // While testing the history system, we want to set the thumbnail to a piece | 53 // While testing the history system, we want to set the thumbnail to a piece |
| 58 // of static memory. | 54 // of static memory. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 // Removes a URL from the blacklist. Should be called from the UI thread. | 108 // Removes a URL from the blacklist. Should be called from the UI thread. |
| 113 virtual void RemoveBlacklistedURL(const GURL& url) = 0; | 109 virtual void RemoveBlacklistedURL(const GURL& url) = 0; |
| 114 | 110 |
| 115 // Returns true if the URL is blacklisted. Should be called from the UI | 111 // Returns true if the URL is blacklisted. Should be called from the UI |
| 116 // thread. | 112 // thread. |
| 117 virtual bool IsBlacklisted(const GURL& url) = 0; | 113 virtual bool IsBlacklisted(const GURL& url) = 0; |
| 118 | 114 |
| 119 // Clear the blacklist. Should be called from the UI thread. | 115 // Clear the blacklist. Should be called from the UI thread. |
| 120 virtual void ClearBlacklistedURLs() = 0; | 116 virtual void ClearBlacklistedURLs() = 0; |
| 121 | 117 |
| 122 // Shuts down top sites. | |
| 123 virtual void Shutdown() = 0; | |
| 124 | |
| 125 // Query history service for the list of available thumbnails. Returns the | 118 // Query history service for the list of available thumbnails. Returns the |
| 126 // task id for the request, or |base::CancelableTaskTracker::kBadTaskId| if a | 119 // task id for the request, or |base::CancelableTaskTracker::kBadTaskId| if a |
| 127 // request could not be made. Public only for testing purposes. | 120 // request could not be made. Public only for testing purposes. |
| 128 virtual base::CancelableTaskTracker::TaskId StartQueryForMostVisited() = 0; | 121 virtual base::CancelableTaskTracker::TaskId StartQueryForMostVisited() = 0; |
| 129 | 122 |
| 130 // Returns true if the given URL is known to the top sites service. | 123 // Returns true if the given URL is known to the top sites service. |
| 131 // This function also returns false if TopSites isn't loaded yet. | 124 // This function also returns false if TopSites isn't loaded yet. |
| 132 virtual bool IsKnownURL(const GURL& url) = 0; | 125 virtual bool IsKnownURL(const GURL& url) = 0; |
| 133 | 126 |
| 134 // Follows the cached redirect chain to convert any URL to its | 127 // Follows the cached redirect chain to convert any URL to its |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 const int kPrepopulatedPagesCount = 0; | 184 const int kPrepopulatedPagesCount = 0; |
| 192 #else | 185 #else |
| 193 const int kPrepopulatedPagesCount = 2; | 186 const int kPrepopulatedPagesCount = 2; |
| 194 #endif | 187 #endif |
| 195 extern const TopSites::PrepopulatedPage | 188 extern const TopSites::PrepopulatedPage |
| 196 kPrepopulatedPages[kPrepopulatedPagesCount]; | 189 kPrepopulatedPages[kPrepopulatedPagesCount]; |
| 197 | 190 |
| 198 } // namespace history | 191 } // namespace history |
| 199 | 192 |
| 200 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_H_ | 193 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_H_ |
| OLD | NEW |