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

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

Issue 1314493013: Popular sites on the NTP: add thumbnails! (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix android_clang_dbg_recipe build Created 5 years, 3 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/popular_sites.h ('k') | components/suggestions/image_manager.h » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "chrome/browser/android/popular_sites.h" 5 #include "chrome/browser/android/popular_sites.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/task_runner_util.h" 14 #include "base/task_runner_util.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/browser/net/file_downloader.h" 16 #include "chrome/browser/net/file_downloader.h"
17 #include "chrome/browser/search_engines/template_url_service_factory.h" 17 #include "chrome/browser/search_engines/template_url_service_factory.h"
18 #include "chrome/common/chrome_paths.h" 18 #include "chrome/common/chrome_paths.h"
19 #include "components/google/core/browser/google_util.h" 19 #include "components/google/core/browser/google_util.h"
20 #include "components/search_engines/search_engine_type.h" 20 #include "components/search_engines/search_engine_type.h"
21 #include "components/search_engines/template_url_prepopulate_data.h" 21 #include "components/search_engines/template_url_prepopulate_data.h"
22 #include "components/search_engines/template_url_service.h" 22 #include "components/search_engines/template_url_service.h"
23 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
24 24
25 using content::BrowserThread; 25 using content::BrowserThread;
26 26
27 namespace { 27 namespace {
28 28
29 const char kPopularSitesURLFormat[] = "https://www.gstatic.com/chrome/ntp/%s"; 29 const char kPopularSitesURLFormat[] = "https://www.gstatic.com/chrome/ntp/%s";
30 const char kPopularSitesFilenameFormat[] = "suggested_sites_%s_1.json"; 30 const char kPopularSitesFilenameFormat[] = "suggested_sites_%s_2.json";
31 const char kPopularSitesDefaultCountryCode[] = "DEFAULT"; 31 const char kPopularSitesDefaultCountryCode[] = "DEFAULT";
32 32
33 33
34 // Find out the country code of the user by using the Google country code if 34 // Find out the country code of the user by using the Google country code if
35 // Google is the default search engine set. Fallback to a default if we can't 35 // Google is the default search engine set. Fallback to a default if we can't
36 // make an educated guess. 36 // make an educated guess.
37 std::string GetCountryCode(Profile* profile) { 37 std::string GetCountryCode(Profile* profile) {
38 DCHECK(profile); 38 DCHECK(profile);
39 39
40 const TemplateURLService* template_url_service = 40 const TemplateURLService* template_url_service =
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 for (size_t i = 0; i < list->GetSize(); i++) { 106 for (size_t i = 0; i < list->GetSize(); i++) {
107 base::DictionaryValue* item; 107 base::DictionaryValue* item;
108 if (!list->GetDictionary(i, &item)) 108 if (!list->GetDictionary(i, &item))
109 continue; 109 continue;
110 base::string16 title; 110 base::string16 title;
111 std::string url; 111 std::string url;
112 if (!item->GetString("title", &title) || !item->GetString("url", &url)) 112 if (!item->GetString("title", &title) || !item->GetString("url", &url))
113 continue; 113 continue;
114 std::string favicon_url; 114 std::string favicon_url;
115 item->GetString("favicon_url", &favicon_url); 115 item->GetString("favicon_url", &favicon_url);
116 sites->push_back(PopularSites::Site(title, GURL(url), GURL(favicon_url))); 116 std::string thumbnail_url;
117 item->GetString("thumbnail_url", &thumbnail_url);
118
119 sites->push_back(PopularSites::Site(title, GURL(url), GURL(favicon_url),
120 GURL(thumbnail_url)));
117 } 121 }
118 122
119 return sites.Pass(); 123 return sites.Pass();
120 } 124 }
121 125
122 } // namespace 126 } // namespace
123 127
124 PopularSites::Site::Site(const base::string16& title, 128 PopularSites::Site::Site(const base::string16& title,
125 const GURL& url, 129 const GURL& url,
126 const GURL& favicon_url) 130 const GURL& favicon_url,
127 : title(title), url(url), favicon_url(favicon_url) {} 131 const GURL& thumbnail_url)
132 : title(title),
133 url(url),
134 favicon_url(favicon_url),
135 thumbnail_url(thumbnail_url) {}
136
137 PopularSites::Site::~Site() {}
128 138
129 PopularSites::PopularSites(Profile* profile, 139 PopularSites::PopularSites(Profile* profile,
130 const std::string& filename, 140 const std::string& filename,
131 net::URLRequestContextGetter* request_context, 141 net::URLRequestContextGetter* request_context,
132 const FinishedCallback& callback) 142 const FinishedCallback& callback)
133 : callback_(callback), weak_ptr_factory_(this) { 143 : callback_(callback), weak_ptr_factory_(this) {
134 base::FilePath path = GetPopularSitesPath(profile, filename); 144 base::FilePath path = GetPopularSitesPath(profile, filename);
135 downloader_.reset(new FileDownloader( 145 downloader_.reset(new FileDownloader(
136 GetPopularSitesURL(profile, filename), path, request_context, 146 GetPopularSitesURL(profile, filename), path, request_context,
137 base::Bind(&PopularSites::OnDownloadDone, base::Unretained(this), path))); 147 base::Bind(&PopularSites::OnDownloadDone, base::Unretained(this), path)));
(...skipping 18 matching lines...) Expand all
156 downloader_.reset(); 166 downloader_.reset();
157 } 167 }
158 168
159 void PopularSites::OnJsonParsed(scoped_ptr<std::vector<Site>> sites) { 169 void PopularSites::OnJsonParsed(scoped_ptr<std::vector<Site>> sites) {
160 if (sites) 170 if (sites)
161 sites_.swap(*sites); 171 sites_.swap(*sites);
162 else 172 else
163 sites_.clear(); 173 sites_.clear();
164 callback_.Run(!!sites); 174 callback_.Run(!!sites);
165 } 175 }
OLDNEW
« no previous file with comments | « chrome/browser/android/popular_sites.h ('k') | components/suggestions/image_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698