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