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

Side by Side Diff: chrome/browser/android/most_visited_sites.cc

Issue 1787633002: Use whitelist large icon for corresponding most visited suggestions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@icon-whitelist
Patch Set: Created 4 years, 9 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 | « chrome/browser/android/most_visited_sites.h ('k') | no next file » | 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 #include "chrome/browser/android/most_visited_sites.h" 5 #include "chrome/browser/android/most_visited_sites.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_array.h" 10 #include "base/android/jni_array.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 for (size_t i = 0; i < num_tiles; ++i) { 151 for (size_t i = 0; i < num_tiles; ++i) {
152 bool is_personal = false; 152 bool is_personal = false;
153 if (source_list->GetBoolean(i, &is_personal) && !is_personal) 153 if (source_list->GetBoolean(i, &is_personal) && !is_personal)
154 return true; 154 return true;
155 } 155 }
156 // The whole grid is already filled with personal suggestions, no point in 156 // The whole grid is already filled with personal suggestions, no point in
157 // bothering with popular ones. 157 // bothering with popular ones.
158 return false; 158 return false;
159 } 159 }
160 160
161 bool AreURLsEquivalent(const GURL& url1, const GURL& url2) {
162 return url1.host() == url2.host() && url1.path() == url2.path();
163 }
164
161 } // namespace 165 } // namespace
162 166
163 MostVisitedSites::Suggestion::Suggestion() : provider_index(-1) {} 167 MostVisitedSites::Suggestion::Suggestion() : provider_index(-1) {}
164 168
165 MostVisitedSites::Suggestion::~Suggestion() {} 169 MostVisitedSites::Suggestion::~Suggestion() {}
166 170
167 std::string MostVisitedSites::Suggestion::GetSourceHistogramName() const { 171 std::string MostVisitedSites::Suggestion::GetSourceHistogramName() const {
168 switch (source) { 172 switch (source) {
169 case MostVisitedSites::TOP_SITES: 173 case MostVisitedSites::TOP_SITES:
170 return kHistogramClientName; 174 return kHistogramClientName;
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 scoped_refptr<TopSites> top_sites = TopSitesFactory::GetForProfile(profile_); 426 scoped_refptr<TopSites> top_sites = TopSitesFactory::GetForProfile(profile_);
423 if (!top_sites) 427 if (!top_sites)
424 return; 428 return;
425 429
426 top_sites->GetMostVisitedURLs( 430 top_sites->GetMostVisitedURLs(
427 base::Bind(&MostVisitedSites::OnMostVisitedURLsAvailable, 431 base::Bind(&MostVisitedSites::OnMostVisitedURLsAvailable,
428 weak_ptr_factory_.GetWeakPtr()), 432 weak_ptr_factory_.GetWeakPtr()),
429 false); 433 false);
430 } 434 }
431 435
436 base::FilePath MostVisitedSites::GetWhitelistLargeIconPath(const GURL& url) {
437 SupervisedUserService* supervised_user_service =
438 SupervisedUserServiceFactory::GetForProfile(profile_);
439
440 for (const auto& whitelist : supervised_user_service->whitelists()) {
441 if (AreURLsEquivalent(whitelist->entry_point(), url))
442 return whitelist->large_icon_path();
443 }
444 return base::FilePath();
445 }
446
432 void MostVisitedSites::OnMostVisitedURLsAvailable( 447 void MostVisitedSites::OnMostVisitedURLsAvailable(
433 const history::MostVisitedURLList& visited_list) { 448 const history::MostVisitedURLList& visited_list) {
434 SupervisedUserURLFilter* url_filter = 449 SupervisedUserURLFilter* url_filter =
435 SupervisedUserServiceFactory::GetForProfile(profile_) 450 SupervisedUserServiceFactory::GetForProfile(profile_)
436 ->GetURLFilterForUIThread(); 451 ->GetURLFilterForUIThread();
452
437 MostVisitedSites::SuggestionsVector suggestions; 453 MostVisitedSites::SuggestionsVector suggestions;
438 size_t num_tiles = 454 size_t num_tiles =
439 std::min(visited_list.size(), static_cast<size_t>(num_sites_)); 455 std::min(visited_list.size(), static_cast<size_t>(num_sites_));
440 for (size_t i = 0; i < num_tiles; ++i) { 456 for (size_t i = 0; i < num_tiles; ++i) {
441 const history::MostVisitedURL& visited = visited_list[i]; 457 const history::MostVisitedURL& visited = visited_list[i];
442 if (visited.url.is_empty()) { 458 if (visited.url.is_empty()) {
443 num_tiles = i; 459 num_tiles = i;
444 break; // This is the signal that there are no more real visited sites. 460 break; // This is the signal that there are no more real visited sites.
445 } 461 }
446 if (url_filter->GetFilteringBehaviorForURL(visited.url) == 462 if (url_filter->GetFilteringBehaviorForURL(visited.url) ==
447 SupervisedUserURLFilter::FilteringBehavior::BLOCK) { 463 SupervisedUserURLFilter::FilteringBehavior::BLOCK) {
448 continue; 464 continue;
449 } 465 }
450 466
451 scoped_ptr<Suggestion> suggestion(new Suggestion()); 467 scoped_ptr<Suggestion> suggestion(new Suggestion());
452 suggestion->title = visited.title; 468 suggestion->title = visited.title;
453 suggestion->url = visited.url; 469 suggestion->url = visited.url;
454 suggestion->source = TOP_SITES; 470 suggestion->source = TOP_SITES;
471 suggestion->whitelist_icon_path = GetWhitelistLargeIconPath(visited.url);
455 472
456 suggestions.push_back(std::move(suggestion)); 473 suggestions.push_back(std::move(suggestion));
457 } 474 }
458 475
459 received_most_visited_sites_ = true; 476 received_most_visited_sites_ = true;
460 mv_source_ = TOP_SITES; 477 mv_source_ = TOP_SITES;
461 SaveNewNTPSuggestions(&suggestions); 478 SaveNewNTPSuggestions(&suggestions);
462 NotifyMostVisitedURLsObserver(); 479 NotifyMostVisitedURLsObserver();
463 } 480 }
464 481
(...skipping 16 matching lines...) Expand all
481 const ChromeSuggestion& suggestion = suggestions_profile.suggestions(i); 498 const ChromeSuggestion& suggestion = suggestions_profile.suggestions(i);
482 if (url_filter->GetFilteringBehaviorForURL(GURL(suggestion.url())) == 499 if (url_filter->GetFilteringBehaviorForURL(GURL(suggestion.url())) ==
483 SupervisedUserURLFilter::FilteringBehavior::BLOCK) { 500 SupervisedUserURLFilter::FilteringBehavior::BLOCK) {
484 continue; 501 continue;
485 } 502 }
486 503
487 scoped_ptr<Suggestion> generated_suggestion(new Suggestion()); 504 scoped_ptr<Suggestion> generated_suggestion(new Suggestion());
488 generated_suggestion->title = base::UTF8ToUTF16(suggestion.title()); 505 generated_suggestion->title = base::UTF8ToUTF16(suggestion.title());
489 generated_suggestion->url = GURL(suggestion.url()); 506 generated_suggestion->url = GURL(suggestion.url());
490 generated_suggestion->source = SUGGESTIONS_SERVICE; 507 generated_suggestion->source = SUGGESTIONS_SERVICE;
508 generated_suggestion->whitelist_icon_path = GetWhitelistLargeIconPath(
509 GURL(suggestion.url()));
491 if (suggestion.providers_size() > 0) 510 if (suggestion.providers_size() > 0)
492 generated_suggestion->provider_index = suggestion.providers(0); 511 generated_suggestion->provider_index = suggestion.providers(0);
493 512
494 suggestions.push_back(std::move(generated_suggestion)); 513 suggestions.push_back(std::move(generated_suggestion));
495 } 514 }
496 515
497 received_most_visited_sites_ = true; 516 received_most_visited_sites_ = true;
498 mv_source_ = SUGGESTIONS_SERVICE; 517 mv_source_ = SUGGESTIONS_SERVICE;
499 SaveNewNTPSuggestions(&suggestions); 518 SaveNewNTPSuggestions(&suggestions);
500 NotifyMostVisitedURLsObserver(); 519 NotifyMostVisitedURLsObserver();
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 } 859 }
841 } 860 }
842 861
843 static jlong Init(JNIEnv* env, 862 static jlong Init(JNIEnv* env,
844 const JavaParamRef<jobject>& obj, 863 const JavaParamRef<jobject>& obj,
845 const JavaParamRef<jobject>& jprofile) { 864 const JavaParamRef<jobject>& jprofile) {
846 MostVisitedSites* most_visited_sites = 865 MostVisitedSites* most_visited_sites =
847 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); 866 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile));
848 return reinterpret_cast<intptr_t>(most_visited_sites); 867 return reinterpret_cast<intptr_t>(most_visited_sites);
849 } 868 }
OLDNEW
« no previous file with comments | « chrome/browser/android/most_visited_sites.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698