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

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

Issue 1772363002: Start using the whitelist icon on the NTP. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Final touches 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 if (source_list->GetBoolean(i, &is_personal) && !is_personal) 157 if (source_list->GetBoolean(i, &is_personal) && !is_personal)
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() : provider_index(-1) {}
168 const std::string& url,
169 MostVisitedSource source)
170 : title(title), url(url), source(source), provider_index(-1) {}
171
172 MostVisitedSites::Suggestion::Suggestion(const base::string16& title,
173 const GURL& url,
174 MostVisitedSource source)
175 : title(title), url(url), source(source), provider_index(-1) {}
176
177 MostVisitedSites::Suggestion::Suggestion(const base::string16& title,
178 const std::string& url,
179 MostVisitedSource source,
180 int provider_index)
181 : title(title), url(url), source(source), provider_index(provider_index) {
182 DCHECK_EQ(MostVisitedSites::SUGGESTIONS_SERVICE, source);
183 }
184 168
185 MostVisitedSites::Suggestion::~Suggestion() {} 169 MostVisitedSites::Suggestion::~Suggestion() {}
186 170
187 std::string MostVisitedSites::Suggestion::GetSourceHistogramName() const { 171 std::string MostVisitedSites::Suggestion::GetSourceHistogramName() const {
188 switch (source) { 172 switch (source) {
189 case MostVisitedSites::TOP_SITES: 173 case MostVisitedSites::TOP_SITES:
190 return kHistogramClientName; 174 return kHistogramClientName;
191 case MostVisitedSites::POPULAR: 175 case MostVisitedSites::POPULAR:
192 return kHistogramPopularName; 176 return kHistogramPopularName;
193 case MostVisitedSites::WHITELIST: 177 case MostVisitedSites::WHITELIST:
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 const history::MostVisitedURL& visited = visited_list[i]; 470 const history::MostVisitedURL& visited = visited_list[i];
487 if (visited.url.is_empty()) { 471 if (visited.url.is_empty()) {
488 num_tiles = i; 472 num_tiles = i;
489 break; // This is the signal that there are no more real visited sites. 473 break; // This is the signal that there are no more real visited sites.
490 } 474 }
491 if (url_filter->GetFilteringBehaviorForURL(visited.url) == 475 if (url_filter->GetFilteringBehaviorForURL(visited.url) ==
492 SupervisedUserURLFilter::FilteringBehavior::BLOCK) { 476 SupervisedUserURLFilter::FilteringBehavior::BLOCK) {
493 continue; 477 continue;
494 } 478 }
495 479
496 suggestions.push_back(make_scoped_ptr( 480 scoped_ptr<Suggestion> suggestion(make_scoped_ptr(new Suggestion()));
Marc Treib 2016/03/17 10:18:29 Actually, you don't even need the make_scoped_ptr
atanasova 2016/03/17 17:15:21 Done.
497 new Suggestion(visited.title, visited.url.spec(), TOP_SITES))); 481 suggestion->title = visited.title;
482 suggestion->url = visited.url;
483 suggestion->source = TOP_SITES;
484
485 suggestions.push_back(std::move(suggestion));
498 } 486 }
499 487
500 received_most_visited_sites_ = true; 488 received_most_visited_sites_ = true;
501 mv_source_ = TOP_SITES; 489 mv_source_ = TOP_SITES;
502 SaveNewNTPSuggestions(&suggestions); 490 SaveNewNTPSuggestions(&suggestions);
503 NotifyMostVisitedURLsObserver(); 491 NotifyMostVisitedURLsObserver();
504 } 492 }
505 493
506 void MostVisitedSites::OnSuggestionsProfileAvailable( 494 void MostVisitedSites::OnSuggestionsProfileAvailable(
507 const SuggestionsProfile& suggestions_profile) { 495 const SuggestionsProfile& suggestions_profile) {
(...skipping 10 matching lines...) Expand all
518 SupervisedUserServiceFactory::GetForProfile(profile_) 506 SupervisedUserServiceFactory::GetForProfile(profile_)
519 ->GetURLFilterForUIThread(); 507 ->GetURLFilterForUIThread();
520 MostVisitedSites::SuggestionsVector suggestions; 508 MostVisitedSites::SuggestionsVector suggestions;
521 for (int i = 0; i < num_tiles; ++i) { 509 for (int i = 0; i < num_tiles; ++i) {
522 const ChromeSuggestion& suggestion = suggestions_profile.suggestions(i); 510 const ChromeSuggestion& suggestion = suggestions_profile.suggestions(i);
523 if (url_filter->GetFilteringBehaviorForURL(GURL(suggestion.url())) == 511 if (url_filter->GetFilteringBehaviorForURL(GURL(suggestion.url())) ==
524 SupervisedUserURLFilter::FilteringBehavior::BLOCK) { 512 SupervisedUserURLFilter::FilteringBehavior::BLOCK) {
525 continue; 513 continue;
526 } 514 }
527 515
528 suggestions.push_back(make_scoped_ptr(new Suggestion( 516 scoped_ptr<Suggestion> generated_suggestion(
529 base::UTF8ToUTF16(suggestion.title()), suggestion.url(), 517 make_scoped_ptr(new Suggestion()));
530 SUGGESTIONS_SERVICE, 518 generated_suggestion->title = base::UTF8ToUTF16(suggestion.title());
531 suggestion.providers_size() > 0 ? suggestion.providers(0) : -1))); 519 generated_suggestion->url = GURL(suggestion.url());
520 generated_suggestion->source = SUGGESTIONS_SERVICE;
521 if (suggestion.providers_size() > 0)
522 generated_suggestion->provider_index = suggestion.providers(0);
523
524 suggestions.push_back(std::move(generated_suggestion));
532 } 525 }
533 526
534 received_most_visited_sites_ = true; 527 received_most_visited_sites_ = true;
535 mv_source_ = SUGGESTIONS_SERVICE; 528 mv_source_ = SUGGESTIONS_SERVICE;
536 SaveNewNTPSuggestions(&suggestions); 529 SaveNewNTPSuggestions(&suggestions);
537 NotifyMostVisitedURLsObserver(); 530 NotifyMostVisitedURLsObserver();
538 } 531 }
539 532
540 MostVisitedSites::SuggestionsVector 533 MostVisitedSites::SuggestionsVector
541 MostVisitedSites::CreateWhitelistEntryPointSuggestions( 534 MostVisitedSites::CreateWhitelistEntryPointSuggestions(
(...skipping 23 matching lines...) Expand all
565 if (personal_hosts.find(whitelist->entry_point().host()) != 558 if (personal_hosts.find(whitelist->entry_point().host()) !=
566 personal_hosts.end()) 559 personal_hosts.end())
567 continue; 560 continue;
568 561
569 // Skip whitelist entry points that are manually blocked. 562 // Skip whitelist entry points that are manually blocked.
570 if (url_filter->GetFilteringBehaviorForURL(whitelist->entry_point()) == 563 if (url_filter->GetFilteringBehaviorForURL(whitelist->entry_point()) ==
571 SupervisedUserURLFilter::FilteringBehavior::BLOCK) { 564 SupervisedUserURLFilter::FilteringBehavior::BLOCK) {
572 continue; 565 continue;
573 } 566 }
574 567
575 whitelist_suggestions.push_back(make_scoped_ptr(new Suggestion( 568 scoped_ptr<Suggestion> suggestion(make_scoped_ptr(new Suggestion()));
576 whitelist->title(), whitelist->entry_point(), WHITELIST))); 569 suggestion->title = whitelist->title();
570 suggestion->url = whitelist->entry_point();
571 suggestion->source = WHITELIST;
572 suggestion->whitelist_icon_path = whitelist->large_icon_path();
573
574 whitelist_suggestions.push_back(std::move(suggestion));
577 if (whitelist_suggestions.size() >= num_whitelist_suggestions) 575 if (whitelist_suggestions.size() >= num_whitelist_suggestions)
578 break; 576 break;
579 } 577 }
580 578
581 return whitelist_suggestions; 579 return whitelist_suggestions;
582 } 580 }
583 581
584 MostVisitedSites::SuggestionsVector 582 MostVisitedSites::SuggestionsVector
585 MostVisitedSites::CreatePopularSitesSuggestions( 583 MostVisitedSites::CreatePopularSitesSuggestions(
586 const MostVisitedSites::SuggestionsVector& personal_suggestions, 584 const MostVisitedSites::SuggestionsVector& personal_suggestions,
(...skipping 20 matching lines...) Expand all
607 scoped_refptr<TopSites> top_sites(TopSitesFactory::GetForProfile(profile_)); 605 scoped_refptr<TopSites> top_sites(TopSitesFactory::GetForProfile(profile_));
608 for (const PopularSites::Site& popular_site : popular_sites_->sites()) { 606 for (const PopularSites::Site& popular_site : popular_sites_->sites()) {
609 // Skip blacklisted sites. 607 // Skip blacklisted sites.
610 if (top_sites && top_sites->IsBlacklisted(popular_site.url)) 608 if (top_sites && top_sites->IsBlacklisted(popular_site.url))
611 continue; 609 continue;
612 std::string host = popular_site.url.host(); 610 std::string host = popular_site.url.host();
613 // Skip suggestions already present in personal or whitelists. 611 // Skip suggestions already present in personal or whitelists.
614 if (hosts.find(host) != hosts.end()) 612 if (hosts.find(host) != hosts.end())
615 continue; 613 continue;
616 614
617 popular_sites_suggestions.push_back(make_scoped_ptr( 615 scoped_ptr<Suggestion> suggestion(make_scoped_ptr(new Suggestion()));
618 new Suggestion(popular_site.title, popular_site.url, POPULAR))); 616 suggestion->title = popular_site.title;
617 suggestion->url = GURL(popular_site.url);
618 suggestion->source = POPULAR;
619
620 popular_sites_suggestions.push_back(std::move(suggestion));
619 if (popular_sites_suggestions.size() >= num_popular_sites_suggestions) 621 if (popular_sites_suggestions.size() >= num_popular_sites_suggestions)
620 break; 622 break;
621 } 623 }
622 } 624 }
623 return popular_sites_suggestions; 625 return popular_sites_suggestions;
624 } 626 }
625 627
626 void MostVisitedSites::SaveNewNTPSuggestions( 628 void MostVisitedSites::SaveNewNTPSuggestions(
627 MostVisitedSites::SuggestionsVector* personal_suggestions) { 629 MostVisitedSites::SuggestionsVector* personal_suggestions) {
628 MostVisitedSites::SuggestionsVector whitelist_suggestions = 630 MostVisitedSites::SuggestionsVector whitelist_suggestions =
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 void MostVisitedSites::NotifyMostVisitedURLsObserver() { 797 void MostVisitedSites::NotifyMostVisitedURLsObserver() {
796 size_t num_suggestions = current_suggestions_.size(); 798 size_t num_suggestions = current_suggestions_.size();
797 if (received_most_visited_sites_ && received_popular_sites_ && 799 if (received_most_visited_sites_ && received_popular_sites_ &&
798 !recorded_uma_) { 800 !recorded_uma_) {
799 RecordImpressionUMAMetrics(); 801 RecordImpressionUMAMetrics();
800 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.NumberOfTiles", num_suggestions); 802 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.NumberOfTiles", num_suggestions);
801 recorded_uma_ = true; 803 recorded_uma_ = true;
802 } 804 }
803 std::vector<base::string16> titles; 805 std::vector<base::string16> titles;
804 std::vector<std::string> urls; 806 std::vector<std::string> urls;
807 std::vector<std::string> whitelist_icon_paths;
805 titles.reserve(num_suggestions); 808 titles.reserve(num_suggestions);
806 urls.reserve(num_suggestions); 809 urls.reserve(num_suggestions);
807 for (const auto& suggestion : current_suggestions_) { 810 for (const auto& suggestion : current_suggestions_) {
808 titles.push_back(suggestion->title); 811 titles.push_back(suggestion->title);
809 urls.push_back(suggestion->url.spec()); 812 urls.push_back(suggestion->url.spec());
813 whitelist_icon_paths.push_back(suggestion->whitelist_icon_path.value());
810 } 814 }
811 JNIEnv* env = AttachCurrentThread(); 815 JNIEnv* env = AttachCurrentThread();
812 DCHECK_EQ(titles.size(), urls.size()); 816 DCHECK_EQ(titles.size(), urls.size());
813 Java_MostVisitedURLsObserver_onMostVisitedURLsAvailable( 817 Java_MostVisitedURLsObserver_onMostVisitedURLsAvailable(
814 env, observer_.obj(), ToJavaArrayOfStrings(env, titles).obj(), 818 env, observer_.obj(), ToJavaArrayOfStrings(env, titles).obj(),
815 ToJavaArrayOfStrings(env, urls).obj()); 819 ToJavaArrayOfStrings(env, urls).obj(),
820 ToJavaArrayOfStrings(env, whitelist_icon_paths).obj());
816 } 821 }
817 822
818 void MostVisitedSites::OnPopularSitesAvailable(bool success) { 823 void MostVisitedSites::OnPopularSitesAvailable(bool success) {
819 received_popular_sites_ = true; 824 received_popular_sites_ = true;
820 825
821 if (!success) { 826 if (!success) {
822 LOG(WARNING) << "Download of popular sites failed"; 827 LOG(WARNING) << "Download of popular sites failed";
823 return; 828 return;
824 } 829 }
825 830
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 } 867 }
863 } 868 }
864 869
865 static jlong Init(JNIEnv* env, 870 static jlong Init(JNIEnv* env,
866 const JavaParamRef<jobject>& obj, 871 const JavaParamRef<jobject>& obj,
867 const JavaParamRef<jobject>& jprofile) { 872 const JavaParamRef<jobject>& jprofile) {
868 MostVisitedSites* most_visited_sites = 873 MostVisitedSites* most_visited_sites =
869 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); 874 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile));
870 return reinterpret_cast<intptr_t>(most_visited_sites); 875 return reinterpret_cast<intptr_t>(most_visited_sites);
871 } 876 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698