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

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

Issue 1851803002: [NTP Popular Sites] Store country/version in prefs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
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 <string>
8 #include <vector> 9 #include <vector>
9 10
10 #include "base/callback.h" 11 #include "base/callback.h"
11 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
15 #include "base/strings/string16.h" 16 #include "base/strings/string16.h"
17 #include "chrome/browser/net/file_downloader.h"
16 #include "url/gurl.h" 18 #include "url/gurl.h"
17 19
18 namespace net { 20 namespace net {
19 class URLRequestContextGetter; 21 class URLRequestContextGetter;
20 } 22 }
21 23
22 namespace user_prefs { 24 namespace user_prefs {
23 class PrefRegistrySyncable; 25 class PrefRegistrySyncable;
24 } 26 }
25 27
26 class FileDownloader;
27 class Profile; 28 class Profile;
28 29
29 // Downloads and provides a list of suggested popular sites, for display on 30 // 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 // the NTP when there are not enough personalized suggestions. Caches the
31 // downloaded file on disk to avoid re-downloading on every startup. 32 // downloaded file on disk to avoid re-downloading on every startup.
32 class PopularSites { 33 class PopularSites {
33 public: 34 public:
34 struct Site { 35 struct Site {
35 Site(const base::string16& title, 36 Site(const base::string16& title,
36 const GURL& url, 37 const GURL& url,
(...skipping 26 matching lines...) Expand all
63 // This fetches the popular sites from a given url and is only used for 64 // This fetches the popular sites from a given url and is only used for
64 // debugging through the popular-sites-internals page. 65 // debugging through the popular-sites-internals page.
65 PopularSites(Profile* profile, 66 PopularSites(Profile* profile,
66 const GURL& url, 67 const GURL& url,
67 const FinishedCallback& callback); 68 const FinishedCallback& callback);
68 69
69 ~PopularSites(); 70 ~PopularSites();
70 71
71 const std::vector<Site>& sites() const { return sites_; } 72 const std::vector<Site>& sites() const { return sites_; }
72 73
73 const base::FilePath& local_path() const { return popular_sites_local_path_; } 74 // The country/version of the file that was loaded. These only have
75 // well-defined values after FinishedCallback has been called!
Bernhard Bauer 2016/04/01 15:49:47 That also applies to sites(), right?
Marc Treib 2016/04/01 16:33:28 sites() will just be empty. These might actually h
76 const std::string& country() const { return country_; }
77 const std::string& version() const { return version_; }
78
79 const base::FilePath& local_path() const { return local_path_; }
74 80
75 // Register preferences used by this class. 81 // Register preferences used by this class.
76 static void RegisterProfilePrefs( 82 static void RegisterProfilePrefs(
77 user_prefs::PrefRegistrySyncable* user_prefs); 83 user_prefs::PrefRegistrySyncable* user_prefs);
78 84
79 private: 85 private:
80 PopularSites(Profile* profile, 86 PopularSites(Profile* profile,
81 const GURL& url, 87 const std::string& country,
88 const std::string& version,
89 const GURL& override_url,
82 bool force_download, 90 bool force_download,
83 const FinishedCallback& callback); 91 const FinishedCallback& callback);
84 92
85 // Fetch the popular sites at the given URL. |force_download| should be true 93 // Fetch the popular sites at the given URL. |force_download| should be true
86 // if any previously downloaded site list should be overwritten. 94 // if any previously downloaded site list should be overwritten.
87 void FetchPopularSites(const GURL& url, 95 void FetchPopularSites(const GURL& url,
88 bool force_download, 96 bool force_download,
89 bool is_fallback); 97 bool is_fallback);
90 98
91 // If the download was not successful and it was not a fallback, attempt to 99 // If the download was not successful and it was not a fallback, attempt to
92 // download the fallback suggestions. 100 // download the fallback suggestions.
93 void OnDownloadDone(bool success, bool is_fallback); 101 void OnDownloadDone(bool is_fallback, FileDownloader::Result result);
94 102
95 void ParseSiteList(const base::FilePath& path); 103 void ParseSiteList(const base::FilePath& path);
96 void OnJsonParsed(scoped_ptr<std::vector<Site>> sites); 104 void OnJsonParsed(scoped_ptr<std::vector<Site>> sites);
97 105
98 FinishedCallback callback_; 106 FinishedCallback callback_;
99 scoped_ptr<FileDownloader> downloader_; 107 scoped_ptr<FileDownloader> downloader_;
100 std::vector<Site> sites_; 108 std::vector<Site> sites_;
109 std::string country_;
110 std::string version_;
101 111
102 base::FilePath popular_sites_local_path_; 112 base::FilePath local_path_;
103 113
104 Profile* profile_; 114 Profile* profile_;
105 115
106 base::WeakPtrFactory<PopularSites> weak_ptr_factory_; 116 base::WeakPtrFactory<PopularSites> weak_ptr_factory_;
107 117
108 DISALLOW_COPY_AND_ASSIGN(PopularSites); 118 DISALLOW_COPY_AND_ASSIGN(PopularSites);
109 }; 119 };
110 120
111 #endif // CHROME_BROWSER_ANDROID_NTP_POPULAR_SITES_H_ 121 #endif // CHROME_BROWSER_ANDROID_NTP_POPULAR_SITES_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/android/ntp/popular_sites.cc » ('j') | chrome/browser/android/ntp/popular_sites.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698