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

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

Issue 441623002: Eliminate sending NOTIFICATION_TOP_SITES_* from TopSites (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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 CHROME_BROWSER_HISTORY_TOP_SITES_H_
6 #define CHROME_BROWSER_HISTORY_TOP_SITES_H_ 6 #define CHROME_BROWSER_HISTORY_TOP_SITES_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 "chrome/browser/history/history_types.h" 13 #include "chrome/browser/history/history_types.h"
14 #include "chrome/browser/history/top_sites_observer.h"
14 #include "components/history/core/common/thumbnail_score.h" 15 #include "components/history/core/common/thumbnail_score.h"
15 #include "third_party/skia/include/core/SkColor.h" 16 #include "third_party/skia/include/core/SkColor.h"
16 #include "ui/gfx/image/image.h" 17 #include "ui/gfx/image/image.h"
17 18
18 class GURL; 19 class GURL;
19 class Profile; 20 class Profile;
20 21
21 namespace base { 22 namespace base {
22 class FilePath; 23 class FilePath;
23 class RefCountedBytes; 24 class RefCountedBytes;
24 class RefCountedMemory; 25 class RefCountedMemory;
25 } 26 }
26 27
27 namespace history { 28 namespace history {
28 29
29 class TopSitesCache; 30 class TopSitesCache;
30 31
31 // 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"
32 // 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
33 // as the corresponding thumbnails of those sites. 34 // as the corresponding thumbnails of those sites.
34 // 35 //
35 // 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
36 // descriptions below). All others are assumed to be threadsafe. 37 // descriptions below). All others are assumed to be threadsafe.
37 class TopSites 38 class TopSites
38 : public base::RefCountedThreadSafe<TopSites>, 39 : public base::RefCountedThreadSafe<TopSites>,
39 public content::NotificationObserver { 40 public content::NotificationObserver {
40 public: 41 public:
41 TopSites() {} 42 TopSites();
42 43
43 // Initializes TopSites. 44 // Initializes TopSites.
44 static TopSites* Create(Profile* profile, const base::FilePath& db_name); 45 static TopSites* Create(Profile* profile, const base::FilePath& db_name);
45 46
46 // 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
47 // 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
48 // 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
49 // from the UI thread. 50 // from the UI thread.
50 virtual bool SetPageThumbnail(const GURL& url, 51 virtual bool SetPageThumbnail(const GURL& url,
51 const gfx::Image& thumbnail, 52 const gfx::Image& thumbnail,
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 int url_id; 161 int url_id;
161 // The string resource for the page title. 162 // The string resource for the page title.
162 int title_id; 163 int title_id;
163 // The raw data resource for the favicon. 164 // The raw data resource for the favicon.
164 int favicon_id; 165 int favicon_id;
165 // The raw data resource for the thumbnail. 166 // The raw data resource for the thumbnail.
166 int thumbnail_id; 167 int thumbnail_id;
167 // The best color to highlight the page (should roughly match favicon). 168 // The best color to highlight the page (should roughly match favicon).
168 SkColor color; 169 SkColor color;
169 }; 170 };
171
172 // TopSitesObserver
sdefresne 2014/08/04 08:47:18 Remove this comment block and the Observer type de
nshaik 2014/08/05 06:38:03 My bad.had the old code left there... deleted On 2
173 // chrome::NOTIFICATION_TOP_SITES_LOADED
174 // chrome::NOTIFICATION_TOP_SITES_CHANGED
175 class Observer {
176 public:
177 virtual void OnTopSitesLoaded(TopSites* top_sites) = 0;
178 virtual void OnTopSitesChanged(TopSites* top_sites) = 0;
179 };
180
181 // Add Observer to the list.
182 void AddObserver(TopSitesObserver* observer) {
sdefresne 2014/08/04 08:47:18 style: do not inline functions, see http://www.chr
nshaik 2014/08/05 06:38:03 Done.
183 observer_list_.AddObserver(observer);
184 }
185
186 // Remove Observer from the list.
187 void RemoveObserver(TopSitesObserver* observer) {
188 observer_list_.RemoveObserver(observer);
189 }
190
191 void NotifyTopSitesLoaded() {
sdefresne 2014/08/04 08:47:18 Move to the protected: section since this is only
nshaik 2014/08/05 06:38:03 Done.
192 FOR_EACH_OBSERVER(TopSitesObserver, observer_list_, TopSitesLoaded(this));
193 }
194
195 void NotifyTopSitesChanged() {
sdefresne 2014/08/04 08:47:18 Move to the protected: section since this is only
nshaik 2014/08/05 06:38:03 Done.
196 FOR_EACH_OBSERVER(TopSitesObserver, observer_list_, TopSitesChanged(this));
197 }
198
199 // Get the current Profile.
sdefresne 2014/08/04 08:47:18 Remove, instead pass the Profile to ChromeHistoryC
nshaik 2014/08/05 06:38:03 Done.
200 virtual Profile* GetProfile();
201
170 protected: 202 protected:
171 virtual ~TopSites() {} 203 virtual ~TopSites();
172 204
173 private: 205 private:
206 ObserverList<TopSitesObserver> observer_list_;
174 friend class base::RefCountedThreadSafe<TopSites>; 207 friend class base::RefCountedThreadSafe<TopSites>;
175 }; 208 };
176 209
177 #if defined(OS_ANDROID) 210 #if defined(OS_ANDROID)
178 extern const TopSites::PrepopulatedPage kPrepopulatedPages[1]; 211 extern const TopSites::PrepopulatedPage kPrepopulatedPages[1];
179 #else 212 #else
180 extern const TopSites::PrepopulatedPage kPrepopulatedPages[2]; 213 extern const TopSites::PrepopulatedPage kPrepopulatedPages[2];
181 #endif 214 #endif
182 215
183 } // namespace history 216 } // namespace history
184 217
185 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_H_ 218 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698