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

Side by Side Diff: chrome/browser/ntp_snippets/download_suggestions_provider.cc

Issue 2513393002: [NTP] Cleanup: offline pages related tests. (Closed)
Patch Set: treib@ comments. 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 | « no previous file | chrome/browser/ntp_snippets/download_suggestions_provider_unittest.cc » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chrome/browser/ntp_snippets/download_suggestions_provider.h" 5 #include "chrome/browser/ntp_snippets/download_suggestions_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 // Ignored. The internal caches are not stored on disk and they are just 226 // Ignored. The internal caches are not stored on disk and they are just
227 // partial copies of the data stored at OfflinePage model and DownloadManager. 227 // partial copies of the data stored at OfflinePage model and DownloadManager.
228 // If it is cleared there, it will be cleared in these caches as well. 228 // If it is cleared there, it will be cleared in these caches as well.
229 } 229 }
230 230
231 void DownloadSuggestionsProvider::GetDismissedSuggestionsForDebugging( 231 void DownloadSuggestionsProvider::GetDismissedSuggestionsForDebugging(
232 Category category, 232 Category category,
233 const ntp_snippets::DismissedSuggestionsCallback& callback) { 233 const ntp_snippets::DismissedSuggestionsCallback& callback) {
234 DCHECK_EQ(provided_category_, category); 234 DCHECK_EQ(provided_category_, category);
235 235
236 // TODO(vitaliii): Query all pages instead by using an empty query.
237 if (offline_page_model_) { 236 if (offline_page_model_) {
237 // Offline pages which are not related to downloads are also queried here,
238 // so that they can be returned in case there are problems with dismissing.
239 OfflinePageModelQueryBuilder query_builder;
238 offline_page_model_->GetPagesMatchingQuery( 240 offline_page_model_->GetPagesMatchingQuery(
239 BuildOfflinePageDownloadsQuery(offline_page_model_), 241 query_builder.Build(offline_page_model_->GetPolicyController()),
240 base::Bind(&DownloadSuggestionsProvider:: 242 base::Bind(&DownloadSuggestionsProvider::
241 GetPagesMatchingQueryCallbackForGetDismissedSuggestions, 243 GetPagesMatchingQueryCallbackForGetDismissedSuggestions,
242 weak_ptr_factory_.GetWeakPtr(), callback)); 244 weak_ptr_factory_.GetWeakPtr(), callback));
243 } else { 245 } else {
244 GetPagesMatchingQueryCallbackForGetDismissedSuggestions( 246 GetPagesMatchingQueryCallbackForGetDismissedSuggestions(
245 callback, std::vector<OfflinePageItem>()); 247 callback, std::vector<OfflinePageItem>());
246 } 248 }
247 } 249 }
248 250
249 void DownloadSuggestionsProvider::ClearDismissedSuggestionsForDebugging( 251 void DownloadSuggestionsProvider::ClearDismissedSuggestionsForDebugging(
(...skipping 15 matching lines...) Expand all
265 // Private methods 267 // Private methods
266 268
267 void DownloadSuggestionsProvider:: 269 void DownloadSuggestionsProvider::
268 GetPagesMatchingQueryCallbackForGetDismissedSuggestions( 270 GetPagesMatchingQueryCallbackForGetDismissedSuggestions(
269 const ntp_snippets::DismissedSuggestionsCallback& callback, 271 const ntp_snippets::DismissedSuggestionsCallback& callback,
270 const std::vector<OfflinePageItem>& offline_pages) const { 272 const std::vector<OfflinePageItem>& offline_pages) const {
271 std::set<std::string> dismissed_ids = ReadOfflinePageDismissedIDsFromPrefs(); 273 std::set<std::string> dismissed_ids = ReadOfflinePageDismissedIDsFromPrefs();
272 std::vector<ContentSuggestion> suggestions; 274 std::vector<ContentSuggestion> suggestions;
273 for (const OfflinePageItem& item : offline_pages) { 275 for (const OfflinePageItem& item : offline_pages) {
274 if (dismissed_ids.count(GetOfflinePagePerCategoryID(item.offline_id))) 276 if (dismissed_ids.count(GetOfflinePagePerCategoryID(item.offline_id)))
275 suggestions.push_back(ConvertOfflinePage(item)); 277 suggestions.push_back(ConvertOfflinePage(item));
Marc Treib 2016/11/21 15:56:57 Random note: Does this need a rebase onto your oth
vitaliii 2016/11/22 06:32:46 Done. Rebase.
276 } 278 }
277 279
278 if (download_manager_) { 280 if (download_manager_) {
279 std::vector<DownloadItem*> all_downloads; 281 std::vector<DownloadItem*> all_downloads;
280 download_manager_->GetAllDownloads(&all_downloads); 282 download_manager_->GetAllDownloads(&all_downloads);
281 283
282 dismissed_ids = ReadAssetDismissedIDsFromPrefs(); 284 dismissed_ids = ReadAssetDismissedIDsFromPrefs();
283 285
284 for (const DownloadItem* item : all_downloads) { 286 for (const DownloadItem* item : all_downloads) {
285 if (dismissed_ids.count(GetAssetDownloadPerCategoryID(item->GetId()))) 287 if (dismissed_ids.count(GetAssetDownloadPerCategoryID(item->GetId())))
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 717
716 void DownloadSuggestionsProvider::UnregisterDownloadItemObservers() { 718 void DownloadSuggestionsProvider::UnregisterDownloadItemObservers() {
717 DCHECK_NE(download_manager_, nullptr); 719 DCHECK_NE(download_manager_, nullptr);
718 720
719 std::vector<DownloadItem*> all_downloads; 721 std::vector<DownloadItem*> all_downloads;
720 download_manager_->GetAllDownloads(&all_downloads); 722 download_manager_->GetAllDownloads(&all_downloads);
721 723
722 for (DownloadItem* item : all_downloads) 724 for (DownloadItem* item : all_downloads)
723 item->RemoveObserver(this); 725 item->RemoveObserver(this);
724 } 726 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ntp_snippets/download_suggestions_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698