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

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: Have python script adhere to guidelines 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/threading/sequenced_worker_pool.h" 17 #include "base/threading/sequenced_worker_pool.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "components/data_use_measurement/core/data_use_user_data.h" 20 #include "components/data_use_measurement/core/data_use_user_data.h"
21 #include "components/google/core/browser/google_util.h" 21 #include "components/google/core/browser/google_util.h"
22 #include "components/ntp_tiles/constants.h" 22 #include "components/ntp_tiles/constants.h"
23 #include "components/ntp_tiles/field_trial.h" 23 #include "components/ntp_tiles/field_trial.h"
24 #include "components/ntp_tiles/icon_cacher.h"
24 #include "components/ntp_tiles/pref_names.h" 25 #include "components/ntp_tiles/pref_names.h"
25 #include "components/ntp_tiles/switches.h" 26 #include "components/ntp_tiles/switches.h"
26 #include "components/pref_registry/pref_registry_syncable.h" 27 #include "components/pref_registry/pref_registry_syncable.h"
27 #include "components/prefs/pref_service.h" 28 #include "components/prefs/pref_service.h"
28 #include "components/search_engines/search_engine_type.h" 29 #include "components/search_engines/search_engine_type.h"
29 #include "components/search_engines/template_url_service.h" 30 #include "components/search_engines/template_url_service.h"
30 #include "components/variations/service/variations_service.h" 31 #include "components/variations/service/variations_service.h"
31 #include "components/variations/variations_associated_data.h" 32 #include "components/variations/variations_associated_data.h"
32 #include "net/base/load_flags.h" 33 #include "net/base/load_flags.h"
33 #include "net/http/http_status_code.h" 34 #include "net/http/http_status_code.h"
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 std::string()); 299 std::string());
299 user_prefs->RegisterStringPref(ntp_tiles::prefs::kPopularSitesOverrideVersion, 300 user_prefs->RegisterStringPref(ntp_tiles::prefs::kPopularSitesOverrideVersion,
300 std::string()); 301 std::string());
301 302
302 user_prefs->RegisterInt64Pref(kPopularSitesLastDownloadPref, 0); 303 user_prefs->RegisterInt64Pref(kPopularSitesLastDownloadPref, 0);
303 user_prefs->RegisterStringPref(kPopularSitesURLPref, std::string()); 304 user_prefs->RegisterStringPref(kPopularSitesURLPref, std::string());
304 user_prefs->RegisterListPref(kPopularSitesJsonPref, 305 user_prefs->RegisterListPref(kPopularSitesJsonPref,
305 DefaultPopularSites().release()); 306 DefaultPopularSites().release());
306 } 307 }
307 308
309 // static
310 void PopularSitesImpl::AddIconsForDefaultPagesToCacher(const PrefService& prefs,
311 IconCacher* cacher) {
312 #if defined(OS_ANDROID) || defined(OS_IOS)
313 PopularSites::SitesVector sites =
314 ParseSiteList(*prefs.GetList(kPopularSitesJsonPref));
315 cacher->AddDefaultImage(sites[0], IDR_DEFAULT_POPULAR_SITES_ICON0);
316 cacher->AddDefaultImage(sites[1], IDR_DEFAULT_POPULAR_SITES_ICON1);
317 cacher->AddDefaultImage(sites[2], IDR_DEFAULT_POPULAR_SITES_ICON2);
318 cacher->AddDefaultImage(sites[3], IDR_DEFAULT_POPULAR_SITES_ICON3);
319 cacher->AddDefaultImage(sites[4], IDR_DEFAULT_POPULAR_SITES_ICON4);
320 cacher->AddDefaultImage(sites[5], IDR_DEFAULT_POPULAR_SITES_ICON5);
321 cacher->AddDefaultImage(sites[6], IDR_DEFAULT_POPULAR_SITES_ICON6);
322 cacher->AddDefaultImage(sites[7], IDR_DEFAULT_POPULAR_SITES_ICON7);
323 #endif
324 }
325
308 void PopularSitesImpl::FetchPopularSites() { 326 void PopularSitesImpl::FetchPopularSites() {
309 fetcher_ = URLFetcher::Create(pending_url_, URLFetcher::GET, this); 327 fetcher_ = URLFetcher::Create(pending_url_, URLFetcher::GET, this);
310 data_use_measurement::DataUseUserData::AttachToFetcher( 328 data_use_measurement::DataUseUserData::AttachToFetcher(
311 fetcher_.get(), data_use_measurement::DataUseUserData::NTP_TILES); 329 fetcher_.get(), data_use_measurement::DataUseUserData::NTP_TILES);
312 fetcher_->SetRequestContext(download_context_); 330 fetcher_->SetRequestContext(download_context_);
313 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | 331 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
314 net::LOAD_DO_NOT_SAVE_COOKIES); 332 net::LOAD_DO_NOT_SAVE_COOKIES);
315 fetcher_->SetAutomaticallyRetryOnNetworkChanges(1); 333 fetcher_->SetAutomaticallyRetryOnNetworkChanges(1);
316 fetcher_->Start(); 334 fetcher_->Start();
317 } 335 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 pending_url_ = GetPopularSitesURL(kPopularSitesDefaultCountryCode, 382 pending_url_ = GetPopularSitesURL(kPopularSitesDefaultCountryCode,
365 kPopularSitesDefaultVersion); 383 kPopularSitesDefaultVersion);
366 FetchPopularSites(); 384 FetchPopularSites();
367 } else { 385 } else {
368 DLOG(WARNING) << "Download fallback site list failed"; 386 DLOG(WARNING) << "Download fallback site list failed";
369 callback_.Run(false); 387 callback_.Run(false);
370 } 388 }
371 } 389 }
372 390
373 } // namespace ntp_tiles 391 } // namespace ntp_tiles
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698