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

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: Fix iOS images and resize only if necessary. Created 3 years, 10 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 continue; 122 continue;
123 std::string favicon_url; 123 std::string favicon_url;
124 item->GetString("favicon_url", &favicon_url); 124 item->GetString("favicon_url", &favicon_url);
125 std::string thumbnail_url; 125 std::string thumbnail_url;
126 item->GetString("thumbnail_url", &thumbnail_url); 126 item->GetString("thumbnail_url", &thumbnail_url);
127 std::string large_icon_url; 127 std::string large_icon_url;
128 item->GetString("large_icon_url", &large_icon_url); 128 item->GetString("large_icon_url", &large_icon_url);
129 129
130 sites.emplace_back(title, GURL(url), GURL(favicon_url), 130 sites.emplace_back(title, GURL(url), GURL(favicon_url),
131 GURL(large_icon_url), GURL(thumbnail_url)); 131 GURL(large_icon_url), GURL(thumbnail_url));
132 item->GetInteger("default_resource_id", &sites.back().default_resource_id);
132 } 133 }
133 return sites; 134 return sites;
134 } 135 }
135 136
137 #if defined(OS_ANDROID) || defined(OS_IOS)
138 void SetDefaultResourceForSite(base::ListValue* sites,
139 int index,
140 int resource_id) {
141 base::DictionaryValue* site;
142 if (!sites->GetDictionary(index, &site)) {
143 return;
144 }
145 site->SetInteger("default_resource_id", resource_id);
146 }
147 #endif
148
136 // Creates the list of popular sites based on a snapshot available for mobile. 149 // Creates the list of popular sites based on a snapshot available for mobile.
137 std::unique_ptr<base::ListValue> DefaultPopularSites() { 150 std::unique_ptr<base::ListValue> DefaultPopularSites() {
138 #if defined(OS_ANDROID) || defined(OS_IOS) 151 #if defined(OS_ANDROID) || defined(OS_IOS)
139 std::unique_ptr<base::ListValue> sites = 152 std::unique_ptr<base::ListValue> sites =
140 base::ListValue::From(base::JSONReader().ReadToValue( 153 base::ListValue::From(base::JSONReader().ReadToValue(
141 ResourceBundle::GetSharedInstance().GetRawDataResource( 154 ResourceBundle::GetSharedInstance().GetRawDataResource(
142 IDR_DEFAULT_POPULAR_SITES_JSON))); 155 IDR_DEFAULT_POPULAR_SITES_JSON)));
143 DCHECK(sites); 156 DCHECK(sites);
157 int index = 0;
158 for (int resource :
159 {IDR_DEFAULT_POPULAR_SITES_ICON0, IDR_DEFAULT_POPULAR_SITES_ICON1,
160 IDR_DEFAULT_POPULAR_SITES_ICON2, IDR_DEFAULT_POPULAR_SITES_ICON3,
161 IDR_DEFAULT_POPULAR_SITES_ICON4, IDR_DEFAULT_POPULAR_SITES_ICON5,
162 IDR_DEFAULT_POPULAR_SITES_ICON6, IDR_DEFAULT_POPULAR_SITES_ICON7}) {
163 SetDefaultResourceForSite(sites.get(), index++, resource);
164 }
165
144 return sites; 166 return sites;
145 #endif 167 #endif
146 return base::MakeUnique<base::ListValue>(); 168 return base::MakeUnique<base::ListValue>();
147 } 169 }
148 170
149 } // namespace 171 } // namespace
150 172
151 PopularSites::Site::Site(const base::string16& title, 173 PopularSites::Site::Site(const base::string16& title,
152 const GURL& url, 174 const GURL& url,
153 const GURL& favicon_url, 175 const GURL& favicon_url,
154 const GURL& large_icon_url, 176 const GURL& large_icon_url,
155 const GURL& thumbnail_url) 177 const GURL& thumbnail_url)
156 : title(title), 178 : title(title),
157 url(url), 179 url(url),
158 favicon_url(favicon_url), 180 favicon_url(favicon_url),
159 large_icon_url(large_icon_url), 181 large_icon_url(large_icon_url),
160 thumbnail_url(thumbnail_url) {} 182 thumbnail_url(thumbnail_url),
183 default_resource_id(-1) {}
161 184
162 PopularSites::Site::Site(const Site& other) = default; 185 PopularSites::Site::Site(const Site& other) = default;
163 186
164 PopularSites::Site::~Site() {} 187 PopularSites::Site::~Site() {}
165 188
166 PopularSitesImpl::PopularSitesImpl( 189 PopularSitesImpl::PopularSitesImpl(
167 const scoped_refptr<base::SequencedWorkerPool>& blocking_pool, 190 const scoped_refptr<base::SequencedWorkerPool>& blocking_pool,
168 PrefService* prefs, 191 PrefService* prefs,
169 const TemplateURLService* template_url_service, 192 const TemplateURLService* template_url_service,
170 VariationsService* variations_service, 193 VariationsService* variations_service,
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 pending_url_ = GetPopularSitesURL(kPopularSitesDefaultCountryCode, 387 pending_url_ = GetPopularSitesURL(kPopularSitesDefaultCountryCode,
365 kPopularSitesDefaultVersion); 388 kPopularSitesDefaultVersion);
366 FetchPopularSites(); 389 FetchPopularSites();
367 } else { 390 } else {
368 DLOG(WARNING) << "Download fallback site list failed"; 391 DLOG(WARNING) << "Download fallback site list failed";
369 callback_.Run(false); 392 callback_.Run(false);
370 } 393 }
371 } 394 }
372 395
373 } // namespace ntp_tiles 396 } // namespace ntp_tiles
OLDNEW
« no previous file with comments | « components/ntp_tiles/popular_sites.h ('k') | components/ntp_tiles/popular_sites_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698