Chromium Code Reviews| Index: chrome/browser/android/most_visited_sites.cc |
| diff --git a/chrome/browser/android/most_visited_sites.cc b/chrome/browser/android/most_visited_sites.cc |
| index 3e8e7f4126877ca965e254b276239f50df322b52..d1f171c2e692568126ffb95f877050e51257b866 100644 |
| --- a/chrome/browser/android/most_visited_sites.cc |
| +++ b/chrome/browser/android/most_visited_sites.cc |
| @@ -29,6 +29,7 @@ |
| #include "chrome/browser/search/suggestions/suggestions_utils.h" |
| #include "chrome/browser/supervised_user/supervised_user_service.h" |
| #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
| +#include "chrome/browser/supervised_user/supervised_user_url_filter.h" |
| #include "chrome/browser/sync/profile_sync_service_factory.h" |
| #include "chrome/browser/thumbnails/thumbnail_list_source.h" |
| #include "chrome/common/chrome_switches.h" |
| @@ -475,6 +476,9 @@ void MostVisitedSites::InitiateTopSitesQuery() { |
| void MostVisitedSites::OnMostVisitedURLsAvailable( |
| const history::MostVisitedURLList& visited_list) { |
| + SupervisedUserURLFilter* url_filter = |
| + SupervisedUserServiceFactory::GetForProfile(profile_) |
| + ->GetURLFilterForUIThread(); |
|
Marc Treib
2016/02/25 10:34:32
Like my late comment on the other CL: Please only
atanasova
2016/02/25 11:09:10
For non-child accounts the behavior will always be
Marc Treib
2016/02/25 11:23:12
Well, my policy has always been to not even get a
|
| MostVisitedSites::SuggestionsVector suggestions; |
| size_t num_tiles = |
| std::min(visited_list.size(), static_cast<size_t>(num_sites_)); |
| @@ -484,6 +488,10 @@ void MostVisitedSites::OnMostVisitedURLsAvailable( |
| num_tiles = i; |
| break; // This is the signal that there are no more real visited sites. |
| } |
| + if (url_filter->GetFilteringBehaviorForURL(visited.url) != |
| + SupervisedUserURLFilter::FilteringBehavior::ALLOW) |
|
Marc Treib
2016/02/25 10:34:32
This should probably be "== BLOCK". (WARN isn't ac
atanasova
2016/02/25 11:09:10
Done.
|
| + continue; |
| + |
| suggestions.push_back(make_scoped_ptr( |
| new Suggestion(visited.title, visited.url.spec(), TOP_SITES))); |
| } |
| @@ -496,6 +504,9 @@ void MostVisitedSites::OnMostVisitedURLsAvailable( |
| void MostVisitedSites::OnSuggestionsProfileAvailable( |
| const SuggestionsProfile& suggestions_profile) { |
| + SupervisedUserURLFilter* url_filter = |
| + SupervisedUserServiceFactory::GetForProfile(profile_) |
| + ->GetURLFilterForUIThread(); |
|
Marc Treib
2016/02/25 10:34:32
nit: Move this down to where it's actually needed.
atanasova
2016/02/25 11:09:10
Done.
|
| int num_tiles = suggestions_profile.suggestions_size(); |
| // With no server suggestions, fall back to local Most Visited. |
| if (num_tiles == 0) { |
| @@ -508,6 +519,10 @@ void MostVisitedSites::OnSuggestionsProfileAvailable( |
| MostVisitedSites::SuggestionsVector suggestions; |
| for (int i = 0; i < num_tiles; ++i) { |
| const ChromeSuggestion& suggestion = suggestions_profile.suggestions(i); |
| + if (url_filter->GetFilteringBehaviorForURL(GURL(suggestion.url())) != |
| + SupervisedUserURLFilter::FilteringBehavior::ALLOW) |
| + continue; |
| + |
| suggestions.push_back(make_scoped_ptr(new Suggestion( |
| base::UTF8ToUTF16(suggestion.title()), suggestion.url(), |
| SUGGESTIONS_SERVICE, |
| @@ -531,8 +546,29 @@ MostVisitedSites::CreateWhitelistEntryPointSuggestions( |
| SupervisedUserService* supervised_user_service = |
| SupervisedUserServiceFactory::GetForProfile(profile_); |
| + SupervisedUserURLFilter* url_filter = |
| + supervised_user_service->GetURLFilterForUIThread(); |
| + |
| + std::set<std::string> personal_hosts; |
| + for (const auto& suggestion : personal_suggestions) |
| + personal_hosts.insert(suggestion->url.host()); |
| + scoped_refptr<TopSites> top_sites(TopSitesFactory::GetForProfile(profile_)); |
| for (const auto& whitelist : supervised_user_service->whitelists()) { |
| + // Skip blacklisted sites. |
| + if (top_sites && top_sites->IsBlacklisted(whitelist->entry_point())) |
| + continue; |
| + |
| + // Skip suggestions already present. |
| + if (personal_hosts.find(whitelist->entry_point().host()) != |
| + personal_hosts.end()) |
| + continue; |
| + |
| + // Skip whitelist entry points that are manually blocked. |
| + if (url_filter->GetFilteringBehaviorForURL(whitelist->entry_point()) != |
| + SupervisedUserURLFilter::FilteringBehavior::ALLOW) |
| + continue; |
| + |
| whitelist_suggestions.push_back(make_scoped_ptr(new Suggestion( |
| whitelist->title(), whitelist->entry_point(), WHITELIST))); |
| if (whitelist_suggestions.size() >= num_whitelist_suggestions) |
| @@ -546,6 +582,12 @@ MostVisitedSites::SuggestionsVector |
| MostVisitedSites::CreatePopularSitesSuggestions( |
| const MostVisitedSites::SuggestionsVector& personal_suggestions, |
| const MostVisitedSites::SuggestionsVector& whitelist_suggestions) { |
| + MostVisitedSites::SuggestionsVector popular_sites_suggestions; |
| + // For unicorn child accounts popular sites suggestions will not be added. |
|
Marc Treib
2016/02/25 10:34:32
What's this "unicorn" thing you speak of? ;) (Just
atanasova
2016/02/25 11:09:10
Done.
|
| + if (profile_->IsChild()) { |
| + return popular_sites_suggestions; |
| + } |
| + |
| size_t num_suggestions = |
| personal_suggestions.size() + whitelist_suggestions.size(); |
| DCHECK_LE(num_suggestions, static_cast<size_t>(num_sites_)); |
| @@ -553,12 +595,13 @@ MostVisitedSites::CreatePopularSitesSuggestions( |
| // Collect non-blacklisted popular suggestions, skipping those already present |
| // in the personal suggestions. |
| size_t num_popular_sites_suggestions = num_sites_ - num_suggestions; |
| - MostVisitedSites::SuggestionsVector popular_sites_suggestions; |
| if (num_popular_sites_suggestions > 0 && popular_sites_) { |
| - std::set<std::string> personal_hosts; |
| + std::set<std::string> hosts; |
| for (const auto& suggestion : personal_suggestions) |
| - personal_hosts.insert(suggestion->url.host()); |
| + hosts.insert(suggestion->url.host()); |
| + for (const auto& suggestion : whitelist_suggestions) |
| + hosts.insert(suggestion->url.host()); |
| scoped_refptr<TopSites> top_sites(TopSitesFactory::GetForProfile(profile_)); |
| for (const PopularSites::Site& popular_site : popular_sites_->sites()) { |
| // Skip blacklisted sites. |
| @@ -566,7 +609,7 @@ MostVisitedSites::CreatePopularSitesSuggestions( |
| continue; |
| std::string host = popular_site.url.host(); |
| // Skip suggestions already present in personal. |
|
Marc Treib
2016/02/25 10:34:32
or whitelists
atanasova
2016/02/25 11:09:10
Done.
|
| - if (personal_hosts.find(host) != personal_hosts.end()) |
| + if (hosts.find(host) != hosts.end()) |
| continue; |
| popular_sites_suggestions.push_back(make_scoped_ptr( |