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

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

Issue 815983002: Topsites become keyedService based. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 6 years 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 2014 The Chromium Authors. All rights reserved.
sdefresne 2014/12/19 15:11:40 Do not change copyright notice when renaming files
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_PROVIDER_H_
6 #define CHROME_BROWSER_HISTORY_TOP_SITES_H_ 6 #define CHROME_BROWSER_HISTORY_TOP_SITES_PROVIDER_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" 11 #include "base/memory/ref_counted.h"
12 #include "chrome/browser/history/history_service.h" 12 #include "chrome/browser/history/history_service.h"
13 #include "components/history/core/browser/history_types.h" 13 #include "components/history/core/browser/history_types.h"
14 #include "components/history/core/browser/top_sites_observer.h" 14 #include "components/history/core/browser/top_sites_observer.h"
15 #include "components/history/core/common/thumbnail_score.h" 15 #include "components/history/core/common/thumbnail_score.h"
16 #include "third_party/skia/include/core/SkColor.h" 16 #include "third_party/skia/include/core/SkColor.h"
(...skipping 11 matching lines...) Expand all
28 namespace history { 28 namespace history {
29 29
30 class TopSitesCache; 30 class TopSitesCache;
31 31
32 // Interface for TopSites, which stores the data for the top "most visited" 32 // Interface for TopSites, which stores the data for the top "most visited"
33 // sites. This includes a cache of the most visited data from history, as well 33 // sites. This includes a cache of the most visited data from history, as well
34 // as the corresponding thumbnails of those sites. 34 // as the corresponding thumbnails of those sites.
35 // 35 //
36 // Some methods should only be called from the UI thread (see method 36 // Some methods should only be called from the UI thread (see method
37 // descriptions below). All others are assumed to be threadsafe. 37 // descriptions below). All others are assumed to be threadsafe.
38 class TopSites 38 class TopSitesProvider : public base::RefCountedThreadSafe<TopSitesProvider>,
sdefresne 2014/12/19 15:11:40 This class must be the KeyedService, not TopSitesS
sdefresne 2014/12/19 15:11:40 Why did you rename this class from TopSites to Top
sdefresne 2014/12/19 15:11:40 Why did you rename this class from TopSites to Top
39 : public base::RefCountedThreadSafe<TopSites>, 39 public content::NotificationObserver {
40 public content::NotificationObserver {
41 public: 40 public:
42 TopSites(); 41 TopSitesProvider() {}
sdefresne 2014/12/19 15:11:40 Do not inline complex constructors.
43 42
44 // Initializes TopSites. 43 // Initializes TopSites.
45 static TopSites* Create(Profile* profile, const base::FilePath& db_name); 44 static TopSitesProvider* Create(Profile* profile,
45 const base::FilePath& db_name);
46 46
47 // Sets the given thumbnail for the given URL. Returns true if the thumbnail 47 // Sets the given thumbnail for the given URL. Returns true if the thumbnail
48 // was updated. False means either the URL wasn't known to us, or we felt 48 // was updated. False means either the URL wasn't known to us, or we felt
49 // that our current thumbnail was superior to the given one. Should be called 49 // that our current thumbnail was superior to the given one. Should be called
50 // from the UI thread. 50 // from the UI thread.
51 virtual bool SetPageThumbnail(const GURL& url, 51 virtual bool SetPageThumbnail(const GURL& url,
52 const gfx::Image& thumbnail, 52 const gfx::Image& thumbnail,
53 const ThumbnailScore& score) = 0; 53 const ThumbnailScore& score) = 0;
54 54
55 // While testing the history system, we want to set the thumbnail to a piece 55 // While testing the history system, we want to set the thumbnail to a piece
56 // of static memory. 56 // of static memory.
57 virtual bool SetPageThumbnailToJPEGBytes( 57 virtual bool SetPageThumbnailToJPEGBytes(const GURL& url,
58 const GURL& url, 58 const base::RefCountedMemory* memory,
59 const base::RefCountedMemory* memory, 59 const ThumbnailScore& score) = 0;
60 const ThumbnailScore& score) = 0;
61 60
62 typedef base::Callback<void(const MostVisitedURLList&)> 61 typedef base::Callback<void(const MostVisitedURLList&)>
63 GetMostVisitedURLsCallback; 62 GetMostVisitedURLsCallback;
64 63
65 // Returns a list of most visited URLs via a callback, if 64 // Returns a list of most visited URLs via a callback, if
66 // |include_forced_urls| is false includes only non-forced URLs. This may be 65 // |include_forced_urls| is false includes only non-forced URLs. This may be
67 // invoked on any thread. NOTE: the callback is called immediately if we have 66 // invoked on any thread. NOTE: the callback is called immediately if we have
68 // the data cached. If data is not available yet, callback will later be 67 // the data cached. If data is not available yet, callback will later be
69 // posted to the thread called this function. 68 // posted to the thread called this function.
70 virtual void GetMostVisitedURLs( 69 virtual void GetMostVisitedURLs(const GetMostVisitedURLsCallback& callback,
71 const GetMostVisitedURLsCallback& callback, 70 bool include_forced_urls) = 0;
72 bool include_forced_urls) = 0;
73 71
74 // Gets a thumbnail for a given page. Returns true iff we have the thumbnail. 72 // Gets a thumbnail for a given page. Returns true iff we have the thumbnail.
75 // This may be invoked on any thread. 73 // This may be invoked on any thread.
76 // If an exact thumbnail URL match fails, |prefix_match| specifies whether or 74 // If an exact thumbnail URL match fails, |prefix_match| specifies whether or
77 // not to try harder by matching the query thumbnail URL as URL prefix (as 75 // not to try harder by matching the query thumbnail URL as URL prefix (as
78 // defined by UrlIsPrefix()). 76 // defined by UrlIsPrefix()).
79 // As this method may be invoked on any thread the ref count needs to be 77 // As this method may be invoked on any thread the ref count needs to be
80 // incremented before this method returns, so this takes a scoped_refptr*. 78 // incremented before this method returns, so this takes a scoped_refptr*.
81 virtual bool GetPageThumbnail( 79 virtual bool GetPageThumbnail(
82 const GURL& url, 80 const GURL& url,
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 169
172 // Add Observer to the list. 170 // Add Observer to the list.
173 void AddObserver(TopSitesObserver* observer); 171 void AddObserver(TopSitesObserver* observer);
174 172
175 // Remove Observer from the list. 173 // Remove Observer from the list.
176 void RemoveObserver(TopSitesObserver* observer); 174 void RemoveObserver(TopSitesObserver* observer);
177 175
178 protected: 176 protected:
179 void NotifyTopSitesLoaded(); 177 void NotifyTopSitesLoaded();
180 void NotifyTopSitesChanged(); 178 void NotifyTopSitesChanged();
181 ~TopSites() override; 179 ~TopSitesProvider() override;
182 180
183 private: 181 private:
184 ObserverList<TopSitesObserver> observer_list_; 182 ObserverList<TopSitesObserver> observer_list_;
185 friend class base::RefCountedThreadSafe<TopSites>; 183 friend class base::RefCountedThreadSafe<TopSitesProvider>;
186 }; 184 };
187 185
188 #if defined(OS_ANDROID) 186 #if defined(OS_ANDROID)
189 const int kPrepopulatedPagesCount = 0; 187 const int kPrepopulatedPagesCount = 0;
190 #else 188 #else
191 const int kPrepopulatedPagesCount = 2; 189 const int kPrepopulatedPagesCount = 2;
192 #endif 190 #endif
193 extern const TopSites::PrepopulatedPage 191 extern const TopSitesProvider::PrepopulatedPage
194 kPrepopulatedPages[kPrepopulatedPagesCount]; 192 kPrepopulatedPages[kPrepopulatedPagesCount];
195 193
196 } // namespace history 194 } // namespace history
197 195
198 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_H_ 196 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698