Chromium Code Reviews| 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 CHROME_BROWSER_ANDROID_NTP_MOST_VISITED_SITES_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_NTP_MOST_VISITED_SITES_H_ |
| 6 #define CHROME_BROWSER_ANDROID_NTP_MOST_VISITED_SITES_H_ | 6 #define CHROME_BROWSER_ANDROID_NTP_MOST_VISITED_SITES_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 } | 34 } |
| 35 | 35 |
| 36 namespace user_prefs { | 36 namespace user_prefs { |
| 37 class PrefRegistrySyncable; | 37 class PrefRegistrySyncable; |
| 38 } | 38 } |
| 39 | 39 |
| 40 namespace variations { | 40 namespace variations { |
| 41 class VariationsService; | 41 class VariationsService; |
| 42 } | 42 } |
| 43 | 43 |
| 44 class Supervisor { | |
| 45 public: | |
| 46 struct Whitelist { | |
| 47 base::string16 title; | |
| 48 GURL entry_point; | |
| 49 base::FilePath large_icon_path; | |
| 50 }; | |
| 51 | |
| 52 class Observer { | |
| 53 public: | |
| 54 virtual void OnURLFilterChanged() {} | |
| 55 | |
| 56 protected: | |
| 57 ~Observer() {} | |
| 58 }; | |
| 59 | |
| 60 virtual void AddObserver(Observer* observer) = 0; | |
| 61 virtual void RemoveObserver(Observer* observer) = 0; | |
|
Marc Treib
2016/05/06 13:24:11
There'll only ever be one observer, namely the Mos
sfiera
2016/05/06 15:48:35
Done.
| |
| 62 virtual SupervisedUserURLFilter* GetURLFilterForUIThread() = 0; | |
|
Marc Treib
2016/05/06 13:24:11
Like this, you still have a dependency on Supervis
sfiera
2016/05/06 15:48:35
Done.
| |
| 63 virtual std::vector<Whitelist> whitelists() const = 0; | |
| 64 | |
| 65 protected: | |
| 66 virtual ~Supervisor() {} | |
| 67 }; | |
| 68 | |
| 69 class SupervisedUserServiceSupervisor : public Supervisor { | |
| 70 public: | |
| 71 SupervisedUserServiceSupervisor(Profile* profile); | |
| 72 | |
| 73 void AddObserver(Observer* observer) override; | |
| 74 void RemoveObserver(Observer* observer) override; | |
| 75 SupervisedUserURLFilter* GetURLFilterForUIThread() override; | |
| 76 std::vector<Supervisor::Whitelist> whitelists() const override; | |
| 77 | |
| 78 private: | |
| 79 struct SUSObserver : public SupervisedUserServiceObserver { | |
| 80 public: | |
| 81 SUSObserver(SupervisedUserService* service, Supervisor::Observer* observer) | |
| 82 : observer_(observer), | |
| 83 scope_(this) { | |
| 84 scope_.Add(service); | |
| 85 } | |
| 86 | |
| 87 void OnURLFilterChanged() override { | |
| 88 observer_->OnURLFilterChanged(); | |
| 89 } | |
| 90 | |
| 91 private: | |
| 92 Supervisor::Observer* observer_; | |
| 93 ScopedObserver<SupervisedUserService, SupervisedUserServiceObserver> scope_; | |
| 94 }; | |
| 95 | |
| 96 Profile* const profile_; | |
| 97 std::map<Supervisor::Observer*, std::unique_ptr<SUSObserver>> | |
| 98 observers_; | |
| 99 }; | |
| 100 | |
| 44 // Tracks the list of most visited sites and their thumbnails. | 101 // Tracks the list of most visited sites and their thumbnails. |
| 45 // | 102 // |
| 46 // Do not use, except from MostVisitedSitesBridge. The interface is in flux | 103 // Do not use, except from MostVisitedSitesBridge. The interface is in flux |
| 47 // while we are extracting the functionality of the Java class to make available | 104 // while we are extracting the functionality of the Java class to make available |
| 48 // in C++. | 105 // in C++. |
| 49 // | 106 // |
| 50 // TODO(sfiera): finalize interface. | 107 // TODO(sfiera): finalize interface. |
| 51 class MostVisitedSites : public history::TopSitesObserver, | 108 class MostVisitedSites : public history::TopSitesObserver, |
| 52 public SupervisedUserServiceObserver { | 109 public Supervisor::Observer { |
| 53 public: | 110 public: |
| 54 struct Suggestion; | 111 struct Suggestion; |
| 55 using SuggestionsVector = std::vector<Suggestion>; | 112 using SuggestionsVector = std::vector<Suggestion>; |
| 56 using PopularSitesVector = std::vector<PopularSites::Site>; | 113 using PopularSitesVector = std::vector<PopularSites::Site>; |
| 57 | 114 |
| 58 // The source of the Most Visited sites. | 115 // The source of the Most Visited sites. |
| 59 enum MostVisitedSource { TOP_SITES, SUGGESTIONS_SERVICE, POPULAR, WHITELIST }; | 116 enum MostVisitedSource { TOP_SITES, SUGGESTIONS_SERVICE, POPULAR, WHITELIST }; |
| 60 | 117 |
| 61 // The observer to be notified when the list of most visited sites changes. | 118 // The observer to be notified when the list of most visited sites changes. |
| 62 class Observer { | 119 class Observer { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 90 DISALLOW_COPY_AND_ASSIGN(Suggestion); | 147 DISALLOW_COPY_AND_ASSIGN(Suggestion); |
| 91 }; | 148 }; |
| 92 | 149 |
| 93 MostVisitedSites(PrefService* prefs, | 150 MostVisitedSites(PrefService* prefs, |
| 94 const TemplateURLService* template_url_service, | 151 const TemplateURLService* template_url_service, |
| 95 variations::VariationsService* variations_service, | 152 variations::VariationsService* variations_service, |
| 96 net::URLRequestContextGetter* download_context, | 153 net::URLRequestContextGetter* download_context, |
| 97 scoped_refptr<history::TopSites> top_sites, | 154 scoped_refptr<history::TopSites> top_sites, |
| 98 suggestions::SuggestionsService* suggestions, | 155 suggestions::SuggestionsService* suggestions, |
| 99 bool is_child_profile, | 156 bool is_child_profile, |
| 100 Profile* profile); | 157 Supervisor* supervisor); |
| 101 | 158 |
| 102 ~MostVisitedSites() override; | 159 ~MostVisitedSites() override; |
| 103 | 160 |
| 104 // Does not take ownership of |observer|, which must outlive this object and | 161 // Does not take ownership of |observer|, which must outlive this object and |
| 105 // must not be null. | 162 // must not be null. |
| 106 void SetMostVisitedURLsObserver(Observer* observer, int num_sites); | 163 void SetMostVisitedURLsObserver(Observer* observer, int num_sites); |
| 107 | 164 |
| 108 using ThumbnailCallback = base::Callback< | 165 using ThumbnailCallback = base::Callback< |
| 109 void(bool /* is_local_thumbnail */, const SkBitmap* /* bitmap */)>; | 166 void(bool /* is_local_thumbnail */, const SkBitmap* /* bitmap */)>; |
| 110 void GetURLThumbnail(const GURL& url, const ThumbnailCallback& callback); | 167 void GetURLThumbnail(const GURL& url, const ThumbnailCallback& callback); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 | 272 |
| 216 // Records UMA histogram metrics related to the number of impressions. | 273 // Records UMA histogram metrics related to the number of impressions. |
| 217 void RecordImpressionUMAMetrics(); | 274 void RecordImpressionUMAMetrics(); |
| 218 | 275 |
| 219 // history::TopSitesObserver implementation. | 276 // history::TopSitesObserver implementation. |
| 220 void TopSitesLoaded(history::TopSites* top_sites) override; | 277 void TopSitesLoaded(history::TopSites* top_sites) override; |
| 221 void TopSitesChanged(history::TopSites* top_sites, | 278 void TopSitesChanged(history::TopSites* top_sites, |
| 222 ChangeReason change_reason) override; | 279 ChangeReason change_reason) override; |
| 223 | 280 |
| 224 // The profile whose most visited sites will be queried. | 281 // The profile whose most visited sites will be queried. |
| 225 Profile* profile_; | |
| 226 | 282 |
| 227 PrefService* prefs_; | 283 PrefService* prefs_; |
| 228 const TemplateURLService* template_url_service_; | 284 const TemplateURLService* template_url_service_; |
| 229 variations::VariationsService* variations_service_; | 285 variations::VariationsService* variations_service_; |
| 230 net::URLRequestContextGetter* download_context_; | 286 net::URLRequestContextGetter* download_context_; |
| 231 scoped_refptr<history::TopSites> top_sites_; | 287 scoped_refptr<history::TopSites> top_sites_; |
| 232 suggestions::SuggestionsService* suggestions_service_; | 288 suggestions::SuggestionsService* suggestions_service_; |
| 289 Supervisor* supervisor_; | |
| 233 | 290 |
| 234 // Children will not be shown popular sites as suggestions. | 291 // Children will not be shown popular sites as suggestions. |
| 235 // TODO(sfiera): enable/disable suggestions if the profile is marked or | 292 // TODO(sfiera): enable/disable suggestions if the profile is marked or |
| 236 // unmarked as a child profile during the lifetime of the object. For now, it | 293 // unmarked as a child profile during the lifetime of the object. For now, it |
| 237 // doesn't matter, because a MostVisitedSites is instantiated for each NTP, | 294 // doesn't matter, because a MostVisitedSites is instantiated for each NTP, |
| 238 // but a longer-lived object would need to update. | 295 // but a longer-lived object would need to update. |
| 239 bool is_child_profile_; | 296 bool is_child_profile_; |
| 240 | 297 |
| 241 Observer* observer_; | 298 Observer* observer_; |
| 242 | 299 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 267 | 324 |
| 268 SuggestionsVector current_suggestions_; | 325 SuggestionsVector current_suggestions_; |
| 269 | 326 |
| 270 // For callbacks may be run after destruction. | 327 // For callbacks may be run after destruction. |
| 271 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; | 328 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; |
| 272 | 329 |
| 273 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); | 330 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); |
| 274 }; | 331 }; |
| 275 | 332 |
| 276 #endif // CHROME_BROWSER_ANDROID_NTP_MOST_VISITED_SITES_H_ | 333 #endif // CHROME_BROWSER_ANDROID_NTP_MOST_VISITED_SITES_H_ |
| OLD | NEW |