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 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 451 scoped_refptr<TopSites> top_sites = TopSitesFactory::GetForProfile(profile_); | 451 scoped_refptr<TopSites> top_sites = TopSitesFactory::GetForProfile(profile_); |
| 452 if (!top_sites) | 452 if (!top_sites) |
| 453 return; | 453 return; |
| 454 | 454 |
| 455 top_sites->GetMostVisitedURLs( | 455 top_sites->GetMostVisitedURLs( |
| 456 base::Bind(&MostVisitedSites::OnMostVisitedURLsAvailable, | 456 base::Bind(&MostVisitedSites::OnMostVisitedURLsAvailable, |
| 457 weak_ptr_factory_.GetWeakPtr()), | 457 weak_ptr_factory_.GetWeakPtr()), |
| 458 false); | 458 false); |
| 459 } | 459 } |
| 460 | 460 |
| 461 base::FilePath MostVisitedSites::GetWhitelistLargeIconPath(const GURL& url) { | |
| 462 SupervisedUserService* supervised_user_service = | |
| 463 SupervisedUserServiceFactory::GetForProfile(profile_); | |
| 464 | |
| 465 for (const auto& whitelist : supervised_user_service->whitelists()) { | |
| 466 if (whitelist->entry_point().GetContent() == url.GetContent()) | |
|
Bernhard Bauer
2016/03/17 15:49:00
Hm... content is everything after the scheme, so i
atanasova
2016/03/17 16:02:08
Marc and I discussed in the previous comments that
Marc Treib
2016/03/17 16:29:02
I think Bernhard's suggesting to use less than the
Bernhard Bauer
2016/03/17 17:44:30
Exactly. And in particular, I'd like to explicitly
atanasova
2016/03/22 12:21:49
Changed to use host+path as discussed here and in
| |
| 467 return whitelist->large_icon_path(); | |
| 468 } | |
| 469 return base::FilePath(); | |
| 470 } | |
| 471 | |
| 461 void MostVisitedSites::OnMostVisitedURLsAvailable( | 472 void MostVisitedSites::OnMostVisitedURLsAvailable( |
| 462 const history::MostVisitedURLList& visited_list) { | 473 const history::MostVisitedURLList& visited_list) { |
| 463 SupervisedUserURLFilter* url_filter = | 474 SupervisedUserURLFilter* url_filter = |
| 464 SupervisedUserServiceFactory::GetForProfile(profile_) | 475 SupervisedUserServiceFactory::GetForProfile(profile_) |
| 465 ->GetURLFilterForUIThread(); | 476 ->GetURLFilterForUIThread(); |
| 477 | |
| 466 MostVisitedSites::SuggestionsVector suggestions; | 478 MostVisitedSites::SuggestionsVector suggestions; |
| 467 size_t num_tiles = | 479 size_t num_tiles = |
| 468 std::min(visited_list.size(), static_cast<size_t>(num_sites_)); | 480 std::min(visited_list.size(), static_cast<size_t>(num_sites_)); |
| 469 for (size_t i = 0; i < num_tiles; ++i) { | 481 for (size_t i = 0; i < num_tiles; ++i) { |
| 470 const history::MostVisitedURL& visited = visited_list[i]; | 482 const history::MostVisitedURL& visited = visited_list[i]; |
| 471 if (visited.url.is_empty()) { | 483 if (visited.url.is_empty()) { |
| 472 num_tiles = i; | 484 num_tiles = i; |
| 473 break; // This is the signal that there are no more real visited sites. | 485 break; // This is the signal that there are no more real visited sites. |
| 474 } | 486 } |
| 475 if (url_filter->GetFilteringBehaviorForURL(visited.url) == | 487 if (url_filter->GetFilteringBehaviorForURL(visited.url) == |
| 476 SupervisedUserURLFilter::FilteringBehavior::BLOCK) { | 488 SupervisedUserURLFilter::FilteringBehavior::BLOCK) { |
| 477 continue; | 489 continue; |
| 478 } | 490 } |
| 479 | 491 |
| 480 scoped_ptr<Suggestion> suggestion(make_scoped_ptr(new Suggestion())); | 492 scoped_ptr<Suggestion> suggestion(make_scoped_ptr(new Suggestion())); |
| 481 suggestion->title = visited.title; | 493 suggestion->title = visited.title; |
| 482 suggestion->url = visited.url; | 494 suggestion->url = visited.url; |
| 483 suggestion->source = TOP_SITES; | 495 suggestion->source = TOP_SITES; |
| 496 suggestion->whitelist_icon_path = GetWhitelistLargeIconPath(visited.url); | |
| 484 | 497 |
| 485 suggestions.push_back(std::move(suggestion)); | 498 suggestions.push_back(std::move(suggestion)); |
| 486 } | 499 } |
| 487 | 500 |
| 488 received_most_visited_sites_ = true; | 501 received_most_visited_sites_ = true; |
| 489 mv_source_ = TOP_SITES; | 502 mv_source_ = TOP_SITES; |
| 490 SaveNewNTPSuggestions(&suggestions); | 503 SaveNewNTPSuggestions(&suggestions); |
| 491 NotifyMostVisitedURLsObserver(); | 504 NotifyMostVisitedURLsObserver(); |
| 492 } | 505 } |
| 493 | 506 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 511 if (url_filter->GetFilteringBehaviorForURL(GURL(suggestion.url())) == | 524 if (url_filter->GetFilteringBehaviorForURL(GURL(suggestion.url())) == |
| 512 SupervisedUserURLFilter::FilteringBehavior::BLOCK) { | 525 SupervisedUserURLFilter::FilteringBehavior::BLOCK) { |
| 513 continue; | 526 continue; |
| 514 } | 527 } |
| 515 | 528 |
| 516 scoped_ptr<Suggestion> generated_suggestion( | 529 scoped_ptr<Suggestion> generated_suggestion( |
| 517 make_scoped_ptr(new Suggestion())); | 530 make_scoped_ptr(new Suggestion())); |
| 518 generated_suggestion->title = base::UTF8ToUTF16(suggestion.title()); | 531 generated_suggestion->title = base::UTF8ToUTF16(suggestion.title()); |
| 519 generated_suggestion->url = GURL(suggestion.url()); | 532 generated_suggestion->url = GURL(suggestion.url()); |
| 520 generated_suggestion->source = SUGGESTIONS_SERVICE; | 533 generated_suggestion->source = SUGGESTIONS_SERVICE; |
| 534 generated_suggestion->whitelist_icon_path = GetWhitelistLargeIconPath( | |
| 535 GURL(suggestion.url())); | |
| 521 if (suggestion.providers_size() > 0) | 536 if (suggestion.providers_size() > 0) |
| 522 generated_suggestion->provider_index = suggestion.providers(0); | 537 generated_suggestion->provider_index = suggestion.providers(0); |
| 523 | 538 |
| 524 suggestions.push_back(std::move(generated_suggestion)); | 539 suggestions.push_back(std::move(generated_suggestion)); |
| 525 } | 540 } |
| 526 | 541 |
| 527 received_most_visited_sites_ = true; | 542 received_most_visited_sites_ = true; |
| 528 mv_source_ = SUGGESTIONS_SERVICE; | 543 mv_source_ = SUGGESTIONS_SERVICE; |
| 529 SaveNewNTPSuggestions(&suggestions); | 544 SaveNewNTPSuggestions(&suggestions); |
| 530 NotifyMostVisitedURLsObserver(); | 545 NotifyMostVisitedURLsObserver(); |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 867 } | 882 } |
| 868 } | 883 } |
| 869 | 884 |
| 870 static jlong Init(JNIEnv* env, | 885 static jlong Init(JNIEnv* env, |
| 871 const JavaParamRef<jobject>& obj, | 886 const JavaParamRef<jobject>& obj, |
| 872 const JavaParamRef<jobject>& jprofile) { | 887 const JavaParamRef<jobject>& jprofile) { |
| 873 MostVisitedSites* most_visited_sites = | 888 MostVisitedSites* most_visited_sites = |
| 874 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); | 889 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); |
| 875 return reinterpret_cast<intptr_t>(most_visited_sites); | 890 return reinterpret_cast<intptr_t>(most_visited_sites); |
| 876 } | 891 } |
| OLD | NEW |