Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(707)

Side by Side Diff: chrome/browser/android/popular_sites.h

Issue 1840033002: Move popular_sites.* files to c/b/a/ntp (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: synced Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/android/ntp/popular_sites.cc ('k') | chrome/browser/android/popular_sites.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/files/file_path.h"
12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/strings/string16.h"
16 #include "url/gurl.h"
17
18 namespace net {
19 class URLRequestContextGetter;
20 }
21
22 namespace user_prefs {
23 class PrefRegistrySyncable;
24 }
25
26 class FileDownloader;
27 class Profile;
28
29 // Downloads and provides a list of suggested popular sites, for display on
30 // the NTP when there are not enough personalized suggestions. Caches the
31 // downloaded file on disk to avoid re-downloading on every startup.
32 class PopularSites {
33 public:
34 struct Site {
35 Site(const base::string16& title,
36 const GURL& url,
37 const GURL& favicon_url,
38 const GURL& large_icon_url,
39 const GURL& thumbnail_url);
40 ~Site();
41
42 base::string16 title;
43 GURL url;
44 GURL favicon_url;
45 GURL large_icon_url;
46 GURL thumbnail_url;
47 };
48
49 using FinishedCallback = base::Callback<void(bool /* success */)>;
50
51 // Usually, the name of the file that's downloaded is based on the user's
52 // locale. |override_country| (if non-empty) is used to override the
53 // auto-detected country. |override_version|, if non-empty, will
54 // override the baked-in default version.
55 // Set |force_download| to enforce re-downloading the suggestions file, even
56 // if it already exists on disk.
57 PopularSites(Profile* profile,
58 const std::string& override_country,
59 const std::string& override_version,
60 bool force_download,
61 const FinishedCallback& callback);
62
63 // This fetches the popular sites from a given url and is only used for
64 // debugging through the popular-sites-internals page.
65 PopularSites(Profile* profile,
66 const GURL& url,
67 const FinishedCallback& callback);
68
69 ~PopularSites();
70
71 const std::vector<Site>& sites() const { return sites_; }
72
73 const base::FilePath& local_path() const { return popular_sites_local_path_; }
74
75 // Register preferences used by this class.
76 static void RegisterProfilePrefs(
77 user_prefs::PrefRegistrySyncable* user_prefs);
78
79 private:
80 PopularSites(Profile* profile,
81 const GURL& url,
82 bool force_download,
83 const FinishedCallback& callback);
84
85 // Fetch the popular sites at the given URL. |force_download| should be true
86 // if any previously downloaded site list should be overwritten.
87 void FetchPopularSites(const GURL& url,
88 bool force_download,
89 bool is_fallback);
90
91 // If the download was not successful and it was not a fallback, attempt to
92 // download the fallback suggestions.
93 void OnDownloadDone(bool success, bool is_fallback);
94
95 void ParseSiteList(const base::FilePath& path);
96 void OnJsonParsed(scoped_ptr<std::vector<Site>> sites);
97
98 FinishedCallback callback_;
99 scoped_ptr<FileDownloader> downloader_;
100 std::vector<Site> sites_;
101
102 base::FilePath popular_sites_local_path_;
103
104 Profile* profile_;
105
106 base::WeakPtrFactory<PopularSites> weak_ptr_factory_;
107
108 DISALLOW_COPY_AND_ASSIGN(PopularSites);
109 };
110
111 #endif // CHROME_BROWSER_ANDROID_POPULAR_SITES_H_
OLDNEW
« no previous file with comments | « chrome/browser/android/ntp/popular_sites.cc ('k') | chrome/browser/android/popular_sites.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698