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

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

Issue 2564163002: [Offline Pages] Remove load state from public OfflinePageModel API. (Closed)
Patch Set: Fix broken tests. 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
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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 for (const DownloadItem* item : all_downloads) { 293 for (const DownloadItem* item : all_downloads) {
294 if (dismissed_ids.count(GetAssetDownloadPerCategoryID(item->GetId()))) { 294 if (dismissed_ids.count(GetAssetDownloadPerCategoryID(item->GetId()))) {
295 suggestions.push_back(ConvertDownloadItem(*item)); 295 suggestions.push_back(ConvertDownloadItem(*item));
296 } 296 }
297 } 297 }
298 } 298 }
299 299
300 callback.Run(std::move(suggestions)); 300 callback.Run(std::move(suggestions));
301 } 301 }
302 302
303 void DownloadSuggestionsProvider::OfflinePageModelLoaded(
304 offline_pages::OfflinePageModel* model) {
305 DCHECK_EQ(offline_page_model_, model);
306 AsynchronouslyFetchOfflinePagesDownloads(/*notify=*/true);
Marc Treib 2016/12/13 10:11:02 I guess we don't need this call, because we'll get
vitaliii 2016/12/15 10:20:37 I believe that even if we get OfflinePageAdded, we
307 }
308
309 void DownloadSuggestionsProvider::OfflinePageAdded( 303 void DownloadSuggestionsProvider::OfflinePageAdded(
310 offline_pages::OfflinePageModel* model, 304 offline_pages::OfflinePageModel* model,
311 const offline_pages::OfflinePageItem& added_page) { 305 const offline_pages::OfflinePageItem& added_page) {
312 // TODO(dewittj, vitaliii): Don't refetch everything when this is called. 306 // TODO(dewittj, vitaliii): Don't refetch everything when this is called.
313 DCHECK_EQ(offline_page_model_, model); 307 DCHECK_EQ(offline_page_model_, model);
314 AsynchronouslyFetchOfflinePagesDownloads(/*notify=*/true); 308 AsynchronouslyFetchOfflinePagesDownloads(/*notify=*/true);
315 } 309 }
316 310
317 void DownloadSuggestionsProvider::OfflinePageDeleted( 311 void DownloadSuggestionsProvider::OfflinePageDeleted(
318 int64_t offline_id, 312 int64_t offline_id,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 387
394 void DownloadSuggestionsProvider::AsynchronouslyFetchOfflinePagesDownloads( 388 void DownloadSuggestionsProvider::AsynchronouslyFetchOfflinePagesDownloads(
395 bool notify) { 389 bool notify) {
396 if (!offline_page_model_) { 390 if (!offline_page_model_) {
397 // Offline pages are explicitly turned off, so we propagate "no pages" 391 // Offline pages are explicitly turned off, so we propagate "no pages"
398 // further e.g. to clean its prefs. 392 // further e.g. to clean its prefs.
399 UpdateOfflinePagesCache(notify, std::vector<OfflinePageItem>()); 393 UpdateOfflinePagesCache(notify, std::vector<OfflinePageItem>());
400 return; 394 return;
401 } 395 }
402 396
403 if (!offline_page_model_->is_loaded()) {
404 // Offline pages model is not ready yet and may return no offline pages.
405 if (notify) {
406 SubmitContentSuggestions();
407 }
408
409 return;
410 }
411
412 offline_page_model_->GetPagesMatchingQuery( 397 offline_page_model_->GetPagesMatchingQuery(
413 BuildOfflinePageDownloadsQuery(offline_page_model_), 398 BuildOfflinePageDownloadsQuery(offline_page_model_),
414 base::Bind(&DownloadSuggestionsProvider::UpdateOfflinePagesCache, 399 base::Bind(&DownloadSuggestionsProvider::UpdateOfflinePagesCache,
415 weak_ptr_factory_.GetWeakPtr(), notify)); 400 weak_ptr_factory_.GetWeakPtr(), notify));
416 } 401 }
417 402
418 void DownloadSuggestionsProvider::FetchAssetsDownloads() { 403 void DownloadSuggestionsProvider::FetchAssetsDownloads() {
419 if (!download_manager_) { 404 if (!download_manager_) {
420 // The manager has gone down or was explicitly turned off. 405 // The manager has gone down or was explicitly turned off.
421 return; 406 return;
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 // The same as the case above. 609 // The same as the case above.
625 FetchAssetsDownloads(); 610 FetchAssetsDownloads();
626 } 611 }
627 } 612 }
628 } 613 }
629 614
630 void DownloadSuggestionsProvider::UpdateOfflinePagesCache( 615 void DownloadSuggestionsProvider::UpdateOfflinePagesCache(
631 bool notify, 616 bool notify,
632 const std::vector<offline_pages::OfflinePageItem>& 617 const std::vector<offline_pages::OfflinePageItem>&
633 all_download_offline_pages) { 618 all_download_offline_pages) {
634 DCHECK(!offline_page_model_ || offline_page_model_->is_loaded());
635
636 std::set<std::string> old_dismissed_ids = 619 std::set<std::string> old_dismissed_ids =
637 ReadOfflinePageDismissedIDsFromPrefs(); 620 ReadOfflinePageDismissedIDsFromPrefs();
638 std::set<std::string> retained_dismissed_ids; 621 std::set<std::string> retained_dismissed_ids;
639 std::vector<const OfflinePageItem*> items; 622 std::vector<const OfflinePageItem*> items;
640 // Filtering out dismissed items and pruning dismissed IDs. 623 // Filtering out dismissed items and pruning dismissed IDs.
641 for (const OfflinePageItem& item : all_download_offline_pages) { 624 for (const OfflinePageItem& item : all_download_offline_pages) {
642 std::string id_within_category = 625 std::string id_within_category =
643 GetOfflinePagePerCategoryID(item.offline_id); 626 GetOfflinePagePerCategoryID(item.offline_id);
644 if (!old_dismissed_ids.count(id_within_category)) { 627 if (!old_dismissed_ids.count(id_within_category)) {
645 items.push_back(&item); 628 items.push_back(&item);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 void DownloadSuggestionsProvider::UnregisterDownloadItemObservers() { 730 void DownloadSuggestionsProvider::UnregisterDownloadItemObservers() {
748 DCHECK_NE(download_manager_, nullptr); 731 DCHECK_NE(download_manager_, nullptr);
749 732
750 std::vector<DownloadItem*> all_downloads; 733 std::vector<DownloadItem*> all_downloads;
751 download_manager_->GetAllDownloads(&all_downloads); 734 download_manager_->GetAllDownloads(&all_downloads);
752 735
753 for (DownloadItem* item : all_downloads) { 736 for (DownloadItem* item : all_downloads) {
754 item->RemoveObserver(this); 737 item->RemoveObserver(this);
755 } 738 }
756 } 739 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698