| OLD | NEW |
| 1 // Copyright 2016 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_IMPL_H_ | 5 #ifndef COMPONENTS_NTP_TILES_POPULAR_SITES_IMPL_H_ |
| 6 #define COMPONENTS_NTP_TILES_POPULAR_SITES_IMPL_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" | |
| 14 #include "base/macros.h" | 13 #include "base/macros.h" |
| 15 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 16 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
| 17 #include "components/ntp_tiles/popular_sites.h" | 16 #include "components/ntp_tiles/popular_sites.h" |
| 18 #include "net/url_request/url_fetcher_delegate.h" | 17 #include "net/url_request/url_fetcher_delegate.h" |
| 19 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 20 | 19 |
| 21 namespace base { | 20 namespace base { |
| 22 class TaskRunner; | |
| 23 class SequencedWorkerPool; | |
| 24 class Value; | 21 class Value; |
| 25 } | 22 } |
| 26 | 23 |
| 27 namespace net { | 24 namespace net { |
| 28 class URLRequestContextGetter; | 25 class URLRequestContextGetter; |
| 29 } | 26 } |
| 30 | 27 |
| 31 namespace user_prefs { | 28 namespace user_prefs { |
| 32 class PrefRegistrySyncable; | 29 class PrefRegistrySyncable; |
| 33 } | 30 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 44 using ParseJSONCallback = base::Callback<void( | 41 using ParseJSONCallback = base::Callback<void( |
| 45 const std::string& unsafe_json, | 42 const std::string& unsafe_json, |
| 46 const base::Callback<void(std::unique_ptr<base::Value>)>& success_callback, | 43 const base::Callback<void(std::unique_ptr<base::Value>)>& success_callback, |
| 47 const base::Callback<void(const std::string&)>& error_callback)>; | 44 const base::Callback<void(const std::string&)>& error_callback)>; |
| 48 | 45 |
| 49 // Actual (non-test) implementation of the PopularSites interface. Caches the | 46 // Actual (non-test) implementation of the PopularSites interface. Caches the |
| 50 // downloaded file on disk to avoid re-downloading on every startup. | 47 // downloaded file on disk to avoid re-downloading on every startup. |
| 51 class PopularSitesImpl : public PopularSites, public net::URLFetcherDelegate { | 48 class PopularSitesImpl : public PopularSites, public net::URLFetcherDelegate { |
| 52 public: | 49 public: |
| 53 PopularSitesImpl( | 50 PopularSitesImpl( |
| 54 const scoped_refptr<base::SequencedWorkerPool>& blocking_pool, | |
| 55 PrefService* prefs, | 51 PrefService* prefs, |
| 56 const TemplateURLService* template_url_service, | 52 const TemplateURLService* template_url_service, |
| 57 variations::VariationsService* variations_service, | 53 variations::VariationsService* variations_service, |
| 58 net::URLRequestContextGetter* download_context, | 54 net::URLRequestContextGetter* download_context, |
| 59 const base::FilePath& directory, | |
| 60 ParseJSONCallback parse_json); | 55 ParseJSONCallback parse_json); |
| 61 | 56 |
| 62 ~PopularSitesImpl() override; | 57 ~PopularSitesImpl() override; |
| 63 | 58 |
| 64 // PopularSites implementation. | 59 // PopularSites implementation. |
| 65 bool MaybeStartFetch(bool force_download, | 60 bool MaybeStartFetch(bool force_download, |
| 66 const FinishedCallback& callback) override; | 61 const FinishedCallback& callback) override; |
| 67 const SitesVector& sites() const override; | 62 const SitesVector& sites() const override; |
| 68 GURL GetLastURLFetched() const override; | 63 GURL GetLastURLFetched() const override; |
| 69 GURL GetURLToFetch() override; | 64 GURL GetURLToFetch() override; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 82 void FetchPopularSites(); | 77 void FetchPopularSites(); |
| 83 | 78 |
| 84 // net::URLFetcherDelegate implementation. | 79 // net::URLFetcherDelegate implementation. |
| 85 void OnURLFetchComplete(const net::URLFetcher* source) override; | 80 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 86 | 81 |
| 87 void OnJsonParsed(std::unique_ptr<base::Value> json); | 82 void OnJsonParsed(std::unique_ptr<base::Value> json); |
| 88 void OnJsonParseFailed(const std::string& error_message); | 83 void OnJsonParseFailed(const std::string& error_message); |
| 89 void OnDownloadFailed(); | 84 void OnDownloadFailed(); |
| 90 | 85 |
| 91 // Parameters set from constructor. | 86 // Parameters set from constructor. |
| 92 scoped_refptr<base::TaskRunner> const blocking_runner_; | |
| 93 PrefService* const prefs_; | 87 PrefService* const prefs_; |
| 94 const TemplateURLService* const template_url_service_; | 88 const TemplateURLService* const template_url_service_; |
| 95 variations::VariationsService* const variations_; | 89 variations::VariationsService* const variations_; |
| 96 net::URLRequestContextGetter* const download_context_; | 90 net::URLRequestContextGetter* const download_context_; |
| 97 ParseJSONCallback parse_json_; | 91 ParseJSONCallback parse_json_; |
| 98 | 92 |
| 99 // Set by MaybeStartFetch() and called after fetch completes. | 93 // Set by MaybeStartFetch() and called after fetch completes. |
| 100 FinishedCallback callback_; | 94 FinishedCallback callback_; |
| 101 | 95 |
| 102 std::unique_ptr<net::URLFetcher> fetcher_; | 96 std::unique_ptr<net::URLFetcher> fetcher_; |
| 103 bool is_fallback_; | 97 bool is_fallback_; |
| 104 SitesVector sites_; | 98 SitesVector sites_; |
| 105 GURL pending_url_; | 99 GURL pending_url_; |
| 106 | 100 |
| 107 base::WeakPtrFactory<PopularSitesImpl> weak_ptr_factory_; | 101 base::WeakPtrFactory<PopularSitesImpl> weak_ptr_factory_; |
| 108 | 102 |
| 109 DISALLOW_COPY_AND_ASSIGN(PopularSitesImpl); | 103 DISALLOW_COPY_AND_ASSIGN(PopularSitesImpl); |
| 110 }; | 104 }; |
| 111 | 105 |
| 112 } // namespace ntp_tiles | 106 } // namespace ntp_tiles |
| 113 | 107 |
| 114 #endif // COMPONENTS_NTP_TILES_POPULAR_SITES_IMPL_H_ | 108 #endif // COMPONENTS_NTP_TILES_POPULAR_SITES_IMPL_H_ |
| OLD | NEW |