| 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> |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 namespace variations { | 35 namespace variations { |
| 36 class VariationsService; | 36 class VariationsService; |
| 37 } | 37 } |
| 38 | 38 |
| 39 class PrefService; | 39 class PrefService; |
| 40 class TemplateURLService; | 40 class TemplateURLService; |
| 41 | 41 |
| 42 namespace ntp_tiles { | 42 namespace ntp_tiles { |
| 43 | 43 |
| 44 class IconCacher; |
| 45 |
| 44 using ParseJSONCallback = base::Callback<void( | 46 using ParseJSONCallback = base::Callback<void( |
| 45 const std::string& unsafe_json, | 47 const std::string& unsafe_json, |
| 46 const base::Callback<void(std::unique_ptr<base::Value>)>& success_callback, | 48 const base::Callback<void(std::unique_ptr<base::Value>)>& success_callback, |
| 47 const base::Callback<void(const std::string&)>& error_callback)>; | 49 const base::Callback<void(const std::string&)>& error_callback)>; |
| 48 | 50 |
| 49 // Actual (non-test) implementation of the PopularSites interface. Caches the | 51 // Actual (non-test) implementation of the PopularSites interface. Caches the |
| 50 // downloaded file on disk to avoid re-downloading on every startup. | 52 // downloaded file on disk to avoid re-downloading on every startup. |
| 51 class PopularSitesImpl : public PopularSites, public net::URLFetcherDelegate { | 53 class PopularSitesImpl : public PopularSites, public net::URLFetcherDelegate { |
| 52 public: | 54 public: |
| 53 PopularSitesImpl( | 55 PopularSitesImpl( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 67 const SitesVector& sites() const override; | 69 const SitesVector& sites() const override; |
| 68 GURL GetLastURLFetched() const override; | 70 GURL GetLastURLFetched() const override; |
| 69 GURL GetURLToFetch() override; | 71 GURL GetURLToFetch() override; |
| 70 std::string GetCountryToFetch() override; | 72 std::string GetCountryToFetch() override; |
| 71 std::string GetVersionToFetch() override; | 73 std::string GetVersionToFetch() override; |
| 72 const base::ListValue* GetCachedJson() override; | 74 const base::ListValue* GetCachedJson() override; |
| 73 | 75 |
| 74 // Register preferences used by this class. | 76 // Register preferences used by this class. |
| 75 static void RegisterProfilePrefs( | 77 static void RegisterProfilePrefs( |
| 76 user_prefs::PrefRegistrySyncable* user_prefs); | 78 user_prefs::PrefRegistrySyncable* user_prefs); |
| 79 // Adds icon resources for default sites in prefs to cache. |
| 80 static void AddIconsForDefaultPagesToCacher(const PrefService& prefs, |
| 81 IconCacher* cacher); |
| 77 | 82 |
| 78 private: | 83 private: |
| 79 // Fetch the popular sites at the given URL, overwriting any cache in prefs | 84 // Fetch the popular sites at the given URL, overwriting any cache in prefs |
| 80 // that already exists. | 85 // that already exists. |
| 81 void FetchPopularSites(); | 86 void FetchPopularSites(); |
| 82 | 87 |
| 83 // net::URLFetcherDelegate implementation. | 88 // net::URLFetcherDelegate implementation. |
| 84 void OnURLFetchComplete(const net::URLFetcher* source) override; | 89 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 85 | 90 |
| 86 void OnJsonParsed(std::unique_ptr<base::Value> json); | 91 void OnJsonParsed(std::unique_ptr<base::Value> json); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 104 GURL pending_url_; | 109 GURL pending_url_; |
| 105 | 110 |
| 106 base::WeakPtrFactory<PopularSitesImpl> weak_ptr_factory_; | 111 base::WeakPtrFactory<PopularSitesImpl> weak_ptr_factory_; |
| 107 | 112 |
| 108 DISALLOW_COPY_AND_ASSIGN(PopularSitesImpl); | 113 DISALLOW_COPY_AND_ASSIGN(PopularSitesImpl); |
| 109 }; | 114 }; |
| 110 | 115 |
| 111 } // namespace ntp_tiles | 116 } // namespace ntp_tiles |
| 112 | 117 |
| 113 #endif // COMPONENTS_NTP_TILES_POPULAR_SITES_IMPL_H_ | 118 #endif // COMPONENTS_NTP_TILES_POPULAR_SITES_IMPL_H_ |
| OLD | NEW |