 Chromium Code Reviews
 Chromium Code Reviews Issue 2570783003:
  [Popular Sites] Split PopularSites interface and PopularSitesImpl  (Closed)
    
  
    Issue 2570783003:
  [Popular Sites] Split PopularSites interface and PopularSitesImpl  (Closed) 
  | Index: components/ntp_tiles/popular_sites.h | 
| diff --git a/components/ntp_tiles/popular_sites.h b/components/ntp_tiles/popular_sites.h | 
| index 639aedf4046614a51c46c6e547cf2b4d43a51c3d..e53fc3ea81e1aac2f3fa72fb0a9ddb92784f80e5 100644 | 
| --- a/components/ntp_tiles/popular_sites.h | 
| +++ b/components/ntp_tiles/popular_sites.h | 
| @@ -43,10 +43,9 @@ using ParseJSONCallback = base::Callback<void( | 
| const base::Callback<void(std::unique_ptr<base::Value>)>& success_callback, | 
| const base::Callback<void(const std::string&)>& error_callback)>; | 
| -// Downloads and provides a list of suggested popular sites, for display on | 
| -// the NTP when there are not enough personalized tiles. Caches the downloaded | 
| -// file on disk to avoid re-downloading on every startup. | 
| -class PopularSites : public net::URLFetcherDelegate { | 
| +// Interface to provide a list of suggested popular sites, for display on the | 
| +// NTP when there are not enough personalized tiles. | 
| +class PopularSites { | 
| public: | 
| struct Site { | 
| Site(const base::string16& title, | 
| @@ -64,15 +63,10 @@ class PopularSites : public net::URLFetcherDelegate { | 
| GURL thumbnail_url; | 
| }; | 
| + using SitesVector = std::vector<Site>; | 
| using FinishedCallback = base::Callback<void(bool /* success */)>; | 
| - PopularSites(const scoped_refptr<base::SequencedWorkerPool>& blocking_pool, | 
| - PrefService* prefs, | 
| - const TemplateURLService* template_url_service, | 
| - variations::VariationsService* variations_service, | 
| - net::URLRequestContextGetter* download_context, | 
| - const base::FilePath& directory, | 
| - ParseJSONCallback parse_json); | 
| + virtual ~PopularSites() = default; | 
| 
sfiera
2016/12/13 10:53:57
I think some bots are going to complain about this
 
mastiz
2016/12/13 12:14:56
Acknowledged, no complaints so far.
 | 
| // Starts the process of retrieving popular sites. When they are available, | 
| // invokes |callback| with the result, on the same thread as the caller. Never | 
| @@ -83,11 +77,33 @@ class PopularSites : public net::URLFetcherDelegate { | 
| // if it already exists on disk. | 
| // | 
| // Must be called at most once on a given PopularSites object. | 
| - void StartFetch(bool force_download, const FinishedCallback& callback); | 
| + // TODO(mastiz): Remove this restriction? | 
| + virtual void StartFetch(bool force_download, | 
| + const FinishedCallback& callback) = 0; | 
| - ~PopularSites() override; | 
| + // Returns the list of available sites. | 
| + virtual const SitesVector& sites() const = 0; | 
| +}; | 
| - const std::vector<Site>& sites() const { return sites_; } | 
| +// Actual (non-test) implementation of the PopularSites interface. Caches the | 
| +// downloaded file on disk to avoid re-downloading on every startup. | 
| +class PopularSitesImpl : public PopularSites, public net::URLFetcherDelegate { | 
| + public: | 
| + PopularSitesImpl( | 
| + const scoped_refptr<base::SequencedWorkerPool>& blocking_pool, | 
| + PrefService* prefs, | 
| + const TemplateURLService* template_url_service, | 
| + variations::VariationsService* variations_service, | 
| + net::URLRequestContextGetter* download_context, | 
| + const base::FilePath& directory, | 
| + ParseJSONCallback parse_json); | 
| + | 
| + ~PopularSitesImpl() override; | 
| + | 
| + // PopularSites implementation. | 
| + void StartFetch(bool force_download, | 
| + const FinishedCallback& callback) override; | 
| + const SitesVector& sites() const override; | 
| // The URL of the file that was last downloaded. | 
| GURL LastURL() const; | 
| @@ -128,12 +144,12 @@ class PopularSites : public net::URLFetcherDelegate { | 
| std::unique_ptr<net::URLFetcher> fetcher_; | 
| bool is_fallback_; | 
| - std::vector<Site> sites_; | 
| + SitesVector sites_; | 
| GURL pending_url_; | 
| - base::WeakPtrFactory<PopularSites> weak_ptr_factory_; | 
| + base::WeakPtrFactory<PopularSitesImpl> weak_ptr_factory_; | 
| - DISALLOW_COPY_AND_ASSIGN(PopularSites); | 
| + DISALLOW_COPY_AND_ASSIGN(PopularSitesImpl); | 
| }; | 
| } // namespace ntp_tiles |