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

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

Issue 2668943002: provide static popular sites for first run (Closed)
Patch Set: Clean build/DEPS files 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
« no previous file with comments | « components/ntp_tiles/DEPS ('k') | components/ntp_tiles/most_visited_sites_unittest.cc » ('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 "components/ntp_tiles/most_visited_sites.h" 5 #include "components/ntp_tiles/most_visited_sites.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 return NTPTilesVector(); 330 return NTPTilesVector();
331 331
332 size_t num_tiles = personal_tiles.size() + whitelist_tiles.size(); 332 size_t num_tiles = personal_tiles.size() + whitelist_tiles.size();
333 DCHECK_LE(num_tiles, static_cast<size_t>(num_sites_)); 333 DCHECK_LE(num_tiles, static_cast<size_t>(num_sites_));
334 334
335 // Collect non-blacklisted popular suggestions, skipping those already present 335 // Collect non-blacklisted popular suggestions, skipping those already present
336 // in the personal suggestions. 336 // in the personal suggestions.
337 size_t num_popular_sites_tiles = num_sites_ - num_tiles; 337 size_t num_popular_sites_tiles = num_sites_ - num_tiles;
338 NTPTilesVector popular_sites_tiles; 338 NTPTilesVector popular_sites_tiles;
339 339
340 if (num_popular_sites_tiles > 0 && popular_sites_) { 340 if (num_popular_sites_tiles > 0 && popular_sites_ &&
341 ShouldShowPopularSites()) {
341 std::set<std::string> hosts; 342 std::set<std::string> hosts;
342 for (const auto& tile : personal_tiles) 343 for (const auto& tile : personal_tiles)
343 hosts.insert(tile.url.host()); 344 hosts.insert(tile.url.host());
344 for (const auto& tile : whitelist_tiles) 345 for (const auto& tile : whitelist_tiles)
345 hosts.insert(tile.url.host()); 346 hosts.insert(tile.url.host());
346 for (const PopularSites::Site& popular_site : popular_sites_->sites()) { 347 for (const PopularSites::Site& popular_site : popular_sites_->sites()) {
347 // Skip blacklisted sites. 348 // Skip blacklisted sites.
348 if (top_sites_ && top_sites_->IsBlacklisted(popular_site.url)) 349 if (top_sites_ && top_sites_->IsBlacklisted(popular_site.url))
349 continue; 350 continue;
350 std::string host = popular_site.url.host(); 351 std::string host = popular_site.url.host();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 return; 411 return;
411 412
412 observer_->OnMostVisitedURLsAvailable(current_tiles_); 413 observer_->OnMostVisitedURLsAvailable(current_tiles_);
413 } 414 }
414 415
415 void MostVisitedSites::OnPopularSitesDownloaded(bool success) { 416 void MostVisitedSites::OnPopularSitesDownloaded(bool success) {
416 if (!success) { 417 if (!success) {
417 LOG(WARNING) << "Download of popular sites failed"; 418 LOG(WARNING) << "Download of popular sites failed";
418 return; 419 return;
419 } 420 }
420
421 // Re-build the tile list. Once done, this will notify the observer.
422 BuildCurrentTiles();
423 } 421 }
424 422
425 void MostVisitedSites::OnIconMadeAvailable(const GURL& site_url, 423 void MostVisitedSites::OnIconMadeAvailable(const GURL& site_url,
426 bool newly_available) { 424 bool newly_available) {
427 if (newly_available) 425 if (newly_available)
428 observer_->OnIconMadeAvailable(site_url); 426 observer_->OnIconMadeAvailable(site_url);
429 } 427 }
430 428
431 void MostVisitedSites::TopSitesLoaded(TopSites* top_sites) {} 429 void MostVisitedSites::TopSitesLoaded(TopSites* top_sites) {}
432 430
433 void MostVisitedSites::TopSitesChanged(TopSites* top_sites, 431 void MostVisitedSites::TopSitesChanged(TopSites* top_sites,
434 ChangeReason change_reason) { 432 ChangeReason change_reason) {
435 if (mv_source_ == NTPTileSource::TOP_SITES) { 433 if (mv_source_ == NTPTileSource::TOP_SITES) {
436 // The displayed tiles are invalidated. 434 // The displayed tiles are invalidated.
437 InitiateTopSitesQuery(); 435 InitiateTopSitesQuery();
438 } 436 }
439 } 437 }
440 438
441 } // namespace ntp_tiles 439 } // namespace ntp_tiles
OLDNEW
« no previous file with comments | « components/ntp_tiles/DEPS ('k') | components/ntp_tiles/most_visited_sites_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698