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

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

Issue 2469933002: Offline Pages: Replace Observer::OfflinePageModelChanged with OfflinePageAdded. (Closed)
Patch Set: Touch ups. Created 4 years, 1 month 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/downloads/download_ui_adapter.cc
diff --git a/components/offline_pages/downloads/download_ui_adapter.cc b/components/offline_pages/downloads/download_ui_adapter.cc
index bb398cb8f025d372546d0d669b1137e76a555acd..6dda27f760b3b84e8e872f6fcd1212d782cd68e8 100644
--- a/components/offline_pages/downloads/download_ui_adapter.cc
+++ b/components/offline_pages/downloads/download_ui_adapter.cc
@@ -76,15 +76,21 @@ void DownloadUIAdapter::RemoveObserver(Observer* observer) {
ClearCache();
}
-void DownloadUIAdapter::OfflinePageModelLoaded(OfflinePageModel* model) {
- // This signal is not used here.
-}
-
-void DownloadUIAdapter::OfflinePageModelChanged(OfflinePageModel* model) {
+void DownloadUIAdapter::OfflinePageAdded(OfflinePageModel* model,
+ SavePageResult result,
+ const OfflinePageItem* added) {
DCHECK(model == model_);
- model_->GetAllPages(
- base::Bind(&DownloadUIAdapter::OnOfflinePagesChanged,
- weak_ptr_factory_.GetWeakPtr()));
+ if (!added || !IsVisibleInUI(added->client_id))
+ return;
+
+ const std::string& guid = added->client_id.id;
+ if (items_.find(guid) != items_.end()) // Item already exists.
fgorski 2016/11/02 15:51:06 If item already exists this should probably never
dewittj 2016/11/02 16:34:37 I was trying not to change the logic from OnOfflin
+ return;
+
+ items_[guid] = base::MakeUnique<ItemInfo>(*added);
+ const DownloadUIItem& item = *(items_[guid]->ui_item);
+ for (Observer& observer : observers_)
+ observer.ItemAdded(item);
}
void DownloadUIAdapter::OfflinePageDeleted(
@@ -185,27 +191,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