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..b2bb66288456b89a8dcc0223b03e9546a440459f 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,36 @@ 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 { |
|
Bernhard Bauer
2015/09/08 15:44:25
Can you make this private and only forward-declare
knn
2015/09/09 09:35:38
Made private but can't forward declare as it is us
|
| + base::string16 title; |
| + std::string url; |
| + std::string host; |
| + MostVisitedSource source; |
| + // Only for source == SUGGESTIONS_SERVICE |
|
Bernhard Bauer
2015/09/08 15:44:25
Document that it's -1 otherwise? (Or at least that
knn
2015/09/09 09:35:38
Done.
|
| + int provider_index; |
| + |
| + Suggestion(const base::string16& title, |
| + const std::string& url, |
| + MostVisitedSource source); |
| + Suggestion(const base::string16& title, |
| + const std::string& url, |
| + const std::string& host, |
| + MostVisitedSource source); |
| + Suggestion(const base::string16& title, |
| + const std::string& url, |
| + MostVisitedSource source, |
| + int provider_index); |
|
Bernhard Bauer
2015/09/08 15:44:25
Add a destructor?
knn
2015/09/09 09:35:38
Done. Just curious, whether this serves any purpos
Marc Treib
2015/09/09 09:58:42
Some trybots check that "non-trivial" structs have
|
| + std::string GetSourceHistogramName() const; |
|
Bernhard Bauer
2015/09/08 15:44:25
Add DISALLOW_COPY_AND_ASSIGN if you are not using
knn
2015/09/09 09:35:38
Done.
|
| }; |
| + private: |
| + friend class MostVisitedSitesTest; |
| + |
| ~MostVisitedSites() override; |
| void QueryMostVisitedURLs(); |
| @@ -77,25 +102,20 @@ 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 ScopedVector<Suggestion> 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); |
| // 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(); |
| void OnPopularSitesAvailable(bool success); |
| @@ -155,16 +175,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_; |