Chromium Code Reviews| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 for (size_t i = 0; i < num_tiles; ++i) { | 151 for (size_t i = 0; i < num_tiles; ++i) { |
| 152 bool is_personal = false; | 152 bool is_personal = false; |
| 153 if (source_list->GetBoolean(i, &is_personal) && !is_personal) | 153 if (source_list->GetBoolean(i, &is_personal) && !is_personal) |
| 154 return true; | 154 return true; |
| 155 } | 155 } |
| 156 // The whole grid is already filled with personal suggestions, no point in | 156 // The whole grid is already filled with personal suggestions, no point in |
| 157 // bothering with popular ones. | 157 // bothering with popular ones. |
| 158 return false; | 158 return false; |
| 159 } | 159 } |
| 160 | 160 |
| 161 bool URLsEquals(const GURL& url1, const GURL& url2) { | |
|
Marc Treib
2016/03/22 12:25:38
nit: AreURLsEquivalent or something? We're not act
atanasova
2016/03/22 14:14:10
Done.
| |
| 162 std::string truncated_url1 = url1.host() + url1.path(); | |
| 163 std::string truncated_url2 = url2.host() + url2.path(); | |
| 164 return truncated_url1 == truncated_url2; | |
|
Marc Treib
2016/03/22 12:25:38
I'd just compare host() and path() separately, tha
atanasova
2016/03/22 14:14:10
Done.
| |
| 165 } | |
| 166 | |
| 161 } // namespace | 167 } // namespace |
| 162 | 168 |
| 163 MostVisitedSites::Suggestion::Suggestion() : provider_index(-1) {} | 169 MostVisitedSites::Suggestion::Suggestion() : provider_index(-1) {} |
| 164 | 170 |
| 165 MostVisitedSites::Suggestion::~Suggestion() {} | 171 MostVisitedSites::Suggestion::~Suggestion() {} |
| 166 | 172 |
| 167 std::string MostVisitedSites::Suggestion::GetSourceHistogramName() const { | 173 std::string MostVisitedSites::Suggestion::GetSourceHistogramName() const { |
| 168 switch (source) { | 174 switch (source) { |
| 169 case MostVisitedSites::TOP_SITES: | 175 case MostVisitedSites::TOP_SITES: |
| 170 return kHistogramClientName; | 176 return kHistogramClientName; |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 422 scoped_refptr<TopSites> top_sites = TopSitesFactory::GetForProfile(profile_); | 428 scoped_refptr<TopSites> top_sites = TopSitesFactory::GetForProfile(profile_); |
| 423 if (!top_sites) | 429 if (!top_sites) |
| 424 return; | 430 return; |
| 425 | 431 |
| 426 top_sites->GetMostVisitedURLs( | 432 top_sites->GetMostVisitedURLs( |
| 427 base::Bind(&MostVisitedSites::OnMostVisitedURLsAvailable, | 433 base::Bind(&MostVisitedSites::OnMostVisitedURLsAvailable, |
| 428 weak_ptr_factory_.GetWeakPtr()), | 434 weak_ptr_factory_.GetWeakPtr()), |
| 429 false); | 435 false); |
| 430 } | 436 } |
| 431 | 437 |
| 438 base::FilePath MostVisitedSites::GetWhitelistLargeIconPath(const GURL& url) { | |
| 439 SupervisedUserService* supervised_user_service = | |
| 440 SupervisedUserServiceFactory::GetForProfile(profile_); | |
| 441 | |
| 442 for (const auto& whitelist : supervised_user_service->whitelists()) { | |
| 443 if (URLsEquals(whitelist->entry_point(), url)) | |
| 444 return whitelist->large_icon_path(); | |
| 445 } | |
| 446 return base::FilePath(); | |
| 447 } | |
| 448 | |
| 432 void MostVisitedSites::OnMostVisitedURLsAvailable( | 449 void MostVisitedSites::OnMostVisitedURLsAvailable( |
| 433 const history::MostVisitedURLList& visited_list) { | 450 const history::MostVisitedURLList& visited_list) { |
| 434 SupervisedUserURLFilter* url_filter = | 451 SupervisedUserURLFilter* url_filter = |
| 435 SupervisedUserServiceFactory::GetForProfile(profile_) | 452 SupervisedUserServiceFactory::GetForProfile(profile_) |
| 436 ->GetURLFilterForUIThread(); | 453 ->GetURLFilterForUIThread(); |
| 454 | |
| 437 MostVisitedSites::SuggestionsVector suggestions; | 455 MostVisitedSites::SuggestionsVector suggestions; |
| 438 size_t num_tiles = | 456 size_t num_tiles = |
| 439 std::min(visited_list.size(), static_cast<size_t>(num_sites_)); | 457 std::min(visited_list.size(), static_cast<size_t>(num_sites_)); |
| 440 for (size_t i = 0; i < num_tiles; ++i) { | 458 for (size_t i = 0; i < num_tiles; ++i) { |
| 441 const history::MostVisitedURL& visited = visited_list[i]; | 459 const history::MostVisitedURL& visited = visited_list[i]; |
| 442 if (visited.url.is_empty()) { | 460 if (visited.url.is_empty()) { |
| 443 num_tiles = i; | 461 num_tiles = i; |
| 444 break; // This is the signal that there are no more real visited sites. | 462 break; // This is the signal that there are no more real visited sites. |
| 445 } | 463 } |
| 446 if (url_filter->GetFilteringBehaviorForURL(visited.url) == | 464 if (url_filter->GetFilteringBehaviorForURL(visited.url) == |
| 447 SupervisedUserURLFilter::FilteringBehavior::BLOCK) { | 465 SupervisedUserURLFilter::FilteringBehavior::BLOCK) { |
| 448 continue; | 466 continue; |
| 449 } | 467 } |
| 450 | 468 |
| 451 scoped_ptr<Suggestion> suggestion(new Suggestion()); | 469 scoped_ptr<Suggestion> suggestion(new Suggestion()); |
| 452 suggestion->title = visited.title; | 470 suggestion->title = visited.title; |
| 453 suggestion->url = visited.url; | 471 suggestion->url = visited.url; |
| 454 suggestion->source = TOP_SITES; | 472 suggestion->source = TOP_SITES; |
| 473 suggestion->whitelist_icon_path = GetWhitelistLargeIconPath(visited.url); | |
| 455 | 474 |
| 456 suggestions.push_back(std::move(suggestion)); | 475 suggestions.push_back(std::move(suggestion)); |
| 457 } | 476 } |
| 458 | 477 |
| 459 received_most_visited_sites_ = true; | 478 received_most_visited_sites_ = true; |
| 460 mv_source_ = TOP_SITES; | 479 mv_source_ = TOP_SITES; |
| 461 SaveNewNTPSuggestions(&suggestions); | 480 SaveNewNTPSuggestions(&suggestions); |
| 462 NotifyMostVisitedURLsObserver(); | 481 NotifyMostVisitedURLsObserver(); |
| 463 } | 482 } |
| 464 | 483 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 481 const ChromeSuggestion& suggestion = suggestions_profile.suggestions(i); | 500 const ChromeSuggestion& suggestion = suggestions_profile.suggestions(i); |
| 482 if (url_filter->GetFilteringBehaviorForURL(GURL(suggestion.url())) == | 501 if (url_filter->GetFilteringBehaviorForURL(GURL(suggestion.url())) == |
| 483 SupervisedUserURLFilter::FilteringBehavior::BLOCK) { | 502 SupervisedUserURLFilter::FilteringBehavior::BLOCK) { |
| 484 continue; | 503 continue; |
| 485 } | 504 } |
| 486 | 505 |
| 487 scoped_ptr<Suggestion> generated_suggestion(new Suggestion()); | 506 scoped_ptr<Suggestion> generated_suggestion(new Suggestion()); |
| 488 generated_suggestion->title = base::UTF8ToUTF16(suggestion.title()); | 507 generated_suggestion->title = base::UTF8ToUTF16(suggestion.title()); |
| 489 generated_suggestion->url = GURL(suggestion.url()); | 508 generated_suggestion->url = GURL(suggestion.url()); |
| 490 generated_suggestion->source = SUGGESTIONS_SERVICE; | 509 generated_suggestion->source = SUGGESTIONS_SERVICE; |
| 510 generated_suggestion->whitelist_icon_path = GetWhitelistLargeIconPath( | |
| 511 GURL(suggestion.url())); | |
| 491 if (suggestion.providers_size() > 0) | 512 if (suggestion.providers_size() > 0) |
| 492 generated_suggestion->provider_index = suggestion.providers(0); | 513 generated_suggestion->provider_index = suggestion.providers(0); |
| 493 | 514 |
| 494 suggestions.push_back(std::move(generated_suggestion)); | 515 suggestions.push_back(std::move(generated_suggestion)); |
| 495 } | 516 } |
| 496 | 517 |
| 497 received_most_visited_sites_ = true; | 518 received_most_visited_sites_ = true; |
| 498 mv_source_ = SUGGESTIONS_SERVICE; | 519 mv_source_ = SUGGESTIONS_SERVICE; |
| 499 SaveNewNTPSuggestions(&suggestions); | 520 SaveNewNTPSuggestions(&suggestions); |
| 500 NotifyMostVisitedURLsObserver(); | 521 NotifyMostVisitedURLsObserver(); |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 840 } | 861 } |
| 841 } | 862 } |
| 842 | 863 |
| 843 static jlong Init(JNIEnv* env, | 864 static jlong Init(JNIEnv* env, |
| 844 const JavaParamRef<jobject>& obj, | 865 const JavaParamRef<jobject>& obj, |
| 845 const JavaParamRef<jobject>& jprofile) { | 866 const JavaParamRef<jobject>& jprofile) { |
| 846 MostVisitedSites* most_visited_sites = | 867 MostVisitedSites* most_visited_sites = |
| 847 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); | 868 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); |
| 848 return reinterpret_cast<intptr_t>(most_visited_sites); | 869 return reinterpret_cast<intptr_t>(most_visited_sites); |
| 849 } | 870 } |
| OLD | NEW |