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

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

Issue 2532103002: Add support for components/ntp_tiles in InstantService (Closed)
Patch Set: rebase 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
« no previous file with comments | « components/ntp_tiles/most_visited_sites.h ('k') | components/ntp_tiles/ntp_tile.h » ('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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 } 102 }
103 103
104 suggestions_subscription_ = suggestions_service_->AddCallback( 104 suggestions_subscription_ = suggestions_service_->AddCallback(
105 base::Bind(&MostVisitedSites::OnSuggestionsProfileAvailable, 105 base::Bind(&MostVisitedSites::OnSuggestionsProfileAvailable,
106 base::Unretained(this))); 106 base::Unretained(this)));
107 107
108 // Immediately build the current set of tiles, getting suggestions from the 108 // Immediately build the current set of tiles, getting suggestions from the
109 // SuggestionsService's cache or, if that is empty, sites from TopSites. 109 // SuggestionsService's cache or, if that is empty, sites from TopSites.
110 BuildCurrentTiles(); 110 BuildCurrentTiles();
111 // Also start a request for fresh suggestions. 111 // Also start a request for fresh suggestions.
112 Refresh();
113 }
114
115 void MostVisitedSites::Refresh() {
112 suggestions_service_->FetchSuggestionsData(); 116 suggestions_service_->FetchSuggestionsData();
113 } 117 }
114 118
115 void MostVisitedSites::AddOrRemoveBlacklistedUrl(const GURL& url, 119 void MostVisitedSites::AddOrRemoveBlacklistedUrl(const GURL& url,
116 bool add_url) { 120 bool add_url) {
117 if (top_sites_) { 121 if (top_sites_) {
118 // Always blacklist in the local TopSites. 122 // Always blacklist in the local TopSites.
119 if (add_url) 123 if (add_url)
120 top_sites_->AddBlacklistedURL(url); 124 top_sites_->AddBlacklistedURL(url);
121 else 125 else
122 top_sites_->RemoveBlacklistedURL(url); 126 top_sites_->RemoveBlacklistedURL(url);
123 } 127 }
124 128
125 // Only blacklist in the server-side suggestions service if it's active. 129 // Only blacklist in the server-side suggestions service if it's active.
126 if (mv_source_ == NTPTileSource::SUGGESTIONS_SERVICE) { 130 if (mv_source_ == NTPTileSource::SUGGESTIONS_SERVICE) {
127 if (add_url) 131 if (add_url)
128 suggestions_service_->BlacklistURL(url); 132 suggestions_service_->BlacklistURL(url);
129 else 133 else
130 suggestions_service_->UndoBlacklistURL(url); 134 suggestions_service_->UndoBlacklistURL(url);
131 } 135 }
132 } 136 }
133 137
138 void MostVisitedSites::ClearBlacklistedUrls() {
139 if (top_sites_) {
140 // Always update the blacklist in the local TopSites.
141 top_sites_->ClearBlacklistedURLs();
142 }
143
144 // Only update the server-side blacklist if it's active.
145 if (mv_source_ == NTPTileSource::SUGGESTIONS_SERVICE) {
146 suggestions_service_->ClearBlacklist();
147 }
148 }
149
134 void MostVisitedSites::OnBlockedSitesChanged() { 150 void MostVisitedSites::OnBlockedSitesChanged() {
135 BuildCurrentTiles(); 151 BuildCurrentTiles();
136 } 152 }
137 153
138 // static 154 // static
139 void MostVisitedSites::RegisterProfilePrefs( 155 void MostVisitedSites::RegisterProfilePrefs(
140 user_prefs::PrefRegistrySyncable* registry) { 156 user_prefs::PrefRegistrySyncable* registry) {
141 registry->RegisterIntegerPref(prefs::kNumPersonalTiles, 0); 157 registry->RegisterIntegerPref(prefs::kNumPersonalTiles, 0);
142 } 158 }
143 159
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 const ChromeSuggestion& suggestion_pb = suggestions_profile.suggestions(i); 228 const ChromeSuggestion& suggestion_pb = suggestions_profile.suggestions(i);
213 GURL url(suggestion_pb.url()); 229 GURL url(suggestion_pb.url());
214 if (supervisor_ && supervisor_->IsBlocked(url)) 230 if (supervisor_ && supervisor_->IsBlocked(url))
215 continue; 231 continue;
216 232
217 NTPTile tile; 233 NTPTile tile;
218 tile.title = base::UTF8ToUTF16(suggestion_pb.title()); 234 tile.title = base::UTF8ToUTF16(suggestion_pb.title());
219 tile.url = url; 235 tile.url = url;
220 tile.source = NTPTileSource::SUGGESTIONS_SERVICE; 236 tile.source = NTPTileSource::SUGGESTIONS_SERVICE;
221 tile.whitelist_icon_path = GetWhitelistLargeIconPath(url); 237 tile.whitelist_icon_path = GetWhitelistLargeIconPath(url);
238 tile.thumbnail_url = GURL(suggestion_pb.thumbnail());
239 tile.favicon_url = GURL(suggestion_pb.favicon_url());
222 240
223 tiles.push_back(std::move(tile)); 241 tiles.push_back(std::move(tile));
224 } 242 }
225 243
226 mv_source_ = NTPTileSource::SUGGESTIONS_SERVICE; 244 mv_source_ = NTPTileSource::SUGGESTIONS_SERVICE;
227 SaveNewTiles(std::move(tiles)); 245 SaveNewTiles(std::move(tiles));
228 NotifyMostVisitedURLsObserver(); 246 NotifyMostVisitedURLsObserver();
229 } 247 }
230 248
231 NTPTilesVector MostVisitedSites::CreateWhitelistEntryPointTiles( 249 NTPTilesVector MostVisitedSites::CreateWhitelistEntryPointTiles(
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 400
383 void MostVisitedSites::TopSitesChanged(TopSites* top_sites, 401 void MostVisitedSites::TopSitesChanged(TopSites* top_sites,
384 ChangeReason change_reason) { 402 ChangeReason change_reason) {
385 if (mv_source_ == NTPTileSource::TOP_SITES) { 403 if (mv_source_ == NTPTileSource::TOP_SITES) {
386 // The displayed tiles are invalidated. 404 // The displayed tiles are invalidated.
387 InitiateTopSitesQuery(); 405 InitiateTopSitesQuery();
388 } 406 }
389 } 407 }
390 408
391 } // namespace ntp_tiles 409 } // namespace ntp_tiles
OLDNEW
« no previous file with comments | « components/ntp_tiles/most_visited_sites.h ('k') | components/ntp_tiles/ntp_tile.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698