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

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: Created 5 years, 11 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
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/browser/top_sites_observer.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"
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
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
36 // as the corresponding thumbnails of those sites.
37 //
38 // Some methods should only be called from the UI thread (see method
39 // descriptions below). All others are assumed to be threadsafe.
40 class TopSites : public RefcountedKeyedService,
41 public content::NotificationObserver {
42 public:
43 TopSites();
44
45 // Initializes TopSites.
46 static TopSites* Create(Profile* profile, const base::FilePath& db_name);
47
48 // Sets the given thumbnail for the given URL. Returns true if the thumbnail
49 // was updated. False means either the URL wasn't known to us, or we felt
50 // that our current thumbnail was superior to the given one. Should be called
51 // from the UI thread.
52 virtual bool SetPageThumbnail(const GURL& url,
53 const gfx::Image& thumbnail,
54 const ThumbnailScore& score) = 0;
55
56 // While testing the history system, we want to set the thumbnail to a piece
57 // of static memory.
58 virtual bool SetPageThumbnailToJPEGBytes(
59 const GURL& url,
60 const base::RefCountedMemory* memory,
61 const ThumbnailScore& score) = 0;
62
63 typedef base::Callback<void(const MostVisitedURLList&)>
64 GetMostVisitedURLsCallback;
65
66 // Returns a list of most visited URLs via a callback, if
67 // |include_forced_urls| is false includes only non-forced URLs. This may be
68 // invoked on any thread. NOTE: the callback is called immediately if we have
69 // the data cached. If data is not available yet, callback will later be
70 // posted to the thread called this function.
71 virtual void GetMostVisitedURLs(
72 const GetMostVisitedURLsCallback& callback,
73 bool include_forced_urls) = 0;
74
75 // Gets a thumbnail for a given page. Returns true iff we have the thumbnail.
76 // This may be invoked on any thread.
77 // If an exact thumbnail URL match fails, |prefix_match| specifies whether or
78 // not to try harder by matching the query thumbnail URL as URL prefix (as
79 // defined by UrlIsPrefix()).
80 // As this method may be invoked on any thread the ref count needs to be
81 // incremented before this method returns, so this takes a scoped_refptr*.
82 virtual bool GetPageThumbnail(
83 const GURL& url,
84 bool prefix_match,
85 scoped_refptr<base::RefCountedMemory>* bytes) = 0;
86
87 // Get a thumbnail score for a given page. Returns true iff we have the
88 // thumbnail score. This may be invoked on any thread. The score will
89 // be copied to |score|.
90 virtual bool GetPageThumbnailScore(const GURL& url,
91 ThumbnailScore* score) = 0;
92
93 // Get a temporary thumbnail score for a given page. Returns true iff we
94 // have the thumbnail score. Useful when checking if we should update a
95 // thumbnail for a given page. The score will be copied to |score|.
96 virtual bool GetTemporaryPageThumbnailScore(const GURL& url,
97 ThumbnailScore* score) = 0;
98
99 // Asks TopSites to refresh what it thinks the top sites are. This may do
100 // nothing. Should be called from the UI thread.
101 virtual void SyncWithHistory() = 0;
102
103 // Blacklisted URLs
104
105 // Returns true if there is at least one item in the blacklist.
106 virtual bool HasBlacklistedItems() const = 0;
107
108 // Add a URL to the blacklist. Should be called from the UI thread.
109 virtual void AddBlacklistedURL(const GURL& url) = 0;
110
111 // Removes a URL from the blacklist. Should be called from the UI thread.
112 virtual void RemoveBlacklistedURL(const GURL& url) = 0;
113
114 // Returns true if the URL is blacklisted. Should be called from the UI
115 // thread.
116 virtual bool IsBlacklisted(const GURL& url) = 0;
117
118 // Clear the blacklist. Should be called from the UI thread.
119 virtual void ClearBlacklistedURLs() = 0;
120
121 // Query history service for the list of available thumbnails. Returns the
122 // task id for the request, or |base::CancelableTaskTracker::kBadTaskId| if a
123 // request could not be made. Public only for testing purposes.
124 virtual base::CancelableTaskTracker::TaskId StartQueryForMostVisited() = 0;
125
126 // Returns true if the given URL is known to the top sites service.
127 // This function also returns false if TopSites isn't loaded yet.
128 virtual bool IsKnownURL(const GURL& url) = 0;
129
130 // Follows the cached redirect chain to convert any URL to its
131 // canonical version. If no redirect chain is known for the URL,
132 // return it without modification.
133 virtual const std::string& GetCanonicalURLString(const GURL& url) const = 0;
134
135 // Returns true if the top sites list of non-forced URLs is full (i.e. we
136 // already have the maximum number of non-forced top sites). This function
137 // also returns false if TopSites isn't loaded yet.
138 virtual bool IsNonForcedFull() = 0;
139
140 // Returns true if the top sites list of forced URLs is full (i.e. we already
141 // have the maximum number of forced top sites). This function also returns
142 // false if TopSites isn't loaded yet.
143 virtual bool IsForcedFull() = 0;
144
145 virtual bool loaded() const = 0;
146
147 // Returns the set of prepopulate pages.
148 virtual MostVisitedURLList GetPrepopulatePages() = 0;
149
150 // Adds or updates a |url| for which we should force the capture of a
151 // thumbnail next time it's visited. If there is already a non-forced URL
152 // matching this |url| this call has no effect. Indicate this URL was laste
153 // forced at |time| so we can evict the older URLs when needed. Should be
154 // called from the UI thread.
155 virtual bool AddForcedURL(const GURL& url, const base::Time& time) = 0;
156
157 struct PrepopulatedPage {
158 // The string resource for the url.
159 int url_id;
160 // The string resource for the page title.
161 int title_id;
162 // The raw data resource for the favicon.
163 int favicon_id;
164 // The raw data resource for the thumbnail.
165 int thumbnail_id;
166 // The best color to highlight the page (should roughly match favicon).
167 SkColor color;
168 };
169
170 // Add Observer to the list.
171 void AddObserver(TopSitesObserver* observer);
172
173 // Remove Observer from the list.
174 void RemoveObserver(TopSitesObserver* observer);
175
176 protected:
177 void NotifyTopSitesLoaded();
178 void NotifyTopSitesChanged();
179 ~TopSites() override;
180
181 private:
182 ObserverList<TopSitesObserver, true> observer_list_;
183 friend class base::RefCountedThreadSafe<TopSites>;
184 };
185
186 #if defined(OS_ANDROID)
187 const int kPrepopulatedPagesCount = 0;
188 #else
189 const int kPrepopulatedPagesCount = 2;
190 #endif
191 extern const TopSites::PrepopulatedPage
192 kPrepopulatedPages[kPrepopulatedPagesCount];
193
194 } // namespace history
195
196 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698