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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 | 54 |
55 base::string16 title; | 55 base::string16 title; |
56 GURL url; | 56 GURL url; |
57 GURL favicon_url; | 57 GURL favicon_url; |
58 GURL large_icon_url; | 58 GURL large_icon_url; |
59 GURL thumbnail_url; | 59 GURL thumbnail_url; |
60 }; | 60 }; |
61 | 61 |
62 using FinishedCallback = base::Callback<void(bool /* success */)>; | 62 using FinishedCallback = base::Callback<void(bool /* success */)>; |
63 | 63 |
64 // When the suggestions have been fetched (from cache or URL) and parsed, | |
65 // invokes |callback|, on the same thread as the caller. | |
66 // | |
67 // Set |force_download| to enforce re-downloading the suggestions file, even | |
68 // if it already exists on disk. | |
69 PopularSites(const scoped_refptr<base::SequencedWorkerPool>& blocking_pool, | 64 PopularSites(const scoped_refptr<base::SequencedWorkerPool>& blocking_pool, |
70 PrefService* prefs, | 65 PrefService* prefs, |
71 const TemplateURLService* template_url_service, | 66 const TemplateURLService* template_url_service, |
72 variations::VariationsService* variations_service, | 67 variations::VariationsService* variations_service, |
73 net::URLRequestContextGetter* download_context, | 68 net::URLRequestContextGetter* download_context, |
74 const base::FilePath& directory, | 69 const base::FilePath& directory); |
75 bool force_download, | 70 |
76 const FinishedCallback& callback); | 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 suggestions file, even | |
77 // if it already exists on disk. | |
78 void StartFetch(bool force_download, const FinishedCallback& callback); | |
Marc Treib
2016/07/26 13:46:22
It is legal to call this multiple times? I suppose
sfiera
2016/07/26 13:56:54
No, done, and done.
| |
77 | 79 |
78 ~PopularSites() override; | 80 ~PopularSites() override; |
79 | 81 |
80 const std::vector<Site>& sites() const { return sites_; } | 82 const std::vector<Site>& sites() const { return sites_; } |
81 | 83 |
82 // The URL of the file that was last downloaded. | 84 // The URL of the file that was last downloaded. |
83 GURL LastURL() const; | 85 GURL LastURL() const; |
84 | 86 |
85 const base::FilePath& local_path() const { return local_path_; } | 87 const base::FilePath& local_path() const { return local_path_; } |
86 | 88 |
(...skipping 10 matching lines...) Expand all Loading... | |
97 | 99 |
98 // net::URLFetcherDelegate implementation. | 100 // net::URLFetcherDelegate implementation. |
99 void OnURLFetchComplete(const net::URLFetcher* source) override; | 101 void OnURLFetchComplete(const net::URLFetcher* source) override; |
100 | 102 |
101 void OnJsonParsed(std::unique_ptr<base::Value> json); | 103 void OnJsonParsed(std::unique_ptr<base::Value> json); |
102 void OnJsonParseFailed(const std::string& error_message); | 104 void OnJsonParseFailed(const std::string& error_message); |
103 void OnFileWriteDone(std::unique_ptr<base::Value> json, bool success); | 105 void OnFileWriteDone(std::unique_ptr<base::Value> json, bool success); |
104 void ParseSiteList(std::unique_ptr<base::Value> json); | 106 void ParseSiteList(std::unique_ptr<base::Value> json); |
105 void OnDownloadFailed(); | 107 void OnDownloadFailed(); |
106 | 108 |
109 // Parameters set from constructor. | |
110 scoped_refptr<base::TaskRunner> const blocking_runner_; | |
111 PrefService* const prefs_; | |
112 const TemplateURLService* const template_url_service_; | |
113 variations::VariationsService* const variations_; | |
114 net::URLRequestContextGetter* const download_context_; | |
115 base::FilePath const local_path_; | |
116 | |
117 // Set by StartFetch() and called after fetch completes. | |
107 FinishedCallback callback_; | 118 FinishedCallback callback_; |
119 | |
108 std::unique_ptr<net::URLFetcher> fetcher_; | 120 std::unique_ptr<net::URLFetcher> fetcher_; |
109 bool is_fallback_; | 121 bool is_fallback_; |
110 std::vector<Site> sites_; | 122 std::vector<Site> sites_; |
111 GURL pending_url_; | 123 GURL pending_url_; |
112 | 124 |
113 base::FilePath local_path_; | |
114 | |
115 PrefService* prefs_; | |
116 net::URLRequestContextGetter* download_context_; | |
117 | |
118 scoped_refptr<base::TaskRunner> blocking_runner_; | |
119 | |
120 base::WeakPtrFactory<PopularSites> weak_ptr_factory_; | 125 base::WeakPtrFactory<PopularSites> weak_ptr_factory_; |
121 | 126 |
122 DISALLOW_COPY_AND_ASSIGN(PopularSites); | 127 DISALLOW_COPY_AND_ASSIGN(PopularSites); |
123 }; | 128 }; |
124 | 129 |
125 } // namespace ntp_tiles | 130 } // namespace ntp_tiles |
126 | 131 |
127 #endif // COMPONENTS_NTP_TILES_POPULAR_SITES_H_ | 132 #endif // COMPONENTS_NTP_TILES_POPULAR_SITES_H_ |
OLD | NEW |