OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 COMPONENTS_NTP_TILES_MOST_VISITED_SITES_H_ | 5 #ifndef COMPONENTS_NTP_TILES_MOST_VISITED_SITES_H_ |
6 #define COMPONENTS_NTP_TILES_MOST_VISITED_SITES_H_ | 6 #define COMPONENTS_NTP_TILES_MOST_VISITED_SITES_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 }; | 46 }; |
47 | 47 |
48 class Observer { | 48 class Observer { |
49 public: | 49 public: |
50 virtual void OnBlockedSitesChanged() = 0; | 50 virtual void OnBlockedSitesChanged() = 0; |
51 | 51 |
52 protected: | 52 protected: |
53 ~Observer() {} | 53 ~Observer() {} |
54 }; | 54 }; |
55 | 55 |
| 56 virtual ~MostVisitedSitesSupervisor() {} |
| 57 |
56 // Pass non-null to set observer, or null to remove observer. | 58 // Pass non-null to set observer, or null to remove observer. |
57 // If setting observer, there must not yet be an observer set. | 59 // If setting observer, there must not yet be an observer set. |
58 // If removing observer, there must already be one to remove. | 60 // If removing observer, there must already be one to remove. |
59 // Does not take ownership. Observer must outlive this object. | 61 // Does not take ownership. Observer must outlive this object. |
60 virtual void SetObserver(Observer* new_observer) = 0; | 62 virtual void SetObserver(Observer* new_observer) = 0; |
61 | 63 |
62 // If true, |url| should not be shown on the NTP. | 64 // If true, |url| should not be shown on the NTP. |
63 virtual bool IsBlocked(const GURL& url) = 0; | 65 virtual bool IsBlocked(const GURL& url) = 0; |
64 | 66 |
65 // Explicitly-specified sites to show on NTP. | 67 // Explicitly-specified sites to show on NTP. |
66 virtual std::vector<Whitelist> whitelists() = 0; | 68 virtual std::vector<Whitelist> whitelists() = 0; |
67 | 69 |
68 // If true, be conservative about suggesting sites from outside sources. | 70 // If true, be conservative about suggesting sites from outside sources. |
69 virtual bool IsChildProfile() = 0; | 71 virtual bool IsChildProfile() = 0; |
70 | |
71 protected: | |
72 virtual ~MostVisitedSitesSupervisor() {} | |
73 }; | 72 }; |
74 | 73 |
75 // Tracks the list of most visited sites and their thumbnails. | 74 // Tracks the list of most visited sites and their thumbnails. |
76 class MostVisitedSites : public history::TopSitesObserver, | 75 class MostVisitedSites : public history::TopSitesObserver, |
77 public MostVisitedSitesSupervisor::Observer { | 76 public MostVisitedSitesSupervisor::Observer { |
78 public: | 77 public: |
79 using PopularSitesVector = std::vector<PopularSites::Site>; | 78 using PopularSitesVector = std::vector<PopularSites::Site>; |
80 | 79 |
81 // The observer to be notified when the list of most visited sites changes. | 80 // The observer to be notified when the list of most visited sites changes. |
82 class Observer { | 81 class Observer { |
83 public: | 82 public: |
84 virtual void OnMostVisitedURLsAvailable(const NTPTilesVector& tiles) = 0; | 83 virtual void OnMostVisitedURLsAvailable(const NTPTilesVector& tiles) = 0; |
85 virtual void OnIconMadeAvailable(const GURL& site_url) = 0; | 84 virtual void OnIconMadeAvailable(const GURL& site_url) = 0; |
86 | 85 |
87 protected: | 86 protected: |
88 virtual ~Observer() {} | 87 virtual ~Observer() {} |
89 }; | 88 }; |
90 | 89 |
91 // Construct a MostVisitedSites instance. | 90 // Construct a MostVisitedSites instance. |
92 // | 91 // |
93 // |prefs| and |suggestions| are required and may not be null. |top_sites|, | 92 // |prefs| and |suggestions| are required and may not be null. |top_sites|, |
94 // |popular_sites|, and |supervisor| are optional and if null the associated | 93 // |popular_sites|, and |supervisor| are optional and if null the associated |
95 // features will be disabled. | 94 // features will be disabled. |
96 MostVisitedSites(PrefService* prefs, | 95 MostVisitedSites(PrefService* prefs, |
97 scoped_refptr<history::TopSites> top_sites, | 96 scoped_refptr<history::TopSites> top_sites, |
98 suggestions::SuggestionsService* suggestions, | 97 suggestions::SuggestionsService* suggestions, |
99 std::unique_ptr<PopularSites> popular_sites, | 98 std::unique_ptr<PopularSites> popular_sites, |
100 std::unique_ptr<IconCacher> icon_cacher, | 99 std::unique_ptr<IconCacher> icon_cacher, |
101 MostVisitedSitesSupervisor* supervisor); | 100 std::unique_ptr<MostVisitedSitesSupervisor> supervisor); |
102 | 101 |
103 ~MostVisitedSites() override; | 102 ~MostVisitedSites() override; |
104 | 103 |
105 // Sets the observer, and immediately fetches the current suggestions. | 104 // Sets the observer, and immediately fetches the current suggestions. |
106 // Does not take ownership of |observer|, which must outlive this object and | 105 // Does not take ownership of |observer|, which must outlive this object and |
107 // must not be null. | 106 // must not be null. |
108 void SetMostVisitedURLsObserver(Observer* observer, int num_sites); | 107 void SetMostVisitedURLsObserver(Observer* observer, int num_sites); |
109 | 108 |
110 // Requests an asynchronous refresh of the suggestions. Notifies the observer | 109 // Requests an asynchronous refresh of the suggestions. Notifies the observer |
111 // once the request completes. | 110 // once the request completes. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 // history::TopSitesObserver implementation. | 169 // history::TopSitesObserver implementation. |
171 void TopSitesLoaded(history::TopSites* top_sites) override; | 170 void TopSitesLoaded(history::TopSites* top_sites) override; |
172 void TopSitesChanged(history::TopSites* top_sites, | 171 void TopSitesChanged(history::TopSites* top_sites, |
173 ChangeReason change_reason) override; | 172 ChangeReason change_reason) override; |
174 | 173 |
175 PrefService* prefs_; | 174 PrefService* prefs_; |
176 scoped_refptr<history::TopSites> top_sites_; | 175 scoped_refptr<history::TopSites> top_sites_; |
177 suggestions::SuggestionsService* suggestions_service_; | 176 suggestions::SuggestionsService* suggestions_service_; |
178 std::unique_ptr<PopularSites> const popular_sites_; | 177 std::unique_ptr<PopularSites> const popular_sites_; |
179 std::unique_ptr<IconCacher> const icon_cacher_; | 178 std::unique_ptr<IconCacher> const icon_cacher_; |
180 MostVisitedSitesSupervisor* supervisor_; | 179 std::unique_ptr<MostVisitedSitesSupervisor> supervisor_; |
181 | 180 |
182 Observer* observer_; | 181 Observer* observer_; |
183 | 182 |
184 // The maximum number of most visited sites to return. | 183 // The maximum number of most visited sites to return. |
185 int num_sites_; | 184 int num_sites_; |
186 | 185 |
187 std::unique_ptr< | 186 std::unique_ptr< |
188 suggestions::SuggestionsService::ResponseCallbackList::Subscription> | 187 suggestions::SuggestionsService::ResponseCallbackList::Subscription> |
189 suggestions_subscription_; | 188 suggestions_subscription_; |
190 | 189 |
191 ScopedObserver<history::TopSites, history::TopSitesObserver> | 190 ScopedObserver<history::TopSites, history::TopSitesObserver> |
192 top_sites_observer_; | 191 top_sites_observer_; |
193 | 192 |
194 // The main source of personal tiles - either TOP_SITES or SUGGESTIONS_SEVICE. | 193 // The main source of personal tiles - either TOP_SITES or SUGGESTIONS_SEVICE. |
195 NTPTileSource mv_source_; | 194 NTPTileSource mv_source_; |
196 | 195 |
197 NTPTilesVector current_tiles_; | 196 NTPTilesVector current_tiles_; |
198 | 197 |
199 // For callbacks may be run after destruction. | 198 // For callbacks may be run after destruction. |
200 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; | 199 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; |
201 | 200 |
202 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); | 201 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); |
203 }; | 202 }; |
204 | 203 |
205 } // namespace ntp_tiles | 204 } // namespace ntp_tiles |
206 | 205 |
207 #endif // COMPONENTS_NTP_TILES_MOST_VISITED_SITES_H_ | 206 #endif // COMPONENTS_NTP_TILES_MOST_VISITED_SITES_H_ |
OLD | NEW |