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

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

Issue 870063002: Componentize TopSites, TopSitesBackend, TopSitesDatabase (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@815983002
Patch Set: Fix typo Created 5 years, 10 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
« no previous file with comments | « chrome/browser/history/history_unittest.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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_HISTORY_TOP_SITES_H_
6 #define CHROME_BROWSER_HISTORY_TOP_SITES_H_
7
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/gtest_prod_util.h"
11 #include "base/observer_list.h"
12 #include "base/task/cancelable_task_tracker.h"
13 #include "components/history/core/browser/history_types.h"
14 #include "components/history/core/common/thumbnail_score.h"
15 #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"
19 #include "ui/gfx/image/image.h"
20
21 class GURL;
22 class Profile;
23
24 namespace base {
25 class FilePath;
26 class RefCountedBytes;
27 class RefCountedMemory;
28 }
29
30 namespace history {
31
32 class TopSitesCache;
33 class TopSitesObserver;
34
35 // 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
37 // as the corresponding thumbnails of those sites.
38 //
39 // Some methods should only be called from the UI thread (see method
40 // descriptions below). All others are assumed to be threadsafe.
41 class TopSites : public RefcountedKeyedService,
42 public content::NotificationObserver {
43 public:
44 TopSites();
45
46 // 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
48 // that our current thumbnail was superior to the given one. Should be called
49 // from the UI thread.
50 virtual bool SetPageThumbnail(const GURL& url,
51 const gfx::Image& thumbnail,
52 const ThumbnailScore& score) = 0;
53
54 // While testing the history system, we want to set the thumbnail to a piece
55 // of static memory.
56 virtual bool SetPageThumbnailToJPEGBytes(
57 const GURL& url,
58 const base::RefCountedMemory* memory,
59 const ThumbnailScore& score) = 0;
60
61 typedef base::Callback<void(const MostVisitedURLList&)>
62 GetMostVisitedURLsCallback;
63
64 // 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
66 // 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
68 // posted to the thread called this function.
69 virtual void GetMostVisitedURLs(
70 const GetMostVisitedURLsCallback& callback,
71 bool include_forced_urls) = 0;
72
73 // Gets a thumbnail for a given page. Returns true iff we have the thumbnail.
74 // This may be invoked on any thread.
75 // 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
77 // defined by UrlIsPrefix()).
78 // 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*.
80 virtual bool GetPageThumbnail(
81 const GURL& url,
82 bool prefix_match,
83 scoped_refptr<base::RefCountedMemory>* bytes) = 0;
84
85 // Get a thumbnail score for a given page. Returns true iff we have the
86 // thumbnail score. This may be invoked on any thread. The score will
87 // be copied to |score|.
88 virtual bool GetPageThumbnailScore(const GURL& url,
89 ThumbnailScore* score) = 0;
90
91 // Get a temporary thumbnail score for a given page. Returns true iff we
92 // have the thumbnail score. Useful when checking if we should update a
93 // thumbnail for a given page. The score will be copied to |score|.
94 virtual bool GetTemporaryPageThumbnailScore(const GURL& url,
95 ThumbnailScore* score) = 0;
96
97 // Asks TopSites to refresh what it thinks the top sites are. This may do
98 // nothing. Should be called from the UI thread.
99 virtual void SyncWithHistory() = 0;
100
101 // Blacklisted URLs
102
103 // Returns true if there is at least one item in the blacklist.
104 virtual bool HasBlacklistedItems() const = 0;
105
106 // Add a URL to the blacklist. Should be called from the UI thread.
107 virtual void AddBlacklistedURL(const GURL& url) = 0;
108
109 // Removes a URL from the blacklist. Should be called from the UI thread.
110 virtual void RemoveBlacklistedURL(const GURL& url) = 0;
111
112 // Returns true if the URL is blacklisted. Should be called from the UI
113 // thread.
114 virtual bool IsBlacklisted(const GURL& url) = 0;
115
116 // Clear the blacklist. Should be called from the UI thread.
117 virtual void ClearBlacklistedURLs() = 0;
118
119 // Query history service for the list of available thumbnails. Returns the
120 // task id for the request, or |base::CancelableTaskTracker::kBadTaskId| if a
121 // request could not be made. Public only for testing purposes.
122 virtual base::CancelableTaskTracker::TaskId StartQueryForMostVisited() = 0;
123
124 // Returns true if the given URL is known to the top sites service.
125 // This function also returns false if TopSites isn't loaded yet.
126 virtual bool IsKnownURL(const GURL& url) = 0;
127
128 // Follows the cached redirect chain to convert any URL to its
129 // canonical version. If no redirect chain is known for the URL,
130 // return it without modification.
131 virtual const std::string& GetCanonicalURLString(const GURL& url) const = 0;
132
133 // Returns true if the top sites list of non-forced URLs is full (i.e. we
134 // already have the maximum number of non-forced top sites). This function
135 // also returns false if TopSites isn't loaded yet.
136 virtual bool IsNonForcedFull() = 0;
137
138 // 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
140 // false if TopSites isn't loaded yet.
141 virtual bool IsForcedFull() = 0;
142
143 virtual bool loaded() const = 0;
144
145 // Returns the set of prepopulate pages.
146 virtual MostVisitedURLList GetPrepopulatePages() = 0;
147
148 // 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
150 // 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
152 // called from the UI thread.
153 virtual bool AddForcedURL(const GURL& url, const base::Time& time) = 0;
154
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.
169 void AddObserver(TopSitesObserver* observer);
170
171 // Remove Observer from the list.
172 void RemoveObserver(TopSitesObserver* observer);
173
174 protected:
175 void NotifyTopSitesLoaded();
176 void NotifyTopSitesChanged();
177 ~TopSites() override;
178
179 private:
180 ObserverList<TopSitesObserver, true> observer_list_;
181 friend class base::RefCountedThreadSafe<TopSites>;
182 };
183
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
193
194 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_H_
OLDNEW
« no previous file with comments | « chrome/browser/history/history_unittest.cc ('k') | chrome/browser/history/top_sites.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698