| 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 COMPONENTS_HISTORY_CORE_BROWSER_TOP_SITES_H_ |
| 6 #define CHROME_BROWSER_HISTORY_TOP_SITES_H_ | 6 #define COMPONENTS_HISTORY_CORE_BROWSER_TOP_SITES_H_ |
| 7 |
| 8 #include <vector> |
| 7 | 9 |
| 8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 9 #include "base/callback.h" | 11 #include "base/callback.h" |
| 10 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 11 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 12 #include "base/task/cancelable_task_tracker.h" | 14 #include "base/task/cancelable_task_tracker.h" |
| 13 #include "components/history/core/browser/history_types.h" | 15 #include "components/history/core/browser/history_types.h" |
| 14 #include "components/history/core/common/thumbnail_score.h" | 16 #include "components/history/core/common/thumbnail_score.h" |
| 15 #include "components/keyed_service/core/refcounted_keyed_service.h" | 17 #include "components/keyed_service/core/refcounted_keyed_service.h" |
| 16 #include "content/public/browser/notification_observer.h" | |
| 17 #include "content/public/browser/notification_registrar.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; | |
| 23 | 22 |
| 24 namespace base { | 23 namespace base { |
| 25 class FilePath; | 24 class FilePath; |
| 26 class RefCountedBytes; | 25 class RefCountedBytes; |
| 27 class RefCountedMemory; | 26 class RefCountedMemory; |
| 28 } | 27 } |
| 29 | 28 |
| 30 namespace history { | 29 namespace history { |
| 31 | 30 |
| 32 class TopSitesCache; | 31 class TopSitesCache; |
| 33 class TopSitesObserver; | 32 class TopSitesObserver; |
| 34 | 33 |
| 34 // PrepopulatedPage stores information for prepopulated page for the |
| 35 // initial run. |
| 36 struct PrepopulatedPage { |
| 37 PrepopulatedPage(); |
| 38 PrepopulatedPage(const GURL& url, |
| 39 const base::string16& title, |
| 40 int favicon_id, |
| 41 int thumbnail_id, |
| 42 SkColor color); |
| 43 |
| 44 MostVisitedURL most_visited; // The prepopulated page URL and title. |
| 45 int favicon_id; // The raw data resource for the favicon. |
| 46 int thumbnail_id; // The raw data resource for the thumbnail. |
| 47 SkColor color; // The best color to highlight the page, should |
| 48 // roughly match the favicon. |
| 49 }; |
| 50 |
| 51 typedef std::vector<PrepopulatedPage> PrepopulatedPageList; |
| 52 |
| 35 // Interface for TopSites, which stores the data for the top "most visited" | 53 // Interface for TopSites, which stores the data for the top "most visited" |
| 36 // sites. This includes a cache of the most visited data from history, as well | 54 // sites. This includes a cache of the most visited data from history, as well |
| 37 // as the corresponding thumbnails of those sites. | 55 // as the corresponding thumbnails of those sites. |
| 38 // | 56 // |
| 39 // Some methods should only be called from the UI thread (see method | 57 // Some methods should only be called from the UI thread (see method |
| 40 // descriptions below). All others are assumed to be threadsafe. | 58 // descriptions below). All others are assumed to be threadsafe. |
| 41 class TopSites : public RefcountedKeyedService, | 59 class TopSites : public RefcountedKeyedService { |
| 42 public content::NotificationObserver { | |
| 43 public: | 60 public: |
| 44 TopSites(); | 61 TopSites(); |
| 45 | 62 |
| 46 // Sets the given thumbnail for the given URL. Returns true if the thumbnail | 63 // Sets the given thumbnail for the given URL. Returns true if the thumbnail |
| 47 // was updated. False means either the URL wasn't known to us, or we felt | 64 // was updated. False means either the URL wasn't known to us, or we felt |
| 48 // that our current thumbnail was superior to the given one. Should be called | 65 // that our current thumbnail was superior to the given one. Should be called |
| 49 // from the UI thread. | 66 // from the UI thread. |
| 50 virtual bool SetPageThumbnail(const GURL& url, | 67 virtual bool SetPageThumbnail(const GURL& url, |
| 51 const gfx::Image& thumbnail, | 68 const gfx::Image& thumbnail, |
| 52 const ThumbnailScore& score) = 0; | 69 const ThumbnailScore& score) = 0; |
| 53 | 70 |
| 54 // While testing the history system, we want to set the thumbnail to a piece | 71 // While testing the history system, we want to set the thumbnail to a piece |
| 55 // of static memory. | 72 // of static memory. |
| 56 virtual bool SetPageThumbnailToJPEGBytes( | 73 virtual bool SetPageThumbnailToJPEGBytes(const GURL& url, |
| 57 const GURL& url, | 74 const base::RefCountedMemory* memory, |
| 58 const base::RefCountedMemory* memory, | 75 const ThumbnailScore& score) = 0; |
| 59 const ThumbnailScore& score) = 0; | |
| 60 | 76 |
| 61 typedef base::Callback<void(const MostVisitedURLList&)> | 77 typedef base::Callback<void(const MostVisitedURLList&)> |
| 62 GetMostVisitedURLsCallback; | 78 GetMostVisitedURLsCallback; |
| 63 | 79 |
| 64 // Returns a list of most visited URLs via a callback, if | 80 // Returns a list of most visited URLs via a callback, if |
| 65 // |include_forced_urls| is false includes only non-forced URLs. This may be | 81 // |include_forced_urls| is false includes only non-forced URLs. This may be |
| 66 // invoked on any thread. NOTE: the callback is called immediately if we have | 82 // invoked on any thread. NOTE: the callback is called immediately if we have |
| 67 // the data cached. If data is not available yet, callback will later be | 83 // the data cached. If data is not available yet, callback will later be |
| 68 // posted to the thread called this function. | 84 // posted to the thread called this function. |
| 69 virtual void GetMostVisitedURLs( | 85 virtual void GetMostVisitedURLs(const GetMostVisitedURLsCallback& callback, |
| 70 const GetMostVisitedURLsCallback& callback, | 86 bool include_forced_urls) = 0; |
| 71 bool include_forced_urls) = 0; | |
| 72 | 87 |
| 73 // Gets a thumbnail for a given page. Returns true iff we have the thumbnail. | 88 // Gets a thumbnail for a given page. Returns true iff we have the thumbnail. |
| 74 // This may be invoked on any thread. | 89 // This may be invoked on any thread. |
| 75 // If an exact thumbnail URL match fails, |prefix_match| specifies whether or | 90 // If an exact thumbnail URL match fails, |prefix_match| specifies whether or |
| 76 // not to try harder by matching the query thumbnail URL as URL prefix (as | 91 // not to try harder by matching the query thumbnail URL as URL prefix (as |
| 77 // defined by UrlIsPrefix()). | 92 // defined by UrlIsPrefix()). |
| 78 // As this method may be invoked on any thread the ref count needs to be | 93 // As this method may be invoked on any thread the ref count needs to be |
| 79 // incremented before this method returns, so this takes a scoped_refptr*. | 94 // incremented before this method returns, so this takes a scoped_refptr*. |
| 80 virtual bool GetPageThumbnail( | 95 virtual bool GetPageThumbnail( |
| 81 const GURL& url, | 96 const GURL& url, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 virtual bool IsNonForcedFull() = 0; | 151 virtual bool IsNonForcedFull() = 0; |
| 137 | 152 |
| 138 // Returns true if the top sites list of forced URLs is full (i.e. we already | 153 // Returns true if the top sites list of forced URLs is full (i.e. we already |
| 139 // have the maximum number of forced top sites). This function also returns | 154 // have the maximum number of forced top sites). This function also returns |
| 140 // false if TopSites isn't loaded yet. | 155 // false if TopSites isn't loaded yet. |
| 141 virtual bool IsForcedFull() = 0; | 156 virtual bool IsForcedFull() = 0; |
| 142 | 157 |
| 143 virtual bool loaded() const = 0; | 158 virtual bool loaded() const = 0; |
| 144 | 159 |
| 145 // Returns the set of prepopulate pages. | 160 // Returns the set of prepopulate pages. |
| 146 virtual MostVisitedURLList GetPrepopulatePages() = 0; | 161 virtual PrepopulatedPageList GetPrepopulatedPages() = 0; |
| 147 | 162 |
| 148 // Adds or updates a |url| for which we should force the capture of a | 163 // Adds or updates a |url| for which we should force the capture of a |
| 149 // thumbnail next time it's visited. If there is already a non-forced URL | 164 // thumbnail next time it's visited. If there is already a non-forced URL |
| 150 // matching this |url| this call has no effect. Indicate this URL was laste | 165 // matching this |url| this call has no effect. Indicate this URL was laste |
| 151 // forced at |time| so we can evict the older URLs when needed. Should be | 166 // forced at |time| so we can evict the older URLs when needed. Should be |
| 152 // called from the UI thread. | 167 // called from the UI thread. |
| 153 virtual bool AddForcedURL(const GURL& url, const base::Time& time) = 0; | 168 virtual bool AddForcedURL(const GURL& url, const base::Time& time) = 0; |
| 154 | 169 |
| 155 struct PrepopulatedPage { | |
| 156 // The string resource for the url. | |
| 157 int url_id; | |
| 158 // The string resource for the page title. | |
| 159 int title_id; | |
| 160 // The raw data resource for the favicon. | |
| 161 int favicon_id; | |
| 162 // The raw data resource for the thumbnail. | |
| 163 int thumbnail_id; | |
| 164 // The best color to highlight the page (should roughly match favicon). | |
| 165 SkColor color; | |
| 166 }; | |
| 167 | |
| 168 // Add Observer to the list. | 170 // Add Observer to the list. |
| 169 void AddObserver(TopSitesObserver* observer); | 171 void AddObserver(TopSitesObserver* observer); |
| 170 | 172 |
| 171 // Remove Observer from the list. | 173 // Remove Observer from the list. |
| 172 void RemoveObserver(TopSitesObserver* observer); | 174 void RemoveObserver(TopSitesObserver* observer); |
| 173 | 175 |
| 174 protected: | 176 protected: |
| 175 void NotifyTopSitesLoaded(); | 177 void NotifyTopSitesLoaded(); |
| 176 void NotifyTopSitesChanged(); | 178 void NotifyTopSitesChanged(); |
| 177 ~TopSites() override; | 179 ~TopSites() override; |
| 178 | 180 |
| 179 private: | 181 private: |
| 180 ObserverList<TopSitesObserver, true> observer_list_; | 182 ObserverList<TopSitesObserver, true> observer_list_; |
| 181 friend class base::RefCountedThreadSafe<TopSites>; | 183 friend class base::RefCountedThreadSafe<TopSites>; |
| 182 }; | 184 }; |
| 183 | 185 |
| 184 #if defined(OS_ANDROID) | |
| 185 const int kPrepopulatedPagesCount = 0; | |
| 186 #else | |
| 187 const int kPrepopulatedPagesCount = 2; | |
| 188 #endif | |
| 189 extern const TopSites::PrepopulatedPage | |
| 190 kPrepopulatedPages[kPrepopulatedPagesCount]; | |
| 191 | |
| 192 } // namespace history | 186 } // namespace history |
| 193 | 187 |
| 194 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_H_ | 188 #endif // COMPONENTS_HISTORY_CORE_BROWSER_TOP_SITES_H_ |
| OLD | NEW |