| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_H_ |
| 6 #define COMPONENTS_NTP_TILES_POPULAR_SITES_H_ | 6 #define COMPONENTS_NTP_TILES_POPULAR_SITES_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 namespace variations { | 32 namespace variations { |
| 33 class VariationsService; | 33 class VariationsService; |
| 34 } | 34 } |
| 35 | 35 |
| 36 class PrefService; | 36 class PrefService; |
| 37 class TemplateURLService; | 37 class TemplateURLService; |
| 38 | 38 |
| 39 namespace ntp_tiles { | 39 namespace ntp_tiles { |
| 40 | 40 |
| 41 using ParseJSONCallback = base::Callback<void( |
| 42 const std::string& unsafe_json, |
| 43 const base::Callback<void(std::unique_ptr<base::Value>)>& success_callback, |
| 44 const base::Callback<void(const std::string&)>& error_callback)>; |
| 45 |
| 41 // Downloads and provides a list of suggested popular sites, for display on | 46 // Downloads and provides a list of suggested popular sites, for display on |
| 42 // the NTP when there are not enough personalized suggestions. Caches the | 47 // the NTP when there are not enough personalized suggestions. Caches the |
| 43 // downloaded file on disk to avoid re-downloading on every startup. | 48 // downloaded file on disk to avoid re-downloading on every startup. |
| 44 class PopularSites : public net::URLFetcherDelegate { | 49 class PopularSites : public net::URLFetcherDelegate { |
| 45 public: | 50 public: |
| 46 struct Site { | 51 struct Site { |
| 47 Site(const base::string16& title, | 52 Site(const base::string16& title, |
| 48 const GURL& url, | 53 const GURL& url, |
| 49 const GURL& favicon_url, | 54 const GURL& favicon_url, |
| 50 const GURL& large_icon_url, | 55 const GURL& large_icon_url, |
| 51 const GURL& thumbnail_url); | 56 const GURL& thumbnail_url); |
| 52 Site(const Site& other); | 57 Site(const Site& other); |
| 53 ~Site(); | 58 ~Site(); |
| 54 | 59 |
| 55 base::string16 title; | 60 base::string16 title; |
| 56 GURL url; | 61 GURL url; |
| 57 GURL favicon_url; | 62 GURL favicon_url; |
| 58 GURL large_icon_url; | 63 GURL large_icon_url; |
| 59 GURL thumbnail_url; | 64 GURL thumbnail_url; |
| 60 }; | 65 }; |
| 61 | 66 |
| 62 using FinishedCallback = base::Callback<void(bool /* success */)>; | 67 using FinishedCallback = base::Callback<void(bool /* success */)>; |
| 63 | 68 |
| 64 PopularSites(const scoped_refptr<base::SequencedWorkerPool>& blocking_pool, | 69 PopularSites(const scoped_refptr<base::SequencedWorkerPool>& blocking_pool, |
| 65 PrefService* prefs, | 70 PrefService* prefs, |
| 66 const TemplateURLService* template_url_service, | 71 const TemplateURLService* template_url_service, |
| 67 variations::VariationsService* variations_service, | 72 variations::VariationsService* variations_service, |
| 68 net::URLRequestContextGetter* download_context, | 73 net::URLRequestContextGetter* download_context, |
| 69 const base::FilePath& directory); | 74 const base::FilePath& directory, |
| 75 ParseJSONCallback parse_json); |
| 70 | 76 |
| 71 // Starts the process of retrieving popular sites. When they are available, | 77 // 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 | 78 // 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 | 79 // invokes |callback| before returning control to the caller, even if the |
| 74 // result is immediately known. | 80 // result is immediately known. |
| 75 // | 81 // |
| 76 // Set |force_download| to enforce re-downloading the suggestions file, even | 82 // Set |force_download| to enforce re-downloading the suggestions file, even |
| 77 // if it already exists on disk. | 83 // if it already exists on disk. |
| 78 // | 84 // |
| 79 // Must be called at most once on a given PopularSites object. | 85 // Must be called at most once on a given PopularSites object. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 108 void ParseSiteList(std::unique_ptr<base::Value> json); | 114 void ParseSiteList(std::unique_ptr<base::Value> json); |
| 109 void OnDownloadFailed(); | 115 void OnDownloadFailed(); |
| 110 | 116 |
| 111 // Parameters set from constructor. | 117 // Parameters set from constructor. |
| 112 scoped_refptr<base::TaskRunner> const blocking_runner_; | 118 scoped_refptr<base::TaskRunner> const blocking_runner_; |
| 113 PrefService* const prefs_; | 119 PrefService* const prefs_; |
| 114 const TemplateURLService* const template_url_service_; | 120 const TemplateURLService* const template_url_service_; |
| 115 variations::VariationsService* const variations_; | 121 variations::VariationsService* const variations_; |
| 116 net::URLRequestContextGetter* const download_context_; | 122 net::URLRequestContextGetter* const download_context_; |
| 117 base::FilePath const local_path_; | 123 base::FilePath const local_path_; |
| 124 ParseJSONCallback parse_json_; |
| 118 | 125 |
| 119 // Set by StartFetch() and called after fetch completes. | 126 // Set by StartFetch() and called after fetch completes. |
| 120 FinishedCallback callback_; | 127 FinishedCallback callback_; |
| 121 | 128 |
| 122 std::unique_ptr<net::URLFetcher> fetcher_; | 129 std::unique_ptr<net::URLFetcher> fetcher_; |
| 123 bool is_fallback_; | 130 bool is_fallback_; |
| 124 std::vector<Site> sites_; | 131 std::vector<Site> sites_; |
| 125 GURL pending_url_; | 132 GURL pending_url_; |
| 126 | 133 |
| 127 base::WeakPtrFactory<PopularSites> weak_ptr_factory_; | 134 base::WeakPtrFactory<PopularSites> weak_ptr_factory_; |
| 128 | 135 |
| 129 DISALLOW_COPY_AND_ASSIGN(PopularSites); | 136 DISALLOW_COPY_AND_ASSIGN(PopularSites); |
| 130 }; | 137 }; |
| 131 | 138 |
| 132 } // namespace ntp_tiles | 139 } // namespace ntp_tiles |
| 133 | 140 |
| 134 #endif // COMPONENTS_NTP_TILES_POPULAR_SITES_H_ | 141 #endif // COMPONENTS_NTP_TILES_POPULAR_SITES_H_ |
| OLD | NEW |