| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef COMPONENTS_NTP_TILES_POPULAR_SITES_H_ | 5 #ifndef COMPONENTS_NTP_TILES_POPULAR_SITES_IMPL_H_ |
| 6 #define COMPONENTS_NTP_TILES_POPULAR_SITES_H_ | 6 #define COMPONENTS_NTP_TILES_POPULAR_SITES_IMPL_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 17 #include "components/ntp_tiles/popular_sites.h" |
| 17 #include "net/url_request/url_fetcher_delegate.h" | 18 #include "net/url_request/url_fetcher_delegate.h" |
| 18 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 19 | 20 |
| 20 namespace base { | 21 namespace base { |
| 21 class Value; | 22 class Value; |
| 22 } | 23 } |
| 23 | 24 |
| 24 namespace net { | 25 namespace net { |
| 25 class URLRequestContextGetter; | 26 class URLRequestContextGetter; |
| 26 } | 27 } |
| 27 | 28 |
| 28 namespace user_prefs { | 29 namespace user_prefs { |
| 29 class PrefRegistrySyncable; | 30 class PrefRegistrySyncable; |
| 30 } | 31 } |
| 31 | 32 |
| 32 namespace variations { | 33 namespace variations { |
| 33 class VariationsService; | 34 class VariationsService; |
| 34 } | 35 } |
| 35 | 36 |
| 36 class PrefService; | 37 class PrefService; |
| 37 class TemplateURLService; | 38 class TemplateURLService; |
| 38 | 39 |
| 39 namespace ntp_tiles { | 40 namespace ntp_tiles { |
| 40 | 41 |
| 41 using ParseJSONCallback = base::Callback<void( | 42 using ParseJSONCallback = base::Callback<void( |
| 42 const std::string& unsafe_json, | 43 const std::string& unsafe_json, |
| 43 const base::Callback<void(std::unique_ptr<base::Value>)>& success_callback, | 44 const base::Callback<void(std::unique_ptr<base::Value>)>& success_callback, |
| 44 const base::Callback<void(const std::string&)>& error_callback)>; | 45 const base::Callback<void(const std::string&)>& error_callback)>; |
| 45 | 46 |
| 46 // Interface to provide a list of suggested popular sites, for display on the | |
| 47 // NTP when there are not enough personalized tiles. | |
| 48 class PopularSites { | |
| 49 public: | |
| 50 struct Site { | |
| 51 Site(const base::string16& title, | |
| 52 const GURL& url, | |
| 53 const GURL& favicon_url, | |
| 54 const GURL& large_icon_url, | |
| 55 const GURL& thumbnail_url); | |
| 56 Site(const Site& other); | |
| 57 ~Site(); | |
| 58 | |
| 59 base::string16 title; | |
| 60 GURL url; | |
| 61 GURL favicon_url; | |
| 62 GURL large_icon_url; | |
| 63 GURL thumbnail_url; | |
| 64 }; | |
| 65 | |
| 66 using SitesVector = std::vector<Site>; | |
| 67 using FinishedCallback = base::Callback<void(bool /* success */)>; | |
| 68 | |
| 69 virtual ~PopularSites() = default; | |
| 70 | |
| 71 // Starts the process of retrieving popular sites. When they are available, | |
| 72 // invokes |callback| with the result, on the same thread as the caller. Never | |
| 73 // invokes |callback| before returning control to the caller, even if the | |
| 74 // result is immediately known. | |
| 75 // | |
| 76 // Set |force_download| to enforce re-downloading the popular sites file, even | |
| 77 // if it already exists on disk. | |
| 78 // | |
| 79 // Must be called at most once on a given PopularSites object. | |
| 80 // TODO(mastiz): Remove this restriction? | |
| 81 virtual void StartFetch(bool force_download, | |
| 82 const FinishedCallback& callback) = 0; | |
| 83 | |
| 84 // Returns the list of available sites. | |
| 85 virtual const SitesVector& sites() const = 0; | |
| 86 | |
| 87 // Various internals exposed publicly for diagnostic pages only. | |
| 88 virtual GURL GetLastURLFetched() const = 0; | |
| 89 virtual const base::FilePath& local_path() const = 0; | |
| 90 virtual GURL GetURLToFetch() = 0; | |
| 91 virtual std::string GetCountryToFetch() = 0; | |
| 92 virtual std::string GetVersionToFetch() = 0; | |
| 93 }; | |
| 94 | |
| 95 // Actual (non-test) implementation of the PopularSites interface. Caches the | 47 // Actual (non-test) implementation of the PopularSites interface. Caches the |
| 96 // downloaded file on disk to avoid re-downloading on every startup. | 48 // downloaded file on disk to avoid re-downloading on every startup. |
| 97 class PopularSitesImpl : public PopularSites, public net::URLFetcherDelegate { | 49 class PopularSitesImpl : public PopularSites, public net::URLFetcherDelegate { |
| 98 public: | 50 public: |
| 99 PopularSitesImpl( | 51 PopularSitesImpl( |
| 100 const scoped_refptr<base::SequencedWorkerPool>& blocking_pool, | 52 const scoped_refptr<base::SequencedWorkerPool>& blocking_pool, |
| 101 PrefService* prefs, | 53 PrefService* prefs, |
| 102 const TemplateURLService* template_url_service, | 54 const TemplateURLService* template_url_service, |
| 103 variations::VariationsService* variations_service, | 55 variations::VariationsService* variations_service, |
| 104 net::URLRequestContextGetter* download_context, | 56 net::URLRequestContextGetter* download_context, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 SitesVector sites_; | 106 SitesVector sites_; |
| 155 GURL pending_url_; | 107 GURL pending_url_; |
| 156 | 108 |
| 157 base::WeakPtrFactory<PopularSitesImpl> weak_ptr_factory_; | 109 base::WeakPtrFactory<PopularSitesImpl> weak_ptr_factory_; |
| 158 | 110 |
| 159 DISALLOW_COPY_AND_ASSIGN(PopularSitesImpl); | 111 DISALLOW_COPY_AND_ASSIGN(PopularSitesImpl); |
| 160 }; | 112 }; |
| 161 | 113 |
| 162 } // namespace ntp_tiles | 114 } // namespace ntp_tiles |
| 163 | 115 |
| 164 #endif // COMPONENTS_NTP_TILES_POPULAR_SITES_H_ | 116 #endif // COMPONENTS_NTP_TILES_POPULAR_SITES_IMPL_H_ |
| OLD | NEW |