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

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

Issue 2897293002: Adding CrHome-specific implementation for home page tile. (Closed)
Patch Set: Refactor tests and initialization Created 3 years, 6 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 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 <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 } 45 }
46 46
47 } // namespace 47 } // namespace
48 48
49 MostVisitedSites::MostVisitedSites( 49 MostVisitedSites::MostVisitedSites(
50 PrefService* prefs, 50 PrefService* prefs,
51 scoped_refptr<history::TopSites> top_sites, 51 scoped_refptr<history::TopSites> top_sites,
52 SuggestionsService* suggestions, 52 SuggestionsService* suggestions,
53 std::unique_ptr<PopularSites> popular_sites, 53 std::unique_ptr<PopularSites> popular_sites,
54 std::unique_ptr<IconCacher> icon_cacher, 54 std::unique_ptr<IconCacher> icon_cacher,
55 std::unique_ptr<MostVisitedSitesSupervisor> supervisor, 55 std::unique_ptr<MostVisitedSitesSupervisor> supervisor)
56 std::unique_ptr<HomePageClient> home_page_client)
57 : prefs_(prefs), 56 : prefs_(prefs),
58 top_sites_(top_sites), 57 top_sites_(top_sites),
59 suggestions_service_(suggestions), 58 suggestions_service_(suggestions),
60 popular_sites_(std::move(popular_sites)), 59 popular_sites_(std::move(popular_sites)),
61 icon_cacher_(std::move(icon_cacher)), 60 icon_cacher_(std::move(icon_cacher)),
62 supervisor_(std::move(supervisor)), 61 supervisor_(std::move(supervisor)),
63 home_page_client_(std::move(home_page_client)),
64 observer_(nullptr), 62 observer_(nullptr),
65 num_sites_(0u), 63 num_sites_(0u),
66 top_sites_observer_(this), 64 top_sites_observer_(this),
67 mv_source_(TileSource::TOP_SITES), 65 mv_source_(TileSource::TOP_SITES),
68 top_sites_weak_ptr_factory_(this) { 66 top_sites_weak_ptr_factory_(this) {
69 DCHECK(prefs_); 67 DCHECK(prefs_);
70 // top_sites_ can be null in tests. 68 // top_sites_ can be null in tests.
71 // TODO(sfiera): have iOS use a dummy TopSites in its tests. 69 // TODO(sfiera): have iOS use a dummy TopSites in its tests.
72 DCHECK(suggestions_service_); 70 DCHECK(suggestions_service_);
73 if (supervisor_) 71 if (supervisor_)
74 supervisor_->SetObserver(this); 72 supervisor_->SetObserver(this);
75 } 73 }
76 74
77 MostVisitedSites::MostVisitedSites(
78 PrefService* prefs,
79 scoped_refptr<history::TopSites> top_sites,
80 SuggestionsService* suggestions,
81 std::unique_ptr<PopularSites> popular_sites,
82 std::unique_ptr<IconCacher> icon_cacher,
83 std::unique_ptr<MostVisitedSitesSupervisor> supervisor)
84 : MostVisitedSites(prefs,
85 top_sites,
86 suggestions,
87 std::move(popular_sites),
88 std::move(icon_cacher),
89 std::move(supervisor),
90 nullptr) {}
91
92 MostVisitedSites::~MostVisitedSites() { 75 MostVisitedSites::~MostVisitedSites() {
93 if (supervisor_) 76 if (supervisor_)
94 supervisor_->SetObserver(nullptr); 77 supervisor_->SetObserver(nullptr);
95 } 78 }
96 79
97 bool MostVisitedSites::DoesSourceExist(TileSource source) const { 80 bool MostVisitedSites::DoesSourceExist(TileSource source) const {
98 switch (source) { 81 switch (source) {
99 case TileSource::TOP_SITES: 82 case TileSource::TOP_SITES:
100 return top_sites_ != nullptr; 83 return top_sites_ != nullptr;
101 case TileSource::SUGGESTIONS_SERVICE: 84 case TileSource::SUGGESTIONS_SERVICE:
102 return suggestions_service_ != nullptr; 85 return suggestions_service_ != nullptr;
103 case TileSource::POPULAR: 86 case TileSource::POPULAR:
104 return popular_sites_ != nullptr; 87 return popular_sites_ != nullptr;
105 case TileSource::WHITELIST: 88 case TileSource::WHITELIST:
106 return supervisor_ != nullptr; 89 return supervisor_ != nullptr;
107 case TileSource::HOMEPAGE: 90 case TileSource::HOMEPAGE:
108 return home_page_client_ != nullptr; 91 return home_page_client_ != nullptr;
109 } 92 }
110 NOTREACHED(); 93 NOTREACHED();
111 return false; 94 return false;
112 } 95 }
113 96
97 void MostVisitedSites::SetHomePageClient(
98 std::unique_ptr<HomePageClient> client) {
99 DCHECK(client);
100 home_page_client_ = std::move(client);
101 }
102
114 void MostVisitedSites::SetMostVisitedURLsObserver(Observer* observer, 103 void MostVisitedSites::SetMostVisitedURLsObserver(Observer* observer,
115 size_t num_sites) { 104 size_t num_sites) {
116 DCHECK(observer); 105 DCHECK(observer);
117 observer_ = observer; 106 observer_ = observer;
118 num_sites_ = num_sites; 107 num_sites_ = num_sites;
119 108
120 // The order for this condition is important, ShouldShowPopularSites() should 109 // The order for this condition is important, ShouldShowPopularSites() should
121 // always be called last to keep metrics as relevant as possible. 110 // always be called last to keep metrics as relevant as possible.
122 if (popular_sites_ && NeedPopularSites(prefs_, num_sites_) && 111 if (popular_sites_ && NeedPopularSites(prefs_, num_sites_) &&
123 ShouldShowPopularSites()) { 112 ShouldShowPopularSites()) {
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 void MostVisitedSites::TopSitesChanged(TopSites* top_sites, 473 void MostVisitedSites::TopSitesChanged(TopSites* top_sites,
485 ChangeReason change_reason) { 474 ChangeReason change_reason) {
486 if (mv_source_ == TileSource::TOP_SITES) { 475 if (mv_source_ == TileSource::TOP_SITES) {
487 // The displayed tiles are invalidated. 476 // The displayed tiles are invalidated.
488 InitiateTopSitesQuery(); 477 InitiateTopSitesQuery();
489 } 478 }
490 } 479 }
491 480
492 bool MostVisitedSites::ShouldAddHomeTile() const { 481 bool MostVisitedSites::ShouldAddHomeTile() const {
493 return base::FeatureList::IsEnabled(kPinHomePageAsTileFeature) && 482 return base::FeatureList::IsEnabled(kPinHomePageAsTileFeature) &&
494 num_sites_ > 0u && home_page_client_ && 483 num_sites_ > 0u &&
484 home_page_client_ && // No platform-specific implementation - no tile.
495 home_page_client_->IsHomePageEnabled() && 485 home_page_client_->IsHomePageEnabled() &&
496 !home_page_client_->IsNewTabPageUsedAsHomePage() && 486 !home_page_client_->IsNewTabPageUsedAsHomePage() &&
487 !home_page_client_->GetHomepageUrl().is_empty() &&
497 !(top_sites_ && 488 !(top_sites_ &&
498 top_sites_->IsBlacklisted(home_page_client_->GetHomepageUrl())); 489 top_sites_->IsBlacklisted(home_page_client_->GetHomepageUrl()));
499 } 490 }
500 491
501 void MostVisitedSites::AddToHostsAndTotalCount(const NTPTilesVector& new_tiles, 492 void MostVisitedSites::AddToHostsAndTotalCount(const NTPTilesVector& new_tiles,
502 std::set<std::string>* hosts, 493 std::set<std::string>* hosts,
503 size_t* total_tile_count) const { 494 size_t* total_tile_count) const {
504 for (const auto& tile : new_tiles) { 495 for (const auto& tile : new_tiles) {
505 hosts->insert(tile.url.host()); 496 hosts->insert(tile.url.host());
506 } 497 }
507 *total_tile_count += new_tiles.size(); 498 *total_tile_count += new_tiles.size();
508 DCHECK_LE(*total_tile_count, num_sites_); 499 DCHECK_LE(*total_tile_count, num_sites_);
509 } 500 }
510 501
511 } // namespace ntp_tiles 502 } // namespace ntp_tiles
OLDNEW
« no previous file with comments | « components/ntp_tiles/most_visited_sites.h ('k') | components/ntp_tiles/most_visited_sites_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698