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

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
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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 return true; 158 return true;
159 } 159 }
160 // The whole grid is already filled with personal suggestions, no point in 160 // The whole grid is already filled with personal suggestions, no point in
161 // bothering with popular ones. 161 // bothering with popular ones.
162 return false; 162 return false;
163 } 163 }
164 164
165 } // namespace 165 } // namespace
166 166
167 MostVisitedSites::Suggestion::Suggestion(const base::string16& title, 167 MostVisitedSites::Suggestion::Suggestion(const base::string16& title,
168 const std::string& url, 168 const GURL& url,
169 MostVisitedSource source) 169 MostVisitedSource source)
170 : title(title), url(url), source(source), provider_index(-1) {} 170 : title(title), url(url), source(source), provider_index(-1) {}
171 171
172 MostVisitedSites::Suggestion::Suggestion(const base::string16& title, 172 MostVisitedSites::Suggestion::Suggestion(const base::string16& title,
173 const std::string& url,
174 MostVisitedSource source,
175 const base::FilePath& large_icon_path)
176 : title(title),
177 url(url),
178 source(source),
179 large_icon_path(large_icon_path),
180 provider_index(-1) {}
181
182 MostVisitedSites::Suggestion::Suggestion(const base::string16& title,
173 const GURL& url, 183 const GURL& url,
174 MostVisitedSource source, 184 MostVisitedSource source,
175 const base::FilePath& large_icon_path) 185 const base::FilePath& large_icon_path)
176 : title(title), 186 : title(title),
177 url(url), 187 url(url),
178 source(source), 188 source(source),
179 large_icon_path(large_icon_path), 189 large_icon_path(large_icon_path),
180 provider_index(-1) { 190 provider_index(-1) {}
181 DCHECK_EQ(MostVisitedSites::WHITELIST, source);
182 }
183
184 MostVisitedSites::Suggestion::Suggestion(const base::string16& title,
185 const GURL& url,
186 MostVisitedSource source)
187 : title(title), url(url), source(source), provider_index(-1) {}
188 191
189 MostVisitedSites::Suggestion::Suggestion(const base::string16& title, 192 MostVisitedSites::Suggestion::Suggestion(const base::string16& title,
190 const std::string& url, 193 const std::string& url,
191 MostVisitedSource source, 194 MostVisitedSource source,
195 const base::FilePath& large_icon_path,
192 int provider_index) 196 int provider_index)
193 : title(title), url(url), source(source), provider_index(provider_index) { 197 : title(title),
198 url(url),
199 source(source),
200 large_icon_path(large_icon_path),
201 provider_index(provider_index) {
194 DCHECK_EQ(MostVisitedSites::SUGGESTIONS_SERVICE, source); 202 DCHECK_EQ(MostVisitedSites::SUGGESTIONS_SERVICE, source);
195 } 203 }
196 204
197 MostVisitedSites::Suggestion::~Suggestion() {} 205 MostVisitedSites::Suggestion::~Suggestion() {}
198 206
199 std::string MostVisitedSites::Suggestion::GetSourceHistogramName() const { 207 std::string MostVisitedSites::Suggestion::GetSourceHistogramName() const {
200 switch (source) { 208 switch (source) {
201 case MostVisitedSites::TOP_SITES: 209 case MostVisitedSites::TOP_SITES:
202 return kHistogramClientName; 210 return kHistogramClientName;
203 case MostVisitedSites::POPULAR: 211 case MostVisitedSites::POPULAR:
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 scoped_refptr<TopSites> top_sites = TopSitesFactory::GetForProfile(profile_); 487 scoped_refptr<TopSites> top_sites = TopSitesFactory::GetForProfile(profile_);
480 if (!top_sites) 488 if (!top_sites)
481 return; 489 return;
482 490
483 top_sites->GetMostVisitedURLs( 491 top_sites->GetMostVisitedURLs(
484 base::Bind(&MostVisitedSites::OnMostVisitedURLsAvailable, 492 base::Bind(&MostVisitedSites::OnMostVisitedURLsAvailable,
485 weak_ptr_factory_.GetWeakPtr()), 493 weak_ptr_factory_.GetWeakPtr()),
486 false); 494 false);
487 } 495 }
488 496
497 base::FilePath MostVisitedSites::GetWhitelistLargeIconPath(const GURL& url) {
498 SupervisedUserService* supervised_user_service =
499 SupervisedUserServiceFactory::GetForProfile(profile_);
500
501 for (const auto& whitelist : supervised_user_service->whitelists()) {
502 if (whitelist->entry_point().GetContent() == url.GetContent())
503 return whitelist->large_icon_path();
504 }
505 return base::FilePath();
506 }
507
489 void MostVisitedSites::OnMostVisitedURLsAvailable( 508 void MostVisitedSites::OnMostVisitedURLsAvailable(
490 const history::MostVisitedURLList& visited_list) { 509 const history::MostVisitedURLList& visited_list) {
491 SupervisedUserURLFilter* url_filter = 510 SupervisedUserURLFilter* url_filter =
492 SupervisedUserServiceFactory::GetForProfile(profile_) 511 SupervisedUserServiceFactory::GetForProfile(profile_)
493 ->GetURLFilterForUIThread(); 512 ->GetURLFilterForUIThread();
513
494 MostVisitedSites::SuggestionsVector suggestions; 514 MostVisitedSites::SuggestionsVector suggestions;
495 size_t num_tiles = 515 size_t num_tiles =
496 std::min(visited_list.size(), static_cast<size_t>(num_sites_)); 516 std::min(visited_list.size(), static_cast<size_t>(num_sites_));
497 for (size_t i = 0; i < num_tiles; ++i) { 517 for (size_t i = 0; i < num_tiles; ++i) {
498 const history::MostVisitedURL& visited = visited_list[i]; 518 const history::MostVisitedURL& visited = visited_list[i];
499 if (visited.url.is_empty()) { 519 if (visited.url.is_empty()) {
500 num_tiles = i; 520 num_tiles = i;
501 break; // This is the signal that there are no more real visited sites. 521 break; // This is the signal that there are no more real visited sites.
502 } 522 }
503 if (url_filter->GetFilteringBehaviorForURL(visited.url) == 523 if (url_filter->GetFilteringBehaviorForURL(visited.url) ==
504 SupervisedUserURLFilter::FilteringBehavior::BLOCK) { 524 SupervisedUserURLFilter::FilteringBehavior::BLOCK) {
505 continue; 525 continue;
506 } 526 }
507 527
508 suggestions.push_back(make_scoped_ptr( 528 suggestions.push_back(make_scoped_ptr(
509 new Suggestion(visited.title, visited.url.spec(), TOP_SITES))); 529 new Suggestion(visited.title, visited.url.spec(), TOP_SITES,
Marc Treib 2016/03/11 14:21:01 nit (pre-existing): ".spec()" isn't needed, Sugges
atanasova 2016/03/11 15:59:25 Done.
530 GetWhitelistLargeIconPath(visited.url))));
510 } 531 }
511 532
512 received_most_visited_sites_ = true; 533 received_most_visited_sites_ = true;
513 mv_source_ = TOP_SITES; 534 mv_source_ = TOP_SITES;
514 SaveNewNTPSuggestions(&suggestions); 535 SaveNewNTPSuggestions(&suggestions);
515 NotifyMostVisitedURLsObserver(); 536 NotifyMostVisitedURLsObserver();
516 } 537 }
517 538
518 void MostVisitedSites::OnSuggestionsProfileAvailable( 539 void MostVisitedSites::OnSuggestionsProfileAvailable(
519 const SuggestionsProfile& suggestions_profile) { 540 const SuggestionsProfile& suggestions_profile) {
(...skipping 12 matching lines...) Expand all
532 MostVisitedSites::SuggestionsVector suggestions; 553 MostVisitedSites::SuggestionsVector suggestions;
533 for (int i = 0; i < num_tiles; ++i) { 554 for (int i = 0; i < num_tiles; ++i) {
534 const ChromeSuggestion& suggestion = suggestions_profile.suggestions(i); 555 const ChromeSuggestion& suggestion = suggestions_profile.suggestions(i);
535 if (url_filter->GetFilteringBehaviorForURL(GURL(suggestion.url())) == 556 if (url_filter->GetFilteringBehaviorForURL(GURL(suggestion.url())) ==
536 SupervisedUserURLFilter::FilteringBehavior::BLOCK) { 557 SupervisedUserURLFilter::FilteringBehavior::BLOCK) {
537 continue; 558 continue;
538 } 559 }
539 560
540 suggestions.push_back(make_scoped_ptr(new Suggestion( 561 suggestions.push_back(make_scoped_ptr(new Suggestion(
541 base::UTF8ToUTF16(suggestion.title()), suggestion.url(), 562 base::UTF8ToUTF16(suggestion.title()), suggestion.url(),
542 SUGGESTIONS_SERVICE, 563 SUGGESTIONS_SERVICE, GetWhitelistLargeIconPath(GURL(suggestion.url())),
Marc Treib 2016/03/11 14:21:01 You could do "GURL url(suggestion.url());" above a
atanasova 2016/03/11 15:59:25 Done.
543 suggestion.providers_size() > 0 ? suggestion.providers(0) : -1))); 564 suggestion.providers_size() > 0 ? suggestion.providers(0) : -1)));
544 } 565 }
545 566
546 received_most_visited_sites_ = true; 567 received_most_visited_sites_ = true;
547 mv_source_ = SUGGESTIONS_SERVICE; 568 mv_source_ = SUGGESTIONS_SERVICE;
548 SaveNewNTPSuggestions(&suggestions); 569 SaveNewNTPSuggestions(&suggestions);
549 NotifyMostVisitedURLsObserver(); 570 NotifyMostVisitedURLsObserver();
550 } 571 }
551 572
552 MostVisitedSites::SuggestionsVector 573 MostVisitedSites::SuggestionsVector
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 } 899 }
879 } 900 }
880 901
881 static jlong Init(JNIEnv* env, 902 static jlong Init(JNIEnv* env,
882 const JavaParamRef<jobject>& obj, 903 const JavaParamRef<jobject>& obj,
883 const JavaParamRef<jobject>& jprofile) { 904 const JavaParamRef<jobject>& jprofile) {
884 MostVisitedSites* most_visited_sites = 905 MostVisitedSites* most_visited_sites =
885 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); 906 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile));
886 return reinterpret_cast<intptr_t>(most_visited_sites); 907 return reinterpret_cast<intptr_t>(most_visited_sites);
887 } 908 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698