Chromium Code Reviews| Index: chrome/browser/android/most_visited_sites.h |
| diff --git a/chrome/browser/android/most_visited_sites.h b/chrome/browser/android/most_visited_sites.h |
| index 4ecc9676c53e187daa9a3a4bdd2d9d32013f13d7..cd595926853fec241d0f08165ceee51433d231f0 100644 |
| --- a/chrome/browser/android/most_visited_sites.h |
| +++ b/chrome/browser/android/most_visited_sites.h |
| @@ -15,7 +15,6 @@ |
| #include "base/memory/scoped_ptr.h" |
| #include "base/memory/weak_ptr.h" |
| #include "base/scoped_observer.h" |
| -#include "chrome/browser/profiles/profile.h" |
| #include "components/history/core/browser/history_types.h" |
| #include "components/history/core/browser/top_sites_observer.h" |
| #include "components/suggestions/proto/suggestions.pb.h" |
| @@ -25,8 +24,13 @@ namespace suggestions { |
| class SuggestionsService; |
| } |
| +namespace user_prefs { |
| +class PrefRegistrySyncable; |
| +} |
| + |
| class GURL; |
| class PopularSites; |
| +class Profile; |
| // Provides the list of most visited sites and their thumbnails to Java. |
| class MostVisitedSites : public sync_driver::SyncServiceObserver, |
| @@ -53,15 +57,34 @@ class MostVisitedSites : public sync_driver::SyncServiceObserver, |
| // Registers JNI methods. |
| static bool Register(JNIEnv* env); |
| - private: |
| - friend class MostVisitedSitesTest; |
| + static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| // The source of the Most Visited sites. |
| - enum MostVisitedSource { |
| - TOP_SITES, |
| - SUGGESTIONS_SERVICE |
| + enum MostVisitedSource { TOP_SITES, SUGGESTIONS_SERVICE, POPULAR }; |
| + |
| + struct Suggestion { |
| + base::string16 title; |
| + std::string url; |
| + std::string host; |
| + MostVisitedSource source; |
| + // Only for source == SUGGESTIONS_SERVICE |
| + int provider_index; |
| + |
| + Suggestion(base::string16 title, std::string url, MostVisitedSource source); |
|
Marc Treib
2015/09/08 11:39:49
nit: Pass strings by const& ?
knn
2015/09/08 13:42:00
Done.
|
| + Suggestion(base::string16 title, |
| + std::string url, |
| + std::string host, |
| + MostVisitedSource source); |
| + Suggestion(base::string16 title, |
| + std::string url, |
| + MostVisitedSource source, |
| + int provider_index); |
| + std::string GetSourceString(); |
|
Marc Treib
2015/09/08 11:39:49
const :)
knn
2015/09/08 13:42:00
Done.
|
| }; |
| + private: |
| + friend class MostVisitedSitesTest; |
| + |
| ~MostVisitedSites() override; |
| void QueryMostVisitedURLs(); |
| @@ -77,25 +100,21 @@ class MostVisitedSites : public sync_driver::SyncServiceObserver, |
| void OnSuggestionsProfileAvailable( |
| const suggestions::SuggestionsProfile& suggestions_profile); |
| - // Adds the suggestions from |popular_sites_| into |titles| and |urls|. This |
| - // might reorder |titles| and |urls| to retain the absolute positions of the |
| - // popular suggestions. Also updates |tile_sources_| accordingly. |
| - void AddPopularSites(std::vector<base::string16>* titles, |
| - std::vector<std::string>* urls); |
| + // Takes the personal suggestions and adds popular suggestions if necessary |
| + // and reorders the suggestions based on the previously displayed order. |
| + void AddPopularSites(ScopedVector<Suggestion>* suggestions); |
| // Workhorse for AddPopularSites above. Implemented as a separate static |
| // method for ease of testing. |
| - static void AddPopularSitesImpl( |
| - int num_sites, |
| - const std::vector<base::string16>& popular_titles, |
| - const std::vector<std::string>& popular_urls, |
| - std::vector<base::string16>* titles, |
| - std::vector<std::string>* urls, |
| - std::vector<std::string>* tile_sources); |
| + static void MergeSuggestions(ScopedVector<Suggestion>* personal_suggestions, |
| + ScopedVector<Suggestion>* popular_suggestions, |
| + const std::vector<std::string>& old_sites_url, |
| + const std::vector<bool>& old_sites_is_personal, |
| + // Return value. |
| + ScopedVector<Suggestion>* merged_suggestions); |
| // Notify the Java side observer about the availability of Most Visited Urls. |
| - void NotifyMostVisitedURLsObserver(const std::vector<base::string16>& titles, |
| - const std::vector<std::string>& urls); |
| + void NotifyMostVisitedURLsObserver(ScopedVector<Suggestion>* suggestions); |
| void OnPopularSitesAvailable(bool success); |
| @@ -155,16 +174,14 @@ class MostVisitedSites : public sync_driver::SyncServiceObserver, |
| // In this case a gray tile is used as the main tile. |
| int num_empty_thumbs_; |
| - // Identifier for where each tile came from (client, server, popular). Used |
| - // for logging. |
| - std::vector<std::string> tile_sources_; |
| - |
| ScopedObserver<history::TopSites, history::TopSitesObserver> scoped_observer_; |
| MostVisitedSource mv_source_; |
| scoped_ptr<PopularSites> popular_sites_; |
| + ScopedVector<Suggestion> current_suggestions_; |
| + |
| // For callbacks may be run after destruction. |
| base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; |