| OLD | NEW |
| 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 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 } | 506 } |
| 507 | 507 |
| 508 std::vector<DownloadItem*> all_downloads; | 508 std::vector<DownloadItem*> all_downloads; |
| 509 download_manager_->GetAllDownloads(&all_downloads); | 509 download_manager_->GetAllDownloads(&all_downloads); |
| 510 std::set<std::string> old_dismissed_ids = ReadAssetDismissedIDsFromPrefs(); | 510 std::set<std::string> old_dismissed_ids = ReadAssetDismissedIDsFromPrefs(); |
| 511 std::set<std::string> retained_dismissed_ids; | 511 std::set<std::string> retained_dismissed_ids; |
| 512 cached_asset_downloads_.clear(); | 512 cached_asset_downloads_.clear(); |
| 513 for (DownloadItem* item : all_downloads) { | 513 for (DownloadItem* item : all_downloads) { |
| 514 std::string within_category_id = | 514 std::string within_category_id = |
| 515 GetAssetDownloadPerCategoryID(item->GetId()); | 515 GetAssetDownloadPerCategoryID(item->GetId()); |
| 516 // TODO(vitaliii): Provide proper last access time here once it is collected | |
| 517 // for asset downloads. | |
| 518 if (old_dismissed_ids.count(within_category_id)) { | 516 if (old_dismissed_ids.count(within_category_id)) { |
| 519 retained_dismissed_ids.insert(within_category_id); | 517 retained_dismissed_ids.insert(within_category_id); |
| 520 } else if (IsAssetDownloadCompleted(*item) && | 518 } else if (IsAssetDownloadCompleted(*item) && |
| 521 !IsDownloadOutdated(GetAssetDownloadPublishedTime(*item), | 519 !IsDownloadOutdated(GetAssetDownloadPublishedTime(*item), |
| 522 base::Time())) { | 520 item->GetLastAccessTime())) { |
| 523 cached_asset_downloads_.push_back(item); | 521 cached_asset_downloads_.push_back(item); |
| 524 // We may already observe this item and, therefore, we remove the | 522 // We may already observe this item and, therefore, we remove the |
| 525 // observer first. | 523 // observer first. |
| 526 item->RemoveObserver(this); | 524 item->RemoveObserver(this); |
| 527 item->AddObserver(this); | 525 item->AddObserver(this); |
| 528 } | 526 } |
| 529 } | 527 } |
| 530 | 528 |
| 531 if (old_dismissed_ids.size() != retained_dismissed_ids.size()) { | 529 if (old_dismissed_ids.size() != retained_dismissed_ids.size()) { |
| 532 StoreAssetDismissedIDsToPrefs(retained_dismissed_ids); | 530 StoreAssetDismissedIDsToPrefs(retained_dismissed_ids); |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 void DownloadSuggestionsProvider::UnregisterDownloadItemObservers() { | 849 void DownloadSuggestionsProvider::UnregisterDownloadItemObservers() { |
| 852 DCHECK_NE(download_manager_, nullptr); | 850 DCHECK_NE(download_manager_, nullptr); |
| 853 | 851 |
| 854 std::vector<DownloadItem*> all_downloads; | 852 std::vector<DownloadItem*> all_downloads; |
| 855 download_manager_->GetAllDownloads(&all_downloads); | 853 download_manager_->GetAllDownloads(&all_downloads); |
| 856 | 854 |
| 857 for (DownloadItem* item : all_downloads) { | 855 for (DownloadItem* item : all_downloads) { |
| 858 item->RemoveObserver(this); | 856 item->RemoveObserver(this); |
| 859 } | 857 } |
| 860 } | 858 } |
| OLD | NEW |