| 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 std::string& 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 GURL& url, | 173 const GURL& 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 DCHECK_EQ(MostVisitedSites::WHITELIST, source); |
| 182 } |
| 183 |
| 184 MostVisitedSites::Suggestion::Suggestion(const base::string16& title, |
| 185 const GURL& url, |
| 174 MostVisitedSource source) | 186 MostVisitedSource source) |
| 175 : title(title), url(url), source(source), provider_index(-1) {} | 187 : title(title), url(url), source(source), provider_index(-1) {} |
| 176 | 188 |
| 177 MostVisitedSites::Suggestion::Suggestion(const base::string16& title, | 189 MostVisitedSites::Suggestion::Suggestion(const base::string16& title, |
| 178 const std::string& url, | 190 const std::string& url, |
| 179 MostVisitedSource source, | 191 MostVisitedSource source, |
| 180 int provider_index) | 192 int provider_index) |
| 181 : title(title), url(url), source(source), provider_index(provider_index) { | 193 : title(title), url(url), source(source), provider_index(provider_index) { |
| 182 DCHECK_EQ(MostVisitedSites::SUGGESTIONS_SERVICE, source); | 194 DCHECK_EQ(MostVisitedSites::SUGGESTIONS_SERVICE, source); |
| 183 } | 195 } |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 if (personal_hosts.find(whitelist->entry_point().host()) != | 577 if (personal_hosts.find(whitelist->entry_point().host()) != |
| 566 personal_hosts.end()) | 578 personal_hosts.end()) |
| 567 continue; | 579 continue; |
| 568 | 580 |
| 569 // Skip whitelist entry points that are manually blocked. | 581 // Skip whitelist entry points that are manually blocked. |
| 570 if (url_filter->GetFilteringBehaviorForURL(whitelist->entry_point()) == | 582 if (url_filter->GetFilteringBehaviorForURL(whitelist->entry_point()) == |
| 571 SupervisedUserURLFilter::FilteringBehavior::BLOCK) { | 583 SupervisedUserURLFilter::FilteringBehavior::BLOCK) { |
| 572 continue; | 584 continue; |
| 573 } | 585 } |
| 574 | 586 |
| 575 whitelist_suggestions.push_back(make_scoped_ptr(new Suggestion( | 587 whitelist_suggestions.push_back(make_scoped_ptr( |
| 576 whitelist->title(), whitelist->entry_point(), WHITELIST))); | 588 new Suggestion(whitelist->title(), whitelist->entry_point(), WHITELIST, |
| 589 whitelist->large_icon_path()))); |
| 577 if (whitelist_suggestions.size() >= num_whitelist_suggestions) | 590 if (whitelist_suggestions.size() >= num_whitelist_suggestions) |
| 578 break; | 591 break; |
| 579 } | 592 } |
| 580 | 593 |
| 581 return whitelist_suggestions; | 594 return whitelist_suggestions; |
| 582 } | 595 } |
| 583 | 596 |
| 584 MostVisitedSites::SuggestionsVector | 597 MostVisitedSites::SuggestionsVector |
| 585 MostVisitedSites::CreatePopularSitesSuggestions( | 598 MostVisitedSites::CreatePopularSitesSuggestions( |
| 586 const MostVisitedSites::SuggestionsVector& personal_suggestions, | 599 const MostVisitedSites::SuggestionsVector& personal_suggestions, |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 void MostVisitedSites::NotifyMostVisitedURLsObserver() { | 808 void MostVisitedSites::NotifyMostVisitedURLsObserver() { |
| 796 size_t num_suggestions = current_suggestions_.size(); | 809 size_t num_suggestions = current_suggestions_.size(); |
| 797 if (received_most_visited_sites_ && received_popular_sites_ && | 810 if (received_most_visited_sites_ && received_popular_sites_ && |
| 798 !recorded_uma_) { | 811 !recorded_uma_) { |
| 799 RecordImpressionUMAMetrics(); | 812 RecordImpressionUMAMetrics(); |
| 800 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.NumberOfTiles", num_suggestions); | 813 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.NumberOfTiles", num_suggestions); |
| 801 recorded_uma_ = true; | 814 recorded_uma_ = true; |
| 802 } | 815 } |
| 803 std::vector<base::string16> titles; | 816 std::vector<base::string16> titles; |
| 804 std::vector<std::string> urls; | 817 std::vector<std::string> urls; |
| 818 std::vector<std::string> large_icon_paths; |
| 805 titles.reserve(num_suggestions); | 819 titles.reserve(num_suggestions); |
| 806 urls.reserve(num_suggestions); | 820 urls.reserve(num_suggestions); |
| 807 for (const auto& suggestion : current_suggestions_) { | 821 for (const auto& suggestion : current_suggestions_) { |
| 808 titles.push_back(suggestion->title); | 822 titles.push_back(suggestion->title); |
| 809 urls.push_back(suggestion->url.spec()); | 823 urls.push_back(suggestion->url.spec()); |
| 824 large_icon_paths.push_back(suggestion->large_icon_path.value()); |
| 810 } | 825 } |
| 811 JNIEnv* env = AttachCurrentThread(); | 826 JNIEnv* env = AttachCurrentThread(); |
| 812 DCHECK_EQ(titles.size(), urls.size()); | 827 DCHECK_EQ(titles.size(), urls.size()); |
| 813 Java_MostVisitedURLsObserver_onMostVisitedURLsAvailable( | 828 Java_MostVisitedURLsObserver_onMostVisitedURLsAvailable( |
| 814 env, observer_.obj(), ToJavaArrayOfStrings(env, titles).obj(), | 829 env, observer_.obj(), ToJavaArrayOfStrings(env, titles).obj(), |
| 815 ToJavaArrayOfStrings(env, urls).obj()); | 830 ToJavaArrayOfStrings(env, urls).obj(), |
| 831 ToJavaArrayOfStrings(env, large_icon_paths).obj()); |
| 816 } | 832 } |
| 817 | 833 |
| 818 void MostVisitedSites::OnPopularSitesAvailable(bool success) { | 834 void MostVisitedSites::OnPopularSitesAvailable(bool success) { |
| 819 received_popular_sites_ = true; | 835 received_popular_sites_ = true; |
| 820 | 836 |
| 821 if (!success) { | 837 if (!success) { |
| 822 LOG(WARNING) << "Download of popular sites failed"; | 838 LOG(WARNING) << "Download of popular sites failed"; |
| 823 return; | 839 return; |
| 824 } | 840 } |
| 825 | 841 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 } | 878 } |
| 863 } | 879 } |
| 864 | 880 |
| 865 static jlong Init(JNIEnv* env, | 881 static jlong Init(JNIEnv* env, |
| 866 const JavaParamRef<jobject>& obj, | 882 const JavaParamRef<jobject>& obj, |
| 867 const JavaParamRef<jobject>& jprofile) { | 883 const JavaParamRef<jobject>& jprofile) { |
| 868 MostVisitedSites* most_visited_sites = | 884 MostVisitedSites* most_visited_sites = |
| 869 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); | 885 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); |
| 870 return reinterpret_cast<intptr_t>(most_visited_sites); | 886 return reinterpret_cast<intptr_t>(most_visited_sites); |
| 871 } | 887 } |
| OLD | NEW |