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

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

Issue 2179233003: Start PopularSites fetch from separate function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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/most_visited_sites.h ('k') | components/ntp_tiles/popular_sites.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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 144
145 MostVisitedSites::Suggestion::~Suggestion() {} 145 MostVisitedSites::Suggestion::~Suggestion() {}
146 146
147 MostVisitedSites::Suggestion::Suggestion(Suggestion&&) = default; 147 MostVisitedSites::Suggestion::Suggestion(Suggestion&&) = default;
148 MostVisitedSites::Suggestion& 148 MostVisitedSites::Suggestion&
149 MostVisitedSites::Suggestion::operator=(Suggestion&&) = default; 149 MostVisitedSites::Suggestion::operator=(Suggestion&&) = default;
150 150
151 MostVisitedSites::MostVisitedSites( 151 MostVisitedSites::MostVisitedSites(
152 scoped_refptr<base::SequencedWorkerPool> blocking_pool, 152 scoped_refptr<base::SequencedWorkerPool> blocking_pool,
153 PrefService* prefs, 153 PrefService* prefs,
154 const TemplateURLService* template_url_service,
155 variations::VariationsService* variations_service,
156 net::URLRequestContextGetter* download_context,
157 const base::FilePath& popular_sites_directory,
158 scoped_refptr<history::TopSites> top_sites, 154 scoped_refptr<history::TopSites> top_sites,
159 SuggestionsService* suggestions, 155 SuggestionsService* suggestions,
156 PopularSites* popular_sites,
160 MostVisitedSitesSupervisor* supervisor) 157 MostVisitedSitesSupervisor* supervisor)
161 : prefs_(prefs), 158 : prefs_(prefs),
162 template_url_service_(template_url_service),
163 variations_service_(variations_service),
164 download_context_(download_context),
165 popular_sites_directory_(popular_sites_directory),
166 top_sites_(top_sites), 159 top_sites_(top_sites),
167 suggestions_service_(suggestions), 160 suggestions_service_(suggestions),
161 popular_sites_(popular_sites),
168 supervisor_(supervisor), 162 supervisor_(supervisor),
169 observer_(nullptr), 163 observer_(nullptr),
170 num_sites_(0), 164 num_sites_(0),
171 received_most_visited_sites_(false), 165 received_most_visited_sites_(false),
172 received_popular_sites_(false), 166 received_popular_sites_(false),
173 recorded_uma_(false), 167 recorded_uma_(false),
174 scoped_observer_(this), 168 scoped_observer_(this),
175 mv_source_(SUGGESTIONS_SERVICE), 169 mv_source_(SUGGESTIONS_SERVICE),
176 blocking_pool_(std::move(blocking_pool)), 170 blocking_runner_(blocking_pool->GetTaskRunnerWithShutdownBehavior(
177 blocking_runner_(blocking_pool_->GetTaskRunnerWithShutdownBehavior(
178 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN)), 171 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN)),
179 weak_ptr_factory_(this) { 172 weak_ptr_factory_(this) {
180 DCHECK(suggestions_service_); 173 DCHECK(suggestions_service_);
181 supervisor_->SetObserver(this); 174 supervisor_->SetObserver(this);
182 } 175 }
183 176
184 MostVisitedSites::~MostVisitedSites() { 177 MostVisitedSites::~MostVisitedSites() {
185 supervisor_->SetObserver(nullptr); 178 supervisor_->SetObserver(nullptr);
186 } 179 }
187 180
188 #if defined(OS_ANDROID) 181 #if defined(OS_ANDROID)
189 // static 182 // static
190 bool MostVisitedSites::Register(JNIEnv* env) { 183 bool MostVisitedSites::Register(JNIEnv* env) {
191 return RegisterNativesImpl(env); 184 return RegisterNativesImpl(env);
192 } 185 }
193 #endif 186 #endif
194 187
195 void MostVisitedSites::SetMostVisitedURLsObserver(Observer* observer, 188 void MostVisitedSites::SetMostVisitedURLsObserver(Observer* observer,
196 int num_sites) { 189 int num_sites) {
197 DCHECK(observer); 190 DCHECK(observer);
198 observer_ = observer; 191 observer_ = observer;
199 num_sites_ = num_sites; 192 num_sites_ = num_sites;
200 193
201 if (ShouldShowPopularSites() && NeedPopularSites(prefs_, num_sites_)) { 194 if (popular_sites_ && ShouldShowPopularSites() &&
202 popular_sites_.reset(new PopularSites( 195 NeedPopularSites(prefs_, num_sites_)) {
203 blocking_pool_, prefs_, template_url_service_, variations_service_, 196 popular_sites_->StartFetch(
204 download_context_, popular_sites_directory_, false, 197 false, base::Bind(&MostVisitedSites::OnPopularSitesAvailable,
205 base::Bind(&MostVisitedSites::OnPopularSitesAvailable, 198 base::Unretained(this)));
206 base::Unretained(this))));
207 } else { 199 } else {
208 received_popular_sites_ = true; 200 received_popular_sites_ = true;
209 } 201 }
210 202
211 if (top_sites_) { 203 if (top_sites_) {
212 // TopSites updates itself after a delay. To ensure up-to-date results, 204 // TopSites updates itself after a delay. To ensure up-to-date results,
213 // force an update now. 205 // force an update now.
214 top_sites_->SyncWithHistory(); 206 top_sites_->SyncWithHistory();
215 207
216 // Register as TopSitesObserver so that we can update ourselves when the 208 // Register as TopSitesObserver so that we can update ourselves when the
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 559
568 void MostVisitedSites::TopSitesChanged(TopSites* top_sites, 560 void MostVisitedSites::TopSitesChanged(TopSites* top_sites,
569 ChangeReason change_reason) { 561 ChangeReason change_reason) {
570 if (mv_source_ == TOP_SITES) { 562 if (mv_source_ == TOP_SITES) {
571 // The displayed suggestions are invalidated. 563 // The displayed suggestions are invalidated.
572 InitiateTopSitesQuery(); 564 InitiateTopSitesQuery();
573 } 565 }
574 } 566 }
575 567
576 } // namespace ntp_tiles 568 } // namespace ntp_tiles
OLDNEW
« no previous file with comments | « components/ntp_tiles/most_visited_sites.h ('k') | components/ntp_tiles/popular_sites.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698