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

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: review 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 | « no previous file | chrome/browser/android/ntp/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
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 last downloaded.
75 std::string GetCountry() const;
76 std::string GetVersion() const;
77
78 const base::FilePath& local_path() const { return local_path_; }
74 79
75 // Register preferences used by this class. 80 // Register preferences used by this class.
76 static void RegisterProfilePrefs( 81 static void RegisterProfilePrefs(
77 user_prefs::PrefRegistrySyncable* user_prefs); 82 user_prefs::PrefRegistrySyncable* user_prefs);
78 83
79 private: 84 private:
80 PopularSites(Profile* profile, 85 PopularSites(Profile* profile,
81 const GURL& url, 86 const std::string& country,
87 const std::string& version,
88 const GURL& override_url,
82 bool force_download, 89 bool force_download,
83 const FinishedCallback& callback); 90 const FinishedCallback& callback);
84 91
92 GURL GetPopularSitesURL() const;
93
85 // Fetch the popular sites at the given URL. |force_download| should be true 94 // Fetch the popular sites at the given URL. |force_download| should be true
86 // if any previously downloaded site list should be overwritten. 95 // if any previously downloaded site list should be overwritten.
87 void FetchPopularSites(const GURL& url, 96 void FetchPopularSites(const GURL& url,
88 bool force_download, 97 bool force_download,
89 bool is_fallback); 98 bool is_fallback);
90 99
91 // If the download was not successful and it was not a fallback, attempt to 100 // If the download was not successful and it was not a fallback, attempt to
92 // download the fallback suggestions. 101 // download the fallback suggestions.
93 void OnDownloadDone(bool success, bool is_fallback); 102 void OnDownloadDone(bool is_fallback, FileDownloader::Result result);
94 103
95 void ParseSiteList(const base::FilePath& path); 104 void ParseSiteList(const base::FilePath& path);
96 void OnJsonParsed(scoped_ptr<std::vector<Site>> sites); 105 void OnJsonParsed(scoped_ptr<std::vector<Site>> sites);
97 106
98 FinishedCallback callback_; 107 FinishedCallback callback_;
99 scoped_ptr<FileDownloader> downloader_; 108 scoped_ptr<FileDownloader> downloader_;
100 std::vector<Site> sites_; 109 std::vector<Site> sites_;
110 std::string pending_country_;
111 std::string pending_version_;
101 112
102 base::FilePath popular_sites_local_path_; 113 base::FilePath local_path_;
103 114
104 Profile* profile_; 115 Profile* profile_;
105 116
106 base::WeakPtrFactory<PopularSites> weak_ptr_factory_; 117 base::WeakPtrFactory<PopularSites> weak_ptr_factory_;
107 118
108 DISALLOW_COPY_AND_ASSIGN(PopularSites); 119 DISALLOW_COPY_AND_ASSIGN(PopularSites);
109 }; 120 };
110 121
111 #endif // CHROME_BROWSER_ANDROID_NTP_POPULAR_SITES_H_ 122 #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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698