| OLD | NEW |
| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 125 |
| 126 MostVisitedSites::Suggestion::~Suggestion() {} | 126 MostVisitedSites::Suggestion::~Suggestion() {} |
| 127 | 127 |
| 128 MostVisitedSites::Suggestion::Suggestion(Suggestion&&) = default; | 128 MostVisitedSites::Suggestion::Suggestion(Suggestion&&) = default; |
| 129 MostVisitedSites::Suggestion& | 129 MostVisitedSites::Suggestion& |
| 130 MostVisitedSites::Suggestion::operator=(Suggestion&&) = default; | 130 MostVisitedSites::Suggestion::operator=(Suggestion&&) = default; |
| 131 | 131 |
| 132 MostVisitedSites::MostVisitedSites( | 132 MostVisitedSites::MostVisitedSites( |
| 133 scoped_refptr<base::SequencedWorkerPool> blocking_pool, | 133 scoped_refptr<base::SequencedWorkerPool> blocking_pool, |
| 134 PrefService* prefs, | 134 PrefService* prefs, |
| 135 const TemplateURLService* template_url_service, | |
| 136 variations::VariationsService* variations_service, | |
| 137 net::URLRequestContextGetter* download_context, | |
| 138 const base::FilePath& popular_sites_directory, | |
| 139 scoped_refptr<history::TopSites> top_sites, | 135 scoped_refptr<history::TopSites> top_sites, |
| 140 SuggestionsService* suggestions, | 136 SuggestionsService* suggestions, |
| 137 PopularSites* popular_sites, |
| 141 MostVisitedSitesSupervisor* supervisor) | 138 MostVisitedSitesSupervisor* supervisor) |
| 142 : prefs_(prefs), | 139 : prefs_(prefs), |
| 143 template_url_service_(template_url_service), | |
| 144 variations_service_(variations_service), | |
| 145 download_context_(download_context), | |
| 146 popular_sites_directory_(popular_sites_directory), | |
| 147 top_sites_(top_sites), | 140 top_sites_(top_sites), |
| 148 suggestions_service_(suggestions), | 141 suggestions_service_(suggestions), |
| 142 popular_sites_(popular_sites), |
| 149 supervisor_(supervisor), | 143 supervisor_(supervisor), |
| 150 observer_(nullptr), | 144 observer_(nullptr), |
| 151 num_sites_(0), | 145 num_sites_(0), |
| 152 received_most_visited_sites_(false), | 146 received_most_visited_sites_(false), |
| 153 received_popular_sites_(false), | 147 received_popular_sites_(false), |
| 154 recorded_uma_(false), | 148 recorded_uma_(false), |
| 155 scoped_observer_(this), | 149 scoped_observer_(this), |
| 156 mv_source_(SUGGESTIONS_SERVICE), | 150 mv_source_(SUGGESTIONS_SERVICE), |
| 157 blocking_pool_(std::move(blocking_pool)), | 151 blocking_runner_(blocking_pool->GetTaskRunnerWithShutdownBehavior( |
| 158 blocking_runner_(blocking_pool_->GetTaskRunnerWithShutdownBehavior( | |
| 159 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN)), | 152 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN)), |
| 160 weak_ptr_factory_(this) { | 153 weak_ptr_factory_(this) { |
| 161 DCHECK(suggestions_service_); | 154 DCHECK(suggestions_service_); |
| 162 supervisor_->SetObserver(this); | 155 supervisor_->SetObserver(this); |
| 163 } | 156 } |
| 164 | 157 |
| 165 MostVisitedSites::~MostVisitedSites() { | 158 MostVisitedSites::~MostVisitedSites() { |
| 166 supervisor_->SetObserver(nullptr); | 159 supervisor_->SetObserver(nullptr); |
| 167 } | 160 } |
| 168 | 161 |
| 169 void MostVisitedSites::SetMostVisitedURLsObserver(Observer* observer, | 162 void MostVisitedSites::SetMostVisitedURLsObserver(Observer* observer, |
| 170 int num_sites) { | 163 int num_sites) { |
| 171 DCHECK(observer); | 164 DCHECK(observer); |
| 172 observer_ = observer; | 165 observer_ = observer; |
| 173 num_sites_ = num_sites; | 166 num_sites_ = num_sites; |
| 174 | 167 |
| 175 if (ShouldShowPopularSites() && NeedPopularSites(prefs_, num_sites_)) { | 168 if (popular_sites_ && ShouldShowPopularSites() && |
| 176 popular_sites_.reset(new PopularSites( | 169 NeedPopularSites(prefs_, num_sites_)) { |
| 177 blocking_pool_, prefs_, template_url_service_, variations_service_, | 170 popular_sites_->StartFetch( |
| 178 download_context_, popular_sites_directory_, false, | 171 false, base::Bind(&MostVisitedSites::OnPopularSitesAvailable, |
| 179 base::Bind(&MostVisitedSites::OnPopularSitesAvailable, | 172 base::Unretained(this))); |
| 180 base::Unretained(this)))); | |
| 181 } else { | 173 } else { |
| 182 received_popular_sites_ = true; | 174 received_popular_sites_ = true; |
| 183 } | 175 } |
| 184 | 176 |
| 185 if (top_sites_) { | 177 if (top_sites_) { |
| 186 // TopSites updates itself after a delay. To ensure up-to-date results, | 178 // TopSites updates itself after a delay. To ensure up-to-date results, |
| 187 // force an update now. | 179 // force an update now. |
| 188 top_sites_->SyncWithHistory(); | 180 top_sites_->SyncWithHistory(); |
| 189 | 181 |
| 190 // Register as TopSitesObserver so that we can update ourselves when the | 182 // Register as TopSitesObserver so that we can update ourselves when the |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 | 533 |
| 542 void MostVisitedSites::TopSitesChanged(TopSites* top_sites, | 534 void MostVisitedSites::TopSitesChanged(TopSites* top_sites, |
| 543 ChangeReason change_reason) { | 535 ChangeReason change_reason) { |
| 544 if (mv_source_ == TOP_SITES) { | 536 if (mv_source_ == TOP_SITES) { |
| 545 // The displayed suggestions are invalidated. | 537 // The displayed suggestions are invalidated. |
| 546 InitiateTopSitesQuery(); | 538 InitiateTopSitesQuery(); |
| 547 } | 539 } |
| 548 } | 540 } |
| 549 | 541 |
| 550 } // namespace ntp_tiles | 542 } // namespace ntp_tiles |
| OLD | NEW |