OLD | NEW |
---|---|
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 Loading... | |
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() {} |
Marc Treib
2016/03/16 18:24:47
Please initialize provider_index (it has an undefi
| |
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 Loading... | |
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 MostVisitedSites::Suggestion suggestion; |
Marc Treib
2016/03/16 18:24:47
You don't need "MostVisitedSites::", you're alread
| |
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(make_scoped_ptr(&suggestion)); | |
Bernhard Bauer
2016/03/16 18:16:36
You can't take ownership of an object on the stack
atanasova
2016/03/16 18:43:07
Done.
| |
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 Loading... | |
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 MostVisitedSites::Suggestion generated_suggestion; |
529 base::UTF8ToUTF16(suggestion.title()), suggestion.url(), | 517 generated_suggestion.title = base::UTF8ToUTF16(suggestion.title()); |
530 SUGGESTIONS_SERVICE, | 518 generated_suggestion.url = GURL(suggestion.url()); |
531 suggestion.providers_size() > 0 ? suggestion.providers(0) : -1))); | 519 generated_suggestion.source = SUGGESTIONS_SERVICE; |
520 generated_suggestion.provider_index = | |
521 suggestion.providers_size() > 0 ? suggestion.providers(0) : -1; | |
522 | |
523 suggestions.push_back(make_scoped_ptr(&generated_suggestion)); | |
532 } | 524 } |
533 | 525 |
534 received_most_visited_sites_ = true; | 526 received_most_visited_sites_ = true; |
535 mv_source_ = SUGGESTIONS_SERVICE; | 527 mv_source_ = SUGGESTIONS_SERVICE; |
536 SaveNewNTPSuggestions(&suggestions); | 528 SaveNewNTPSuggestions(&suggestions); |
537 NotifyMostVisitedURLsObserver(); | 529 NotifyMostVisitedURLsObserver(); |
538 } | 530 } |
539 | 531 |
540 MostVisitedSites::SuggestionsVector | 532 MostVisitedSites::SuggestionsVector |
541 MostVisitedSites::CreateWhitelistEntryPointSuggestions( | 533 MostVisitedSites::CreateWhitelistEntryPointSuggestions( |
(...skipping 23 matching lines...) Expand all Loading... | |
565 if (personal_hosts.find(whitelist->entry_point().host()) != | 557 if (personal_hosts.find(whitelist->entry_point().host()) != |
566 personal_hosts.end()) | 558 personal_hosts.end()) |
567 continue; | 559 continue; |
568 | 560 |
569 // Skip whitelist entry points that are manually blocked. | 561 // Skip whitelist entry points that are manually blocked. |
570 if (url_filter->GetFilteringBehaviorForURL(whitelist->entry_point()) == | 562 if (url_filter->GetFilteringBehaviorForURL(whitelist->entry_point()) == |
571 SupervisedUserURLFilter::FilteringBehavior::BLOCK) { | 563 SupervisedUserURLFilter::FilteringBehavior::BLOCK) { |
572 continue; | 564 continue; |
573 } | 565 } |
574 | 566 |
575 whitelist_suggestions.push_back(make_scoped_ptr(new Suggestion( | 567 MostVisitedSites::Suggestion suggestion; |
576 whitelist->title(), whitelist->entry_point(), WHITELIST))); | 568 suggestion.title = whitelist->title(); |
569 suggestion.url = whitelist->entry_point(); | |
570 suggestion.source = WHITELIST; | |
571 suggestion.whitelist_icon_path = whitelist->large_icon_path(); | |
572 | |
573 whitelist_suggestions.push_back(make_scoped_ptr(&suggestion)); | |
577 if (whitelist_suggestions.size() >= num_whitelist_suggestions) | 574 if (whitelist_suggestions.size() >= num_whitelist_suggestions) |
578 break; | 575 break; |
579 } | 576 } |
580 | 577 |
581 return whitelist_suggestions; | 578 return whitelist_suggestions; |
582 } | 579 } |
583 | 580 |
584 MostVisitedSites::SuggestionsVector | 581 MostVisitedSites::SuggestionsVector |
585 MostVisitedSites::CreatePopularSitesSuggestions( | 582 MostVisitedSites::CreatePopularSitesSuggestions( |
586 const MostVisitedSites::SuggestionsVector& personal_suggestions, | 583 const MostVisitedSites::SuggestionsVector& personal_suggestions, |
(...skipping 20 matching lines...) Expand all Loading... | |
607 scoped_refptr<TopSites> top_sites(TopSitesFactory::GetForProfile(profile_)); | 604 scoped_refptr<TopSites> top_sites(TopSitesFactory::GetForProfile(profile_)); |
608 for (const PopularSites::Site& popular_site : popular_sites_->sites()) { | 605 for (const PopularSites::Site& popular_site : popular_sites_->sites()) { |
609 // Skip blacklisted sites. | 606 // Skip blacklisted sites. |
610 if (top_sites && top_sites->IsBlacklisted(popular_site.url)) | 607 if (top_sites && top_sites->IsBlacklisted(popular_site.url)) |
611 continue; | 608 continue; |
612 std::string host = popular_site.url.host(); | 609 std::string host = popular_site.url.host(); |
613 // Skip suggestions already present in personal or whitelists. | 610 // Skip suggestions already present in personal or whitelists. |
614 if (hosts.find(host) != hosts.end()) | 611 if (hosts.find(host) != hosts.end()) |
615 continue; | 612 continue; |
616 | 613 |
617 popular_sites_suggestions.push_back(make_scoped_ptr( | 614 MostVisitedSites::Suggestion suggestion; |
618 new Suggestion(popular_site.title, popular_site.url, POPULAR))); | 615 suggestion.title = popular_site.title; |
616 suggestion.url = GURL(popular_site.url); | |
617 suggestion.source = POPULAR; | |
618 | |
619 popular_sites_suggestions.push_back(make_scoped_ptr(&suggestion)); | |
619 if (popular_sites_suggestions.size() >= num_popular_sites_suggestions) | 620 if (popular_sites_suggestions.size() >= num_popular_sites_suggestions) |
620 break; | 621 break; |
621 } | 622 } |
622 } | 623 } |
623 return popular_sites_suggestions; | 624 return popular_sites_suggestions; |
624 } | 625 } |
625 | 626 |
626 void MostVisitedSites::SaveNewNTPSuggestions( | 627 void MostVisitedSites::SaveNewNTPSuggestions( |
627 MostVisitedSites::SuggestionsVector* personal_suggestions) { | 628 MostVisitedSites::SuggestionsVector* personal_suggestions) { |
628 MostVisitedSites::SuggestionsVector whitelist_suggestions = | 629 MostVisitedSites::SuggestionsVector whitelist_suggestions = |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
795 void MostVisitedSites::NotifyMostVisitedURLsObserver() { | 796 void MostVisitedSites::NotifyMostVisitedURLsObserver() { |
796 size_t num_suggestions = current_suggestions_.size(); | 797 size_t num_suggestions = current_suggestions_.size(); |
797 if (received_most_visited_sites_ && received_popular_sites_ && | 798 if (received_most_visited_sites_ && received_popular_sites_ && |
798 !recorded_uma_) { | 799 !recorded_uma_) { |
799 RecordImpressionUMAMetrics(); | 800 RecordImpressionUMAMetrics(); |
800 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.NumberOfTiles", num_suggestions); | 801 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.NumberOfTiles", num_suggestions); |
801 recorded_uma_ = true; | 802 recorded_uma_ = true; |
802 } | 803 } |
803 std::vector<base::string16> titles; | 804 std::vector<base::string16> titles; |
804 std::vector<std::string> urls; | 805 std::vector<std::string> urls; |
806 std::vector<std::string> whitelist_icon_paths; | |
805 titles.reserve(num_suggestions); | 807 titles.reserve(num_suggestions); |
806 urls.reserve(num_suggestions); | 808 urls.reserve(num_suggestions); |
807 for (const auto& suggestion : current_suggestions_) { | 809 for (const auto& suggestion : current_suggestions_) { |
808 titles.push_back(suggestion->title); | 810 titles.push_back(suggestion->title); |
809 urls.push_back(suggestion->url.spec()); | 811 urls.push_back(suggestion->url.spec()); |
812 whitelist_icon_paths.push_back(suggestion->whitelist_icon_path.value()); | |
810 } | 813 } |
811 JNIEnv* env = AttachCurrentThread(); | 814 JNIEnv* env = AttachCurrentThread(); |
812 DCHECK_EQ(titles.size(), urls.size()); | 815 DCHECK_EQ(titles.size(), urls.size()); |
813 Java_MostVisitedURLsObserver_onMostVisitedURLsAvailable( | 816 Java_MostVisitedURLsObserver_onMostVisitedURLsAvailable( |
814 env, observer_.obj(), ToJavaArrayOfStrings(env, titles).obj(), | 817 env, observer_.obj(), ToJavaArrayOfStrings(env, titles).obj(), |
815 ToJavaArrayOfStrings(env, urls).obj()); | 818 ToJavaArrayOfStrings(env, urls).obj(), |
819 ToJavaArrayOfStrings(env, whitelist_icon_paths).obj()); | |
816 } | 820 } |
817 | 821 |
818 void MostVisitedSites::OnPopularSitesAvailable(bool success) { | 822 void MostVisitedSites::OnPopularSitesAvailable(bool success) { |
819 received_popular_sites_ = true; | 823 received_popular_sites_ = true; |
820 | 824 |
821 if (!success) { | 825 if (!success) { |
822 LOG(WARNING) << "Download of popular sites failed"; | 826 LOG(WARNING) << "Download of popular sites failed"; |
823 return; | 827 return; |
824 } | 828 } |
825 | 829 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
862 } | 866 } |
863 } | 867 } |
864 | 868 |
865 static jlong Init(JNIEnv* env, | 869 static jlong Init(JNIEnv* env, |
866 const JavaParamRef<jobject>& obj, | 870 const JavaParamRef<jobject>& obj, |
867 const JavaParamRef<jobject>& jprofile) { | 871 const JavaParamRef<jobject>& jprofile) { |
868 MostVisitedSites* most_visited_sites = | 872 MostVisitedSites* most_visited_sites = |
869 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); | 873 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); |
870 return reinterpret_cast<intptr_t>(most_visited_sites); | 874 return reinterpret_cast<intptr_t>(most_visited_sites); |
871 } | 875 } |
OLD | NEW |