Chromium Code Reviews| Index: components/ntp_tiles/most_visited_sites.h |
| diff --git a/components/ntp_tiles/most_visited_sites.h b/components/ntp_tiles/most_visited_sites.h |
| index 17fc09401aca9ade54aec7a93b8994161642364b..ef3f1d5d1298af9d19352d2add92fd6a017bca92 100644 |
| --- a/components/ntp_tiles/most_visited_sites.h |
| +++ b/components/ntp_tiles/most_visited_sites.h |
| @@ -14,6 +14,7 @@ |
| #include "base/files/file_path.h" |
| #include "base/macros.h" |
| #include "base/memory/weak_ptr.h" |
| +#include "base/observer_list.h" |
| #include "base/scoped_observer.h" |
| #include "base/strings/string16.h" |
| #include "components/history/core/browser/history_types.h" |
| @@ -77,7 +78,7 @@ class MostVisitedSitesSupervisor { |
| class MostVisitedSites : public history::TopSitesObserver, |
| public MostVisitedSitesSupervisor::Observer { |
| public: |
| - // The observer to be notified when the list of most visited sites changes. |
| + // Observer to be notified when the list of most visited sites changes. |
| class Observer { |
| public: |
| virtual void OnMostVisitedURLsAvailable(const NTPTilesVector& tiles) = 0; |
| @@ -92,6 +93,8 @@ class MostVisitedSites : public history::TopSitesObserver, |
| // |prefs| and |suggestions| are required and may not be null. |top_sites|, |
| // |popular_sites|, and |supervisor| are optional and if null the associated |
| // features will be disabled. |
| + // |
| + // Clients must call Refresh() to fetch the initial tiles. |
| MostVisitedSites(PrefService* prefs, |
| scoped_refptr<history::TopSites> top_sites, |
| suggestions::SuggestionsService* suggestions, |
| @@ -101,15 +104,15 @@ class MostVisitedSites : public history::TopSitesObserver, |
| ~MostVisitedSites() override; |
| - // Sets the observer, and immediately fetches the current suggestions. |
| - // Does not take ownership of |observer|, which must outlive this object and |
| - // must not be null. |
| - void SetMostVisitedURLsObserver(Observer* observer, int num_sites); |
| + // Observer registration. |
| + void AddObserver(Observer* observer); |
| + void RemoveObserver(Observer* observer); |
| - // Requests an asynchronous refresh of the suggestions. Notifies the observer |
| + // Requests an asynchronous refresh of the suggestions. Notifies the observers |
| // once the request completes. |
|
sfiera
2017/01/18 09:58:33
This is now also necessary after every AddObserver
|
| void Refresh(); |
| + // Blacklist manipulation. |
| void AddOrRemoveBlacklistedUrl(const GURL& url, bool add_url); |
| void ClearBlacklistedUrls(); |
| @@ -156,9 +159,9 @@ class MostVisitedSites : public history::TopSitesObserver, |
| // if appropriate, and saves the new tiles. |
| void SaveNewTiles(NTPTilesVector personal_tiles); |
| - // Notifies the observer about the availability of tiles. |
| + // Notifies the observers about the availability of tiles. |
| // Also records impressions UMA if not done already. |
| - void NotifyMostVisitedURLsObserver(); |
| + void NotifyMostVisitedURLsObservers(); |
| void OnPopularSitesAvailable(bool success); |
| @@ -176,10 +179,7 @@ class MostVisitedSites : public history::TopSitesObserver, |
| std::unique_ptr<IconCacher> const icon_cacher_; |
| std::unique_ptr<MostVisitedSitesSupervisor> supervisor_; |
| - Observer* observer_; |
| - |
| - // The maximum number of most visited sites to return. |
| - int num_sites_; |
| + base::ObserverList<Observer> observer_list_; |
| std::unique_ptr< |
| suggestions::SuggestionsService::ResponseCallbackList::Subscription> |