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

Side by Side Diff: components/ntp_tiles/popular_sites_impl.cc

Issue 2695713004: Add baked-in favicons for default popular sites on NTP (Closed)
Patch Set: Drop bool from callback Created 3 years, 9 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 #include "components/ntp_tiles/popular_sites_impl.h" 5 #include "components/ntp_tiles/popular_sites_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 continue; 123 continue;
124 std::string favicon_url; 124 std::string favicon_url;
125 item->GetString("favicon_url", &favicon_url); 125 item->GetString("favicon_url", &favicon_url);
126 std::string thumbnail_url; 126 std::string thumbnail_url;
127 item->GetString("thumbnail_url", &thumbnail_url); 127 item->GetString("thumbnail_url", &thumbnail_url);
128 std::string large_icon_url; 128 std::string large_icon_url;
129 item->GetString("large_icon_url", &large_icon_url); 129 item->GetString("large_icon_url", &large_icon_url);
130 130
131 sites.emplace_back(title, GURL(url), GURL(favicon_url), 131 sites.emplace_back(title, GURL(url), GURL(favicon_url),
132 GURL(large_icon_url), GURL(thumbnail_url)); 132 GURL(large_icon_url), GURL(thumbnail_url));
133 item->GetInteger("default_resource_id", &sites.back().default_resource_id);
133 } 134 }
134 return sites; 135 return sites;
135 } 136 }
136 137
138 #if defined(GOOGLE_CHROME_BUILD) && (defined(OS_ANDROID) || defined(OS_IOS))
139 void SetDefaultResourceForSite(base::ListValue* sites,
mastiz 2017/03/01 08:48:12 Nit: output params should be last according to the
fhorschig 2017/03/01 20:57:36 Done.
140 int index,
141 int resource_id) {
142 base::DictionaryValue* site;
143 if (!sites->GetDictionary(index, &site)) {
144 return;
145 }
146 site->SetInteger("default_resource_id", resource_id);
147 }
148 #endif
149
137 // Creates the list of popular sites based on a snapshot available for mobile. 150 // Creates the list of popular sites based on a snapshot available for mobile.
138 std::unique_ptr<base::ListValue> DefaultPopularSites() { 151 std::unique_ptr<base::ListValue> DefaultPopularSites() {
139 #if defined(OS_ANDROID) || defined(OS_IOS) 152 #if defined(OS_ANDROID) || defined(OS_IOS)
mastiz 2017/03/01 08:48:12 Nit: how about inverting this logic and returning
fhorschig 2017/03/01 20:57:36 Done.
140 std::unique_ptr<base::ListValue> sites = 153 std::unique_ptr<base::ListValue> sites =
141 base::ListValue::From(base::JSONReader().ReadToValue( 154 base::ListValue::From(base::JSONReader::Read(
142 ResourceBundle::GetSharedInstance().GetRawDataResource( 155 ResourceBundle::GetSharedInstance().GetRawDataResource(
143 IDR_DEFAULT_POPULAR_SITES_JSON))); 156 IDR_DEFAULT_POPULAR_SITES_JSON)));
144 DCHECK(sites); 157 DCHECK(sites);
158 #if defined(GOOGLE_CHROME_BUILD)
159 int index = 0;
160 for (int resource :
mastiz 2017/03/01 08:48:12 Nit: rename to resource_id for consistency with th
fhorschig 2017/03/01 20:57:36 Done.
161 {IDR_DEFAULT_POPULAR_SITES_ICON0, IDR_DEFAULT_POPULAR_SITES_ICON1,
162 IDR_DEFAULT_POPULAR_SITES_ICON2, IDR_DEFAULT_POPULAR_SITES_ICON3,
163 IDR_DEFAULT_POPULAR_SITES_ICON4, IDR_DEFAULT_POPULAR_SITES_ICON5,
164 IDR_DEFAULT_POPULAR_SITES_ICON6, IDR_DEFAULT_POPULAR_SITES_ICON7}) {
165 SetDefaultResourceForSite(sites.get(), index++, resource);
166 }
167 #endif // GOOGLE_CHROME_BUILD
145 return sites; 168 return sites;
146 #endif 169 #else
147 return base::MakeUnique<base::ListValue>(); 170 return base::MakeUnique<base::ListValue>();
171 #endif // OS_ANDROID || OS_IOS
148 } 172 }
149 173
150 } // namespace 174 } // namespace
151 175
152 PopularSites::Site::Site(const base::string16& title, 176 PopularSites::Site::Site(const base::string16& title,
153 const GURL& url, 177 const GURL& url,
154 const GURL& favicon_url, 178 const GURL& favicon_url,
155 const GURL& large_icon_url, 179 const GURL& large_icon_url,
156 const GURL& thumbnail_url) 180 const GURL& thumbnail_url)
157 : title(title), 181 : title(title),
158 url(url), 182 url(url),
159 favicon_url(favicon_url), 183 favicon_url(favicon_url),
160 large_icon_url(large_icon_url), 184 large_icon_url(large_icon_url),
161 thumbnail_url(thumbnail_url) {} 185 thumbnail_url(thumbnail_url),
186 default_resource_id(-1) {}
162 187
163 PopularSites::Site::Site(const Site& other) = default; 188 PopularSites::Site::Site(const Site& other) = default;
164 189
165 PopularSites::Site::~Site() {} 190 PopularSites::Site::~Site() {}
166 191
167 PopularSitesImpl::PopularSitesImpl( 192 PopularSitesImpl::PopularSitesImpl(
168 const scoped_refptr<base::SequencedWorkerPool>& blocking_pool, 193 const scoped_refptr<base::SequencedWorkerPool>& blocking_pool,
169 PrefService* prefs, 194 PrefService* prefs,
170 const TemplateURLService* template_url_service, 195 const TemplateURLService* template_url_service,
171 VariationsService* variations_service, 196 VariationsService* variations_service,
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 pending_url_ = GetPopularSitesURL(kPopularSitesDefaultCountryCode, 411 pending_url_ = GetPopularSitesURL(kPopularSitesDefaultCountryCode,
387 kPopularSitesDefaultVersion); 412 kPopularSitesDefaultVersion);
388 FetchPopularSites(); 413 FetchPopularSites();
389 } else { 414 } else {
390 DLOG(WARNING) << "Download fallback site list failed"; 415 DLOG(WARNING) << "Download fallback site list failed";
391 callback_.Run(false); 416 callback_.Run(false);
392 } 417 }
393 } 418 }
394 419
395 } // namespace ntp_tiles 420 } // namespace ntp_tiles
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698