summaryrefslogtreecommitdiff
path: root/chromium/components/ntp_tiles/most_visited_sites.h
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/components/ntp_tiles/most_visited_sites.h')
-rw-r--r--chromium/components/ntp_tiles/most_visited_sites.h159
1 files changed, 46 insertions, 113 deletions
diff --git a/chromium/components/ntp_tiles/most_visited_sites.h b/chromium/components/ntp_tiles/most_visited_sites.h
index efbae53ff45..28f9b070df0 100644
--- a/chromium/components/ntp_tiles/most_visited_sites.h
+++ b/chromium/components/ntp_tiles/most_visited_sites.h
@@ -8,7 +8,6 @@
#include <stddef.h>
#include <memory>
-#include <string>
#include <vector>
#include "base/compiler_specific.h"
@@ -16,33 +15,23 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h"
+#include "base/strings/string16.h"
#include "components/history/core/browser/history_types.h"
#include "components/history/core/browser/top_sites_observer.h"
+#include "components/ntp_tiles/ntp_tile.h"
#include "components/ntp_tiles/popular_sites.h"
#include "components/suggestions/proto/suggestions.pb.h"
#include "components/suggestions/suggestions_service.h"
#include "url/gurl.h"
-namespace gfx {
-class Image;
-}
-
namespace history {
class TopSites;
}
-namespace suggestions {
-class SuggestionsService;
-}
-
namespace user_prefs {
class PrefRegistrySyncable;
}
-namespace variations {
-class VariationsService;
-}
-
namespace ntp_tiles {
// Shim interface for SupervisedUserService.
@@ -71,7 +60,7 @@ class MostVisitedSitesSupervisor {
// If true, |url| should not be shown on the NTP.
virtual bool IsBlocked(const GURL& url) = 0;
- // Explicit suggestions for sites to show on NTP.
+ // Explicitly-specified sites to show on NTP.
virtual std::vector<Whitelist> whitelists() = 0;
// If true, be conservative about suggesting sites from outside sources.
@@ -91,8 +80,6 @@ class MostVisitedSitesSupervisor {
class MostVisitedSites : public history::TopSitesObserver,
public MostVisitedSitesSupervisor::Observer {
public:
- struct Suggestion;
- using SuggestionsVector = std::vector<Suggestion>;
using PopularSitesVector = std::vector<PopularSites::Site>;
// The visual type of a most visited tile.
@@ -114,79 +101,39 @@ class MostVisitedSites : public history::TopSitesObserver,
NUM_TILE_TYPES,
};
- // The source of the Most Visited sites.
- // A Java counterpart will be generated for this enum.
- // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.ntp
- enum MostVisitedSource {
- // Item comes from the personal top sites list.
- TOP_SITES,
- // Item comes from the suggestions service.
- SUGGESTIONS_SERVICE,
- // Item is regionally popular.
- POPULAR,
- // Item is on an custodian-managed whitelist.
- WHITELIST
- };
-
// The observer to be notified when the list of most visited sites changes.
class Observer {
public:
- virtual void OnMostVisitedURLsAvailable(
- const SuggestionsVector& suggestions) = 0;
- virtual void OnPopularURLsAvailable(const PopularSitesVector& sites) = 0;
+ virtual void OnMostVisitedURLsAvailable(const NTPTilesVector& tiles) = 0;
+ virtual void OnPopularURLsAvailable(const PopularSitesVector& sites) {}
protected:
virtual ~Observer() {}
};
- struct Suggestion {
- base::string16 title;
- GURL url;
- MostVisitedSource source;
-
- // Only valid for source == WHITELIST (empty otherwise).
- base::FilePath whitelist_icon_path;
-
- // Only valid for source == SUGGESTIONS_SERVICE (-1 otherwise).
- int provider_index;
-
- Suggestion();
- ~Suggestion();
-
- Suggestion(Suggestion&&);
- Suggestion& operator=(Suggestion&&);
-
- private:
- DISALLOW_COPY_AND_ASSIGN(Suggestion);
- };
-
- MostVisitedSites(scoped_refptr<base::SequencedWorkerPool> blocking_pool,
- PrefService* prefs,
- const TemplateURLService* template_url_service,
- variations::VariationsService* variations_service,
- net::URLRequestContextGetter* download_context,
- const base::FilePath& popular_sites_directory,
+ // Construct a MostVisitedSites instance.
+ //
+ // |prefs| and |suggestions| are required and may not be null. |top_sites|,
+ // |popular_sites|, and |supervisor| are optional and if null the associated
+ // features will be disabled.
+ MostVisitedSites(PrefService* prefs,
scoped_refptr<history::TopSites> top_sites,
suggestions::SuggestionsService* suggestions,
+ std::unique_ptr<PopularSites> popular_sites,
MostVisitedSitesSupervisor* supervisor);
~MostVisitedSites() override;
-#if defined(OS_ANDROID)
- static bool Register(JNIEnv* env);
-#endif
-
// Does not take ownership of |observer|, which must outlive this object and
// must not be null.
void SetMostVisitedURLsObserver(Observer* observer, int num_sites);
- using ThumbnailCallback = base::Callback<
- void(bool /* is_local_thumbnail */, const SkBitmap* /* bitmap */)>;
void AddOrRemoveBlacklistedUrl(const GURL& url, bool add_url);
- void RecordTileTypeMetrics(const std::vector<int>& tile_types,
- const std::vector<int>& sources,
- const std::vector<int>& provider_indices);
- void RecordOpenedMostVisitedItem(int index, int tile_type);
+ void RecordTileTypeMetrics(const std::vector<MostVisitedTileType>& tile_types,
+ const std::vector<NTPTileSource>& sources);
+ void RecordOpenedMostVisitedItem(int index,
+ MostVisitedTileType tile_type,
+ NTPTileSource source);
// MostVisitedSitesSupervisor::Observer implementation.
void OnBlockedSitesChanged() override;
@@ -196,7 +143,7 @@ class MostVisitedSites : public history::TopSitesObserver,
private:
friend class MostVisitedSitesTest;
- void BuildCurrentSuggestions();
+ void BuildCurrentTiles();
// Initialize the query to Top Sites. Called if the SuggestionsService
// returned no data.
@@ -215,37 +162,30 @@ class MostVisitedSites : public history::TopSitesObserver,
// Takes the personal suggestions and creates whitelist entry point
// suggestions if necessary.
- SuggestionsVector CreateWhitelistEntryPointSuggestions(
- const SuggestionsVector& personal_suggestions);
-
- // Takes the personal and whitelist suggestions and creates popular
- // suggestions if necessary.
- SuggestionsVector CreatePopularSitesSuggestions(
- const SuggestionsVector& personal_suggestions,
- const SuggestionsVector& whitelist_suggestions);
+ NTPTilesVector CreateWhitelistEntryPointTiles(
+ const NTPTilesVector& personal_tiles);
- // Takes the personal suggestions, creates and merges in whitelist and popular
- // suggestions if appropriate, and saves the new suggestions.
- void SaveNewSuggestions(SuggestionsVector personal_suggestions);
+ // Takes the personal and whitelist tiles and creates popular tiles if
+ // necessary.
+ NTPTilesVector CreatePopularSitesTiles(const NTPTilesVector& personal_tiles,
+ const NTPTilesVector& whitelist_tiles);
- // Workhorse for SaveNewSuggestions above. Implemented as a separate static
- // method for ease of testing.
- static SuggestionsVector MergeSuggestions(
- SuggestionsVector personal_suggestions,
- SuggestionsVector whitelist_suggestions,
- SuggestionsVector popular_suggestions);
+ // Takes the personal tiles, creates and merges in whitelist and popular tiles
+ // if appropriate, and saves the new tiles.
+ void SaveNewTiles(NTPTilesVector personal_tiles);
- void SaveCurrentSuggestionsToPrefs();
+ // Workhorse for SaveNewTiles above. Implemented as a separate static method
+ // for ease of testing.
+ static NTPTilesVector MergeTiles(NTPTilesVector personal_tiles,
+ NTPTilesVector whitelist_tiles,
+ NTPTilesVector popular_tiles);
- // Notifies the observer about the availability of suggestions.
+ // Notifies the observer about the availability of tiles.
// Also records impressions UMA if not done already.
void NotifyMostVisitedURLsObserver();
void OnPopularSitesAvailable(bool success);
- // Records thumbnail-related UMA histogram metrics.
- void RecordThumbnailUMAMetrics();
-
// Records UMA histogram metrics related to the number of impressions.
void RecordImpressionUMAMetrics();
@@ -255,12 +195,9 @@ class MostVisitedSites : public history::TopSitesObserver,
ChangeReason change_reason) override;
PrefService* prefs_;
- const TemplateURLService* template_url_service_;
- variations::VariationsService* variations_service_;
- net::URLRequestContextGetter* download_context_;
- base::FilePath popular_sites_directory_;
scoped_refptr<history::TopSites> top_sites_;
suggestions::SuggestionsService* suggestions_service_;
+ std::unique_ptr<PopularSites> const popular_sites_;
MostVisitedSitesSupervisor* supervisor_;
Observer* observer_;
@@ -268,15 +205,15 @@ class MostVisitedSites : public history::TopSitesObserver,
// The maximum number of most visited sites to return.
int num_sites_;
- // Whether we have received an initial set of most visited sites (from either
- // TopSites or the SuggestionsService).
- bool received_most_visited_sites_;
+ // True if we are still waiting for an initial set of most visited sites (from
+ // either TopSites or the SuggestionsService).
+ bool waiting_for_most_visited_sites_;
- // Whether we have received the set of popular sites. Immediately set to true
- // if popular sites are disabled.
- bool received_popular_sites_;
+ // True if we are still waiting for the set of popular sites. Immediately set
+ // to false if popular sites are disabled, or are not required.
+ bool waiting_for_popular_sites_;
- // Whether we have recorded one-shot UMA metrics such as impressions. They are
+ // True if we have recorded one-shot UMA metrics such as impressions. They are
// recorded once both the previous flags are true.
bool recorded_uma_;
@@ -284,17 +221,13 @@ class MostVisitedSites : public history::TopSitesObserver,
suggestions::SuggestionsService::ResponseCallbackList::Subscription>
suggestions_subscription_;
- ScopedObserver<history::TopSites, history::TopSitesObserver> scoped_observer_;
-
- MostVisitedSource mv_source_;
-
- std::unique_ptr<PopularSites> popular_sites_;
+ ScopedObserver<history::TopSites, history::TopSitesObserver>
+ top_sites_observer_;
- SuggestionsVector current_suggestions_;
+ // The main source of personal tiles - either TOP_SITES or SUGGESTIONS_SEVICE.
+ NTPTileSource mv_source_;
- base::ThreadChecker thread_checker_;
- scoped_refptr<base::SequencedWorkerPool> blocking_pool_;
- scoped_refptr<base::TaskRunner> blocking_runner_;
+ NTPTilesVector current_tiles_;
// For callbacks may be run after destruction.
base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_;