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

Side by Side Diff: chrome/browser/android/ntp/most_visited_sites.h

Issue 1954973004: Remove MostVisitedSites => SupervisedUserService dep. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « no previous file | chrome/browser/android/ntp/most_visited_sites.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
18 #include "base/scoped_observer.h" 18 #include "base/scoped_observer.h"
19 #include "chrome/browser/android/ntp/popular_sites.h" 19 #include "chrome/browser/android/ntp/popular_sites.h"
20 #include "chrome/browser/supervised_user/supervised_user_service.h"
21 #include "chrome/browser/supervised_user/supervised_user_service_observer.h"
22 #include "components/history/core/browser/history_types.h" 20 #include "components/history/core/browser/history_types.h"
23 #include "components/history/core/browser/top_sites_observer.h" 21 #include "components/history/core/browser/top_sites_observer.h"
24 #include "components/suggestions/proto/suggestions.pb.h" 22 #include "components/suggestions/proto/suggestions.pb.h"
25 #include "components/suggestions/suggestions_service.h" 23 #include "components/suggestions/suggestions_service.h"
26 #include "url/gurl.h" 24 #include "url/gurl.h"
27 25
28 namespace history { 26 namespace history {
29 class TopSites; 27 class TopSites;
30 } 28 }
31 29
32 namespace suggestions { 30 namespace suggestions {
33 class SuggestionsService; 31 class SuggestionsService;
34 } 32 }
35 33
36 namespace user_prefs { 34 namespace user_prefs {
37 class PrefRegistrySyncable; 35 class PrefRegistrySyncable;
38 } 36 }
39 37
40 namespace variations { 38 namespace variations {
41 class VariationsService; 39 class VariationsService;
42 } 40 }
43 41
42 // Shim interface for SupervisedUserService.
43 class MostVisitedSitesSupervisor {
44 public:
45 struct Whitelist {
46 base::string16 title;
47 GURL entry_point;
48 base::FilePath large_icon_path;
49 };
50
51 class Observer {
52 public:
53 virtual void OnBlockedSitesChanged() = 0;
54
55 protected:
56 ~Observer() {}
57 };
58
59 // Pass non-null to set observer, or null to remove observer.
60 // If setting observer, there must not yet be an observer set.
61 // If removing observer, there must already be one to remove.
62 // Does not take ownership. Observer must outlive this object.
63 virtual void SetObserver(Observer* new_observer) = 0;
Marc Treib 2016/05/09 09:55:13 nit: I'd call this just "observer" - any reason fo
sfiera 2016/05/09 10:26:17 I found the naming to help with reading the implem
64
65 // If true, |url| should not be shown on the NTP.
66 virtual bool IsBlocked(const GURL& url) = 0;
67
68 // Explicit suggestions for sites to show on NTP.
69 virtual std::vector<Whitelist> whitelists() = 0;
70
71 // If true, be conservative about suggesting sites from outside sources.
72 virtual bool IsChildProfile() = 0;
73
74 protected:
75 virtual ~MostVisitedSitesSupervisor() {}
76 };
77
44 // Tracks the list of most visited sites and their thumbnails. 78 // Tracks the list of most visited sites and their thumbnails.
45 // 79 //
46 // Do not use, except from MostVisitedSitesBridge. The interface is in flux 80 // 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 81 // while we are extracting the functionality of the Java class to make available
48 // in C++. 82 // in C++.
49 // 83 //
50 // TODO(sfiera): finalize interface. 84 // TODO(sfiera): finalize interface.
51 class MostVisitedSites : public history::TopSitesObserver, 85 class MostVisitedSites : public history::TopSitesObserver,
52 public SupervisedUserServiceObserver { 86 public MostVisitedSitesSupervisor::Observer {
53 public: 87 public:
54 struct Suggestion; 88 struct Suggestion;
55 using SuggestionsVector = std::vector<Suggestion>; 89 using SuggestionsVector = std::vector<Suggestion>;
56 using PopularSitesVector = std::vector<PopularSites::Site>; 90 using PopularSitesVector = std::vector<PopularSites::Site>;
57 91
58 // The source of the Most Visited sites. 92 // The source of the Most Visited sites.
59 enum MostVisitedSource { TOP_SITES, SUGGESTIONS_SERVICE, POPULAR, WHITELIST }; 93 enum MostVisitedSource { TOP_SITES, SUGGESTIONS_SERVICE, POPULAR, WHITELIST };
60 94
61 // The observer to be notified when the list of most visited sites changes. 95 // The observer to be notified when the list of most visited sites changes.
62 class Observer { 96 class Observer {
(...skipping 26 matching lines...) Expand all
89 private: 123 private:
90 DISALLOW_COPY_AND_ASSIGN(Suggestion); 124 DISALLOW_COPY_AND_ASSIGN(Suggestion);
91 }; 125 };
92 126
93 MostVisitedSites(PrefService* prefs, 127 MostVisitedSites(PrefService* prefs,
94 const TemplateURLService* template_url_service, 128 const TemplateURLService* template_url_service,
95 variations::VariationsService* variations_service, 129 variations::VariationsService* variations_service,
96 net::URLRequestContextGetter* download_context, 130 net::URLRequestContextGetter* download_context,
97 scoped_refptr<history::TopSites> top_sites, 131 scoped_refptr<history::TopSites> top_sites,
98 suggestions::SuggestionsService* suggestions, 132 suggestions::SuggestionsService* suggestions,
99 bool is_child_profile, 133 MostVisitedSitesSupervisor* supervisor);
100 Profile* profile);
101 134
102 ~MostVisitedSites() override; 135 ~MostVisitedSites() override;
103 136
104 // Does not take ownership of |observer|, which must outlive this object and 137 // Does not take ownership of |observer|, which must outlive this object and
105 // must not be null. 138 // must not be null.
106 void SetMostVisitedURLsObserver(Observer* observer, int num_sites); 139 void SetMostVisitedURLsObserver(Observer* observer, int num_sites);
107 140
108 using ThumbnailCallback = base::Callback< 141 using ThumbnailCallback = base::Callback<
109 void(bool /* is_local_thumbnail */, const SkBitmap* /* bitmap */)>; 142 void(bool /* is_local_thumbnail */, const SkBitmap* /* bitmap */)>;
110 void GetURLThumbnail(const GURL& url, const ThumbnailCallback& callback); 143 void GetURLThumbnail(const GURL& url, const ThumbnailCallback& callback);
111 void AddOrRemoveBlacklistedUrl(const GURL& url, bool add_url); 144 void AddOrRemoveBlacklistedUrl(const GURL& url, bool add_url);
112 void RecordTileTypeMetrics(const std::vector<int>& tile_types); 145 void RecordTileTypeMetrics(const std::vector<int>& tile_types);
113 void RecordOpenedMostVisitedItem(int index, int tile_type); 146 void RecordOpenedMostVisitedItem(int index, int tile_type);
114 147
115 // SupervisedUserServiceObserver implementation. 148 // MostVisitedSitesSupervisor::Observer implementation.
116 void OnURLFilterChanged() override; 149 void OnBlockedSitesChanged() override;
Marc Treib 2016/05/09 09:55:12 Not your doing, but this can be private.
117 150
118 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 151 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
119 152
120 private: 153 private:
121 friend class MostVisitedSitesTest; 154 friend class MostVisitedSitesTest;
122 155
123 // TODO(treib): use SuggestionsVector in internal functions. crbug.com/601734 156 // TODO(treib): use SuggestionsVector in internal functions. crbug.com/601734
124 using SuggestionsPtrVector = std::vector<std::unique_ptr<Suggestion>>; 157 using SuggestionsPtrVector = std::vector<std::unique_ptr<Suggestion>>;
125 158
126 void BuildCurrentSuggestions(); 159 void BuildCurrentSuggestions();
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 void RecordThumbnailUMAMetrics(); 247 void RecordThumbnailUMAMetrics();
215 248
216 // Records UMA histogram metrics related to the number of impressions. 249 // Records UMA histogram metrics related to the number of impressions.
217 void RecordImpressionUMAMetrics(); 250 void RecordImpressionUMAMetrics();
218 251
219 // history::TopSitesObserver implementation. 252 // history::TopSitesObserver implementation.
220 void TopSitesLoaded(history::TopSites* top_sites) override; 253 void TopSitesLoaded(history::TopSites* top_sites) override;
221 void TopSitesChanged(history::TopSites* top_sites, 254 void TopSitesChanged(history::TopSites* top_sites,
222 ChangeReason change_reason) override; 255 ChangeReason change_reason) override;
223 256
224 // The profile whose most visited sites will be queried.
225 Profile* profile_;
226
227 PrefService* prefs_; 257 PrefService* prefs_;
228 const TemplateURLService* template_url_service_; 258 const TemplateURLService* template_url_service_;
229 variations::VariationsService* variations_service_; 259 variations::VariationsService* variations_service_;
230 net::URLRequestContextGetter* download_context_; 260 net::URLRequestContextGetter* download_context_;
231 scoped_refptr<history::TopSites> top_sites_; 261 scoped_refptr<history::TopSites> top_sites_;
232 suggestions::SuggestionsService* suggestions_service_; 262 suggestions::SuggestionsService* suggestions_service_;
233 263 MostVisitedSitesSupervisor* supervisor_;
234 // Children will not be shown popular sites as suggestions.
235 // 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
237 // doesn't matter, because a MostVisitedSites is instantiated for each NTP,
238 // but a longer-lived object would need to update.
239 bool is_child_profile_;
240 264
241 Observer* observer_; 265 Observer* observer_;
242 266
243 // The maximum number of most visited sites to return. 267 // The maximum number of most visited sites to return.
244 int num_sites_; 268 int num_sites_;
245 269
246 // Whether we have received an initial set of most visited sites (from either 270 // Whether we have received an initial set of most visited sites (from either
247 // TopSites or the SuggestionsService). 271 // TopSites or the SuggestionsService).
248 bool received_most_visited_sites_; 272 bool received_most_visited_sites_;
249 273
(...skipping 17 matching lines...) Expand all
267 291
268 SuggestionsVector current_suggestions_; 292 SuggestionsVector current_suggestions_;
269 293
270 // For callbacks may be run after destruction. 294 // For callbacks may be run after destruction.
271 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; 295 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_;
272 296
273 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); 297 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites);
274 }; 298 };
275 299
276 #endif // CHROME_BROWSER_ANDROID_NTP_MOST_VISITED_SITES_H_ 300 #endif // CHROME_BROWSER_ANDROID_NTP_MOST_VISITED_SITES_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/android/ntp/most_visited_sites.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698