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

Unified Diff: components/offline_pages/core/downloads/download_ui_adapter.cc

Issue 2560573003: [Offline Pages] Convert Download UI Adapter to using OfflinePageAdded (Closed)
Patch Set: rebase 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 side-by-side diff with in-line comments
Download patch
Index: components/offline_pages/core/downloads/download_ui_adapter.cc
diff --git a/components/offline_pages/core/downloads/download_ui_adapter.cc b/components/offline_pages/core/downloads/download_ui_adapter.cc
index 053dce7d0986229bee58e87a6022db2e4435e844..193bfdb7f67e09a4addddcbdb3ad36468e7edb4e 100644
--- a/components/offline_pages/core/downloads/download_ui_adapter.cc
+++ b/components/offline_pages/core/downloads/download_ui_adapter.cc
@@ -82,8 +82,16 @@ void DownloadUIAdapter::OfflinePageModelLoaded(OfflinePageModel* model) {
void DownloadUIAdapter::OfflinePageAdded(OfflinePageModel* model,
const OfflinePageItem& added_page) {
DCHECK(model == model_);
- model_->GetAllPages(base::Bind(&DownloadUIAdapter::OnOfflinePagesChanged,
- weak_ptr_factory_.GetWeakPtr()));
+ if (!IsVisibleInUI(added_page.client_id))
+ return;
+
+ const std::string& guid = added_page.client_id.id;
+ DCHECK(items_.find(guid) == items_.end());
+
+ items_[guid] = base::MakeUnique<ItemInfo>(added_page);
+ const DownloadUIItem& item = *(items_[guid]->ui_item);
+ for (Observer& observer : observers_)
+ observer.ItemAdded(item);
}
void DownloadUIAdapter::OfflinePageDeleted(int64_t offline_id,
@@ -179,27 +187,6 @@ void DownloadUIAdapter::NotifyItemsLoaded(Observer* observer) {
observer->ItemsLoaded();
}
-// This method is only called by OPM when a single item added.
-// TODO(dimich): change OPM to have real OnPageAdded/OnPageUpdated and
-// simplify this code.
-void DownloadUIAdapter::OnOfflinePagesChanged(
- const MultipleOfflinePageItemResult& pages) {
- std::vector<std::string> added_guids;
- for (const auto& page : pages) {
- if (!IsVisibleInUI(page.client_id)) // Item should be filtered out.
- continue;
- const std::string& guid = page.client_id.id;
- if (items_.find(guid) != items_.end()) // Item already exists.
- continue;
- items_[guid] = base::MakeUnique<ItemInfo>(page);
- added_guids.push_back(guid);
- }
- for (auto& guid : added_guids) {
- const DownloadUIItem& item = *(items_.find(guid)->second->ui_item.get());
- for (Observer& observer : observers_)
- observer.ItemAdded(item);
- }
-}
void DownloadUIAdapter::OnDeletePagesDone(DeletePageResult result) {
// TODO(dimich): Consider adding UMA to record user actions.

Powered by Google App Engine
This is Rietveld 408576698