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

Side by Side Diff: components/history/core/browser/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
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/browser/top_sites_observer.h" 16 #include "components/history/core/browser/top_sites_observer.h"
15 #include "components/history/core/common/thumbnail_score.h" 17 #include "components/history/core/common/thumbnail_score.h"
16 #include "components/keyed_service/core/refcounted_keyed_service.h" 18 #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 "third_party/skia/include/core/SkColor.h"
19 #include "ui/gfx/image/image.h" 20 #include "ui/gfx/image/image.h"
20 21
21 class GURL; 22 class GURL;
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 // 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 url; // The prepopulated page URL and title.
droger 2015/01/27 10:08:37 Should this be: MostVisitedURL most_visited; or Mo
sdefresne 2015/01/27 13:55:16 Done.
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 roughly
48 // match favicon).
49 };
50
51 typedef std::vector<PrepopulatedPage> PrepopulatedPageList;
52
34 // 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"
35 // 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
36 // as the corresponding thumbnails of those sites. 55 // as the corresponding thumbnails of those sites.
37 // 56 //
38 // 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
39 // descriptions below). All others are assumed to be threadsafe. 58 // descriptions below). All others are assumed to be threadsafe.
40 class TopSites : public RefcountedKeyedService, 59 class TopSites : public RefcountedKeyedService {
41 public content::NotificationObserver {
42 public: 60 public:
43 TopSites(); 61 TopSites();
44 62
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 63 // 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 64 // 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 65 // that our current thumbnail was superior to the given one. Should be called
51 // from the UI thread. 66 // from the UI thread.
52 virtual bool SetPageThumbnail(const GURL& url, 67 virtual bool SetPageThumbnail(const GURL& url,
53 const gfx::Image& thumbnail, 68 const gfx::Image& thumbnail,
54 const ThumbnailScore& score) = 0; 69 const ThumbnailScore& score) = 0;
55 70
56 // 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
57 // of static memory. 72 // of static memory.
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 virtual bool IsNonForcedFull() = 0; 153 virtual bool IsNonForcedFull() = 0;
139 154
140 // Returns true if the top sites list of forced URLs is full (i.e. we already 155 // 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 156 // have the maximum number of forced top sites). This function also returns
142 // false if TopSites isn't loaded yet. 157 // false if TopSites isn't loaded yet.
143 virtual bool IsForcedFull() = 0; 158 virtual bool IsForcedFull() = 0;
144 159
145 virtual bool loaded() const = 0; 160 virtual bool loaded() const = 0;
146 161
147 // Returns the set of prepopulate pages. 162 // Returns the set of prepopulate pages.
148 virtual MostVisitedURLList GetPrepopulatePages() = 0; 163 virtual PrepopulatedPageList GetPrepopulatedPages() = 0;
149 164
150 // Adds or updates a |url| for which we should force the capture of a 165 // 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 166 // 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 167 // 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 168 // forced at |time| so we can evict the older URLs when needed. Should be
154 // called from the UI thread. 169 // called from the UI thread.
155 virtual bool AddForcedURL(const GURL& url, const base::Time& time) = 0; 170 virtual bool AddForcedURL(const GURL& url, const base::Time& time) = 0;
156 171
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. 172 // Add Observer to the list.
171 void AddObserver(TopSitesObserver* observer); 173 void AddObserver(TopSitesObserver* observer);
172 174
173 // Remove Observer from the list. 175 // Remove Observer from the list.
174 void RemoveObserver(TopSitesObserver* observer); 176 void RemoveObserver(TopSitesObserver* observer);
175 177
176 protected: 178 protected:
177 void NotifyTopSitesLoaded(); 179 void NotifyTopSitesLoaded();
178 void NotifyTopSitesChanged(); 180 void NotifyTopSitesChanged();
179 ~TopSites() override; 181 ~TopSites() override;
180 182
181 private: 183 private:
182 ObserverList<TopSitesObserver, true> observer_list_; 184 ObserverList<TopSitesObserver, true> observer_list_;
183 friend class base::RefCountedThreadSafe<TopSites>; 185 friend class base::RefCountedThreadSafe<TopSites>;
184 }; 186 };
185 187
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 188 } // namespace history
195 189
196 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_H_ 190 #endif // COMPONENTS_HISTORY_CORE_BROWSER_TOP_SITES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698