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

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

Issue 1919043005: Remove Profile dependency from PopularSites. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
OLDNEW
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 CHROME_BROWSER_ANDROID_NTP_POPULAR_SITES_H_ 5 #ifndef CHROME_BROWSER_ANDROID_NTP_POPULAR_SITES_H_
6 #define CHROME_BROWSER_ANDROID_NTP_POPULAR_SITES_H_ 6 #define CHROME_BROWSER_ANDROID_NTP_POPULAR_SITES_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" 13 #include "base/files/file_path.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/strings/string16.h" 16 #include "base/strings/string16.h"
17 #include "chrome/browser/net/file_downloader.h" 17 #include "chrome/browser/net/file_downloader.h"
18 #include "url/gurl.h" 18 #include "url/gurl.h"
19 19
20 namespace net { 20 namespace net {
21 class URLRequestContextGetter; 21 class URLRequestContextGetter;
22 } 22 }
23 23
24 namespace user_prefs { 24 namespace user_prefs {
25 class PrefRegistrySyncable; 25 class PrefRegistrySyncable;
26 } 26 }
27 27
28 class Profile; 28 class PrefService;
29 class TemplateURLService;
29 30
30 // Downloads and provides a list of suggested popular sites, for display on 31 // Downloads and provides a list of suggested popular sites, for display on
31 // the NTP when there are not enough personalized suggestions. Caches the 32 // the NTP when there are not enough personalized suggestions. Caches the
32 // downloaded file on disk to avoid re-downloading on every startup. 33 // downloaded file on disk to avoid re-downloading on every startup.
33 class PopularSites { 34 class PopularSites {
34 public: 35 public:
35 struct Site { 36 struct Site {
36 Site(const base::string16& title, 37 Site(const base::string16& title,
37 const GURL& url, 38 const GURL& url,
38 const GURL& favicon_url, 39 const GURL& favicon_url,
(...skipping 10 matching lines...) Expand all
49 }; 50 };
50 51
51 using FinishedCallback = base::Callback<void(bool /* success */)>; 52 using FinishedCallback = base::Callback<void(bool /* success */)>;
52 53
53 // Usually, the name of the file that's downloaded is based on the user's 54 // Usually, the name of the file that's downloaded is based on the user's
54 // locale. |override_country| (if non-empty) is used to override the 55 // locale. |override_country| (if non-empty) is used to override the
55 // auto-detected country. |override_version|, if non-empty, will 56 // auto-detected country. |override_version|, if non-empty, will
56 // override the baked-in default version. 57 // override the baked-in default version.
57 // Set |force_download| to enforce re-downloading the suggestions file, even 58 // Set |force_download| to enforce re-downloading the suggestions file, even
58 // if it already exists on disk. 59 // if it already exists on disk.
59 PopularSites(Profile* profile, 60 PopularSites(PrefService* prefs,
61 const TemplateURLService* template_url_service,
62 net::URLRequestContextGetter* download_context,
60 const std::string& override_country, 63 const std::string& override_country,
61 const std::string& override_version, 64 const std::string& override_version,
62 bool force_download, 65 bool force_download,
63 const FinishedCallback& callback); 66 const FinishedCallback& callback);
64 67
65 // This fetches the popular sites from a given url and is only used for 68 // This fetches the popular sites from a given url and is only used for
66 // debugging through the popular-sites-internals page. 69 // debugging through the popular-sites-internals page.
67 PopularSites(Profile* profile, 70 PopularSites(PrefService* prefs,
71 const TemplateURLService* template_url_service,
72 net::URLRequestContextGetter* download_context,
68 const GURL& url, 73 const GURL& url,
69 const FinishedCallback& callback); 74 const FinishedCallback& callback);
70 75
71 ~PopularSites(); 76 ~PopularSites();
72 77
73 const std::vector<Site>& sites() const { return sites_; } 78 const std::vector<Site>& sites() const { return sites_; }
74 79
75 // The country/version of the file that was last downloaded. 80 // The country/version of the file that was last downloaded.
76 std::string GetCountry() const; 81 std::string GetCountry() const;
77 std::string GetVersion() const; 82 std::string GetVersion() const;
78 83
79 const base::FilePath& local_path() const { return local_path_; } 84 const base::FilePath& local_path() const { return local_path_; }
80 85
81 // Register preferences used by this class. 86 // Register preferences used by this class.
82 static void RegisterProfilePrefs( 87 static void RegisterProfilePrefs(
83 user_prefs::PrefRegistrySyncable* user_prefs); 88 user_prefs::PrefRegistrySyncable* user_prefs);
84 89
85 private: 90 private:
86 PopularSites(Profile* profile, 91 PopularSites(PrefService* prefs,
92 const TemplateURLService* template_url_service,
93 net::URLRequestContextGetter* download_context,
87 const std::string& country, 94 const std::string& country,
88 const std::string& version, 95 const std::string& version,
89 const GURL& override_url, 96 const GURL& override_url,
90 bool force_download, 97 bool force_download,
91 const FinishedCallback& callback); 98 const FinishedCallback& callback);
92 99
93 GURL GetPopularSitesURL() const; 100 GURL GetPopularSitesURL() const;
94 101
95 // Fetch the popular sites at the given URL. |force_download| should be true 102 // Fetch the popular sites at the given URL. |force_download| should be true
96 // if any previously downloaded site list should be overwritten. 103 // if any previously downloaded site list should be overwritten.
97 void FetchPopularSites(const GURL& url, 104 void FetchPopularSites(const GURL& url,
98 bool force_download, 105 bool force_download,
99 bool is_fallback); 106 bool is_fallback);
100 107
101 // If the download was not successful and it was not a fallback, attempt to 108 // If the download was not successful and it was not a fallback, attempt to
102 // download the fallback suggestions. 109 // download the fallback suggestions.
103 void OnDownloadDone(bool is_fallback, FileDownloader::Result result); 110 void OnDownloadDone(bool is_fallback, FileDownloader::Result result);
104 111
105 void ParseSiteList(const base::FilePath& path); 112 void ParseSiteList(const base::FilePath& path);
106 void OnJsonParsed(std::unique_ptr<std::vector<Site>> sites); 113 void OnJsonParsed(std::unique_ptr<std::vector<Site>> sites);
107 114
108 FinishedCallback callback_; 115 FinishedCallback callback_;
109 std::unique_ptr<FileDownloader> downloader_; 116 std::unique_ptr<FileDownloader> downloader_;
110 std::vector<Site> sites_; 117 std::vector<Site> sites_;
111 std::string pending_country_; 118 std::string pending_country_;
112 std::string pending_version_; 119 std::string pending_version_;
113 120
114 base::FilePath local_path_; 121 base::FilePath local_path_;
115 122
116 Profile* profile_; 123 PrefService* prefs_;
124 const TemplateURLService* template_url_service_;
125 net::URLRequestContextGetter* download_context_;
117 126
118 base::WeakPtrFactory<PopularSites> weak_ptr_factory_; 127 base::WeakPtrFactory<PopularSites> weak_ptr_factory_;
119 128
120 DISALLOW_COPY_AND_ASSIGN(PopularSites); 129 DISALLOW_COPY_AND_ASSIGN(PopularSites);
121 }; 130 };
122 131
123 #endif // CHROME_BROWSER_ANDROID_NTP_POPULAR_SITES_H_ 132 #endif // CHROME_BROWSER_ANDROID_NTP_POPULAR_SITES_H_
OLDNEW
« no previous file with comments | « chrome/browser/android/ntp/most_visited_sites.cc ('k') | chrome/browser/android/ntp/popular_sites.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698