| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_ANDROID_POPULAR_SITES_H_ |
| 6 #define CHROME_BROWSER_ANDROID_POPULAR_SITES_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/strings/string16.h" |
| 15 #include "url/gurl.h" |
| 16 |
| 17 namespace base { |
| 18 class FilePath; |
| 19 } |
| 20 |
| 21 namespace net { |
| 22 class URLRequestContextGetter; |
| 23 } |
| 24 |
| 25 class FileDownloader; |
| 26 |
| 27 // Downloads and provides a list of suggested popular sites, for display on |
| 28 // the NTP when there are not enough personalized suggestions. Caches the |
| 29 // downloaded file on disk to avoid re-downloading on every startup. |
| 30 class PopularSites { |
| 31 public: |
| 32 struct Site { |
| 33 Site(const base::string16& title, const GURL& url); |
| 34 |
| 35 base::string16 title; |
| 36 GURL url; |
| 37 }; |
| 38 |
| 39 using FinishedCallback = base::Callback<void(bool /* success */)>; |
| 40 |
| 41 PopularSites(net::URLRequestContextGetter* request_context, |
| 42 const FinishedCallback& callback); |
| 43 ~PopularSites(); |
| 44 |
| 45 const std::vector<Site>& sites() const { return sites_; } |
| 46 |
| 47 private: |
| 48 void OnDownloadDone(const base::FilePath& path, bool success); |
| 49 void OnJsonParsed(scoped_ptr<std::vector<Site>> sites); |
| 50 |
| 51 FinishedCallback callback_; |
| 52 scoped_ptr<FileDownloader> downloader_; |
| 53 std::vector<Site> sites_; |
| 54 |
| 55 base::WeakPtrFactory<PopularSites> weak_ptr_factory_; |
| 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(PopularSites); |
| 58 }; |
| 59 |
| 60 #endif // CHROME_BROWSER_ANDROID_POPULAR_SITES_H_ |
| OLD | NEW |