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/ntp/most_visited_sites.h" | 5 #include "chrome/browser/android/ntp/most_visited_sites.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 supervised_user_service->AddObserver(this); | 184 supervised_user_service->AddObserver(this); |
185 } | 185 } |
186 | 186 |
187 MostVisitedSites::~MostVisitedSites() { | 187 MostVisitedSites::~MostVisitedSites() { |
188 SupervisedUserService* supervised_user_service = | 188 SupervisedUserService* supervised_user_service = |
189 SupervisedUserServiceFactory::GetForProfile(profile_); | 189 SupervisedUserServiceFactory::GetForProfile(profile_); |
190 supervised_user_service->RemoveObserver(this); | 190 supervised_user_service->RemoveObserver(this); |
191 } | 191 } |
192 | 192 |
193 void MostVisitedSites::SetMostVisitedURLsObserver( | 193 void MostVisitedSites::SetMostVisitedURLsObserver( |
194 MostVisitedSitesObserver* observer, int num_sites) { | 194 MostVisitedSites::Observer* observer, int num_sites) { |
195 observer_ = observer; | 195 observer_ = observer; |
196 num_sites_ = num_sites; | 196 num_sites_ = num_sites; |
197 | 197 |
198 if (ShouldShowPopularSites() && | 198 if (ShouldShowPopularSites() && |
199 NeedPopularSites(profile_->GetPrefs(), num_sites_)) { | 199 NeedPopularSites(profile_->GetPrefs(), num_sites_)) { |
200 popular_sites_.reset(new PopularSites( | 200 popular_sites_.reset(new PopularSites( |
201 profile_, | 201 profile_, |
202 GetPopularSitesCountry(), | 202 GetPopularSitesCountry(), |
203 GetPopularSitesVersion(), | 203 GetPopularSitesVersion(), |
204 false, | 204 false, |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 if (received_most_visited_sites_ && received_popular_sites_ && | 743 if (received_most_visited_sites_ && received_popular_sites_ && |
744 !recorded_uma_) { | 744 !recorded_uma_) { |
745 RecordImpressionUMAMetrics(); | 745 RecordImpressionUMAMetrics(); |
746 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.NumberOfTiles", num_suggestions); | 746 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.NumberOfTiles", num_suggestions); |
747 recorded_uma_ = true; | 747 recorded_uma_ = true; |
748 } | 748 } |
749 | 749 |
750 if (!observer_) | 750 if (!observer_) |
751 return; | 751 return; |
752 | 752 |
753 std::vector<base::string16> titles; | 753 observer_->OnMostVisitedURLsAvailable(current_suggestions_); |
754 std::vector<std::string> urls; | |
755 std::vector<std::string> whitelist_icon_paths; | |
756 titles.reserve(num_suggestions); | |
757 urls.reserve(num_suggestions); | |
758 for (const auto& suggestion : current_suggestions_) { | |
759 titles.push_back(suggestion->title); | |
760 urls.push_back(suggestion->url.spec()); | |
761 whitelist_icon_paths.push_back(suggestion->whitelist_icon_path.value()); | |
762 } | |
763 | |
764 observer_->OnMostVisitedURLsAvailable(titles, urls, whitelist_icon_paths); | |
765 } | 754 } |
766 | 755 |
767 void MostVisitedSites::OnPopularSitesAvailable(bool success) { | 756 void MostVisitedSites::OnPopularSitesAvailable(bool success) { |
768 received_popular_sites_ = true; | 757 received_popular_sites_ = true; |
769 | 758 |
770 if (!success) { | 759 if (!success) { |
771 LOG(WARNING) << "Download of popular sites failed"; | 760 LOG(WARNING) << "Download of popular sites failed"; |
772 return; | 761 return; |
773 } | 762 } |
774 | 763 |
775 if (!observer_) | 764 if (!observer_) |
776 return; | 765 return; |
777 | 766 |
778 std::vector<std::string> urls; | 767 observer_->OnPopularURLsAvailable(popular_sites_->sites()); |
779 std::vector<std::string> favicon_urls; | |
780 std::vector<std::string> large_icon_urls; | |
781 for (const PopularSites::Site& popular_site : popular_sites_->sites()) { | |
782 urls.push_back(popular_site.url.spec()); | |
783 favicon_urls.push_back(popular_site.favicon_url.spec()); | |
784 large_icon_urls.push_back(popular_site.large_icon_url.spec()); | |
785 } | |
786 observer_->OnPopularURLsAvailable(urls, favicon_urls, large_icon_urls); | |
787 QueryMostVisitedURLs(); | 768 QueryMostVisitedURLs(); |
788 } | 769 } |
789 | 770 |
790 void MostVisitedSites::RecordImpressionUMAMetrics() { | 771 void MostVisitedSites::RecordImpressionUMAMetrics() { |
791 for (size_t i = 0; i < current_suggestions_.size(); i++) { | 772 for (size_t i = 0; i < current_suggestions_.size(); i++) { |
792 std::string histogram = base::StringPrintf( | 773 std::string histogram = base::StringPrintf( |
793 "NewTabPage.SuggestionsImpression.%s", | 774 "NewTabPage.SuggestionsImpression.%s", |
794 current_suggestions_[i]->GetSourceHistogramName().c_str()); | 775 current_suggestions_[i]->GetSourceHistogramName().c_str()); |
795 LogHistogramEvent(histogram, static_cast<int>(i), num_sites_); | 776 LogHistogramEvent(histogram, static_cast<int>(i), num_sites_); |
796 } | 777 } |
797 } | 778 } |
798 | 779 |
799 void MostVisitedSites::TopSitesLoaded(TopSites* top_sites) {} | 780 void MostVisitedSites::TopSitesLoaded(TopSites* top_sites) {} |
800 | 781 |
801 void MostVisitedSites::TopSitesChanged(TopSites* top_sites, | 782 void MostVisitedSites::TopSitesChanged(TopSites* top_sites, |
802 ChangeReason change_reason) { | 783 ChangeReason change_reason) { |
803 if (mv_source_ == TOP_SITES) { | 784 if (mv_source_ == TOP_SITES) { |
804 // The displayed suggestions are invalidated. | 785 // The displayed suggestions are invalidated. |
805 InitiateTopSitesQuery(); | 786 InitiateTopSitesQuery(); |
806 } | 787 } |
807 } | 788 } |
OLD | NEW |