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

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

Issue 2577253003: ntp_tiles: Avoid redundant calls to TopSites (Closed)
Patch Set: Renamed weak ptr factory. Created 3 years, 11 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 <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 : prefs_(prefs), 56 : prefs_(prefs),
57 top_sites_(top_sites), 57 top_sites_(top_sites),
58 suggestions_service_(suggestions), 58 suggestions_service_(suggestions),
59 popular_sites_(std::move(popular_sites)), 59 popular_sites_(std::move(popular_sites)),
60 icon_cacher_(std::move(icon_cacher)), 60 icon_cacher_(std::move(icon_cacher)),
61 supervisor_(std::move(supervisor)), 61 supervisor_(std::move(supervisor)),
62 observer_(nullptr), 62 observer_(nullptr),
63 num_sites_(0), 63 num_sites_(0),
64 top_sites_observer_(this), 64 top_sites_observer_(this),
65 mv_source_(NTPTileSource::TOP_SITES), 65 mv_source_(NTPTileSource::TOP_SITES),
66 weak_ptr_factory_(this) { 66 top_sites_weak_ptr_factory_(this) {
67 DCHECK(prefs_); 67 DCHECK(prefs_);
68 // top_sites_ can be null in tests. 68 // top_sites_ can be null in tests.
69 // TODO(sfiera): have iOS use a dummy TopSites in its tests. 69 // TODO(sfiera): have iOS use a dummy TopSites in its tests.
70 DCHECK(suggestions_service_); 70 DCHECK(suggestions_service_);
71 if (supervisor_) 71 if (supervisor_)
72 supervisor_->SetObserver(this); 72 supervisor_->SetObserver(this);
73 } 73 }
74 74
75 MostVisitedSites::~MostVisitedSites() { 75 MostVisitedSites::~MostVisitedSites() {
76 if (supervisor_) 76 if (supervisor_)
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 // Get the current suggestions from cache. If the cache is empty, this will 162 // Get the current suggestions from cache. If the cache is empty, this will
163 // fall back to TopSites. 163 // fall back to TopSites.
164 OnSuggestionsProfileAvailable( 164 OnSuggestionsProfileAvailable(
165 suggestions_service_->GetSuggestionsDataFromCache().value_or( 165 suggestions_service_->GetSuggestionsDataFromCache().value_or(
166 SuggestionsProfile())); 166 SuggestionsProfile()));
167 } 167 }
168 168
169 void MostVisitedSites::InitiateTopSitesQuery() { 169 void MostVisitedSites::InitiateTopSitesQuery() {
170 if (!top_sites_) 170 if (!top_sites_)
171 return; 171 return;
172 if (top_sites_weak_ptr_factory_.HasWeakPtrs())
173 return; // Ongoing query.
172 top_sites_->GetMostVisitedURLs( 174 top_sites_->GetMostVisitedURLs(
173 base::Bind(&MostVisitedSites::OnMostVisitedURLsAvailable, 175 base::Bind(&MostVisitedSites::OnMostVisitedURLsAvailable,
174 weak_ptr_factory_.GetWeakPtr()), 176 top_sites_weak_ptr_factory_.GetWeakPtr()),
175 false); 177 false);
176 } 178 }
177 179
178 base::FilePath MostVisitedSites::GetWhitelistLargeIconPath(const GURL& url) { 180 base::FilePath MostVisitedSites::GetWhitelistLargeIconPath(const GURL& url) {
179 if (supervisor_) { 181 if (supervisor_) {
180 for (const auto& whitelist : supervisor_->whitelists()) { 182 for (const auto& whitelist : supervisor_->whitelists()) {
181 if (AreURLsEquivalent(whitelist.entry_point, url)) 183 if (AreURLsEquivalent(whitelist.entry_point, url))
182 return whitelist.large_icon_path; 184 return whitelist.large_icon_path;
183 } 185 }
184 } 186 }
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 411
410 void MostVisitedSites::TopSitesChanged(TopSites* top_sites, 412 void MostVisitedSites::TopSitesChanged(TopSites* top_sites,
411 ChangeReason change_reason) { 413 ChangeReason change_reason) {
412 if (mv_source_ == NTPTileSource::TOP_SITES) { 414 if (mv_source_ == NTPTileSource::TOP_SITES) {
413 // The displayed tiles are invalidated. 415 // The displayed tiles are invalidated.
414 InitiateTopSitesQuery(); 416 InitiateTopSitesQuery();
415 } 417 }
416 } 418 }
417 419
418 } // namespace ntp_tiles 420 } // 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