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

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: 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"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "components/data_use_measurement/core/data_use_user_data.h" 19 #include "components/data_use_measurement/core/data_use_user_data.h"
20 #include "components/favicon/core/favicon_service.h"
21 #include "components/favicon_base/favicon_types.h"
20 #include "components/google/core/browser/google_util.h" 22 #include "components/google/core/browser/google_util.h"
21 #include "components/ntp_tiles/constants.h" 23 #include "components/ntp_tiles/constants.h"
22 #include "components/ntp_tiles/field_trial.h" 24 #include "components/ntp_tiles/field_trial.h"
23 #include "components/ntp_tiles/pref_names.h" 25 #include "components/ntp_tiles/pref_names.h"
24 #include "components/ntp_tiles/switches.h" 26 #include "components/ntp_tiles/switches.h"
25 #include "components/pref_registry/pref_registry_syncable.h" 27 #include "components/pref_registry/pref_registry_syncable.h"
26 #include "components/prefs/pref_service.h" 28 #include "components/prefs/pref_service.h"
27 #include "components/search_engines/search_engine_type.h" 29 #include "components/search_engines/search_engine_type.h"
28 #include "components/search_engines/template_url_service.h" 30 #include "components/search_engines/template_url_service.h"
29 #include "components/variations/service/variations_service.h" 31 #include "components/variations/service/variations_service.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 item->GetString("large_icon_url", &large_icon_url); 129 item->GetString("large_icon_url", &large_icon_url);
128 130
129 sites.emplace_back(title, GURL(url), GURL(favicon_url), 131 sites.emplace_back(title, GURL(url), GURL(favicon_url),
130 GURL(large_icon_url), GURL(thumbnail_url)); 132 GURL(large_icon_url), GURL(thumbnail_url));
131 } 133 }
132 return sites; 134 return sites;
133 } 135 }
134 136
135 // This allows instantiation of PopularSites without registered prefs. 137 // This allows instantiation of PopularSites without registered prefs.
136 // That case can occur during tests. 138 // That case can occur during tests.
137 PopularSites::SitesVector GetDefaultFromPrefs(const PrefService& prefs) { 139 PopularSites::SitesVector GetDefaultFromPrefs(
jkrcal 2017/02/14 08:23:06 drive-by comment: When is this function called? Y
sfiera 2017/02/14 09:59:16 Even in the absence of sync, I think this implemen
fhorschig 2017/02/14 17:29:02 Good remark. It's now called by the IconCacher whi
140 const PrefService& prefs,
141 favicon::FaviconService* favicons) {
138 if (!ShouldShowPopularSites()) { 142 if (!ShouldShowPopularSites()) {
139 return PopularSites::SitesVector(); 143 return PopularSites::SitesVector();
140 } 144 }
141 return ParseSiteList(*prefs.GetList(kPopularSitesJsonPref)); 145 PopularSites::SitesVector sites =
146 ParseSiteList(*prefs.GetList(kPopularSitesJsonPref));
147 #if defined(OS_ANDROID) || defined(OS_IOS)
tschumann 2017/02/14 11:56:51 i wonder why is this part only relevant to mobile
fhorschig 2017/02/14 17:29:02 It used to load the defaults and if on mobile, reg
148 if (!favicons) {
149 return sites;
150 }
151 favicons->SetFavicons(sites[0].url, sites[0].large_icon_url,
tschumann 2017/02/14 11:56:51 +mastiz who looked into this. Feels weird to set t
mastiz 2017/02/14 14:44:59 This comment seems obsolete now. Please loop me in
fhorschig 2017/02/14 17:29:02 Like Jan and Chris have pointed out, this was neit
fhorschig 2017/02/14 17:29:02 Absolutely. It seems to be quite an interesting CL
152 favicon_base::IconType::FAVICON,
153 ResourceBundle::GetSharedInstance().GetImageNamed(
154 IDR_DEFAULT_POPULAR_SITES_ICON0));
155 favicons->SetFavicons(sites[1].url, sites[1].large_icon_url,
156 favicon_base::IconType::FAVICON,
157 ResourceBundle::GetSharedInstance().GetImageNamed(
158 IDR_DEFAULT_POPULAR_SITES_ICON1));
159 favicons->SetFavicons(sites[2].url, sites[2].large_icon_url,
160 favicon_base::IconType::FAVICON,
161 ResourceBundle::GetSharedInstance().GetImageNamed(
162 IDR_DEFAULT_POPULAR_SITES_ICON2));
163 favicons->SetFavicons(sites[3].url, sites[3].large_icon_url,
164 favicon_base::IconType::FAVICON,
165 ResourceBundle::GetSharedInstance().GetImageNamed(
166 IDR_DEFAULT_POPULAR_SITES_ICON3));
167 favicons->SetFavicons(sites[4].url, sites[4].large_icon_url,
168 favicon_base::IconType::FAVICON,
169 ResourceBundle::GetSharedInstance().GetImageNamed(
170 IDR_DEFAULT_POPULAR_SITES_ICON4));
171 favicons->SetFavicons(sites[5].url, sites[5].large_icon_url,
172 favicon_base::IconType::FAVICON,
173 ResourceBundle::GetSharedInstance().GetImageNamed(
174 IDR_DEFAULT_POPULAR_SITES_ICON5));
175 favicons->SetFavicons(sites[6].url, sites[6].large_icon_url,
176 favicon_base::IconType::FAVICON,
177 ResourceBundle::GetSharedInstance().GetImageNamed(
178 IDR_DEFAULT_POPULAR_SITES_ICON6));
179 favicons->SetFavicons(sites[7].url, sites[7].large_icon_url,
180 favicon_base::IconType::FAVICON,
181 ResourceBundle::GetSharedInstance().GetImageNamed(
182 IDR_DEFAULT_POPULAR_SITES_ICON7));
183 #endif
184 return sites;
142 } 185 }
143 186
144 // Creates the List of popular sites based on a snapshot available for mobile. 187 // Creates the List of popular sites based on a snapshot available for mobile.
145 std::unique_ptr<base::ListValue> DefaultPopularSites() { 188 std::unique_ptr<base::ListValue> DefaultPopularSites() {
146 #if defined(OS_ANDROID) || defined(OS_IOS) 189 #if defined(OS_ANDROID) || defined(OS_IOS)
147 std::unique_ptr<base::ListValue> sites = 190 std::unique_ptr<base::ListValue> sites =
148 base::ListValue::From(base::JSONReader().ReadToValue( 191 base::ListValue::From(base::JSONReader().ReadToValue(
149 ResourceBundle::GetSharedInstance().GetRawDataResource( 192 ResourceBundle::GetSharedInstance().GetRawDataResource(
150 IDR_DEFAULT_POPULAR_SITES_JSON))); 193 IDR_DEFAULT_POPULAR_SITES_JSON)));
151 DCHECK(sites); 194 DCHECK(sites);
(...skipping 17 matching lines...) Expand all
169 212
170 PopularSites::Site::Site(const Site& other) = default; 213 PopularSites::Site::Site(const Site& other) = default;
171 214
172 PopularSites::Site::~Site() {} 215 PopularSites::Site::~Site() {}
173 216
174 PopularSitesImpl::PopularSitesImpl( 217 PopularSitesImpl::PopularSitesImpl(
175 const scoped_refptr<base::SequencedWorkerPool>& blocking_pool, 218 const scoped_refptr<base::SequencedWorkerPool>& blocking_pool,
176 PrefService* prefs, 219 PrefService* prefs,
177 const TemplateURLService* template_url_service, 220 const TemplateURLService* template_url_service,
178 VariationsService* variations_service, 221 VariationsService* variations_service,
222 favicon::FaviconService* favicon_service,
179 net::URLRequestContextGetter* download_context, 223 net::URLRequestContextGetter* download_context,
180 const base::FilePath& directory, 224 const base::FilePath& directory,
181 ParseJSONCallback parse_json) 225 ParseJSONCallback parse_json)
182 : blocking_runner_(blocking_pool->GetTaskRunnerWithShutdownBehavior( 226 : blocking_runner_(blocking_pool->GetTaskRunnerWithShutdownBehavior(
183 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN)), 227 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN)),
184 prefs_(prefs), 228 prefs_(prefs),
185 template_url_service_(template_url_service), 229 template_url_service_(template_url_service),
186 variations_(variations_service), 230 variations_(variations_service),
187 download_context_(download_context), 231 download_context_(download_context),
188 parse_json_(std::move(parse_json)), 232 parse_json_(std::move(parse_json)),
189 is_fallback_(false), 233 is_fallback_(false),
190 sites_(GetDefaultFromPrefs(*prefs_)), 234 sites_(GetDefaultFromPrefs(*prefs_, favicon_service)),
sfiera 2017/02/14 09:59:16 Initializing the favicon service in PopularSitesIm
fhorschig 2017/02/14 17:29:02 Agreed and removed.
191 weak_ptr_factory_(this) { 235 weak_ptr_factory_(this) {
192 // If valid path provided, remove local files created by older versions. 236 // If valid path provided, remove local files created by older versions.
193 if (!directory.empty() && blocking_runner_) { 237 if (!directory.empty() && blocking_runner_) {
194 blocking_runner_->PostTask( 238 blocking_runner_->PostTask(
195 FROM_HERE, 239 FROM_HERE,
196 base::Bind(base::IgnoreResult(&base::DeleteFile), 240 base::Bind(base::IgnoreResult(&base::DeleteFile),
197 directory.AppendASCII(kPopularSitesLocalFilenameToCleanup), 241 directory.AppendASCII(kPopularSitesLocalFilenameToCleanup),
198 /*recursive=*/false)); 242 /*recursive=*/false));
199 } 243 }
200 } 244 }
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 pending_url_ = GetPopularSitesURL(kPopularSitesDefaultCountryCode, 416 pending_url_ = GetPopularSitesURL(kPopularSitesDefaultCountryCode,
373 kPopularSitesDefaultVersion); 417 kPopularSitesDefaultVersion);
374 FetchPopularSites(); 418 FetchPopularSites();
375 } else { 419 } else {
376 DLOG(WARNING) << "Download fallback site list failed"; 420 DLOG(WARNING) << "Download fallback site list failed";
377 callback_.Run(false); 421 callback_.Run(false);
378 } 422 }
379 } 423 }
380 424
381 } // namespace ntp_tiles 425 } // namespace ntp_tiles
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698