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

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

Issue 2579813002: ntp_tiles: Add tests covering tile-fetching logic (Closed)
Patch Set: Created 4 years 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 <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/feature_list.h" 13 #include "base/feature_list.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "components/history/core/browser/top_sites.h" 15 #include "components/history/core/browser/top_sites.h"
16 #include "components/ntp_tiles/constants.h" 16 #include "components/ntp_tiles/constants.h"
17 #include "components/ntp_tiles/field_trial.h" 17 #include "components/ntp_tiles/field_trial.h"
18 #include "components/ntp_tiles/icon_cacher.h" 18 #include "components/ntp_tiles/icon_cacher.h"
19 #include "components/ntp_tiles/pref_names.h" 19 #include "components/ntp_tiles/pref_names.h"
20 #include "components/ntp_tiles/switches.h" 20 #include "components/ntp_tiles/switches.h"
21 #include "components/pref_registry/pref_registry_syncable.h" 21 #include "components/prefs/pref_registry_simple.h"
Marc Treib 2016/12/19 09:11:50 Nice! Once we do the same for PopularSites, we can
mastiz 2017/01/09 10:40:58 sfiera@ raised some concerns so I reverted this ch
22 #include "components/prefs/pref_service.h" 22 #include "components/prefs/pref_service.h"
23 23
24 using history::TopSites; 24 using history::TopSites;
25 using suggestions::ChromeSuggestion; 25 using suggestions::ChromeSuggestion;
26 using suggestions::SuggestionsProfile; 26 using suggestions::SuggestionsProfile;
27 using suggestions::SuggestionsService; 27 using suggestions::SuggestionsService;
28 28
29 namespace ntp_tiles { 29 namespace ntp_tiles {
30 30
31 namespace { 31 namespace {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 if (mv_source_ == NTPTileSource::SUGGESTIONS_SERVICE) { 146 if (mv_source_ == NTPTileSource::SUGGESTIONS_SERVICE) {
147 suggestions_service_->ClearBlacklist(); 147 suggestions_service_->ClearBlacklist();
148 } 148 }
149 } 149 }
150 150
151 void MostVisitedSites::OnBlockedSitesChanged() { 151 void MostVisitedSites::OnBlockedSitesChanged() {
152 BuildCurrentTiles(); 152 BuildCurrentTiles();
153 } 153 }
154 154
155 // static 155 // static
156 void MostVisitedSites::RegisterProfilePrefs( 156 void MostVisitedSites::RegisterProfilePrefs(PrefRegistrySimple* registry) {
157 user_prefs::PrefRegistrySyncable* registry) {
158 registry->RegisterIntegerPref(prefs::kNumPersonalTiles, 0); 157 registry->RegisterIntegerPref(prefs::kNumPersonalTiles, 0);
159 } 158 }
160 159
161 void MostVisitedSites::BuildCurrentTiles() { 160 void MostVisitedSites::BuildCurrentTiles() {
162 // Get the current suggestions from cache. If the cache is empty, this will 161 // Get the current suggestions from cache. If the cache is empty, this will
163 // fall back to TopSites. 162 // fall back to TopSites.
164 OnSuggestionsProfileAvailable( 163 OnSuggestionsProfileAvailable(
165 suggestions_service_->GetSuggestionsDataFromCache().value_or( 164 suggestions_service_->GetSuggestionsDataFromCache().value_or(
166 SuggestionsProfile())); 165 SuggestionsProfile()));
167 } 166 }
(...skipping 12 matching lines...) Expand all
180 for (const auto& whitelist : supervisor_->whitelists()) { 179 for (const auto& whitelist : supervisor_->whitelists()) {
181 if (AreURLsEquivalent(whitelist.entry_point, url)) 180 if (AreURLsEquivalent(whitelist.entry_point, url))
182 return whitelist.large_icon_path; 181 return whitelist.large_icon_path;
183 } 182 }
184 } 183 }
185 return base::FilePath(); 184 return base::FilePath();
186 } 185 }
187 186
188 void MostVisitedSites::OnMostVisitedURLsAvailable( 187 void MostVisitedSites::OnMostVisitedURLsAvailable(
189 const history::MostVisitedURLList& visited_list) { 188 const history::MostVisitedURLList& visited_list) {
189 // TODO(mastiz): Verify if suggestion service results have been fetched in
190 // the meantime, and if that's the case ignore this event.
190 NTPTilesVector tiles; 191 NTPTilesVector tiles;
191 size_t num_tiles = 192 size_t num_tiles =
192 std::min(visited_list.size(), static_cast<size_t>(num_sites_)); 193 std::min(visited_list.size(), static_cast<size_t>(num_sites_));
193 for (size_t i = 0; i < num_tiles; ++i) { 194 for (size_t i = 0; i < num_tiles; ++i) {
194 const history::MostVisitedURL& visited = visited_list[i]; 195 const history::MostVisitedURL& visited = visited_list[i];
195 if (visited.url.is_empty()) { 196 if (visited.url.is_empty()) {
196 num_tiles = i; 197 num_tiles = i;
197 break; // This is the signal that there are no more real visited sites. 198 break; // This is the signal that there are no more real visited sites.
198 } 199 }
199 if (supervisor_ && supervisor_->IsBlocked(visited.url)) 200 if (supervisor_ && supervisor_->IsBlocked(visited.url))
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 403
403 void MostVisitedSites::TopSitesChanged(TopSites* top_sites, 404 void MostVisitedSites::TopSitesChanged(TopSites* top_sites,
404 ChangeReason change_reason) { 405 ChangeReason change_reason) {
405 if (mv_source_ == NTPTileSource::TOP_SITES) { 406 if (mv_source_ == NTPTileSource::TOP_SITES) {
406 // The displayed tiles are invalidated. 407 // The displayed tiles are invalidated.
407 InitiateTopSitesQuery(); 408 InitiateTopSitesQuery();
408 } 409 }
409 } 410 }
410 411
411 } // namespace ntp_tiles 412 } // namespace ntp_tiles
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698